How can I access the time variable in modelica
Asked Answered
R

1

9

I would like to model an explictly time dependent differential equation in Modelica.

Say I would like to model

Real x(start=1);
der(x) = t;

in Modelica. What is the correct way to access the time variable t?

Rib answered 5/8, 2011 at 22:7 Comment(0)
M
15

The time variable in Modelica is called time and it is accessible in any model or block (but not packages, record, connectors or functions).

Also, instead of using the start attribute I suggest using initial equations. So your complete model would look like this:

model FirstOrder
  Real x;
initial equation
  x = 1;
equation
  der(x) = time;
end FirstOrder;

The equations in the initial equation section are only applied to solve for initial values of states. The equation shown above is trivial, but you can do interesting stuff like:

model FirstOrder_IC2
  Real x;
initial equation
  x*x*x = 3.0*time+7.0;
equation
  der(x) = time;
end FirstOrder_IC2;

The point here is that you can use other equations besides ones that directly specify the value of the state. The above initial equation is not "physically" interesting, but mathematically it is because it is both non-linear and time-varying (i.e. sensitive to the start time of the simulation).

Meister answered 7/8, 2011 at 16:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.