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 us
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']
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)
For fmpy you can also inspect this jupyter notebook: https://notebooks.azure.com/t-sommer/projects/CoupledClutches, which contains the lines
model_description = read_model_description(filename) # read the model description
for variable in model_description.modelVariables: # iterate over the variables
if variable.causality == 'parameter': # and print the names of all parameters
print('%-25s %s' % (variable.name, variable.start)) # and the respective start values