I use the code bellow to assess time events:
model Test
equation
when { time < 0.1, time >= 0.6} then
Modelica.Utilities.Streams.print("print: time= "+ String(time));
end when;
end Test;
I find the following:
Dymola (2024x-1) generates 2 time-events, but seems to execute only the one at time 0.6 (only one « print » a time 0.6)
OME (1.24beta) says it generates 2 state-events, 0 time event, identically executes only the one at time 0.6 (only one « print » at time 0.6)
In what ways time events { time<x }
and {time >=x}
are different in the execution ?
The Modelica Language Specification mentions in Section 8.6 that
It is a quality of implementation issue that the following special relations
time >= discrete expression
time < discrete expression
trigger a time event at time = discrete expression, i.e., the event instant is known in advance and no iteration is needed to find the exact event instant.
What I understand from this is, that only the above formulations can trigger time-events (depending on the implementation). From what I know, this is what Dymola does. But as this dependents on the implementation and not specified more precisely, other tools can behave differently. It seems this is the case for OpenModelica.
According to my tests (using the "Simulation Analysis" or "Performance") tool in Dymola, two time events are triggered. As expected, at 0.1s and 0.6s. The one at 0.1s is triggered by the condition, but the when
-statement is not executed, as it is only run if the condition changes from false
to true
. The latter one changes from false
to true
, therefore the print
at 0.6s is executed.
If you change the code to
model Test
equation
when {not time < 0.1, time >= 0.6} then
Modelica.Utilities.Streams.print("print: time= "+ String(time));
end when;
end Test;
the print
is run at both events.
Also note that this differs from a numerical point of view (at least in Dymola) from the following
model Test
equation
when {time > 0.1, time >= 0.6} then
Modelica.Utilities.Streams.print("print: time= "+ String(time));
end when;
end Test;
as this will generate one state- and one time event, whereas the former generates two time events. This is in accordance with the quote from the Modelica specification from the beginning.