Manage, Configure, Reduce, and Analyze System Variants with Variant Manager for Simulink
This example provides an overview of the Variant Manager tool in Simulink®.
In Model-Based Design for system development, components can have multiple design alternatives. You can represent these design alternatives in a single Simulink model by using variant elements such as variant blocks, variant parameters, and variant transitions. For more information on variants, see What Are Variants and When to Use Them.
Variant Manager allows centralized management of variant elements across the model hierarchy. This tool helps you create or generate variant configurations, allowing you to represent multiple variant designs as combinations of variant choices. You can then activate, save, reduce, and analyze these configurations.
Explore Example Model
Open the model slexVariantManagement
.
The slexVariantManagement
model uses variant elements in Simulink to implement a plant controller feedback system. The system aims to control and regulate the behavior of a plant based on feedback received from sensors. The plant component represents the physical system or process under control. The controller component is responsible for generating control signals based on the feedback received from the plant.
open_system("slexVariantManagement");
Modeling Elements Used
Blocks
The Controller
and Plant
components are modeled using Variant Subsystem blocks, which allows you to represent multiple implementations (variants) of a component in a separate hierarchy within the same model and then conditionally switch the active variant based on requirements.
The Smart Controller
and External
plant are choices of the Controller
and Plant
variant subsystems, respectively. These components use Model blocks that help you to create model hierarchy by referencing another model in the top-level model.
The Internal
plant is a choice of the Plant
variant subsystem. The component is implemented using a Variant Assembly Subsystem block that references model files. This block enables you to specify the source of variant choices once and then later modify only the source to add or remove choices from the block without opening the block or modifying the model.
Variant Parameters
The model uses variant parameters (Simulink.VariantVariable
objects) to represent block parameters whose values vary conditionally.
The Nonlinear Controller
contains a 1-D Lookup Table block that uses the Simulink.VariantVariable
objects LUTBPs
and LUTData
to store the breakpoints and table data. These variant parameters have two sets of choice values corresponding to high- and low-fidelity levels and each set of values has a different dimension.
The Linear Controller
and Nonlinear Controller
blocks also use a variant parameter Kc
to set the value of a Gain block based on the type of controller.
To represent dimensions as symbols in the generated code, the configuration parameter Allow symbolic dimension specification is enabled. To represent the variant parameters using symbolic names in the generated code, the Default parameter behavior configuration parameter is set to Tunable
.
Variant Controls and Variant Activation Time
All variant blocks in the model use variant control variables of type Simulink.VariantControl
and have their variant activation time set to inherit from Simulink.VariantControl
. As a result, all the blocks that use the same control variable have the same activation time and are activated simultaneously.
The control variables used in the Plant
component have activation time set to update diagram
because they are not used in code generation. Remaining control variables in the model have activation time set to code compile
so that the generated code includes all the choices.
Install Variant Manager for Simulink Support Package
You can install the Variant Manager for Simulink support package from the Add-On Explorer. For detailed steps, see Install Variant Manager for Simulink.
Open Variant Manager
On the Modeling tab, open the Design section and click Variant Manager.
Overview of Variant Management Use Cases
Visualize and Interact with Model Hierarchy
Variant Manager provides a tree view of the model hierarchy where each node represents a block or a referenced component. Multiple tabs present different views of the hierarchy in which you can manage variant blocks, variant transitions, and variant parameters. To learn how to interact with the model hierarchy, see Interact with Model Hierarchy.
Define Variant Configurations and Constraints
Variant configurations represent multiple modes of operation of a system, for example, a linear controller with an internal plant with no noise
or a nonlinear controller with an external low fidelity plant
. Variant Manager defines a variant configuration as a set of variant control variables and their values that can activate a specific variation in the model hierarchy. You can create multiple named variant configurations for a model, or you can create variant control variables in the data sources used by the model to use as a temporary variant configuration for the model. For more information on variant configurations, see Variant Configurations.
You can create constraints, which are user-defined checks that you can use to prevent invalid variant configurations in a model. For example, you can create a constraint that checks that a Linear
controller in a system does not have an External
plant. Simulink validates the variant configurations that you create for a model against these constraints during Variant Manager activation, update diagram, simulation, and code generation workflows.
This image shows the high-level workflow to create and save a new named variant configuration for a model from Variant Manager. For detailed steps, see Create and Activate Variant Configurations. For programmatic interface, use the Simulink.VariantConfigurationData
class.
Use Model Compilation Information in Variant Manager
(since R2024b)
You can obtain 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. See Obtain and Use Model Compilation Information in Variant Manager.
Generate Variant Configurations
You can automatically generate variant configurations for a model using Variant Manager. This image shows the Generate Configurations window in Variant Manager.
This image shows the steps to generate configurations. For more information, see Generate Variant Configurations Automatically. To generate variant configurations programmatically, use the Simulink.VariantManager.generateConfigurations
method.
Activate Variant Configuration on Model
When you activate a variant configuration using Variant Manager, the tool checks that the variant elements in the model and the variant configuration are set up correctly. It also evaluates the configuration against applicable constraints. Once validated, Variant Manager applies the configuration to the model. You can easily switch between configurations, activate them, and then inspect the model hierarchy table to visualize the active and inactive elements in those configurations. You can also compile, simulate, or generate code from the model for the active configuration.
For detailed steps to create and activate a variant configuration, see Create and Activate Variant Configurations. To activate a variant configuration programmatically, use the Simulink.VariantManager.activateModel
method.
Compose Top Model Configurations Using Referenced Component Configurations
The variant configurations for a top-level model must also define the variant control variables used by any referenced components in the model hierarchy, such as referenced models. If the referenced component has existing named variant configurations of its own, you can use them to set up the corresponding variant control variables in the top-level model configuration. For more information, see Compose Variant Configurations for Top Model Using Referenced Model Configurations.
This image shows how to use the Component Configurations tab in the model hierarchy pane to select a referenced component configuration.
Save and Reuse Variant Configurations
Use a variant configuration data object of type Simulink.VariantConfigurationData
to store and reuse variant configurations and constraints for a model. You can define the object in the base workspace or in the Configurations section of a data dictionary. If you define the object in the base workspace, you can export the object to a MAT-file or MATLAB® script and import it back into Variant Manager later. For an example, see Save and Reuse Variant Configurations Using Variant Configuration Data Object.
Run Simulations and Tests Using Variant Configurations
You can programmatically run single or multiple simulations on a model using variant configurations (since R2024a). See, Run Simulations for Variant Models Using Variant Configurations.
When running a test case or a test iteration on a model, you can specify the variant configuration to use from Simulink Test Manager (since R2024b) or by using the Simulink Test™ programmatic interface (since R2024a). See Run Tests for Variant Models Using Variant Configurations.
Reduce Variant Model
You can use Variant Reducer to generate a simplified, standalone model 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 corresponds to a product line from a product line family (multi-configuration reduction). For information on using Variant Reducer, see Reduce Variant Models Using Variant Reducer. To reduce a variant model programmatically, use the Simulink.VariantManager.reduceModel
method.
This image shows the Variant Reducer window in Variant Manager.
Analyze Variant Configurations
You can use Variant Analyzer to analyze the active status of all blocks in a model hierarchy across the selected configurations or variable groups. The variant analysis report helps you to understand the common and differing model elements used between configurations, to check if all variant choices have been activated at least once, and to see whether the model is covered completely for simulation and code generation. For steps to use Variant Analyzer, see Analyze Variant Configurations in Models Containing Variant Blocks. For programmatic interface, see the Simulink.VariantConfigurationAnalysis
class.
This image shows the Variant Analyzer window in Variant Manager.
See Also
Simulink.VariantConfigurationData
| Simulink.VariantConfigurationAnalysis
| Simulink.VariantControl
| Model | Variant Subsystem, Variant Model, Variant Assembly Subsystem