从Modelica模型中提取具有start属性的变量列表 [英] Extract list of variables with start attribute from Modelica model

查看:84
本文介绍了从Modelica模型中提取具有start属性的变量列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简便的方法可以从Modelica模型中提取具有开始属性的所有变量的列表?最终目标是运行模拟直到达到稳态,然后运行python脚本,将start属性的值与稳态值进行比较,以便我可以识别出错误选择的起始值.

Is there an easy way to extract a list of all variables with start attribute from a Modelica model? The ultimate goal is to run a simulation until it reaches steady-state, then run a python script that compares the values of start attribute against the steady-state value, so that I can identify start values that were chosen badly.

在Dymola Python界面中,我找不到这种功能.另一种方法可能是生成modelDescription.xml并对其进行解析,我假设信息可以在其中找到,但是对于这种方法,我也觉得我需要帮助才能开始.

In the Dymola Python interface I could not find such a functionality. Another approach could be to generate the modelDescription.xml and parse it, I assume the information is available somewhere in there, but for that approach I also feel I need help to get started.

推荐答案

类似于答案,您可以提取该答案使用FMPy从FMU内的modelDescription.xml轻松获取信息.

Similar to this answer, you can extract that info easily from the modelDescription.xml inside a FMU with FMPy.

这是一个小的可运行示例:

Here is a small runnable example:

from fmpy import read_model_description
from fmpy.util import download_test_file
from pprint import pprint

fmu_filename = 'CoupledClutches.fmu'

download_test_file('2.0', 'CoSimulation', 'MapleSim', '2016.2', 'CoupledClutches', fmu_filename)

model_description = read_model_description(fmu_filename)

start_vars = [v for v in model_description.modelVariables if v.start and v.causality == 'local']

pprint(start_vars)

这篇关于从Modelica模型中提取具有start属性的变量列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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