Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redeclare package in a model before making an instance?

Tags:

modelica

I would like to do

    M_type(redeclare package L=L2) m2_instance;

but does not work. Instead I can write

    model M2_type
       extends M_type(redeclare package L=L2);
    end M2_type;
    M2_type m2_instance;

Is here not a shorter way to do this and avoid declaring M2_type?

like image 596
janpeter Avatar asked Nov 16 '25 09:11

janpeter


1 Answers

The redeclare modifier must be moved to the instance name.

M_type(redeclare package L=L2) m2_instance;  // wrong syntax
M_type m2_instance(redeclare package L=L2);  // correct

Below is a small package, which demonstrates everything and simulates perfectly fine in Dymola 2021x and OpenModelica 1.16.2.

package Redeclaration
  package L1
    constant Real x = 1;
  end L1;

  package L2
    constant Real x = 2;
  end L2;

  model M_type
    replaceable package L = L1;
    Real x = L.x;
  end M_type;
  
  model Example
    M_type m_instance(redeclare package L=L2);
  end Example;
end Redeclaration;
like image 197
marco Avatar answered Nov 19 '25 10:11

marco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!