Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Print out of variables after an event occured

Print out of variables after an event occured

class Spacecraft
  Real y0(start=7.15014E6);
  Real y1(start=0);
  Real y2(start=0);
  Real y3(start=0.937045E-3);
equation
  der(y0) = y1;
  der(y1) = y0*y3*y3-3.9860E14/(y0*y0);
  der(y2) = y3;
  der(y3) = -2.0*y1*y3/y0;
end Spacecraft;

The spacecraft hits earth when y0=6.37814E6. How can the simulation be stopped when the spacecraft hits earth. How can I print out the time and the values of the remaining variables y1,y2,y3 ?
Thank you for your help

Re: Print out of variables after an event occured

Normally you would put an if-equation:
if (y0 <= 6.37814E6) then terminate("Simulation ended at time: " + String(time)) end if;

But OpenModelica seems to have issues with it.

You can use:
assert(y0 > 6.37814E6, "Simulation ended at time: " + String(time));

After simulation, call readFile("output.log"), and use val() on the time shown for each of the variables y1,y2,y3.

There are 0 guests and 0 other users also viewing this topic
You are here: