What Are Variants and When to Use Them
What Are Variants?
In Model-Based Design workflows, creating multiple design variations for system components is essential to meet different sets of requirements. These requirements can cater to diverse market needs, customer preferences, or geographical features. Throughout the development lifecycle, from requirements to deployment, you may need to switch between these design choices.
Simulink® variant capabilities allow you to represent all design alternatives of a system in a single model. Each design choice is incorporated into the model as a variant choice. Such models have a fixed common structure and a finite set of variable components that are activated depending on the variant choice. This model shows how Variant Source blocks help you implement variant choices for the input signals to a system. The inactive choice appears faded.
For an example, see Use Variants to Create One Model for Many Systems.
Advantages of Using Variants
Using variants in Model-Based Design provides several advantages:
Variants allow you to design one model for many systems.
You can rapidly prototype design possibilities as variants without having to comment out sections of your model.
Variants help you develop modular design platforms for reuse and customization. This approach improves workflow speed by reducing complexity.
If a model component has several alternative configurations, you can explore the alternatives without altering the fixed components.
You can use different variant configurations for simulation or code generation from the same model.
You can simulate every design possibility for a given test suite.
If you are working with large-scale designs, you can distribute the process of testing these designs on a cluster of multicore computers. Alternatively, you can map different test suites to design alternatives for efficient management of design-specific tests.
You can generate a reduced model for a subset of variant configurations from a model with many variants.
When to Use Variants
Here are three scenarios where you can use variants.
Models that represent multiple simulation, code generation, or testing workflows.
Models that contain multiple design choices at the component level.
|Models that are mostly similar but have slight variations, such as in cases where you want to separate a test model from a debugging model. The test model on the left has a fixed design. On the right, the same test model includes a variant that is introduced for debugging purposes.||
Types of Variants in Simulink
Variant blocks help you represent multiple structural or algorithmic implementations of a system component in a single model and allow you to switch between them as per requirements. For an overview of the types of variant blocks in Simulink, see Variant Blocks in Simulink.
Variant parameters help you implement design variations that require varying values for block parameters. For more information, see Use Variant Parameters to Reuse Block Parameters with Different Values.
Variant transitions allow you to transition to multiple design configurations within the same Stateflow® chart. For more information, see Code Generation Using Variant Transitions (Stateflow).
Dimension variants allow you to specify symbolic dimensions that vary based on variant conditions. See Implement Dimension Variants for Array Sizes in Generated Code (Embedded Coder).
AUTOSAR variants enable you to use variant blocks to implement AUTOSAR software components with variation points. See Model AUTOSAR Variants (AUTOSAR Blockset).
Variant Blocks in Simulink
Use these variant blocks depending on the model design:
Hierarchical variant blocks to create multiple implementations of a component in a separate hierarchy in the model.
Inline variant blocks to represent all variant implementations at the same level in the model.
Event-based variants to use variants to model context-dependent system behaviors.
|Type of Variant||Variant Block||Use|
|Hierarchical variant blocks||Variant Subsystem|
The Variant Subsystem block is a template preconfigured with Subsystem blocks to represent the variant choices.
The Variant Subsystem block allows a combination of Subsystem blocks, Model blocks, or Subsystem Reference blocks as variant choices.
The Variant Model block is a template preconfigured with two Model blocks to represent the variant choices.
The Variant Model block allows a combination of Subsystem blocks, Model blocks, or Subsystem Reference blocks as variant choices.
|Inline variant blocks||Variant Source||The Variant Source block allows you to define variant choices as block regions connected to each of its inports. The block provides variation on the source of a signal.|
|Variant Sink||The Variant Sink block allows you to define variant choices as block regions connected to each of its outports. The block provides variation on the destination of a signal.|
|Manual Variant Source||The Manual Variant Source block is a toggle switch that allows you to define multiple variant choices at its inports.|
|Manual Variant Sink||The Manual Variant Sink block is a toggle switch that allows you to define multiple variant choices at its outports.|
|Variant Connector (Simscape)||The Variant Connector block lets you define variant choices in a physical network. You can switch between components in the network during simulation without having to physically remove the components or exclude them from simulation.|
|Event-based variants||Simulink Function||The variant functionality in the Simulink Function block allows the block to be conditionally available. You can specify variant conditions on the function call port block or the block can inherit the condition from its function caller blocks.|
|Initialize Function, Reset Function, and Terminate Function blocks||The variant functionality in Initialize, Reset, and Terminate blocks allow the blocks to be conditionally available. You can specify variant conditions on the event listener block.|
Compare Variant Blocks
This table presents a comparison between hierarchical and inline variant blocks.
Variant Source and Variant Sink blocks
Variant Subsystem and Variant Model blocks
Variant choice representation
Number of ports
Subsystem, Model, or Subsystem Reference blocks
Allows to implement variant choices in a separate hierarchy
Supports flexible number of inputs and outputs among variant choices (the choices do not have similar interface)
Yes, if the Propagate conditions outside of
variant subsystem parameter is set to
Option to specify default variant
Supports control ports
Can be saved as standalone file
Supports Connection Port used for modeling physical connection lines
Only when the Variant activation
time parameter is set to
Comment a variant choice (by adding the
Use Variants to Create One Model for Many Systems
This example shows variant design in a Simulink model. Consider the requirement to model a system that represents an automobile with several configurations. These configurations, although similar in several aspects, can differ in properties such as fuel consumption, motor type, or emission standard.
Instead of designing separate models for each configuration, you can represent the configurations as variant choices in a single model. You can choose to activate any one of the variant choices based on your requirements. This approach keeps the common components fixed.
This model contains a Variant Subsystem block,
Variant Subsystem, that represents the motor of the vehicle. The motor
has two possible configurations,
Electric, that are represented as variant choices within the
Variant Subsystem block. A Variant Subsystem block
adapts its interface according to the state of the underlying blocks. Here, the
Electric motor does not have an
temperature input. When you activate the
variant, Simulink automatically disables the corresponding port on the
Variant Subsystem and any other model components associated with that
exhaust temperature sensor for this model, consider the
need to switch between five different sensors provided by two vendors. You can use
Variant Source blocks to represent all the choices in the same
model and activate only one choice at a time.
Working with Variants
Visual Elements in Variant Models
|Variant Condition Legend|
The Variant Condition Legend dialog box helps you visualize the variant conditions applied on the model. Simulink annotates model components that have variant conditions, and the Variant Condition Legend displays the conditions for each annotation. See Visualize Propagated Variant Conditions Using Variant Conditions Legend.
Each variant block displays a badge that changes with different parameter values set on the block. See Variant Badges.
|Variant Fading and Signal Highlighting|
The color of inactive variant choices fades by default. You can choose to disable the fading effect by using the Variant Fading option in the Information Overlays menu on the Debug tab of the Simulink Editor.
Highlighting a signal that passes through variant blocks highlights the path of the active variant choice. See Signal Highlighting in Variant Systems.
Each variant block displays a badge. The color and icon of the variant badge changes according to values of these parameters set on the block:
Variant activation time
Variant control mode
Allow zero active variant controls (for Variant Source and Variant Sink blocks)
Propagate conditions outside of variant subsystem (for Variant Subsystem block)
Variant Badges also provide quick access to some variant commands. Right-click the variant badge to access these commands.
Define and Control Variant Choices
You must associate each variant choice in a model with a variant control that is used to determine if the choice is active or inactive. For variant blocks, you can choose the mode in which you want to specify the variant controls using the Variant control mode parameter. For more information, see Introduction to Variant Controls.
Automatically Identify Variant Regions Using Variant Condition Propagation
Simulink determines the model components that are active during simulation by the process of variant condition propagation. This process evaluates the variant controls specified on the variant blocks and automatically propagates the variant conditions to the connecting blocks. Variant conditions can propagate through signal lines, buses, and function calls. The process deactivates the model components associated with the inactive choices and they are not included in simulation. You can stop condition propagation to define variant regions in the model. See Variant Condition Propagation Overview.
Choose a Variant Activation Time
You can also choose when the active variant choice is determined using the Variant activation time parameter. This parameter also determines how the active and inactive choices participate in the simulation and code generation workflows. See Activate Variant During Different Stages of Simulation and Code Generation Workflow.
You can choose the variant activation time for a variant block only when
Variant control mode is set to
Manual Variant Source and Manual Variant Sink blocks do not support variant controls and variant activation time. They determine the active variant choice based on the active inports and outports, respectively.
Variant Connector blocks do not support variant activation time.
Manage All Variants Using Variant Manager
The Variant Manager is a central tool that allows you to manage all variation points in a model. The tool helps you to visualize the model hierarchy and the usage of variants at all levels. See Variant Manager Overview.
Create and Activate Variant Configurations:
A model hierarchy may contain several variant blocks, each with many variant choices. Combinations of these variant choices correspond to specific configurations of the system. Switching between these configurations and validating them manually can be complicated and can introduce errors. You can use the Variant Manager to create predefined configurations for a model and run the model under any of the configurations. You can also validate the configurations against a set of constraints.
Analyze and Reduce Variant Configurations:
You can use the Variant Configuration Analysis tool in the Variant Manager to compare variant configurations for a model and to determine which blocks are used in each configuration. The tool helps in model verification and validation workflows because it can identify unused regions in the model.
You can use the Variant Reducer tool in the Variant
Manager to automatically generate a reduced model for a subset of variant
configurations and analyze the reduced model in a detailed report. The reduction
process removes inactive components for the specified variant configurations.
Variant Reducer reduces associated model references, subsystem references, and
libraries in the model. The tool also reduces any dependent artifacts, such as
.sldd files, and packages all the reduced artifacts in
a specified output folder. An example use case for the tool is a vendor-supplier
Generate Code from Variant Models
You can use Simulink Coder™ or Embedded Coder® to generate code from variant models. See Prepare Variant-Containing Model for Code Generation.
For examples that show variant code generation capabilities, see Variant Systems (Embedded Coder).
- Variants Example Models
- Create a Simple Variant Model
- Create a Simple Variant Parameter Model
- Create and Validate Variant Configurations
- Variant Subsystems
- Variant Source and Variant Sink Blocks
- Code Generation Using Variant Transitions (Stateflow)
- Transform Model to Variant System (Simulink Check)
- Create Custom Check to Evaluate Active and Inactive Variant Paths from a Model (Simulink Check)
- Variant System Design
- Variant Terminology
- Introduction to Variant Controls
- Working with Variant Choices
- Create and Validate Variant Configurations
- Managing Design Variants
- Using Variant Subsystems (3 min, 38 sec)
- Variant Source and Sink Blocks with Condition Propagation
- Variant Condition Propagation
- Variant Configuration Management
- Generate Code from Variant Source and Sink Blocks
- Model AUTOSAR Variants