Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

less than or equal not equal less than or equal in modelica?

I tried a simple example with OpenModelica v1.20.0, but I find a confusing results.

The code is as follows:

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;

And the corresponding result is as follows: simulation result

Obviously, the result of state1(<=) is not equal state2(< or ==), and state1 is not a desired result.

Why?

like image 204
Jack Hsueh Avatar asked Dec 03 '25 17:12

Jack Hsueh


1 Answers

There are some things to consider in Modelica:

  • The <, <=, >, and >= are not necessarily taken strictly but generate events. However, the state1 should ideally still be true from 1 to 7s where f<=0.4, and false otherwise; https://specification.modelica.org/maint/3.5/equations.html#events-and-synchronization So simulating that in Dymola generates Dymola. state1 is true from 1 to 7s
  • The == is not legal for reals outside of functions, so state2 cannot be defined like that https://specification.modelica.org/maint/3.5/operators-and-expressions.html#equality-relational-and-logical-operators

The reason I write ideally is that it is not always possible to guarantee that relations are handled literally at events. That was specified in Modelica up to version 3.2; but did not work in all cases in practice and has thus later been removed.

like image 82
Hans Olsson Avatar answered Dec 05 '25 17:12

Hans Olsson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!