Engee documentation
Notebook

The concept of an algebraic loop

Algebraic loops (loops) occur when a feedback system contains only forward-passing blocks in the feedback circuit. Forward pass blocks are those that use the input value of the current time step to calculate the output value at the current time step. Thus, a closed loop containing blocks of only direct passage creates a cyclic dependence of the output and input values of the blocks in one time step.

Examples of direct transit blocks:

Blocks that are not directly transmitted maintain one or more state variables that store input values from previous time steps. For example, this is the integration unit Integrator and the signal delay block Delay.

Consider a model that contains a block of sums. It subtracts the output value of the block from the input value .

newmodel_1--1742392010658.png

The model implements the following equation:

As you can see, there is an algebraic loop. And the solution in this case will be simple - to rewrite the equation:

Mathematical interpretation

Engee has numerical solvers for simulating ordinary differential equations (ODES)*. ODES are systems of equations that can be written as:

where - the vector of the state and - independent time variable.

Some systems of equations include additional constraints that include an independent variable and a state vector, but not a derivative of the state vector. Such systems are called differential algebraic equations (DAU).

The term "algebraic" refers to equations in which there are no derivatives. You can express partial differential equations.:

where:

  • and they can be vector functions;
  • The first equation is a differential equation;
  • The second equation is an algebraic equation;
  • The vector of differential variables is
  • The vector of algebraic variables is

In the model, an algebraic cycle is an algebraic constraint. Models with algebraic cycles define a system of differential algebraic equations. The algebraic cycle is solved numerically for at each step of the simulation using the ODE solver.

Let's consider this model, which implements a simple system of differential equations. The inner loop is an algebraic constraint, and the outer loop is a differential equation.

newmodel_1--1742389181735.png

The model implements the DOW system:

For each step performed by the ODE solver, the algebraic cycle solver must solve the algebraic constraint for before calculating the derivative .

Artificial algebraic loops

Artificial algebraic loops can occur, for example, when using atomic subsystems. Such systems implement a non-virtual hierarchy, and during simulation they are treated as separate units. The atomic subsystem is executed during a given time step until each block inside the subsystem is completed before proceeding to execute other blocks outside the subsystem.

Let's look at an example. A model is given that is a control system with a proportional object controller described by

There are no algebraic variables in the system, no feedback from the forward passage blocks, and it does not contain an algebraic contour.

newmodel_1-19.03.25 15_44_58.png

Open the model create_alg_loop.engee as described in the following steps:

  • Enclose the controller and the control object in a subsystem.

  • In the subsystem settings, select "Convert to atomic unit" to make the subsystem atomic.

  • Run the model.

You can also run a ready-made model. atomic_alg_loop.engee.

As a result, you will get an error:
image.png

When modeling this model, an algebraic loop arises because the subsystem is straight, even if the path inside the atomic subsystem is not straight. The simulation stops due to the finding of an algebraic loop.

Conclusion

If your model contains an algebraic cycle, then you will not be able to simulate the model in Engee. You also cannot generate code from such a model. Algebraic loops should be avoided. How to do this was described in [publication removing algebraic loops] (https://engee.com/community/ru/catalogs/projects/udalenie-algebraicheskikh-petel ).

Blocks used in example