为带有pyfmi的fmu模型的model.simulate()创建2偶作为输入时出错

2024-04-28 05:50:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我在gt套件中创建了一个fmu。我正在尝试使用python PyFMI包在python中使用它。 我的代码

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将输入作为其参数之一

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是数据矩阵

我的代码给出了一个错误 给出一个错误-

TypeError: tuple indices must be integers or slices, not tuple

输入对象是否创建错误?有人能帮助您根据文档正确创建输入元组吗


Tags: the代码importinputmodel错误npload
1条回答
网友
1楼 · 发布于 2024-04-28 05:50:08

创建的输入对象不正确。输入元组中的第二个变量应该是单个数据矩阵,而不是两个数据矩阵

正确的输入应为:

data = np.transpose(np.vstack((t,u,v)))
input_object = (['InputVarI','InputVarP'],data)

另见pyFMI parameter change don't change the simulation output

相关问题 更多 >