Search code examples
modelicaopenmodelica

How to broadcast boolean value to an array


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:

  • Is the translation warning I get for the second variant an OpenModelica bug, or is this expected Modelica behaviour, considering the error thrown without an each?
  • Is there a better way to broadcast a true to all fixed attributes in the array element members?

Solution

  • 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.