问题描述
我在 gt-suite 中创建了一个 fmu.我正在尝试使用 python PyFMI 包在 python 中使用它.我的代码
I have a fmu created in gt-suite. I am trying to work with it in python using python PyFMI package.My code
from pyfmi import load_fmu
import numpy as np
model = load_fmu('AHUPIv2b.fmu')
t = np.linspace(0.,100.,100)
u = np.linspace(3.5,4.5,100)
v = np.linspace(900,1000,100)
u_traj = np.transpose(np.vstack((t,u)))
v_traj = np.transpose(np.vstack((t,v)))
input_object = (('InputVarI','InputVarP'),(u_traj,v_traj))
res = model.simulate(final_time=500, input=input_object, options={'ncp':500})
res = model.simulate(final_time=10)
model.simulate 将输入作为其参数之一,文档说
model.simulate takes input as one of its parameters, Documentation says
input --
Input signal for the simulation. The input should be a 2-tuple
consisting of first the names of the input variable(s) and then
the data matrix.
'InputVarI','InputVarP'是输入变量,u_traj,v_traj是数据矩阵.
'InputVarI','InputVarP' are the input variables and u_traj,v_traj are data matrices.
我的代码出错了给出一个错误 -
My code gives an errorgives an error -
TypeError: tuple indices must be integers or slices, not tuple
input_object 是不是创建错了?有人可以帮助如何根据文档正确创建输入元组吗?
Is the input_object created wrong? Can someone help with how to create the input tuples correctly as per the documentation?
推荐答案
输入对象创建不正确.输入元组中的第二个变量应该是单个数据矩阵,而不是两个数据矩阵.
The input object is created incorrect. The second variable in the input tuple should be a single data matrix, not two data matrices.
正确的输入应该是:
data = np.transpose(np.vstack((t,u,v)))
input_object = (['InputVarI','InputVarP'],data)
这篇关于使用 pyfmi 创建 2 元组作为 fmu 模型的 model.simulate() 的输入时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!