FMU FMI模拟,设置某类参数时不修改结果 [英] FMU FMI simulation, no modification of results when setting certain type of parameter

查看:84
本文介绍了FMU FMI模拟,设置某类参数时不修改结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为示例开发了一个基于 MSL 流体库的简单 Modelica 模型.我将 MassFlowSource 与管道和 Boundary_PT 作为汇函数连接,如下图所示:

I developed for the example a simple Modelica model based on the fluid library of the MSL. I connected a MassFlowSource with a pipe and a Boundary_PT as sink function as in the picture below:

http://www.casimages.com/img.php?i=14061806120359130.png

我使用 OpenModelica(模型交换模式)生成了一个 FMU 包.我用 python 管理这个 FMU 包,代码如下:

I generate a FMU package with OpenModelica (in mode model-exchange). I manage this FMU package with python with the code below:

import pyfmi, os
from pyfmi import load_fmu

myModel = load_fmu('PathToFolder\\test3.fmu')
res1 = myModel.simulate() # First simulation with m_flow in source set to [1] Kg/s
x = myModel.get('boundary1.m_flow') # Mass flow rate of the source
y = myModel.get('pipe.port_a.m_flow') # Mass flow rate in pipe
print x, y

myModel.set('boundary1.m_flow', 2)
option = myModel.simulate_options()
option['initialize'] = False # Need to initialize the simulation
res2 = myModel.simulate(options = option) # Second simulation with m_flow in source set to [2] Kg/s
x = myModel.get('boundary1.m_flow') # Mass flow rate of the source
y = myModel.get('pipe.port_a.m_flow') # Mass flow rate in pipe
print x, y

os.system('pause')

目标是在您更改模型中的参数时显示问题,这里是源组件中的m_flow"变量.这个新设置为2"应该会改变管道中的m_flow",但它不会.结果:在第一次模拟中,m_flow"都变成了1",这是正常的,因为模型是这样设置的.在第二次模拟中,我在源代码中将参数设置为2",但管道m_flow"保持为1"(它应该是2").http://www.casimages.com/img.php?i=140618060905759619.png

The objective is to show a problem when you change a parameter in the model, here the "m_flow" variable in source component. This new set to "2" should change the "m_flow" in pipe but it does not. Results: In the first simulation the both "m_flow" are gotten to "1" and it's normal because the model is set like this. In the second simulation, I set the parameter to "2" in the source but the pipe "m_flow" stay to "1" (It should be "2"). http://www.casimages.com/img.php?i=140618060905759619.png

Modelica 中流体源的模型是这个(只是我们感兴趣的部分):

The model of the fluid source in Modelica is this one (only our interesting part):

equation
 if not use_m_flow_in then
  m_flow_in_internal = m_flow;
 end if;
 connect(m_flow_in, m_flow_in_internal);

我认为 FMU 在处于 if 条件时不考虑参数.对我来说这是一个问题,因为我需要管理 FMU 并确保如果我设置一个参数,模拟将使用这个新设置.如何确定 FMU/FMI 运行良好?我们无法在 FMU 中管理的参数类型的详尽列表在哪里?

I think the FMU don't consider parameter when they are in a if-condition. For me it's a problem because I need to manage FMU and to be sure that if I set a parameter, the simulation will use this new set. How be sure that FMU/FMI works well? Where is the exhaustive list with the type of parameters we can't manage in FMU?

我已经知道在 FMU 管理中不能考虑改变方程数量的参数(对于改变 DAE 索引的变量也是如此).

I already know that parameters which change the number of equations can't be consider in FMU management (idem for variables which change the index of DAEs).

推荐答案

注意 OpenModelica 有结构参数的概念和 Evaluate=true 注释.例如,如果一个参数被用作数组维度,它可能会被评估为一个整数值.该参数的所有使用都将使用评估值,就好像它是一个常量一样.

Note that OpenModelica has a concept of structural parameters and the Evaluate=true annotation. For example, if a parameter is used as an array dimension, it might be evaluated to an Integer value. All uses of that parameter will use the evaluated value, as if it was a constant.

与包含图表图片相比,Modelica 源代码更容易查看,以便了解 OpenModelica 对系统做了什么.

Rather than including a picture of the diagram, the Modelica source code would have been easier to look at in order to find out what OpenModelica did to the system.

我怀疑对参数进行了评估.如果您生成非 FMU 代码,您可以检查 OpenModelica 生成的 modelName_init.xml 并找到参数条目并查找属性 isValueChangeable.

I suspect a parameter was evaluated. If you generate non-FMU code, you could inspect the modelName_init.xml generated by OpenModelica and find the entry for a parameter and look for the property isValueChangeable.

您还可以使用 OMEdit 来调试系统并查看初始方程(生成包含调试信息的可执行文件).File->Open Transformations File,然后选择modelName_info.xml 文件.搜索您尝试更改的变量并转到定义它的初始方程.很可能忽略起始值(由 PyFMI 设置),因为它不需要生成解决方案.

You could also use OMEdit to debug the system and view the initial equation (generate the executable including debug information). File->Open Transformations File, then select the modelName_info.xml file. Search for the variable you tried to change and go to the initial equation that defined it. It could very well be that a start-value (set by PyFMI) is ignored because it is not needed to produce a solution.

这篇关于FMU FMI模拟,设置某类参数时不修改结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆