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

Extract FMU parameters through python

Extract FMU parameters through python

Let's say that I have exported a battery as an FMU and I want to use it for co-simulation in python. Is there a way to get parameter values, such as the capacity of the battery in [Wh] or the minimum SOC of the battery, instead of manually observing them from the XML file?

Re: Extract FMU parameters through python

You can call the functions for getting and setting variable values, see FMI Standard 2.0.2 section 2.1.7 Getting and Setting Variable Values. I guess most FMI simulation tools will have a similar function to use the fmi2GetXXX functions.

If you are using OMSimulator with the Python interface you can do something similar to this example:

Code:


from OMSimulator import OMSimulator

oms = OMSimulator()
oms.setTempDirectory("./temp/")
oms.newModel("model")
oms.addSystem("model.root", oms.system_sc)

# instantiate FMUs
oms.addSubModel("model.root.system1", "FMUs/System1.fmu")
oms.addSubModel("model.root.system2", "FMUs/System2.fmu")

# add connections
oms.addConnection("model.root.system1.y", "model.root.system2.u")
oms.addConnection("model.root.system2.y", "model.root.system1.u")

# simulation settings
oms.setResultFile("model", "results.mat")
oms.setStopTime("model", 0.1)
oms.setFixedStepSize("model.root", 1e-4)

oms.instantiate("model")
value, status = oms.getReal("model.root.system1.x_start")

oms.initialize("model")
oms.simulate("model")
oms.terminate("model")
oms.delete("model")

Compare with the documentation of OMSimulatorPython.

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