0

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;

enter image description here

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;

enter image description here

Jack
  • 1,094
  • 6
  • 16

1 Answers1

7

You can read in the Modelica Language Specification (section 3.7.3 on event related operators -> table) that the argument of pre needs to be a variable, but not an expression.

tbeu
  • 1,235
  • 7
  • 12