Jac*_*ueh 3 modelica openmodelica
我使用 OpenModelica v1.20.0 尝试了一个简单的示例,但发现结果令人困惑。
代码如下:
model test
Boolean state1;
Boolean state2;
Real f;
equation
f = if time<1 then 0.5 else if time<3 then 0.4 else if time<5 then 0.3 else if time<7 then 0.4 else 0.5;
state1 = f<=0.4;
state2 = f<0.4 or f==0.4;
end test;
Run Code Online (Sandbox Code Playgroud)
显然,state1(<=)的结果不等于state2(<或==),state1不是期望的结果。
为什么?
在 Modelica 中需要考虑一些事项:
state1, 当 f<=0.4 时,在 1 到 7 秒内 仍应为真,否则为假;https://specation.modelica.org/maint/3.5/equations.html#events-and-synchronization因此在 Dymola 中进行模拟会生成
state2不能像这样定义https://specation.modelica.org/maint/3.5/operators-and-expressions.html#equality-relational-and-logic-operators我之所以写得很理想,是因为并不总是能够保证在事件中按字面意思处理关系。这是在 Modelica 3.2 版本之前指定的;但实际上并非在所有情况下都有效,因此后来被删除。