parametersmodelicagraphical-interaction

How to get references right for package parametrisation


I have for long time made good use of what I call package parametrisation which means that all components in the package get adapted for a change of a parameter on the package level. The advantage with the technique is when you have many components in a package that should be adapted. All components adapted directly. Below a most simplified example where the package Elib only have one component Tank.

package DEMO_v90

   package LBase
      constant Integer nc=1;
      type Real_nc = Real[nc];
      replaceable type C = Real[nc] constrainedby Real_nc;
   end LBase;

   package Elib
      replaceable package L = LBase constrainedby LBase;

      model Tank
   //    import DEMO_v90.Elib.L;
         parameter L.C c_start = ones(L.nc);
         L.C c (start=c_start, each fixed = true);
      equation
         for i in 1:L.nc loop
            der(c[i]) = -c[i];
         end for;
      end Tank;
   end Elib; 

   // Create L with nc=2
   package L2
      import DEMO_v90.LBase;
      extends LBase(nc=2);
   end L2;

   model M
      import DEMO_v90;
      replaceable package L_local = DEMO_v90.L2;

      // Create E as an adapted version of Elib to L2
      package E
         import DEMO_v90.Elib;
         extends Elib(
            redeclare package L = L_local);
      end E;        
      E.Tank tank;
   equation
      annotation(Icon(graphics = {Rectangle(extent = {{-60, 80}, {60, -80}}), 
      Text(origin = {1, 88}, extent = {{-59, 8}, {59, -8}}, 
      textString = "%name")}));
   end M;

end DEMO_v90;

Here I like to combine traditional component parametrisation for model M with package parametrisation inside M and right now just one component but will be many interconnected in the future. The idea is to give M a proper icon while the internal structure of M is without icons.

The current code just provide a tank adapted for nc=1 as in LBase. And if I change LBase.nc to another number that is what the tank get adapted too, i.e. not to nc=2 that we have in L2.

The code tested in both OpenModelica 1.23.1 and JModelica 2.14 with the same result.

How should the code be corrected?


Solution

  • I found the problem myself and corrected the code for DEMO_v90 above.

    1. In model Tank skip the import .
    2. In model M introduce L_local, since otherwise interpreted as recursive definition.