I am trying to understand the intended modeling behavior when using a non-zero StartTime
parameter in the experiment
annotation in Modelica. I would expect that it would simply suppress all output prior to StartTime
, rather than affecting the behavior of the model. However, it appears that this is not the case. Consider this MWE:
model testStartTime
Real x;
Real y;
Real z;
initial equation
x = 1;
equation
der(x)=x;
y = 200*time;
z = exp(time);
annotation (
experiment(StartTime = 3, StopTime = 8, Tolerance = 1e-06, Interval = 0.01));
end testStartTime;
I would expect x and z to match (to within numerical precision). That is, x(3.0) = z(3.0) = exp(3.0) ~= 20.08
. What I actually get is z(3.0) = 20.08
(as expected), but x(3.0) = 1
. Changing the initial value of x in the initial equation
section causes x(3.0)
to have this set initial value, without any system evolution over the interval 0 <= time < 3.0
taken into account. I see this same behavior using both Dymola 2023 and OpenModelica v1.23.1.
To me, this suggests that Modelica effectively imposes an additional set of steady-state equations (der(x)=0)
during the [0, StartTime)
interval, such that state variables retain their initial values at time=StartTime
. Equations that are explicit in time
(such as y
and z
in my example above) appear to work as expected-- the first output value of y
is indeed 200*3.0 = 600.0,
as expected by StartTime=3.0.
My question: is my assumption that Modelica imposes an implicit steady-state condition prior to the StartTime
parameter correct? I cannot find a definition for this parameter in Sec 18.4 of the Modelica Specification (or anywhere else in the spec for that matter) and cannot understand the rationale for such behavior. I have several use-cases where suppressing all output prior to a prescribed StartTime
is helpful, but I still need the system to evolve from initial conditions prior to that time. What is the StartTime parameter intended for?
This behaviour is the one I would expect: The integration starts at StartTime
. It means that there is nothing happening before that time, because there simply is nothing.
The system of equation you are trying to solve is:
dx/dt = x
AND
x(StartTime) = 1
If my math is correct, the exact solution to this differential equation is:
x(t) = x(StartTime) * exp(t - StartTime)
for t > StartTime
Changing the initial condition changes the solution: exp(t)
is the solution of dx/dt=x
AND x(0)=1
.