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

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.

Edited by: Perun - Apr-11-18 11:08:44

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)

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

Edited by: Perun - Apr-12-18 08:56:39

Re: OMPython.OMCSessionZMQ parameter change

OMPython and OMShell are the same. You use the same commands with them.

There are 0 guests and 0 other users also viewing this topic
You are here: