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