Removal of algebraic loops¶
Let's look at methods for removing algebraic loops from the model.
Introduction of 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 returns to subsystem A and subsystem B, creating two feedback loops.
If you run the model, you will see an error message in the Diagnostics window.
To remove algebraic loops 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 added after the gain unit in each feedback loop.
Run the model to ensure that no algebraic loops are detected when the model is assembled.
With this arrangement of delay blocks, subsystem A and subsystem B use the output of subsystem C from the previous time slot.
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
.
With this arrangement of the One Step Lag 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 displays an error. Use one of the following methods to eliminate the loop:
- Rewrite the equation to avoid loop dependence;
- Convert the DAU to an ODE, which will eliminate any algebraic loops;
- For some algebraic loops, specify initial values for the algebraic states in the loop. You can use, for example, the IC block for this purpose.
Elimination of artificial algebraic loops caused by atomic systems¶
If an atomic subsystem causes an artificial algebraic loop, convert it to a virtual loop.
Convert an atomic subsystem into a virtual subsystem:
Open the model containing the atomic subsystem.
Right-click the atomic subsystem and select Subsystem Options.
Uncheck Consider as atomic unit.
Combined signals creating artificial Algebraic cycles¶
In some models, signals are combined into groups. This grouping can cause Engee to detect an algebraic loop even though no algebraic constraint exists. If you reroute one or more signals, you can eliminate the artificial algebraic loop.
In this example, the linearised model simulates the dynamics of a system of two reservoirs fed by a single pump. IN alg_loop_ss.engee
:
Capacity $q1$ is the flow rate of fluid entering the reservoir from the pump.
Output $h2$ is the height of the fluid in the second reservoir.
The State Space block defines the dynamic response of the reservoir system to pump operation.
The output of the "State Space" block is a vector containing $q1$ and $h2$.
If we try to simulate the model, we will get a message that an algebraic loop has been detected. To eliminate it perform the following steps:
Modify the matrices $C$ and $D$ as follows:
Pass $q1$ directly to the input instead of through the State Space block.
You can open the finished model with the edited model alg_loop_ss_sol.engee
. Now the input signal ($q1$) does not pass directly to the output ( matrix $D = 0$), so the State Space block no longer has a direct connection.
Conclusion¶
We have looked at several methods for removing algebraic loops in Engee models. Let us repeat that it is incorrect and suboptimal to build a model with algebraic loops. It increases the computational cost and causes difficulties in analysing the results. Therefore, we advise to avoid algebraic loops by rearranging the equations or introducing additional lag blocks into the model.