Propagate Variant Conditions to Define Variant Regions with Variant Blocks
Variant condition propagation is the process whereby Simulink® determines which model components are active during simulation. This process evaluates the variant controls specified on the variant blocks and propagates the conditions of blocks using variant conditions. Variant conditions can propagate through signal lines, buses, and function calls to reach other blocks in the model. This process deactivates the model components associated with the inactive choices, and they are not included in the simulation. You can control the condition propagation to define the variant regions in the model. Simulink uses the variant activation time to determine 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.
Propagating the conditions of the blocks can:
Improve the accuracy of the model and avoid the manual computation of variant conditions. By propagating block conditions, you can ensure that each block is always in the correct state, and that the state is consistent across the entire model. This approach also makes it easier to modify and maintain your model over time, as you don't have to manually assign variant conditions to every dependent block. Instead, you can rely on the propagation mechanism to automatically manage the block states.
Reduce the computational load of your model and improve its performance. By using variant condition propagation, you can turn off the execution of blocks that are not currently active. Deactivating inactive components can help you manage the complexity of your model and make it easier to navigate.
Visualize Propagated Variant Conditions in Variant Conditions Legend
You can use the Variant Conditions Legend to visualize the propagated variant conditions that activate each variant choice. Simulink annotates model components if there are variant conditions on them, and the Variant Conditions Legend displays the condition that corresponds to each annotation.
Consider this model containing multiple variant choices feeding into the Variant Source blocks. A specific variant condition activates each variant choice.
To view the Variant Conditions Legend, on the Debug tab,
select Information Overlays > Variant Legend. If Variant Legend is not available, on the
Debug tab, select Information Overlays > Variant Conditions. Alternatively, to view the Variant Condition
Legend programmatically, use the variantLegend
function in the MATLAB® Command Window.
Note
Variant Conditions Legend does not display the variant conditions for variant parameters. Use the Variant Parameters tab in the Variant Manager window to view the values and variant conditions for choices of variant parameters.
By default, the Variant Conditions Legend displays these fields:
Annotation — Annotations for the variant conditions on the blocks. The variant conditions are annotated as
v:C
, wherev
is the variant semantic indicator andC
represents the variant condition index. You can click through the hyperlinked variant annotations to observe which parts of the model the variant condition corresponds to. For example, if you clickv:1
, the parts of the model that have the variant conditionV == 1
are highlighted.Simulation — Computed variant conditions on the blocks.
Workspace — Source of variant control variables in variant blocks. The variables can originate from a mask, a model, or a base workspace. All the variables used in a block must originate from a single source. If variables in a model come from different mask workspaces, they can share the same name, but their values must be different. To observe the source of the variables, click the hyperlinked workspaces. For more information, see Storage Locations for Variant Control Variables (Operands) in Variant Blocks.
Note
When you set the Variant activation time parameter to
update diagram
, the inactive choices are removed prior to the propagation of the signal attributes and are therefore not evaluated. As a result, the source of variables displayed for the inactive choices may be inaccurate.
To view the variant condition in the generated code, select Show generated code conditions.
When you pause on a block that has a variant condition, the tooltip displays the variant annotation and the related variant condition for the block. To view the variant condition annotation tooltip, you must select the Variant Condition option.
Variant condition annotations have these properties:
There are no annotations on unconditional blocks.
To reduce clutter, the legend displays only the final computed variant conditions. For example, if you enter a variant condition in a Variant Source block, that variant condition appears in the annotations only when you apply your changes.
The variant conditions in the legend are sorted alphabetically.
A variant condition is set to
false
if the blocks associated with that variant condition are never active.For example, the
Inport4
block is connected to theVariant Source1
block, whose variant condition isV == 1
.Variant Source1
is connected to theVariant Source2
block, which activatesVariant Source1
only whenV == 4
. Therefore,Inport4
can only be active whenV == 1 && V == 4
, a condition that is alwaysfalse
.The
(default)
variant condition is displayed as a negated condition. For example, the default choice of theVariant Source2
blockInport3
has a negated conditionW ~= 1
. During simulation, if none of the inputs toVariant Source2
is active, the default choiceInport3
becomes active. For more information of default choices, see Default Variant Choice.
Propagate Variant Conditions from Variant Blocks Upstream and Downstream
You can expand the variability control to any region of your model by automatically propagating variant conditions from variant blocks to other blocks upstream and downstream. Variant conditions can propagate through signal lines, buses, and function calls to reach blocks in a model affected by variant selection. For information on how variant conditions are constructed, see Assemble Variant Conditions Propagated from Variant Blocks.
Note
When variant control variables are defined within a mask or model workspace, the variant conditions that contain these variables are limited to the scope of that workspace and do not propagate beyond it. For more information, see Approaches to Control Active Variant Choice of a Variant Block Using Mask or Model Workspace.
This table lists the examples that explain how variant condition propagation works with different model components.
Example | Goal |
---|---|
Propagate Variant Conditions to Define Variant Regions Outside Variant Subsystems | Propagate the states of the underlying blocks outside of the parent variant block. |
Propagate Variant Conditions to Define Variant Regions Using Variant Source and Variant Sink Blocks | Propagate the states of the variant blocks to all their connected blocks. |
Variant Elements Within Buses | Reduce visual complexity by propagating variant conditions in composite signals. |
Propagate Variant Conditions to Define Variant Regions in Virtual and Nonvirtual Subsystems | Conditionally execute subsystem blocks using variant blocks. |
Propagate Variant Conditions to Control Execution of Conditional Subsystems | Conditionally provide input signals to conditional subsystems using variant blocks. |
Propagate Variant Conditions to Enable or Disable Model or Subsystem References in Hierarchy | Conditionally execute referenced models or subsystems using variant blocks. |
Conditionally Execute Custom Initialize, Reinitialize, Reset, and Terminate Routines | Conditionally execute custom model initialize, reset, and terminate routines using variant blocks. |
Conditionally Execute Simulink Functions | Conditionally execute Simulink functions (analogous to functions in a procedural programming language) using variant blocks. |
Control Variant Condition Propagation | Stop propagating variant conditions upstream and downstream. |
Limitations
Signals from variant blocks to a Mux, Demux, or Vector Concatenate block must have the same variant condition.