I try to avoid the algebraic loop in Modelica by using pre
operator, but when I use something like pre(x>0.5)
, there will be an error of Internal error in code generation for pre
.
And if I use pre(cond)
, where cond
is a boolean type variable, there won't be any error.
My question is: Is there some regulation of pre
operator which requires that I could NOT use expressions within pre
operator.
Here are the code and screenshot:
model WithAlgebraicLoop_Wrong2
"Demonstration of how to avoid generating algebraic loop,
but end up with internal error in code generation for pre"
Real x,y(start=1,fixed=true);
equation
when pre(x>0.5) then
y=1*time;
end when;
x=sin(y*10*time);
end WithAlgebraicLoop_Wrong2;
model WithAlgebraicLoop_Right "Demonstration of how to avoid generating algebraic loop"
Real x,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;