Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I call an OpenModelica model in Python with OMPython?

I have an OpenModelica model made with OMEdit. In order to get a concrete example I designed the following:

OpenModelica Model from OMEdit called myGain

Now I would like to run the model in Python. I can do this by using OMPython. After importing OMPython and loading the files I use the following command to run the simulation:

result = OMPython.execute("simulate(myGain, numberOfIntervals=2, outputFormat=\"mat\")")

The simulation now runs and the results are written to a file.

Now I would like to run the same model but with an different parameter for the constant block.

How can I do this?

Since the parameter is compiled into the model it should not be possible to change it. So what I need is a model like that:

myGain with a variable as parameter

Is it possible to call the model from Python and set the variable "a" to a specific value?

With the command OMPython.execute("simulate(...)") I can specify some environment variables like "numberOfIntervals" or "outputFormat" but not more.

like image 860
jonie83 Avatar asked Jan 07 '14 07:01

jonie83


1 Answers

You can send more flags to the simulate command. For example simflags to override parameters. See https://openmodelica.org/index.php/forum/topic?id=1011 for some details.

You can also use the buildModel(...) command followed by system("./ModelName -overrideFile ...") to avoid re-translation and re-compilation or with some minor scripting parallel parameter sweeps. If you use Linux or OSX it should be easy to call OMPython to create the executable and then call it yourself. On Windows you need to setup some environment variables for it to work as expected.

like image 74
sjoelund.se Avatar answered Oct 23 '22 16:10

sjoelund.se