arraysmodelicadymolaredeclare

Modelica: Can a replaceable model of a component within an array of components be redeclared individually?


When instantiating an array of components in Modelica, parameters can be passed in the modifier as an array as well to parametrize each component in the array individually.

If the Class of the component also includes replaceable models, is it possible to redeclare them individually when instantiating the array of components?

model System   
  BaseComponent[2] components(    
    each param1 = 0,    
    param2 = {1,2},    
    redeclare model ModelTypeToReplace = SubModel2); 
end System;
model BaseComponent   
    parameter Real param1 = 0;   
    parameter Real param2 = 0;   
    replaceable model ModelTypeToReplace = SubModel1 constrainedby PartialModel;   
    ModelTypeToReplace replaceableModel; 
end BaseComponent;

In the example above, I replace the ModelTypeToReplace of component[1] and component[2] both with the SubModel2. I would like to do something like redeclare model ModelTypeToReplace = {SubModel1, SubModel2}, but that Syntax is not supported.

There is a workaround for records by treating the record as a parameter. Unfortunately, this does not work for models.


Solution

  • No, the syntax does currently not allow it, including the following attempts:

    1. Array of redeclare
    2. Switching between classes based on a boolean/enumeration/integer parameter (E.g., model A=(if first then B else C);)
    3. Modifier for a specific element of the array including a redeclare (I believe this was once syntactically possible, but not implemented in any tool)

    The closest is to have conditionally enabled elements of different types as follows:

    model BaseComponent   
        parameter Real param1 = 0;   
        parameter Real param2 = 0;
        parameter Boolean first=true;
        SubModel1 a if first; 
        SubModel2 b if not first;
    end BaseComponent;
    
    model System   
      BaseComponent[2] components(    
        each param1 = 0,    
        param2 = {1,2},    
        first = {true, false}); 
    end System;
    

    I haven't investigated how difficult it would be to support - except that variant 3 is the most problematic; as it seems very difficult to merge modifiers if there are both modifiers for the array and for array elements (especially if the subscripts aren't literals).

    Added: If you want it implemented it would be helpful with actual examples.