'Get stop time of a simulation with OMPython
i'm developing a system in openmodelica which design the behaviour of a swarm of drone in various simulation. Now, i want to get the simulation result with OMPython, because i will use matplotlib to make charts of the various KPI. If i want to get values, the openmodelica scripting function requires:
val(String valueName, Real timePoint, String file);
And i want to take the value at the end of the simulation. The problem is that the simulation stop time is not constant! So, is there a function to retrieve the stop time of the simulation?
EDIT 1:
I managed to retrieve this information in python using the simulate function. But i want to use BuildModel function, because with it i can change variables in the system and simulate again without any problem. any suggestion?
Solution 1:[1]
You can read the result-file after the simulation in order to get the stopTime. You do need to read the entire vector since there is no API to just get the last time though. (It is also possible to open the mat-file using other Python packages; this might be easier if you want to perform more operations on the data in the results):
installPackage(Modelica);
loadModel(Modelica);getErrorString();
simulate(Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum, fileNamePrefix="M");
// Or buildModel(...); system("./M"), etc...
vars:=readSimulationResult("M_res.mat",{time});getErrorString();
stopTime:=vars[1,end];
Solution 2:[2]
You could use terminal()
to store the termination time in the model itself:
model StoreFinalTime
Real t_stop;
equation
when terminal() then
t_stop = time;
end when;
end StoreFinalTime;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | sjoelund.se |
Solution 2 | Christoph |