- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » OpenModelica "-override" usage
OpenModelica "-override" usage
OpenModelica "-override" usage
Hi ! I am a new one to use OpenModelica.
My demand: I want to co-simulate with python and openmodelica by OMPython. I will run many loops to optimize the result. So i want to have a data exchange between python and modelica by set and get variable value in Openmodelica at the start and end of each simulation loop.
Question: I want to set value of a variable(not parameter, i can set value by setParameter for parameter) at the beginning of a simulation. So i find the function "-override" but failed.
My Openmodelica version:OpenModelica v1.14.1 (64-bit). Python version: 3.7.6. and latest OMPython.
Code:
model_name = "LoopTestcase_py"
omc = OMCSessionZMQ()
#Build the model's file path for OMPython to load.
path_trans = ""
for i in os.getcwd().split('\\'):path_trans = path_trans + i +'/'
mod=ModelicaSystem(path_trans + model_name + ".mo",model_name,["Modelica"])
mod.buildModel()
mod.setParameters("Input_Position.k="+str(100))
#omc.sendExpression('simulate(LoopTestcase_py, simflags="-override spring.flange_a.s=1", stopTime = 0.01)')
mod.setSimulationOptions("spring.flange_a.s=10")
mod.setSimulationOptions("stopTime = 0.01")
mod.simulate(resultfile= model_name + ".mat")
position = mod.getSolutions("spring.flange_a.s")
print('return position',position)
running result:
spring.flange_a.s !is not a simulation-option variable
LOG_SUCCESS | info | The initialization finished successfully without homotopy method.
LOG_SUCCESS | info | The simulation finished successfully.
return position [[1. 1. 1. 1. 1. 1. 1.]]
Result i wish to get:
1. I can set the value of varialbe spring.flange_a.s, for example spring.flange_a.s=10 at the start of simulation and get its value at the end the simulation by 10+1=11.
2.Another wish is get rid of log information(the LOG_SUCCESS infor, not the information i print).
Thans for your advice!
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » OpenModelica "-override" usage