在 Modelica 中处理 jumps/discontinuities
Dealing with jumps/discontinuities in Modelica
我想知道是否有人在处理 Modelica 中的 jumps/discontinuities 方面有任何提示或技巧。我正在使用 OpenModelica,下面显示了针对我的问题的简化示例代码。
model PowerGenerator
Modelica.SIunits.Power P(start=0);
output Modelica.SIunits.Energy E;
equation
if (5 < time) and (time < 15) then P = 3;
else P = 0;
end if;
der(E) = P;
end PowerGenerator;
如何将 5 秒和 15 秒的跳跃变成连续的过渡,其中斜率的导数是有限的?我已经尝试了 noEvent
和 smooth
函数,但我无法让它们执行我需要的操作。
编辑:
我的主要模型中的问题是这些事件会引起抖动,因此我还需要它实时工作。同样在我的完整模型中,事件是状态事件,因此时间是未知的。
也许像下面的代码这样的行为就是您想要的?
model PowerGenerator
Modelica.SIunits.Power Plow;
Modelica.SIunits.Power Phigh;
Modelica.SIunits.Power P(start=0);
output Modelica.SIunits.Energy E;
Modelica.SIunits.Power Pold(start=0);
output Modelica.SIunits.Energy Eold;
equation
if (5 < time) and (time < 15) then
Pold = 3;
else
Pold = 0;
end if;
der(Eold) = Pold;
Plow = Modelica.Media.Air.MoistAir.Utilities.spliceFunction(3,0,time-5,1);
Phigh = Modelica.Media.Air.MoistAir.Utilities.spliceFunction(0,3,time-15,1);
P = Modelica.Media.Air.MoistAir.Utilities.spliceFunction(Phigh,Plow,time-10,1);
der(E) = P;
end Power Generator;
下面是输出图:
Scott G 的回答很好,但只有当更改仅取决于时间时才有效。更通用的解决方案是使用低通滤波器:
model PowerGenerator
Modelica.SIunits.Power P(start=0);
output Modelica.SIunits.Energy E;
Modelica.Blocks.Continuous.LowpassButterworth lowpassButterworth(f=1)
annotation (Placement(transformation(extent={{-40,20},{-20,40}})));
equation
if (5 < time) and (time < 15) then
P = 3;
else
P = 0;
end if;
lowpassButterworth.u=P;
der(E) = lowpassButterworth.y;
end PowerGenerator;
(我建议改为使用连接语句 - 但以上内容也应该是合法的 Modelica。)
我想知道是否有人在处理 Modelica 中的 jumps/discontinuities 方面有任何提示或技巧。我正在使用 OpenModelica,下面显示了针对我的问题的简化示例代码。
model PowerGenerator
Modelica.SIunits.Power P(start=0);
output Modelica.SIunits.Energy E;
equation
if (5 < time) and (time < 15) then P = 3;
else P = 0;
end if;
der(E) = P;
end PowerGenerator;
如何将 5 秒和 15 秒的跳跃变成连续的过渡,其中斜率的导数是有限的?我已经尝试了 noEvent
和 smooth
函数,但我无法让它们执行我需要的操作。
编辑: 我的主要模型中的问题是这些事件会引起抖动,因此我还需要它实时工作。同样在我的完整模型中,事件是状态事件,因此时间是未知的。
也许像下面的代码这样的行为就是您想要的?
model PowerGenerator
Modelica.SIunits.Power Plow;
Modelica.SIunits.Power Phigh;
Modelica.SIunits.Power P(start=0);
output Modelica.SIunits.Energy E;
Modelica.SIunits.Power Pold(start=0);
output Modelica.SIunits.Energy Eold;
equation
if (5 < time) and (time < 15) then
Pold = 3;
else
Pold = 0;
end if;
der(Eold) = Pold;
Plow = Modelica.Media.Air.MoistAir.Utilities.spliceFunction(3,0,time-5,1);
Phigh = Modelica.Media.Air.MoistAir.Utilities.spliceFunction(0,3,time-15,1);
P = Modelica.Media.Air.MoistAir.Utilities.spliceFunction(Phigh,Plow,time-10,1);
der(E) = P;
end Power Generator;
下面是输出图:
Scott G 的回答很好,但只有当更改仅取决于时间时才有效。更通用的解决方案是使用低通滤波器:
model PowerGenerator
Modelica.SIunits.Power P(start=0);
output Modelica.SIunits.Energy E;
Modelica.Blocks.Continuous.LowpassButterworth lowpassButterworth(f=1)
annotation (Placement(transformation(extent={{-40,20},{-20,40}})));
equation
if (5 < time) and (time < 15) then
P = 3;
else
P = 0;
end if;
lowpassButterworth.u=P;
der(E) = lowpassButterworth.y;
end PowerGenerator;
(我建议改为使用连接语句 - 但以上内容也应该是合法的 Modelica。)