Search code examples
inheritancemodelica

Modelica - 'extends' with drop-down menu


I think it is possible but I am not sure since I could not find any example. I would like to be able to choose the model I what to inherit directly in the parameter panel.

I can imagine two kinds of solutions:

extends model1 annotation(choices(choice(model1 "Ref"),choice(model2 "New")));

or

extends replaceable model1 annotation(choices(choice(redeclare model1 "Ref"),choice(redeclare model2 "New")));

Update: example to better explain what I would like to do: I would like to choose from the parameter panel of 'Final' which model to extend, among 'Data1' and 'Data2'.

package test

 partial model Data1
  parameter Real a=1;
  parameter Real b=2;
 end Data1;

 partial model Data2
  parameter Real a=1.1;
  parameter Real b=1.8;
 end Data1;

 model Final
  extends Data1; //(or Data2)
  Real y;
 equation
  y = a*time+b;
 end Final;

end test;

Solution

  • It is not possible to have replaceable extends. You can have replaceable models that are redeclared within the model being extended but not the extended model itself. For example:

    extends model1(redeclare replaceable ...)

    You should be able to reorganize your structure so that it is not necessary to use a replaceable extends.