I have a Modelica model where I am initialising an array of submodels. I'm wondering how to best broadcast one value to all array elements. Let me illustrate, only one of the three demonstrated alternatives works without errors/warnings.
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;
This is using OpenModelica v1.18.0-dev.beta1 (64-bit)
So, my questions:
each
?true
to all fixed
attributes in the array element members?The second variant with each
should work in Modelica; https://specification.modelica.org/master/inheritance-modification-and-redeclaration.html#modifiers-for-array-elements
And I cannot see any better alternatives.