【问题标题】:error while creating a 2-tuple as input for model.simulate() of fmu model with pyfmi使用 pyfmi 创建 2 元组作为 fmu 模型的 model.simulate() 的输入时出错
【发布时间】:2019-06-04 08:29:34
【问题描述】:

我在 gt-suite 中创建了一个 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

input_object 是不是创建错了?有人可以帮助如何根据文档正确创建输入元组吗?

【问题讨论】:

    标签: python tuples fmi jmodelica


    【解决方案1】:

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

    正确的输入应该是:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-29
      • 2020-06-14
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多