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() 的输入时出错
基础教程推荐
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
