- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » OMPython.OMCSessionZMQ parameter change
OMPython.OMCSessionZMQ parameter change
OMPython.OMCSessionZMQ parameter change
Hi
I am simulating the following Modelica model
Code:
model HelloWorld
Real x(start=1);
parameter Real a = -1;
equation
der(x) = a*x;
annotation(
uses(Modelica(version = "3.2.2")));
end HelloWorld;
with the following Python code
Code:
from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
omc.sendExpression("loadFile(\"C:/Users/user/Desktop/HelloWorld.mo\")")
omc.sendExpression("loadModel(HelloWorld)")
results = omc.sendExpression("simulate(HelloWorld, outputFormat=\"csv\")")
The simulation is successful and the value ofparameter a is -1. What I want is to perform the simulation with different value of a. How can I change the parameter value within OMCSessionZMQ() and then perform the simulation using the new value of a? I know that this is possible with OMPython.ModelicaSystem.
Re: OMPython.OMCSessionZMQ parameter change
If you don't want to use buildModel and run the simulation yourself (or ModelicaSystem to wrap around that):
Code:
omc.sendExpression('simulate(HelloWorld, simflags="-override a=3.0")'
(Or using -overrideFile if you have many overrides, especially on Windows)
- sjoelund.se
- 1700 Posts
Re: OMPython.OMCSessionZMQ parameter change
Thank you very much. This is what I wanted to do.
I have been mostly using OMedit so I just want to clarify some things. "buildModel" command is OpenModelica scripting command and can be used when using OMshell for example. Is this what you meant with the first part of your answer, or there exist another(better?) option to change the parameter value within Python environment (besides ModelicaSystem or "-override" flag)?
Best regards
Re: OMPython.OMCSessionZMQ parameter change
OMPython and OMShell are the same. You use the same commands with them.
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » OMPython.OMCSessionZMQ parameter change