创建2tuple作为的输入时出错模型.模拟()带pyfmi的fmu模型

2024-04-27 22:11:43 发布

您现在位置: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)

你知道吗模型.模拟文档中说,将输入作为其参数之一

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\u traj、v\u traj是数据矩阵。你知道吗

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

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

输入对象是否创建错误?有人能帮助我们如何根据文档正确地创建输入元组吗?你知道吗


Tags: the代码importinputmodelobjectnpload
1条回答
网友
1楼 · 发布于 2024-04-27 22:11:43

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

正确的输入应该是:

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

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

相关问题 更多 >