本文介绍了Dymola 中的 FMU-Export:是否可以使 Modelica 枚举类型变量“可调"?导出为 FMU/FMI 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 Modelica 模型中实现了三个类似的出版物,使用枚举类型变量来选择出版物.目标是通过在线更改枚举类型变量的值来切换计算方法(即在出版物之间).
计算包括三个步骤,每个步骤都有自己的枚举变量.这允许混合计算方法,例如通过设置第1步根据出版物1计算,第2步和第3步根据出版物2计算.

I have implemented three similar publications in one Modelica model, using an enumeration type variable to select the publication. The goal is to switch between calculation methods (i.e. between publications) by changing the value of the enumeration type variable online.
The calculation consists of three steps, each of which has its own enumeration variable. This allows for mixed calculation methods, e.g. by setting step 1 to calculate according to publication 1 and steps 2 and 3 according to publication 2.

每一步都是这样的

model Calculation_step

  type pubSelect = enumeration(
      Publication_1,
      Publication_2,
      Publication_3);
  // ####### Publication Selection #######
  parameter pubSelect selection = pubSelect.Publication_2;
  // ##### End Publication Selection #####

  Modelica.Blocks.Interfaces.RealInput incoming;
  Modelica.Blocks.Interfaces.RealOutput outgoing;

  parameter Real factor = 5;

equation
  if selection == pubSelect.Publication_1 then
    outgoing = factor * sin(incoming);
  elseif selection == pubSelect.Publication_2 then
    outgoing = factor * sin(incoming)^2;
  elseif selection == pubSelect.Publication_3 then
    outgoing = factor * sin(incoming)^3;
  else
    outgoing = 99999;
  end if;

  annotation (uses(Publicationica(version="3.2.1"), Modelica(version="3.2.1")));
end Calculation_step;

模型不会在 Dymola 中计算.相反,功能模型单元 (FMU) 是使用 Dymola 创建的.这将创建一个描述模型的 XML 文件.为了启用在线更改,变量必须在此 XML 中设置属性 variability="tunable".

The model will not be calculated in Dymola. Instead, a functional mock-up unit (FMU) is created using Dymola. This creates an XML file describing the model. In order to enable online changes, a variable has to have the attribute variability="tunable" set in this XML.

但是,变量 selection不可调整的,如以下 XML 摘录所示:

However, the variable selection is not tunable, as shown in the following excerpt of the XML:

-<ModelVariables>

<!-- Index for next variable = 1 -->


-<ScalarVariable name="selection" variability="constant" valueReference="100663296">

<Enumeration start="2" declaredType="Calculation_step"/>

</ScalarVariable>

对变量 factor 的声明使用相同的代码产生一个 可调 FMU 变量:

Using the same code for the declaration of the variable factor yields a tunable FMU variable:

<!-- Index for next variable = 4 -->


-<ScalarVariable name="factor" variability="tunable" valueReference="16777216" causality="parameter">

<Real start="5"/>

</ScalarVariable>

tl;博士:导出为 FMU/FMI 时,是否可以使 Modelica 枚举类型变量可调"?

tl;dr:Is it possible to make a Modelica enumeration type variable "tunable" when exported as FMU / FMI?

Dymola 2015 版 FD01(32 位),2014-11-04

Dymola Version 2015 FD01 (32-bit), 2014-11-04

推荐答案

我尝试向选择参数添加一个起始值,并且通过注释 (Evaluate=false) 使其变得可调.

I tried to add a start value to the selection parameter, and with annotation (Evaluate=false) it became tunable.

parameter pubSelect selection(start=pubSelect.Publication_2) annotation (Evaluate=false);

它会给你一个关于未分配参数的警告,我还没有真正尝试过它是否真的有效(在事件/通信点更改值),如果你有机会给它一个,请告诉我结果尝试.谢谢~

It will give you a warning about an unassigned parameter tho, I have not really tried if it really works(change the value at events/communication points), please let me know the result if you have a chance to give it a try. Thanks~

这篇关于Dymola 中的 FMU-Export:是否可以使 Modelica 枚举类型变量“可调"?导出为 FMU/FMI 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 21:42