Thursday, 23 September 2021

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.



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

No comments:

Post a Comment