- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Issue with relational operators
Issue with relational operators
Issue with relational operators
Hello,
I'm facing a problem with relational operators in OpenModelica (1.9.1 r22929).
Here is a small model that produces weird results:
Code:
model Test
Modelica.Blocks.Continuous.Integrator i1;
Modelica.Blocks.Nonlinear.Limiter sat(uMin = 0.0, uMax = 100.0);
Real u(start = 0);
Real y;
Boolean b1 = y < 100;
Boolean b2 = y <= 100;
Boolean b3 = y == 100;
Boolean b4 = y >= 100;
Boolean b5 = y > 100;
equation
der(u) = 50;
connect(i1.u, u);
connect(i1.y, sat.u);
connect(sat.y, y);
end Test;
After running the simulation for two seconds, 'y' is equal to 100.
The problem is that 'b1', 'b2' and 'b3' are all true although that is illogical.
Is anyone able to reproduce the results?
Thanks
- Raph85
- 4 Posts
Re: Issue with relational operators
I tried this in Dymola as well but had to use b3 = y >= 100 and y <= 100 since you are not allowed to compare Real with equality in equation context in Modelica (and also not connect Real values since they are not connectors). Dymola seems to do it OK. OpenModelica does the == better.
Detecting the zero-crossing for y < 100 I guess is the problem. Keep in mind you are dealing with floating point which is not really precise; this model depends on exact values being calculated. https://trac.openmodelica.org/OpenModelica/newticket
- sjoelund.se
- 1700 Posts
Re: Issue with relational operators
Alright, I'm creating a ticket for the issue.
I was able to reproduce the bug on a smaller model, which narrows the problem to the "if" statement:
Code:
model Test
Real y;
Boolean b1 = y < 100.0;
Boolean b2 = y <= 100.0;
Boolean b3 = y == 100.0;
Boolean b4 = y >= 100.0;
Boolean b5 = y > 100.0;
equation
y = if time > 2 then 100 else 0;
end Test;
- Raph85
- 4 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Issue with relational operators