【发布时间】:2017-02-17 07:34:14
【问题描述】:
我有一个应用程序,我使用 Dymola 作为开发环境,但将以 FMU 形式导出模型以在另一个应用程序中使用。我正在建模的系统具有可互换的组件,使其非常适合在 Modelica 中建模。但是,当我想以 FMU 形式导出模型时,我不确定是否可以利用该功能。
考虑下面这个非常简单的包。该包的目标是定义两个非常简单的模型,并允许用户在执行模型时在可能的模型之间进行选择。虽然这在 Modelica IDE 中很容易做到,但我需要在 FMU 中实现类似的功能。
部分模型定义了一个模型,其中 y = p0 + p1*x。这两个扩展模型只是为参数 p0 和 p1 分配不同的值。最后,TestModel 添加了一个名为 modelIndex 的参数,用于定义两种可能的模型类型的条件表达式。在 Dymola 中这很有效,因为用户可以轻松设置参数 modelIndex 的值。我试图通过将 modelIndex 作为 FMU 的输入来确定是否可以通过 FMU 完成此操作。但是,如果我为 modelIndex 变量设置注释 Evaluate=false,编译将失败。声明的错误是: “当前版本的 Modelica 翻译器只能处理具有固定条件的条件组件......条件声明条件中使用的所有变量都必须声明为常量或参数。”
如果有人可以帮助提供有关如何创建条件 FMU 的指导,我们将不胜感激。这个简单的示例仅用于演示该问题。被建模的真实系统有 4-5 个主要组件,每个组件都有 5 种以上可能的不同模型,从而产生大量可能的排列。简单地批量导出所有配置可能不可行。
谢谢! 贾斯汀
package ConfigurableModel
"Package to test whether or not models can be configured by external inputs"
partial model partialModel
"Partial model used to control selectable options in Dymola"
Modelica.Blocks.Interfaces.RealInput x(start = 1) "input value";
Modelica.Blocks.Interfaces.RealOutput y "output value";
parameter Real p0 = 0;
parameter Real p1 = 0;
equation
y = p0 + p1*x;
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)));
end partialModel;
model linearModel_NoOffset "Linear model with no offset"
extends partialModel(p0 = 0, p1 = 1);
end linearModel_NoOffset;
model linearModel_Offset "Linear model with offset"
extends partialModel(p0=1, p1=1);
end linearModel_Offset;
model TestModel "Model to test configurability"
// parameter Integer modelIndex = 2 "1 = linear_NoOffset, 2 = linear_Offset" annotation(Evaluate=false);
parameter Integer modelIndex = 2 "1 = linear_NoOffset, 2 = linear_Offset";
// Conditional instances, only one model is created based upon value of modelIndex
linearModel_NoOffset linear_NoOffset if modelIndex == 1;
linearModel_Offset linear_Offset if modelIndex == 2;
// Input and output blocks
Modelica.Blocks.Sources.Constant xMaster(k=1) annotation (Placement(transformation(extent={{-100,-10},{-80,10}})));
Modelica.Blocks.Interfaces.RealOutput yMaster annotation (Placement(transformation(extent={{100,-10},{120,10}})));
equation
// Note that only the connections for the components that exist will be used
// Connect input to each model instance
connect(xMaster.y, linear_NoOffset.x);
connect(xMaster.y, linear_Offset.x);
// Connect output to each model instance
connect(yMaster, linear_NoOffset.y);
connect(yMaster, linear_Offset.y);
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)));
end TestModel;
annotation (uses(Modelica(version="3.2.1")));
end ConfigurableModel;
【问题讨论】: