2

I am writing this question related to this. In his reply, Marco gave me an excellent answer but, unfortunately, I am new with OpenModelica so I would need some further help.

I am actually using OpenModelica and not Dymola so unfortunately I have to build the function that does it for me and I am very new with OpenModelica language.

So far, I have a model that simulates the physical behavior based on a DAEs. Now, I am trying to build what you suggest here:

With get time() you can build a function that: reads the system time as t_start translates the model and simulate for 0 seconds reads the system time again and as t_stop computes the difference between t_start and t_stop.

Could you please, give me more details: Which command can I use to read the system at time t_start and to simulate it for 0 seconds? To do this for both t_start and t_stop do I need to different function?

Once I have done this, do I have to call the function (or functions) inside the OpenModelica Model of which I want to know its time?

Thank you so much again for your precious help!

Very best regards, Gabriele

1 Answers1

2

From the other question:

I noticed in Modelica there are different flags for the simulation time but actually the time I get is very small compared to the time that elapses since I press the simulation button to the end of the simulation (approximately measured with the clock of my phone).

The time that is reported is correct. Most of the time taken is not initialisation or simulation, but compilation. If you use the re-simulate option in OMEdit (right-click a result-file in the plot view for variables), you will notice the simulation is very fast.

$ cat e.mos
loadString("model M
  Real r(fixed=true, start=2.0);
equation
  der(r) = time;
end M;");getErrorString();
simulate(M);getErrorString();
$ omc e.mos
true
""
record SimulationResult
    resultFile = "/mnt/data/@Mech/martin/tmp/M_res.mat",
    simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'M', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
    messages = "LOG_SUCCESS       | info    | The initialization finished successfully without homotopy method.
LOG_SUCCESS       | info    | The simulation finished successfully.
",                                                                                                                                                                                                    
    timeFrontend = 0.004114061,                                                                                                                                                                       
    timeBackend = 0.00237546,                                                                                                                                                                         
    timeSimCode = 0.0008126780000000001,                                                                                                                                                              
    timeTemplates = 0.062749837,                                                                                                                                                                      
    timeCompile = 0.633754155,                                                                                                                                                                        
    timeSimulation = 0.006627571000000001,                                                                                                                                                            
    timeTotal = 0.7106012479999999                                                                                                                                                                    
end SimulationResult;                                                                                                                                                                                 
""

OMEdit does not report these other numbers (time to translate and compile the model) as far as I know. On Windows, these times are quite big because linking takes longer.

sjoelund.se
  • 3,468
  • 12
  • 15
  • Are these numbers also available when calling OMC from [OMPython](https://github.com/OpenModelica/OMPython)? Working from python might be nicer than writing mos scripts. Run a for-loop to simulate several times, then do a box-plot and so on. – Priyanka May 05 '20 at 11:52
  • 1
    Yes, OMPython has access to these numbers. The record is returned as a dict: `{u'timeCompile': 0.838674783, ...}` – sjoelund.se May 06 '20 at 05:47
  • Thank you for your reply! Is the code you reported in the answer from OMShell? Does the time you obtained in your example (i.e. from timeFrontend to timeTotal) also include the compilation time? I means, is the sum of the times (from timeFrontend to timeTotal) you reported in your example the total time since I press the simulation button to the end of the simulation? Thank you! – Gabriele Galli May 07 '20 at 23:13
  • timeTotal is basically the time from pressing simulate until results can be read in OMEdit. I run the omc command-line executable (no OMShell or anything; just a mos-script). – sjoelund.se May 12 '20 at 11:16