我想知道Modelica是否符合从嵌套的可替换模型扩展模型,即在特定示例中:
package ReplaceableBaseClass
model ExampleUseReplaceable
ModelWithReplaceableExtend replaceableExtend1(
redeclare model LocalModelBase = Extend1,
input1 = time)
"Instance with one input and one output";
ModelWithReplaceableExtend replaceableExtend2(
redeclare model LocalModelBase = Extend2,
input1 = Modelica.Math.sin(4*time + 0.3))
"Instance with one input and two output";
end ExampleUseReplaceable;
model ModelWithReplaceableExtend
"Model which extends from its nested replaceable class"
extends LocalModelBase;
replaceable model LocalModelBase = Extend1
constrainedby PartialToBeExtended;
end ModelWithReplaceableExtend;
partial model PartialToBeExtended
input Real input1;
output Real output1;
end PartialToBeExtended;
model Extend1
extends PartialToBeExtended;
equation
output1 = 3*input1;
end Extend1;
model Extend2
extends PartialToBeExtended;
output Real output2;
equation
output1 = input1 + 0.2;
output2 = input1 * input1;
end Extend2;
end ReplaceableBaseClass;
这实际上适用于Dymola,但我对它有一种奇怪的感觉,并且不确定使用它是否真的好主意。
答案 0 :(得分:2)
这不是合法的Modelica(自Modelica 3.0以来),Dymola将在2017年Dymola之后产生诊断(但只是一个警告)。
Modelica的限制是基类必须是可传递的不可替换的(第7.1.4和6.2.1节)。