目标:所有派生类都应该从其基类继承一些默认方程。如果默认方程对派生类无效,则应重新声明它。
这是一个有点愚蠢的简约例子。
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
等式。