Define variant choice regions in the Variant Source and Sink blocks based on the block connectivity. The variant choice regions are computed by Simulink when you update diagram (Simulation > Prepare > Update Model).
The process of computing the variant choice regions is called
variant condition propagation. The Variant Source block provides variation on the source of a signal, and the Variant Sink blocks provides variation on the destination (sink) of a signal.
Consider a model containing two Variant Source blocks (
Variant Source1 ,
Variant Source2) and a Sink block (
Variant Sink ).
The variant conditions at the inports and outports of Variant Source and Sink blocks, respectively, determine the activation and deactivation of the blocks connected to them. To view the annotations and the variant conditions, in the Debug tab of the toolstrip, click Information Overlays > Variant Conditions.
Let's analyze the variant conditions and the block activation state.
Variant Source1, when
Sine3 block is active, and when
Sine4 block is active.
Variant Source2, when
V==1, the Sine1 block is active, and when
Add1 block is active.
Add1 block the condition propagation continues making
Variant Source1 block to be active only when the
V==2. This further propagates to
Sine3 block and
Sine4 block, making the
Sine3 block active at
V==2 && W==1 and the
Sine4 block active at
V==2 && W==2, respectively.
Gain3 block is active when either
V==2, and hence the condition
V==2 | |
V==1. The variant condition is further propagated to
The blocks connected to the outport of
Variant Sink are active when
Sum block illustrates two key concepts in variant condition propagation: Signals are only variant if explicitly marked or when all paths can be proven to be variant. To make the
Out2 variant, place a Single-Input Single-Output Variant Source before Out2 (or after the
Sine6). Reading an inactive signal is equivalent to reading ground. When
W ~= 1, then the bottom input to the
Sum block is inactive and
Out2 = Sine6 + ground.
If you select the Analyze all choices during update diagram and generate preprocessor conditionals parameter for the Variant Source and Variant Sink block, the generated code contains the code for the active and the inactive (
#if COND). If this parameter is not selected, then code is generated only for the active choices.
If you select the Allow zero active variant controls parameter for the Variant Source and Variant Sink block, you can simulate the variant model without an active variant. In such cases, Simulink disables the blocks connected to the input and output stream of Variant Source and Variant Sink. These disabled blocks are ignored from update diagram or simulation.