error while creating a 2-tuple as input for model.simulate() of fmu model with pyfmi(使用 pyfmi 创建 2 元组作为 fmu 模型的 model.simulate() 的输入时出错)
问题描述
我在 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 error gives 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 参数更改不会更改模拟输出
这篇关于使用 pyfmi 创建 2 元组作为 fmu 模型的 model.simulate() 的输入时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 pyfmi 创建 2 元组作为 fmu 模型的 model.simulate() 的输入时出错


基础教程推荐
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 筛选NumPy数组 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01