Engee documentation
Notebook

Removing algebraic loops

Let's consider methods for removing algebraic cycles from the model.

Introducing a delay

Blocks of direct passage in the feedback circuit can create algebraic cycles in the model. You can remove these algebraic cycles by introducing a delay using the [Delay] block (https://engee.com/helpcenter/stable/ru/base-lib-discrete/delay.html ) or Unit Delay.

Open the model algebraic_loop. The model contains three atomic subsystems: A, B, and C. The output of subsystem A is the input to subsystem B, and the output of subsystem B is the input to subsystem C. The output of subsystem C is returned to subsystem A and subsystem B, creating two feedback loops.

algebraic_loop-27.03.25 09_25_40.png

If you run the model, you will see an error message in the Diagnostic window.

image.png

To remove algebraic cycles from your model, add a delay before or after each algebraic variable. To see this solution, open the model algebraic_loop_two_UnitDelay, which is similar to the model algebraic_loop, but with a unit delay block added after the gain block in each feedback cycle.

algebraic_loop_two_UnitDelay-27.03.25 09_29_04.png

Run the model to make sure that no algebraic loops are detected when building the model.

With this arrangement of delay blocks, subsystem A and subsystem B use the output of subsystem C from the previous time interval.

In this model, you can also remove the algebraic loop by adding one unit delay block between subsystem B and subsystem C. This signal path is part of both feedback loops, so the delay affects the path of both algebraic variables. To see this solution, open the model algebraic_loop_one_UnitDelay.engee.

algebraic_loop_one_UnitDelay-27.03.25 09_27_22.png

With this arrangement of the "One step Delay" block, subsystem C uses the value of the previous time step to output from subsystem B to obtain the feedback value for the current time step.

Other ways to eliminate algebraic loops

If the solver cannot solve an algebraic problem, Engee returns an error. Use one of the following methods to eliminate the loop:

Elimination of artificial algebraic loops caused by atomic systems

If an atomic subsystem causes an artificial algebraic loop, transform it into a virtual one.

Transformation of an atomic subsystem into a virtual subsystem:

  • Open the model containing the atomic subsystem.

  • Right-click the atomic subsystem and select Subsystem Settings.

  • Uncheck Consider as an atomic unit.

Combined signals that create artificial Algebraic cycles

In some models, the signals are grouped together. Such a union can cause Engee to detect an algebraic loop, even if there is no algebraic constraint. If you redirect one or more signals, you can eliminate the artificial algebraic loop.

In this example, the linearized model simulates the dynamics of a system of two reservoirs powered by a single pump. alg_loop_ss.engee:

alg_loop_ss-27.03.25 09_34_46.png
  • Performance — this is the flow rate of the liquid entering the tank from the pump.

  • Exit - this is the height of the liquid in the second tank.

  • The "State Space" block determines the dynamic response of the tank system to pump operation.

  • At the output of the "State Space" block, a vector is obtained containing and .

If we try to simulate the model, we will receive a message about the detection of an algebraic loop. To fix it, follow these steps:

  • Change the matrices and as follows:
    image.png

  • Send directly to the input, not through the State Space block.

You can open the finished model edited model alg_loop_ss_sol.engee. Now the input signal () does not pass directly to the output (matrix ), therefore, the "State Space" block no longer has a direct connection.

alg_loop_ss_sol-27.03.25 09_36_21.png

Conclusion

We have reviewed several methods for removing algebraic loops in Engee models. We repeat that it is wrong and suboptimal to build a model with algebraic loops. This increases computational costs and causes difficulties in analyzing the results. Therefore, we recommend avoiding algebraic loops by rearranging equations or adding additional delay blocks to the model.

Blocks used in example