Variant Source and Variant Sink Blocks
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 us analyze the variant conditions and the block activation state.
In
Variant Source1
, whenW==1
, theSine3
block is active, and whenV==4
, theSine4
block is active.In
Variant Source2
, whenV==1
, the Sine1 block is active, and whenV==2
, theAdd1
block is active.At
Add1
block the condition propagation continues makingVariant Source1
block to be active only when theV==2
. This further propagates toSine3
block andSine4
block, making theSine3
block active atV==2 && W==1
and theSine4
block active atV==2 && W==2
, respectively.The
Gain3
block is active when eitherV==1
orV==2
, and hence the conditionV==2
| |V==1
. The variant condition is further propagated toScope1
andOut1
.The blocks connected to the outport of
Variant Sink
are active whenW==1
(Gain5
), orW==2
(Sine
,Subtract
,Terminator
).The
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 theSine6
,Sum
,Out2
variant, place a Single-Input Single-Output Variant Source before Out2 (or after theSine6
). Reading an inactive signal is equivalent to reading ground. WhenW ~= 1
, then the bottom input to theSum
block is inactive andOut2 = Sine6 + ground
.
If you set the Variant activation time parameter to code compile
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.