Variant Condition Propagation with Variant Sources and Sinks
How Variant Condition Propagation Works
When you specify variant conditions in models containing Variant Source and Variant Sink blocks, Simulink® evaluates the variant controls specified on the variant blocks and automatically propagates the variant conditions to the connecting blocks to determine which components of the model are active during simulation. Simulink then deactivates the model components associated with the inactive choices and visualizes the active connections. Simulink uses the Variant activation time block parameter to determine the time frame when it chooses the active variant choice. For more information on variant activation time, see Activate Variant During Different Stages of Simulation and Code Generation Workflow.
Note
The variant condition annotations displayed on model components help you visualize the propagated conditions.
To view the variant condition 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.
Cross-Coupling of Inputs and Outputs
In this model, the Variant Source block has two inputs with
variant conditions Var == 1
and Var==2
,
respectively. The first input to the Variant Source block
branches into its second input before connecting to the block. The second input
with variant condition Var==2
is the default variant choice.
During simulation, this model exhibits three modes of operation:
Variant Condition | Active Choice |
---|---|
Var == 1 | First input of |
Var == 1 || Var == 2 | Second input of Variant Source and the
branch of the first input. |
Var == 2 | Second input of Variant
Source . |
Cascading Blocks and Compounding Conditions
In this model, Variant Source A
and Variant Source
B
are two Variant Source blocks, each fed by two
input ports, and connected in a cascading manner. The inputs to Variant
Source A
are active when VarA == 1
or
VarA == 2
. The output of Variant Source
A
branches into one of the inputs of Variant
SourceB
. The inputs to Variant SourceB
are
active when VarB == 1
or VarB == 2
.
During simulation, this model exhibits eight modes of operation:
Variant Condition | Active Choice |
---|---|
VarA == 1 && VarB == 1 | First inputs of |
VarA == 1 && VarB == 2 | First input of Variant Source A and
the second input of Variant Source
B . |
VarA == 2 && VarB == 1 | Second input of Variant Source A and
the first input of Variant Source
B . |
VarA == 2 && VarB == 2 | Second inputs of Variant Source A and
Variant Source B . |
VarA == 1 && VarB !=
(1,2) | First input of Variant Source
A . |
VarA == 2 && VarB !=
(1,2) | Second input of Variant Source
B . |
VarA != (1,2) && VarB ==
1 | None |
VarA != (1,2) && VarB ==
2 | Second input of Variant Source
B . |
VarA != (1,2) && VarB !=
(1,2) | None |
Hierarchical Nesting of Sources or Sinks
In this model, multiple Variant Source blocks are used to
create hierarchical nesting of variant choices and provides variation on sensor
inputs . Multiple choices for sensors are first grouped by series: A
Series
, B Series
, and C
Series
. The Variant Source block, Device
Model
, selects a sensor from one of the series. The
Vendor
then chooses amongst the sensor choices provided
by Device Model
and XSensor
.
Simulink propagates complex variant control conditions to determine which model components are active during compilation.
For more information, see Hierarchical Nesting of Variant Sources and Variant Sinks.
Net Variant Condition
The net variant condition is the total of the local condition and its ancestral condition.
In this model, Variant Source
and Variant
Source1
are two single-input/single-output Variant
Source blocks with the variant conditions V==1
and W==1
, respectively. The Allow zero active
variant controls parameter is set to on
for
both the variant blocks. When this option is selected and there is no active
variant choice, Simulink disables all the blocks connected to the input and output stream
of the Variant Source block.
When you simulate this model, the Variant Source1
block and
other blocks within the Subsystem block receive a local condition
W==1
propagated from the Variant
Source1
block. The ancestral condition V==1
is
propagated from the Variant Source
block onto the
Subsystem block. Therefore, the net variant condition on the
Variant Source1
block and other blocks within the
Subsystem block is V==1 && W==1
.
If the Allow zero active variant controls parameter is set
to off
for the Variant Source block, then
condition on the Subsystem block is
W==1
.
Condition Propagation with Subsystems
A variant condition can activate or deactivate a Subsystem block, but variant conditions cannot propagate into the subsystem. A Subsystem block can propagate variant conditions from its output port if that variant condition originates at a port inside the subsystem.
A subsystem can either be a virtual (grouped or ungrouped) or an atomic subsystem depending on the selections made in its Block Parameters dialog box.
Grouped Virtual: Select the Treat as grouped when propagating variant conditions check box. A grouped virtual subsystem has a continuous line.
Ungrouped Virtual: Clear the Treat as grouped when propagating variant conditions check box. An ungrouped virtual subsystem has a dotted line.
Atomic: Select the Treat as atomic unit check box. An atomic virtual subsystem has a solid line.
Simulink propagates variant conditions differently to these subsystem types.
In this model, three types of subsystems are provided as input to the block
Variant Source2
.
The grouped virtual subsystem is activated when
V == 1
. Simulink propagates the variant activation condition to all the blocks in the subsystem.The ungrouped virtual subsystem is activated when
V == 2
. Simulink propagates the variant activation condition to the blocks that were available in the subsystem while marking the subsystem virtual.The atomic subsystem is activated when
V == 3
. Simulink does not propagate the variant activation condition into this subsystem.
For more information, see Propagate Variant Conditions from Variant Source Blocks to Subsystem Blocks.
Condition Propagation with Other Simulink Blocks
Variant Condition Propagation with Model Block
Simulink compiles referenced models before propagating variant conditions. A variant condition can activate or deactivate a Model block, but variant conditions cannot propagate into the referenced model. A Model block can propagate variant conditions from its interface (input, output, or control port), if that variant condition originates at a port inside the model.
In this example, variant condition V==1
activates the
Model block iv_20_model_reference_sub
.
However, the condition does not propagate into the model referenced by the
block. Model block iv_20_model_reference_sub2
propagates the same variant condition from its output port.
Variant Condition Propagation with Simulink Function block
Argument Inport and Argument Outport blocks interfacing with Simulink Function blocks cannot be connected to Variant Source or Variant Sink blocks. One variant condition must control the entire Simulink Function.
Consider the model
slexVariantSimulinkFunctionInherit
.
In this example, the function-call port block within the Simulink
Function block has the Enable variant condition
option selected. The (inherit)
keyword is used to specify the
value for the Variant control parameter. As a result, the
Simulink Function block inherits the variant condition from
the corresponding Function Caller blocks in the model. The
Generate preprocessor conditionals parameter value is
also inherited.
Note
Use the Configure C Step Function Interface dialog box to customize the generated C entry-point step function interface for a model. If input and output ports share an argument name and have propagated variant conditions, this level of interface control is not supported.
Variant Condition Propagation with Initialize, Reset, and Terminate Blocks
The Initialize, Reset, and Terminate function blocks are pre-configured subsystem blocks that execute during model initialize, reset, and terminate events. Similar to a Simulink Function block these blocks support variant condition propagation. You can propagate variant conditions in Model blocks that have Reset Event ports. This results in optimized existence of blocks connected to the Reset Event ports. Models with inactive Variant Reset Event functions (in referenced models) also supports variant condition propagation.
Note
Initialize and Terminate event ports are always unconditional because they control both the model default and block-specific initialize and terminate events of the referenced model. If you define an Initialize Function or Terminate Function block in the referenced model, it corresponds to an explicit initialize or terminate event.
If you enable variants and define a variant condition on the Initialize Function or Terminate Function block in the referenced model, the variant condition will not contribute to the variant condition of the Model block instance.
In this example, the Event Listener
block within the
Init
, Reset
, and
Term
blocks have the Enable variant
condition option selected. The Variant
control parameter of the Event Listener
block
is specified as V==0
. If you change the value of
V
to any value other than 0
, the
Init
, Reset
, and
Term
blocks become inactive.
Variant Condition Propagation with Bus
A Variant Source block can accept either virtual or nonvirtual bus inputs. When generating code with preprocessor conditionals, the bus types and hierarchies of all bus inputs must be the same.
However, all elements of a Mux, Demux, or a Vector Concatenate block signal must have the same variant condition.
For more information, see Variant Condition Propagation with Bus.
Variant Condition Propagation with Variant Connector block
A Variant Connector block propagates variant conditions to all the connected components within the physical network. See, Variant Connector (Simscape).
Limitations
Variant condition propagation from Simulink Function inside Stateflow block is not supported.
The Variant Connector block does not propagate the variant condition across the boundary between the Simscape™ physical network and the Simulink blocks connected to it.
Related Examples
- Propagate Variant Conditions from Variant Source Blocks to Subsystem Blocks
- Propagate Variant Conditions from Variant Source Blocks to Conditionally Executed Subsystems