Variant Manager for Simulink
Note
This functionality requires Variant Manager for Simulink®.
In Model-Based Design for system development, you might have to use multiple design alternatives for components in the system. For example, in a model that represents an automobile, you might have several exhaust temperature sensors supplied by different vendors. Throughout the development life cycle, from requirements to deployment, you may need to switch between these design choices.
You might also model systems that represent a product line such as cars, aeroplanes, and communication systems. Product lines are created by adding variation points to a system. For example, vehicles in a product line of passenger cars can have multiple variation points such as fuel consumption, motor type, or engine size.
Instead of designing multiple models to represent all possible variants, you can use variant elements in Simulink to represent all the variations in a single model. For an introduction to variants in Simulink, see What Are Variants and When to Use Them.
Variant Manager
Variant Manager is a tool that allows you to visualize the model hierarchy and centrally manage the usage of variant elements such as variant blocks, variant parameters, and variant transitions across the hierarchy.
The tool is available as a support package named Variant Manager for Simulink with these main capabilities:
Variant Manager — Visualize the model hierarchy, manage the usage of variant elements across the hierarchy, and create and manage variant configurations.
Variant Reducer — Generate a reduced model that contains only selected variant configurations.
Variant Analyzer — Compare and contrast variant configurations to identify errors or inconsistencies.
Install Variant Manager for Simulink
To install the support package, use one of these methods:
Open Variant Manager:
In Simulink, on the Modeling tab, open the Design section and click Variant Manager. You can also use any of the alternate methods to open Variant Manager.
In the Install Variant Manager for Simulink dialog box, click Add. This action opens the Variant Manager for Simulink page in Add-On Explorer from where you can install the add-on.
Use Add-On Explorer:
In MATLAB®, on the Home tab, in the Environment section, click Add-Ons and then select Get Add-ons.
In the Add-On Explorer, find and click the Variant Manager for Simulink support package, and click Install.
When you execute any Variant Manager related APIs from the MATLAB Command-Line, the APIs return an error with a hyperlink to launch the installer.
For information on the behavior changes in the support package, see Compatibility Considerations When Using Variant Manager for Simulink Support Package.
Open Variant Manager
Use any of these methods to open Variant Manager:
Right-click the variant badge icon on any variant block and select Open in Variant Manager.
On the Modeling tab, open the Design section and click Variant Manager.
Right-click a variant block and select Variant > Open in Variant Manager.
Select a variant block, for example, a Variant Subsystem block, and then in the Variant Subsystem tab of the Simulink toolstrip select Variant Manager.
Click Open block in Variant Manager available on the variant block’s Block Parameter dialog box.
Tip
You can also open Variant Manager without a Simulink model to manage variant configurations and constraints. See Use Variant Manager Without Simulink Model.
Explore Variant Manager Window
This image shows the default view of the Variant Manager window for the
slexVariantManagement
model. To open the model, run the below
command from the MATLAB Command-Line.
openExample("simulink_variants/VariantManagementInSimulinkExample","supportingFile","slexVariantManagement.slx");
You can change the layout of the window according to your preference. To move a pane, click at the top of the pane and drag.
You can minimize unused panes. When you want to work on a minimized pane again, restore it to stop it from collapsing automatically.
The Getting Started pane appears on the right side of the window by default and provides a quick overview of the common workflows.
You can use the Help button in the top right corner of the Variant Manager window to access the documentation.
The Diagnostics pane appears at the bottom of the window by default and displays messages, errors, and warnings related to the actions performed from the Variant Manager.
This image shows a custom layout of the window.
Manage Variant Elements
Visualize Model Hierarchy
The model hierarchy table presents a tree view of the model where each node represents a block or a referenced component. You can expand the nodes and navigate the hierarchy.
To get different views of the model hierarchy, use these tabs:
System — Displays all blocks
Blocks — Displays variant blocks
Stateflow — Displays variant transitions used in Stateflow® charts
Variant Parameters — Displays variant parameters defined in the base workspace or data dictionaries associated with the model
Component Configurations — Displays available variant configurations for referenced components
Note
When you open the Variant Manager for a top-level model, variant elements inside referenced components such as Model blocks, Subsystem Reference blocks, and libraries are not loaded. The referenced components are loaded and activated only when you explicitly activate the model or expand them in the model hierarchy.
The Component Configurations tab is not shown by default. To open the tab, click the Show Component Configurations button in the Control Variables section of a selected variant configuration.
Interact with Model Hierarchy
You can perform these actions from the model hierarchy.
Action | Model Hierarchy Interaction |
---|---|
Edit the variant condition expression for variant blocks and transitions | The Variant control expression column in the table is similar to the Variant control field in the block parameter dialog box of variant blocks. You can edit this field for variant elements in the hierarchy. For
variant elements, the field shows a list of
context-specific keywords that are allowed as the
variant control for a variant block. For example, for a
Variant Subsystem with Variant control
mode set to
|
Edit variant parameter objects | In the Variant Parameters tab,
you can edit the |
View variant parameters used by model hierarchy for a configuration | The Variant Parameters tab
shows all To view only the variant parameters used by the model hierarchy:
|
View variant parameters individually or grouped by variant parameter bank | In the Variant Parameters tab, select Bank to switch to a view in which the parameters are grouped based on the variant parameter bank they belong to. The view shows parameters that are not part of any variant bank in a separate section and groups them by variant conditions. The Choice view shows variant parameter choices per row. These images show the views for the Choice and Bank options for a model. By Choice: By Bank: |
Search | Use the Search in model hierarchy view button to search for any element in the hierarchy. |
See block parameter values | Point to any variant block to see a tooltip with the block parameter values. |
See context menu | Right-click an element in the table to find these context-specific options:
|
Filter variant blocks by their Variant control mode | Use the View list in the Blocks tab of the model hierarchy. |
Show or hide the usage of control variables in a configuration in the model hierarchy |
Alternatively, right-click the variable in the control variables table and select Show usage or Hide usage. |
Navigate the model hierarchy based on filters | Use the Navigate list along with the buttons to step through the model hierarchy based on these filters:
Note: This functionality is not supported for variant parameters. |
Identify active variant choices | The inactive choice appears greyed out. |
Identify rows with errors | They are highlighted in red. |
Identify type of block by the block icon | For the list of block icons, see Model Hierarchy Table. |
Manage Variant Configurations
Create and Activate Variant Configurations
A variant configuration represents a combination of variant choices across the model hierarchy. From Variant Manager, you can:
Create a named variant configuration.
Create a temporary configuration in the base workspace or data dictionary used by the model.
Add, import, export, and edit control variables in a configuration.
Select referenced component configurations. If referenced components such as referenced models in the model hierarchy have existing variant configurations of their own, you can use them to set up the top-level configuration.
Add constraints applicable for all configurations.
Validate and activate a configuration on a model.
Set a preferred variant configuration for a model.
Apply a valid configuration on the model for simulation.
For an overview of variant configurations, see Variant Configurations.
For steps to create a variant configuration, see Create and Activate Variant Configurations.
For information on composing top-level configurations using referenced component configurations, see Compose Variant Configurations for Top Model Using Referenced Model Configurations.
Obtain and Use Model Compilation Information in Variant Manager
Since R2024b
You can obtain and use model compilation information in Variant Manager to
produce more accurate results for user workflows such as importing control
variables to a configuration, activation, and identifying variant parameters
used by the model hierarchy. To obtain model compilation information, click
Update Model in the Variant Manager toolstrip or use
the Simulink.VariantManager.updateModel
function. Variant Manager
uses the compilation information subsequently in these scenarios:
If a model defines variant control variables in the model or mask workspaces, Variant Manager supports them in these operations:
When you import variant control variables to a configuration, the operation adds any control variables defined in the mask workspace and model workspace to the configuration. When you activate such a configuration, activation results are based on the mask and model workspace control variable definitions in the configuration.
If the mask initialization code of a block defines variant control variables, Variant Manager verifies that the definitions of these variables within a configuration are consistent with those in the mask initialization code.
The variant control variable usage option shows the variable usage in the model hierarchy pane based on the model or mask workspace in which the variable is defined.
If a model's
InitFcn
callback defines variant control variables in the base workspace or in a linked data dictionary, importing control variables adds these variables to a configuration. Variant Manager verifies that the definitions of these variables within a configuration are consistent with theInitFcn
callback specifications.Variant Manager identifies the variant parameters used by the model hierarchy. It then considers only these parameters for subsequent activation and importing of variant control variable operations.
Once Variant Manager has the compilation information, it reuses the information until you update the model again.
Auto-generate Variant Configurations
Creating all possible variant configurations for a model manually can be time consuming. You must activate them individually to check if they are valid and if they satisfy necessary constraints. Instead, you can automatically generate variant configurations for a model using Variant Manager, which enables you to:
Consider all possible combinations of variant control variables while creating configurations.
Specify the value range that must be considered for each control variable, to generate only the required subset of configurations.
Specify preconditions to restrict the configurations to generate, and optionally export the preconditions as constraints.
Automatically validate generated configurations to identify invalid cases.
Generate valid, valid and unique, or all configurations.
Export the configurations to a variant configuration data object. You can export valid configurations for which the model compiles successfully or all configurations including invalid ones.
For detailed steps to generate variant configurations, see Generate Variant Configurations Automatically.
Save Variant Configurations
You can use a variant configuration data object of type Simulink.VariantConfigurationData
to manage and reuse variant configurations
for a model. The object stores all the variant configurations and constraints created for a
model. You can define the object in the base workspace or in the
Configurations section of a data dictionary. If the model is not
associated with a variant configuration data object, Variant Manager helps you to setup a
new variant configuration data object.
From the Manage tab in Variant Manager, you can:
Specify a name for the variant configuration data object for the model.
Apply the changes made to the variant configuration data object from Variant Manager to the base workspace or data dictionary used by the model.
Export the variant configuration data object to a MAT-file or MATLAB script file.
Import a variant configuration data object from a MAT-file or MATLAB script file into Variant Manager.
Reload the object from the base workspace or data dictionary used by the model. This allows you to revert the changes that are not yet exported to the data sources used by the model.
When you export the variant control variables in a variant configuration or when you activate a variant configuration, the control variables are pushed to the data sources where the variables are stored. Reloading the variant configuration object from Variant Manager does not revert these changes.
Disassociate the variant configuration data object from the model.
For an example that shows how to perform these actions from Variant Manager, see Save and Reuse Variant Configurations Using Variant Configuration Data Object.
The Simulink.VariantConfigurationData
class has methods that enable you to
add or remove variant configurations, constraints, and control variables.
Use Variant Configurations in Simulation and Testing Workflows
Since R2024a
When you run simulations for your variant model programmatically, you can specify the
variant configuration to apply to the model during simulation. For simulation functions such
as sim
, parsim
, and batchsim
,
you can set the VariantConfiguration
property in the Simulink.SimulationInput
object. For an example, see Run Simulations for Variant Models Using Variant Configurations.
You can specify the variant configuration to use when running a test case or a test iteration on a model from Simulink Test Manager (since R2024b) or by using the Simulink Test™ programmatic interface. For an example, see Run Tests for Variant Models Using Variant Configurations.
Use Variant Manager Without Simulink Model
You can define and edit variant configurations and constraints without a
Simulink model. To use this workflow, create a Simulink.VariantConfigurationData
object in the base workspace or in the Configurations
section of a data dictionary. Open Variant Manager by double-clicking the
object. From this dialog box, you can modify variant configurations, control
variables, and constraints in the variant configuration object. The Import
control variables from model data source button allows you to import variant control
variables of type Simulink.VariantControl
defined in the base
workspace or a data dictionary linked to the model even if the variant control
is not yet used by the model. In top-down variant management workflows where you
may need to define variant configurations before setting up variation points in
the model, this operation allows you to access the variant controls that you
have already defined in a data source from Variant Manager.
Reduce a Variant Model
You can use Variant Reducer to generate simplified, stand alone models that contains only the specified set of variant configurations from the parent model. For example, to generate a model that maps to a specific product from a product line (single configuration reduction), or that which corresponds to a product line from a product line family (multi-configuration reduction).
To open Variant Reducer, in the Variant Manager toolstrip, in the APPS section, click Variant Reducer.
Variant Reducer performs these high-level operations during the reduction process:
Removes inactive model components based on the variant configurations that you choose to retain in the reduced model.
Removes or modifies model components such as blocks, variant parameter objects, masks, model references, subsystem references, libraries, dependent files, and variables in the input model to create the reduced model.
Packages the reduced model and related artifacts into a user-specified output folder.
Generates a detailed summary of the reduction process that helps you to analyze these changes.
Analyze Variant Configurations
You can use Variant Analyzer to analyze and compare the variant configurations for a model. To open Variant Analyzer, in the Variant Manager toolstrip, in the APPS section, click Variant Analyzer.
You can analyze the named variant configurations created for a model or perform an analysis after setting values for the variant control variables. The variant analysis report generated by the app helps you to:
Compare different variant configurations for a model to understand the common and differing model elements used between them.
Check if all variant choices have been activated at least once and whether the model is covered completely for simulation and code generation.
Verify if the active, implemented model is different between different variant configurations.
Find the dependent model artifacts such as referenced models and libraries used by a particular variant configuration.
See, Analyze Variant Configurations in Models Containing Variant Blocks.
Icons in Variant Manager
Configurations
Button | Description |
---|---|
Add a variant configuration. | |
Delete a variant configuration. | |
Copy a variant configuration. |
Control Variables
This table lists the icons used to represent different types of control variables.
Control Variable Icon | Type of Control Variable |
---|---|
Normal MATLAB variable | |
Simulink.Parameter or
AUTOSAR.Parameter | |
Simulink.VariantControl with value as normal
MATLAB variable | |
|
Control Variables Section
Button | Description |
---|---|
Import control variables from the entire model
hierarchy by default. To import variant control variables of
type Note Control variables from blocks in
| |
Add a control variable. | |
Create a copy of a control variable. | |
Delete a control variable. | |
Change the data type of a control variable. | |
Edit Note To specify | |
Show usage of selected control variables. | |
Hide usage of selected control variables. | |
Show or hide the VAT and Source columns in the table. | |
Export control variables to data sources where the variables are stored. | |
Filter the table based on type of control variables. |
Component Configurations Tab
Icon | Purpose |
---|---|
This icon next to a referenced model in the Component Configurations view indicates that the referenced component has its own predefined variant configurations. |
Model Hierarchy Table
Icon | Element |
---|---|
Model block with Simulation
mode set to | |
Model block with Simulation
mode set to
| |
Inline Variant Blocks (Variant Source and Variant Sink) | |
Variant Subsystem block | |
Subsystem block | |
Variant Model block | |
Subsystem Reference block | |
Simulink Function block | |
Trigger port block | |
Stateflow chart block | |
Variant Sink output port | |
Variant Source input port | |
Variant Subsystem block with Propagate conditions outside of variant subsystem option selected. | |
Variant Subsystem block with
Variant activation time set to
| |
Variant Subsystem block with
Variant activation time set to
| |
Variant Subsystem block with
Variant activation time set to
| |
Variant Subsystem block with
Variant activation time set to
| |
Variant Subsystem block with
Variant activation time set to
| |
Variant Subsystem block with
Allow zero active variant controls
selected and Variant activation time
set to | |
Variant Subsystem block with
Allow zero active variant controls
selected and Variant activation time
set to | |
Variant Subsystem block with
Allow zero active variant controls
selected and Variant activation time
set to | |
Variant Subsystem block with
Allow zero active variant controls
selected and Variant activation time
set to | |
Variant Subsystem block with
Variant control mode set to
| |
Variant Subsystem block with
Variant control mode set to
| |
Variant Subsystem block with
Variant control mode set to
| |
Variant Subsystem block with
Propagate conditions outside of variant
subsystem and Variant activation
time set to | |
Variant Subsystem block with
Propagate conditions outside of variant
subsystem and Variant activation
time set to | |
Variant Subsystem block with
Propagate conditions outside of variant
subsystem and Variant activation
time set to | |
Variant Subsystem block with
Propagate conditions outside of variant
subsystem and Variant activation
time set to
| |
Variant Subsystem block with
Propagate conditions outside of variant
subsystem option selected. Also,
Variant control mode is set to
| |
Inline Variants Block (Variant Source and Variant Sink) with Allow zero active variant control option selected. | |
Inline Variants Block (Variant Source
and Variant Sink) with Variant
control mode set to
| |
Inline Variants Block (Variant Source
and Variant Sink) with Variant
control mode set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Variant
control mode set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Variant
activation time set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Variant
activation time set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Variant
activation time set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Variant
activation time set to
| |
Inline Variants Block (Variant Source
and Variant Sink) with Allow zero
active variant control and Variant
activation time set to | |
Inline Variants Block (Variant Source
and | |
Inline Variants Block (Variant Source
and Variant Sink) with Allow zero
active variant control and Variant
activation time set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Allow zero
active variant control and Variant
activation time set to
| |
Variant Assembly Subsystem block with
Variant control mode set to
| |
Variant Assembly Subsystem block with
Variant control mode set to
| |
Variant Assembly Subsystem block with
Variant control mode set to
| |
Variant Assembly Subsystem block with
Variant control mode set to
| |
Variant Assembly Subsystem block with
Variant control mode set to
| |
Variant Assembly Subsystem block with
Propagate conditions outside of variant
subsystem option selected, Variant
control mode set to
| |
Variant Assembly Subsystem block with
Propagate conditions outside of variant
subsystem option selected, Variant
control mode set to
| |
Variant Assembly Subsystem block with
Propagate conditions outside of variant
subsystem option selected, Variant
control mode set to
| |
Variant Assembly Subsystem block with
Propagate conditions outside of variant
subsystem option selected, Variant
control mode set to
| |
Variant Start block with Variant
activation time set to update
diagram . | |
Variant Start block with Variant
activation time set to update
diagram analyze all choices . | |
Variant Start block with Variant
activation time set to code
compile . | |
Variant Start block with Variant
activation time set to
startup . | |
Variant Start block with Variant
control mode set to
label . | |
Variant Start block with Variant
control mode set to sim codegen
switching and Variant activation
time set to update
diagram . | |
Variant Start block with Variant
control mode set to sim codegen
switching and Variant activation
time set to update diagram analyze
all choices . | |
Variant End block with Variant
activation time set to update
diagram . | |
Variant End block with Variant
activation time set to update
diagram analyze all choices . | |
Variant End block with Variant
activation time set to code
compile . | |
Variant End block with Variant
activation time set to
startup . | |
Variant End block with Variant
control mode set to
label . | |
Variant End block with Variant
control mode set to sim codegen
switching and Variant activation
time set to update
diagram . | |
Variant End block with Variant
control mode set to sim codegen
switching and Variant activation
time set to update diagram analyze
all choices . | |
Initialize Function block | |
Event Listener block of Initialize Function block | |
Reset Function block | |
Event Listener block of Reset Function block | |
Terminate Function block | |
Event Listener block of Terminate Function block | |
Stateflow chart with Variant activation
time set to | |
Stateflow chart with Variant activation
time set to | |
Stateflow chart with Variant activation
time set to
| |
Stateflow transition with Treat as Variant Transition option selected. | |
◯ | Connective junction in a Stateflow chart |
• | Default transition in a Stateflow chart |
⬤ | Entry port in a Stateflow chart |
⭙ | Exit port in a Stateflow chart |
Note
For variant blocks with Variant activation time set
to Inherit from Simulink.VariantControl
, the
variant manager activation process updates the variant badge for the block
in the model hierarchy to indicate the activation time that is computed from
the corresponding Simulink.VariantControl
variables.
Access the Variant Manager Functionality Programmatically
The Simulink.VariantManager
namespace provides a set of functions
to access Variant Manager functionality from the MATLAB Command Line.
The Simulink.VariantConfigurationData
class has methods to add or remove variant configurations, constraints, and control
variables programmatically.
The Simulink.VariantConfigurationAnalysis
class has methods to analyze or
compare variant configurations programmatically.
Limitations
Variant Manager reports errors and warnings related to variant elements only.
The model hierarchy table does not show protected referenced models.
Variant Manager constraints are evaluated based on the values of variant control variables defined in the base workspace or data dictionaries linked to the model.
Variant Manager constraints are not validated post compilation, for example, at
startup
variant activation time.For a variant block, you can define variant configurations only if the Variant control mode parameter of the block is set to
expression
.Variant Manager does not support workflows such as activation, viewing, or importing of control variables from variations inside a protected model. These variations are present when variant control variables of variant blocks with startup activation time are specified as
TunableParameters
(Simulink Coder) while creating the protected model.Variant Manager does not support creating or deleting variant parameter objects from the Variant Parameters tab.
See Also
Simulink.VariantConfigurationData
| Simulink.VariantConfigurationAnalysis
Related Topics
- Compatibility Considerations When Using Variant Manager for Simulink Support Package
- Variant Configurations
- What Are Variants and When to Use Them
- Simulink Variant Examples
- Manage, Configure, Reduce, and Analyze System Variants with Variant Manager for Simulink
- V-Model for System Development with Simulink Variants