Main Content

Propagate Variant Conditions to Define Variant Regions Using Variant Source and Variant Sink Blocks

Simulink® automatically propagates the variant conditions from the Variant Source and Variant Sink blocks to their connecting blocks. The propagation of variant conditions enables Simulink to determine which components of the model remain active during simulation. Simulink then deactivates the model components associated with the inactive choices and highlights the active connections.

Tip

The variant condition annotations on model components help you visualize the propagated conditions. To view the annotations, on the Debug tab, select Information Overlays > Variant Legend. If Variant Legend is not available, on the Debug tab, select Information Overlays > Variant Conditions. For more information, Visualize Propagated Variant Conditions in Variant Conditions Legend.

Variant Source and Variant Sink Blocks

Consider the slexVariantSourceAndSink model containing two Variant Source blocks Variant Source1 and Variant Source2, and a Variant Sink block. The variant conditions at the inports and the outports of the Variant Source and the Variant Sink blocks determine the activation and deactivation of the blocks connected to them. V and W are the variant control variables and are defined in the PostLoadFcn callback of the model.

open_system("slexVariantSourceAndSink");

When you simulate the model, the variant conditions are propagated as follows:

  • In Variant Source1, when W == 1 evaluates to true, the Sine3 block is active, and when V == 4 evaluates to true, the Sine4 block is active.

  • In Variant Source2, when V == 1 evaluates to true, the Sine1 block is active, and when V == 2, the Add1 block is active.

  • For the Variant Source1 block to be active, the Add1 block must be active. This further propagates to the Sine3 block and Sine4 blocks, making the Sine3 block active when V == 2 and W == 1 evaluate to true and the Sine4 block active when V == 2 and W == 2 evaluate to true.

  • The Gain3 block is active when V == 1 or V == 2 evaluates to true. The variant condition is further propagated to Scope1 and Out1.

  • The blocks connected to the outport of the Variant Sink block are active when W == 1 (Gain5), or W == 2 (Sine, Subtract, Terminator).

  • The Sum block illustrates two key concepts of variant condition propagation: Signals are variant only if explicitly marked or when all paths can be proven to be variant. For example, the Sine6, Sum, and Out2 blocks are unconditional. To mark the blocks as conditional, place a single-input, single-output Variant Source block before Out2 or after Sine6. Reading an inactive signal is equivalent to reading ground. For example, when W == 1 evaluates to false, the bottom input to the Sum block is inactive and Out2 = Sine6 + ground.

If you set Allow zero active variant controls of the Variant Sink block to on, Simulink® also propagates the variant conditions to the unconditional blocks Sine5 and Gain4 of the variant region also. The variant conditions on Sine5 and Gain4 are the logical OR of the variant conditions, W == 1 and W == 2 of the Variant Sink block. When W == 1 and W == 2 evaluate to false, the condition W == 1 OR W == 2 evaluates to false, thus making Sine5 and Gain4 inactive. This ensures that Sine5 and Gain4 are removed from simulation and are not left unused when the Variant Sink block is inactive.

Related Topics