I'm using python fmpy to run a fmu model. Executing, running and plotting results works fine. Defining inputs as well (following the tutorials).
But I'm struggling with changing the value of global parameter within the fmu model.
For example, if I run the same model in the GUI (https://fmpy.readthedocs.io/en/latest/tutorial/), I have the full list of all parameters available. There I can set the value for a parameter with the name "l1" to 412. If I log the FMI calls of the GUI, I can see, that the following command was used to set "l1" to the value of 412:
fmi2SetReal(fmu, vr=[671088641], nvr=1, value=[412])
How can I set "l1" to 412 with a python command?
from fmpy.util import plot_result
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
from fmpy import *
fmu = 'CrankCase_ME2.fmu'
dump(fmu)
# read the model description
model_description = read_model_description(fmu)
# collect the value references
vrs = {}
for variable in model_description.modelVariables:
vrs[variable.name] = variable.valueReference
L = 412
hPLug = 215
alphaDrvie = 60
start_vrs = [vrs['l1'], vrs['h_plug'], vrs['Alpha_drive']]
start_values = [L, hPLug, alphaDrvie]
dtype = [('time', np.double), ('l1', np.int), ('h_plug', np.int), ('Alpha_drive', np.int)]
signals = np.array([(0.0, L, hPLug, alphaDrvie)], dtype=dtype)
print_interval = 1e-5
result = simulate_fmu(fmu, start_time=0, stop_time=0.1, relative_tolerance=1e-7, output_interval=print_interval, input=signals)
t = result['time']
y_Force = result['expseu_.Out2'] # y force
plt.plot(t, y_Force)
My fmu is of type Model Exchange. I tried to define this as an input but this doesn’t work.
Any suggestions?
Cheers