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

Saving and loading states

Saving and loading states

Hi,
my first post here.
I was able to get the old WasteWater library (Reichl) to run in OM including a view OM-related fixes and also extended it by another ASM (actvated sludge model).

In Wastewater treatment, we are dealing with comlex non-steady-state systems. System state initialization is an important step before simulation itself. System states are usually a result of a simulation prerun.

I can't figure out (and didn't find profound information) on how to save a final state (an hopefully the final state only, the "_res.mat" is usually several hundred MB) and than reuse it for initialization.

Any help is appreciated.

Regards.
André

Re: Saving and loading states

Hi,

This should be possible but I don't know if we have an easy way to do it.
You can use variableFilter when you call the simulate command in a script:

Code:


simulate(Model, variableFilter="x1|x2|x3");

to only keep the variables you want in the .mat file.
Then you can use the generated .mat file for initialization via:

Code:


simulate(Model, simflags="-iif=file.mat");

Se more here:
https://build.openmodelica.org/Document … ulate.html

Also call omc --help=simulation for more about the command line parameters for the generated Model[.exe] executable.

I suggest you do something like this in a script.mos file:

Code:


// load your libs
loadModel(Modelica); getErrorString();
loadModel(YourLib); getErrorString();
// generate the executable for your model
buildModel(Model); getErrorString();
// run the model to get the .mat file
system("Model -override stopTime=value,variableFilter="x1|x2|x3"); getErrorString();
// run the model again with the previous .mat file as input and direct the results to a new .mat file
system("Model -iif Model_res.mat -r NewResults.mat");

Then run the script.mos via command line:

Code:


> omc +locale=C script.mos

Cheers,
Adrian Pop/

There are 0 guests and 0 other users also viewing this topic