Dahmani Merzaka
Dahmani Merzaka

Reputation: 173

How to save OpenModelica Simulation results

I am using OpenModelica in my work.
How do I save OpenModelica simulations results?

Upvotes: 2

Views: 676

Answers (1)

JKRT
JKRT

Reputation: 1207

It depends. If you are using OMEdit you can find the result in the working directory of OMEdit

enter image description here

If you want to save your model as an executable via OpenModelica-scripting you can use mos scripts in the following way:

setCommandLineOptions({"-d=execstat"});
loadFile("model.mo");getErrorString();
buildModel(model); getErrorString();

To run the executable for two seconds, here with the IDA solver:

"./model -override=stopTime=2.0 -s=ida", "log.log"

The resulting simulation will be saved in your working directory with this approach.

Or you can write the following mos script:

loadFile("HelloWorld.mo");getErrorString();
simulate(HelloWorld);getErrorString();

with the following Modelica model:

model HelloWorld
  Real x( start = 1, fixed = true );
  parameter Real a = 1;
equation
  der(x) = - a * x;
end HelloWorld;

The output will be as follows:

true

""
record SimulationResult
    resultFile = "/mnt/c/<Path>/HelloWorld_res.mat",
    simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'HelloWorld', 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.007985600000000001,
    timeBackend = 0.0152096,
    timeSimCode = 0.0033462,
    timeTemplates = 0.09332140000000001,
    timeCompile = 1.7051749,
    timeSimulation = 0.0506992,
    timeTotal = 1.8771728
end SimulationResult;

The result will then be available in HelloWorld_res.mat in your working directory

Upvotes: 2

Related Questions