I’m trying to control a grid connected photovoltaic system based on the grid voltage.
The idea is this: when the grid voltage rises above VMax, I want to switch off the system for timeOff. When timeOff has passed, i want to switch on again, but only when the grid voltage is lower than VMax.
I currently have two implementations; both are creating many events and i wonder if there’s a more efficient way. This is how it is implemented now:
package Foo
model PVControl1 "Generating most events"
parameter Real VMax=253;
parameter Real timeOff=60;
input Real P_init "uncontrolled power";
input Real VGrid;
Real P_final "controlled power";
Boolean switch (start = true) "if true, system is producing";
discrete Real restartTime (start=-1, fixed=true)
"system is off until time>restartTime";
equation
when {VGrid > VMax, time > pre(restartTime)} then
if VGrid > VMax then
switch = false;
restartTime = time + timeOff;
else
switch = true;
restartTime = -1;
end if;
end when;
if pre(switch) then
P_final = P_init;
else
P_final = 0;
end if;
end PVControl1;
model PVControl2;
"Generating less events, but off-time is no multiple of timeOff"
parameter Real VMax=253;
parameter Real timeOff=60;
input Real P_init "uncontrolled power";
input Real VGrid;
Real P_final "controlled power";
discrete Real stopTime( start=-1-timeOff, fixed=true)
"system is off until time > stopTime + timeOff";
equation
when VGrid > VMax then
stopTime=time;
end when;
if noEvent(VGrid > VMax) or noEvent(time < stopTime + timeOff) then
P_final = 0;
else
P_final = P_init;
end if;
end PVControl2;
model TestPVControl;
"Simulate 1000s to get an idea"
PVControl pvControl2(P_init=4000, VGrid = 300*sin(time/100));
end TestPVControl;
end foo;
When run, I get 8 events with PVControl1, and 4 events with PVControl2.
Looking at PVControl2, I actually need only an event at the moment where VGrid becomes larger than VMax. This would give only 2 events. The other 2 events are generated when VGrid drops below VMax again.
Is there a way to improve my model further?
Thanks,
Roel
I have a few comments. I think you are viewing an event as when the equations within a when clause are activated. But that isn’t quite right. An event occurs when the value of a discrete variable changes. The point is that the continuous integrator must be stopped at that point and the equations integrated with the new value.
To understand how that is affecting you in this case, you should consider that an anonymous expression (like the one in your when clauses) is probably being treated as an anonymous discrete variable. In other words, you can think of it as being equivalent to this:
…and the important thing to note is that an event (i.e. a change in the value of
c1) occurs both whenVGridbecomes greater thanVMaxand when it becomes less thanVMax. Now consider this:Now you’ve got even more events because there are two conditions involved and you generate events each time either one of them changes value.
All that having been said, are you actually having a performance issue here? Normally, such events only become an issue when you have “chattering” (cases where the value of the condition changes sign due to numerical noise in the integration process). Do you have any numbers to indicate how much of an issue these events really are? It might also help to know what tool you are using to simulate these things.
Finally, one thing I don’t understand from your logic is what happens if VGrid>VMax and then, after timeOff, VGrid is still greater than VMax?
Assuming it handles this last case correctly, I think PVControl2 is actually what you want (and generates exactly the number of events I would expect and for the reasons I would expect).