会员未按预期更换,为什么?

时间:2012-04-16 12:46:34

标签: modelica

目标:所有派生类都应该从其基类继承一些默认方程。如果默认方程对派生类无效,则应重新声明它。

这是一个有点愚蠢的简约例子。

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; 

出于某种神秘的原因,默认方程式未被覆盖:

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

为什么会这样?为什么 x=0 x=3 生成?

如果我注释掉package声明,我只会得到预期的x=3等式。

1 个答案:

答案 0 :(得分:1)

The type has to be redeclared, not the component,正如Adrian Pop所指出的那样。