Support : Knowledge base

Knowledge Base

Welcome to OPAL-RT’s Knowledge Base

OPAL-RT offers a repository of support information for optimal use of its technology.

Loading…

Please note that OPAL-RT knowledge base is not fully optimized for mobile platforms.

For optimal experience, use a desktop computer.

Reference Number: AA-02015// Views: AA-02015// Created: 2021-05-11 04:18:43// Last Updated: 2021-05-12 03:26:56
Problem & Solution
RT-LAB building model error: Algebraic loops are not supported in generated code

Problem

The model could run normally in offline without errors. But it cannot compiled properly during process of RT-LAB building model. The error message is:

??? Error using tlc_c (line 199)

Algebraic loops are not supported in generated code.

Solution

Algebraic loop creates a circular dependency of block outputs and inputs in a same time-step, which is not supported in real-time simulation. It must be located and break properly before compilation. There are 2 effective solutions to locate and identify the algebraic loop in the model, which are:


1. Using Simulink Debug Tool:

a. At the top toolbar of Simulink, check Simulation > Debug > Debug Model....


b. At the panel of debugging tool, Click 'Play' button and check the debug outputs. It will generate a simulation debug log that including the detected 'algebraic loops' info.


3. Go back to your model and relocate the blocks that mentioned in the debug tool. Then, adding computational cost like 'memory' or 'delay' block before algebraic loop outputs. Especially for the subsystems outputs, or the controller outputs. These operations will break the loop and make sure the algebraic equation results are solved at each time-step. Please check the figure below, the 'memory' block is added for controller outputs that generated the gating pulses for switches in electrical circuit. 


Please also noted that placing lots of 'memory' blocks are not very accurate and may affect the simulation stability. 


2. Using Matlab commands:

Type Simulink.BlockDiagram.getAlgebraicLoops('modelname') in the Matlab command window. This function will detect and highlight the loops with potential issue. For example:


Then, we could analysis and break the algebraic loop as the solution mentioned above.

More details for Algebraic Loop Concepts in Simulink: Algebraic Loop Concepts in Simulink