'How to edit parameters of modelica model with OMPython or Python CLI interface
I want to edit modelica model parameters in Python CLI interface, But don't know how to find the correct method to make it.
Modelica model code :
model Syslam_Q5
HePackage.Components.Hlam hlam(
UCfile=
"C:/Users/Pikachu/Docs/i_v2/H50.txt",
A_HS_mod1 = 0.0786,
CSize_flag=false,
A_HS_mod2 = 0.0914,
A_HS_mod3 = 0.0223,
A_HS_mod4 = 0.0245)
Python code :
from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
cmds = [
'loadFile("HePackage.mo")',
#'removeElementModifiers(HePackage.Systems.Syslam_Q5, "component", false)',
'setElementModifierValue(HePackage.Systems.Syslam_Q5, HePackage.Components.Hlam, hlam.UCfile = C:/Users/Pikachu/Docs/i_v2/H100.txt)',
#'setParameterValue(HePackage.Systems.Syslam_Q5, hlam.UCfile, $Code(=C:/Users/Pikachu/Docs/i_v2/H100.txt))',
'saveModel("example_edit.mo", Example)',
]
for cmd in cmds:
answer = omc.sendExpression(cmd)
print(cmd, ':', answer)
In a folder i have around 10 text files, I want to run the modelica model for all the text files. How to do that with Python interface. Thanks
Solution 1:[1]
There are multiple ways to do this.
Use set methods
Use mod.setParameters(["radius=14","c=0.5"]), see the user's guide on OMPython.
Override variables at simulation
You can also override variables, including parameters with the simulation flags -override and -overrideFile.
So adding a command to cmds
simulate(example_edit, simflags=\"-override=radius=14,c=0.5\")
should work.
If you have a lot of parameters to change use a override file:
radius=14
c=0.5
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AnHeuermann |
