Dymola中的初始化警告
在我的模型中,我对为什么没有完全指定初始条件感到困惑。
下面是代码和截图:
model WithAlgebraicLoop_Right
extends Modelica.Icons.Example;
Real x;
Real y(start=1, fixed=true);
Boolean cond;
equation
cond = x > 0.5;
when pre(cond) then
y = 1*time;
end when;
x = sin(y*10*time);
end WithAlgebraicLoop_Right;
我认为在初始化期间,x
可以从 计算y
,所以cond
可以从 计算x
,那么为什么 Dymola 没有像我想的那样做呢?
回答
当然,离散时间变量cond
可以根据给定的方程进行计算。但是,它在初始化时事件迭代的预值是未知的,必须通过设置固定的起始值或初始方程来设置,无论您喜欢什么。
model WithAlgebraicLoop_Right1
Real x;
Real y(start=1, fixed=true);
Boolean cond(start=false, fixed=true);
equation
cond = x > 0.5;
when pre(cond) then
y = 1*time;
end when;
x = sin(y*10*time);
end WithAlgebraicLoop_Right1;
或者
model WithAlgebraicLoop_Right2
Real x;
Real y(start=1, fixed=true);
Boolean cond;
initial equation
pre(cond) = false;
equation
cond = x > 0.5;
when pre(cond) then
y = 1*time;
end when;
x = sin(y*10*time);
end WithAlgebraicLoop_Right2;
- By the way, my preference would be the fixed start value, since you can easily modify them in components, which is not the case for initial equations. See this discussion for some more background: https://github.com/mtiller/ModelicaBook/issues/133