【发布时间】:2023-04-06 16:52:02
【问题描述】:
我有一个 Modelica 模型,我正在其中初始化一组子模型。 我想知道如何最好地将一个值广播到所有数组元素。让我来说明一下,三个演示的替代方案中只有一个可以在没有错误/警告的情况下工作。
model test_each_fixed
model sub
Real p;
end sub;
//sub sub_instance[6](p(start=linspace(0.0, 1.0, 6), fixed=true));
// gives Translation Error Non-array modification ‘true‘ for
// array component ‘fixed‘, possibly due to missing ‘each‘.
// fair enough, let's add an "each":
//sub sub_instance[6](p(start=linspace(0.0, 1.0, 6), each fixed=true));
// gives Translation Warning 'each' used when modifying non-array element p.
// damned if I do, damned if I don't?
// The following works, but is there a better way than an explicit fill()?
sub sub_instance[6](p(start=linspace(0.0, 1.0, 6), fixed=fill(true,6)));
equation
end test_each_fixed;
这是使用 OpenModelica v1.18.0-dev.beta1(64 位)
所以,我的问题:
- 考虑到在没有
each的情况下引发的错误,我收到的第二个变体的翻译警告是 OpenModelica 错误,还是这是预期的 Modelica 行为? - 有没有更好的方法将
true广播到数组元素成员中的所有fixed属性?
【问题讨论】:
-
我认为
p不是参数是故意的,对吗? -
是的。这是我试图从我正在尝试改进的现有更大模型中提取的 MWE。
标签: modelica openmodelica