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
, whenW == 1
evaluates totrue
, theSine3
block is active, and whenV == 4
evaluates totrue
, theSine4
block is active.In
Variant Source2
, whenV == 1
evaluates totrue
, theSine1
block is active, and whenV == 2
, theAdd1
block is active.For the
Variant Source1
block to be active, theAdd1
block must be active. This further propagates to theSine3
block andSine4
blocks, making theSine3
block active whenV == 2
andW == 1
evaluate totrue
and theSine4
block active whenV == 2
andW == 2
evaluate totrue
.The
Gain3
block is active whenV == 1
orV == 2
evaluates totrue
. The variant condition is further propagated toScope1
andOut1
.The blocks connected to the outport of the
Variant Sink
block are active whenW == 1
(Gain5
), orW == 2
(Gain2
,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, theSine6
,Sum
, andOut2
blocks are unconditional. To mark the blocks as conditional, place a single-input, single-output Variant Source block beforeOut2
or afterSine6
. Reading an inactive signal is equivalent to reading ground. For example, whenW == 1
evaluates tofalse
, the bottom input to theSum
block is inactive andOut2 = 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.
See Also
Propagate Variant Conditions to Define Variant Regions with Variant Blocks
Related Topics
- Generate Code for Variant Source and Variant Sink Blocks (Simulink Coder)