错误消息中的“涉及整数或布尔值的代数循环”是什么意思

JAG*_*KOO 1 modelica dymola

我正在使用Dymola平台制作PI控制器,但遇到如下错误消息

错误信息

这是我的一些代码,其中包括用于计算分配量的阀和控制分配量的PI控制器。他们正在使用标志互相交流

  //PI controller///

  if flag_input==1 then //flag_input==1 : Stop control / flag_input==0 : Restart control//
    control:=0;
  else
    control:=(P_term+I_term)/unit;
  end if;

  if error<0 then // error<0 : flag to Valve to restart calculating the disp//
    flag_output:=1;
  else
    flag_output:=0;
  end if;

//Valve//

  if (26/5)*(thetta/(2*pi))*0.001>0.026 and flag_input==0 then
  //restart calculating the disp when received flag==1 from the PI controller//
    disp:=0.026;
    flag:=1;
  elseif (26/5)*(thetta/(2*pi))*0.001<0 and flag_input==0 then
    disp:=0;
    flag:=1;
  else
    disp:=(26/5)*(thetta/(2*pi))*0.001;
    flag:=0;
  end if;
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我代数循环错误的含义并找出问题所在吗?

mar*_*rco 5

From your code snippet it's hard to tell where exactly the problem is.

Dymola tells you that you created a large algebraic loop over all the variables listed at the top under Unknowns and the equations listed below in the section Equations. This can happen easily when you create if statements with variables which depend on each other. Often you just have to use pre() at the right place to break the loop.

Let`s use another small example to explain the problem. For some reason we try to count the full milliseconds, which have passed in the current simulation and stop, once we reach 100.

model count_ms
  Integer y(start=0);
equation 
  if y >= 100 then
    y = 100;
  else
    y = integer(1000*time);
  end if;
end count_ms;
Run Code Online (Sandbox Code Playgroud)

This code will produce a similar error as yours:

An algebraic loop involving Integers or Booleans has been detected.
Unknowns: y

Equations: y = (if y >= 100 then 100 else integer(1000*time));

From the error message we see that y can not be solved, due to the equation resulting from the if statement. The equation is not solvable, as y depends on itself. To solve such problems pre was introduced, which gives you access to the value of a variable had when the event was triggered.

To fix the code above, we simply have to use pre when we check for y

if pre(y) >= 100 then
Run Code Online (Sandbox Code Playgroud)

and the model simulates as expected.