我在 Dymola 中有一个模型,我从 Python 运行该模型(使用 Dymola 安装文件夹中给出的示例界面)。 一切正常,但是当我想在 Dymola 中添加必须采用向量形式的输入参数时(在 de Dymola 语法中,这意味着该值必须位于两个大括号 {} 之间),一切都会失败。
下面是我在 Python 中用来执行 Dymola 模型的代码行:
result = dymola.simulateExtendedModel(problem=My_Model, startTime=0.0, stopTime=50000, numberOfIntervals=500, method="Dassl", tolerance=1e-07, resultFile = r"C:\Users\arty\Desktop\DYMOLAEXTRACT\Resultats", initialNames=["evaporatorGas_altered.Shot", "evaporatorGas_altered.Scold", "PI2.y_start", "HPT.Xi_cool_stat", "HPT.Xi_cool_rot"], initialValues=[i, i, PI_initial_output_propeller_torque[counter], **0.0208189** , **0.03122835**], finalNames=dym_lst_vars)
粗体字的两个值是给我带来问题的两个值。 Dymola 仅接受向量形式的这些值(因此,如果我转到 Dymola 模型并手动输入 {0.0208189} 和 {0.03122835},一切正常。
我尝试在 Python 中以相同的语法输入这些值,但这不起作用。我试过:
result = dymola.simulateExtendedModel(problem=My_Model, startTime=0.0, stopTime=50000, numberOfIntervals=500, method="Dassl", tolerance=1e-07, resultFile = r"C:\Users\arty\Desktop\DYMOLAEXTRACT\Resultats", initialNames=["evaporatorGas_altered.Shot", "evaporatorGas_altered.Scold", "PI2.y_start", "HPT.Xi_cool_stat", "HPT.Xi_cool_rot"], initialValues=[i, i, PI_initial_output_propeller_torque[counter], "{"+str(0.0208189)+"}" , "{"+str(0.03122835)+"}"], finalNames=dym_lst_vars)
但 Dymola 似乎不明白这一点。
我在Python中得到的错误代码是: 错误:无法解析 Dymola 的响应。调用 Dymola 函数“simulateExtendedModel”时出错。
如果没有模型,这似乎很难调查。然而,根据正常命名,我会假设
Xi
是一个向量,并且考虑到它可以设置为 {0.0208189}
,它是一个元素的向量。
这表明正确的命令是:
result = dymola.simulateExtendedModel(problem=My_Model,
startTime=0.0,
stopTime=50000,
numberOfIntervals=500,
method="Dassl",
tolerance=1e-07,
resultFile = r"C:\Users\arty\Desktop\DYMOLAEXTRACT\Resultats",
initialNames=["evaporatorGas_altered.Shot", "evaporatorGas_altered.Scold", "PI2.y_start",
"HPT.Xi_cool_stat[1]", "HPT.Xi_cool_rot[1]"],
initialValues=[i, i, PI_initial_output_propeller_torque[counter],
0.0208189, 0.03122835],
finalNames=dym_lst_vars)
请注意,它已更改为
"HPT.Xi_cool_stat[1]"
和 "HPT.Xi_cool_rot[1]"
。