Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to list of parameters of FMU (or of submodel in FMU) using the python libraries FMPy or pyFMI?

I have a FMU of a model and the use case is to change parameter values of the FMU to see the impact on the results. Is there a way to list top level parameters of the FMU using either FMPy or pyFMI if I dont' have access to the Modelica model?

One of the process I have been following is to open the FMU using FMPy.gui and go through the list of parameters and then use them in the script but I would like to know if there an easier way of doing it so that I can list then in the Jupyter notebook and change the parameters as needed?

like image 346
Kaustubh Avatar asked Mar 02 '20 15:03

Kaustubh


2 Answers

In FMI there is no distinction between top level parameters and other parameters. To list all available parameters in the model using PyFMI (FMI 2.0):

from pyfmi import load_fmu
import pyfmi.fmi as fmi

model = load_fmu("MyModel.fmu")
params = model.get_model_variables(causality=fmi.FMI2_PARAMETER)
like image 75
Christian Winther Avatar answered Sep 18 '22 08:09

Christian Winther


With fmpy you can loop over the modelVariables in the model description as follows:

from fmpy import read_model_description
from fmpy.util import download_test_file

fmu_filename = 'CoupledClutches.fmu'

download_test_file('2.0', 'CoSimulation', 'MapleSim', '2016.2', 'CoupledClutches', fmu_filename)

model_description = read_model_description(fmu_filename)

parameters = [v for v in model_description.modelVariables if v.causality == 'parameter']
like image 28
marco Avatar answered Sep 21 '22 08:09

marco