Modelica 中无事件的开/关控制
我正在尝试根据电网电压控制并网光伏系统。 这个想法是这样的:当电网电压上升到VMax以上时,我想关闭系统一段时间。当 timeOff 过去后,我想再次打开,但只有当电网电压低于 VMax 时。
我目前有两个实现;两者都在创建许多事件,我想知道是否有更有效的方法。这就是它现在的实现方式:
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;
运行时,我通过 PVControl1 获取 8 个事件,通过 PVControl2 获取 4 个事件。 看看PVControl2,我实际上只需要在VGrid 变得大于VMax 时发生一个事件。这只会给出 2 个事件。当 VGrid 再次低于 VMax 时,会生成其他 2 个事件。
有没有办法进一步改进我的模型?
谢谢, 罗尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有几点意见。我认为您正在将事件视为何时激活when子句中的方程。但这并不完全正确。当离散变量的值发生变化时,就会发生事件。关键是连续积分器必须在该点停止并将方程与新值积分。
要了解在这种情况下这对您有何影响,您应该考虑匿名表达式(如 when 子句中的表达式)可能被视为匿名离散变量。换句话说,您可以将其视为等价于:
...并且需要注意的重要一点是,当
当 >VGrid
变得大于VMax
时,以及当它变得小于VMax
时。现在考虑一下:现在您已经获得了更多事件,因为涉及两个条件,并且每次其中一个条件更改值时您都会生成事件。
说了这么多,你真的遇到性能问题了吗?通常,此类事件仅在出现“抖动”(由于积分过程中的数值噪声而导致条件值改变符号的情况)时才成为问题。您是否有任何数字可以表明这些事件的严重程度?了解您使用什么工具来模拟这些事情也可能会有所帮助。
最后,我从你的逻辑中不明白的一件事是,如果 VGrid>VMax 然后在 timeOff 之后,VGrid 仍然大于 VMax 会发生什么?
假设它正确处理最后一种情况,我认为 PVControl2 实际上就是您想要的(并且生成的事件数量正是我期望的,并且出于我期望的原因)。
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 whenVGrid
becomes greater thanVMax
and 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).
也许我的答案是 1/2 一年太晚了,但在这种情况下,系统似乎有可能不僵硬,在这种情况下,显式积分器(如 Dymola 中的 CERK 积分器)将使您的模拟运行时间快得多。
Probably my answer is 1/2 a year too late, but in this case there seems to be a chance that the system is not stiff, and in that case an explicit integrator (like the CERK ones in Dymola) will make your simulation run time much faster.