我正在使用 python fmpy 来运行 fmu 模型。执行、运行和绘制结果工作正常。也定义输入(按照教程)。
但我正在努力改变 fmu 模型中全局参数的值。
例如,如果我在 GUI ( https://fmpy.readthedocs.io/en/latest/tutorial/ ) 中运行相同的模型,我将获得所有可用参数的完整列表。在那里,我可以将名为“l1”的参数的值设置为 412。如果我记录 GUI 的 FMI 调用,我可以看到,使用以下命令将“l1”设置为 412:
fmi2SetReal(fmu, vr=[671088641], nvr=1, value=[412])
如何使用 python 命令将“l1”设置为 412?
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)
我的 fmu 是 Model Exchange 类型。我试图将其定义为输入,但这不起作用。
有什么建议么?
干杯