0

Aims: all the derived classes should inherit some default equations from their base class. When the default equation is not valid for a derived class then it should redeclare it.

Here is a somewhat silly minimalistic example.

package Pkg

  class Equations
    Real x;
  end Equations;

  class DefaultEquations
    extends Equations;
    equation
      x = 0.0;
  end DefaultEquations;

  class Base
    replaceable DefaultEquations equations extends Equations;
  end Base;

end Pkg;

model DuplicateEquations

    import Pkg.*;

    class CustomizedClass
      extends Base;
      redeclare Equations equations;
      equation
        equations.x = 3;
    end CustomizedClass;

    CustomizedClass customized;

end DuplicateEquations; 

For some mysterious reason, the default equation is not overriden:

omc Test.mo Package.mo
class DuplicateEquations
  Real customized.equations.x;
equation
  customized.equations.x = 0.0;
  customized.equations.x = 3.0;
end DuplicateEquations;

Why is this happening? Why are both x=0 and x=3 generated?

If I comment out the package declaration I get only the expected x=3 equation.

Ali
  • 56,466
  • 29
  • 168
  • 265

1 Answers1

1

The type has to be redeclared, not the component, as pointed out by Adrian Pop.

Ali
  • 56,466
  • 29
  • 168
  • 265