Main Content

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.

Overview of Variant Manager capabilities

Install Variant Manager for Simulink

To install the support package, use one of these methods:

  • Open Variant Manager:

    1. 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.

    2. In the Install Variant Manager for Simulink dialog box, click Add to install the Variant Manager for Simulink add-on.

  • Use Add-On Explorer:

    1. In MATLAB®, on the Home tab, in the Environment section, click Add-Ons and then select Get Add-ons.

    2. 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.

    Variant badge on a Variant Source block

  • 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.

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/ValidateAndActivateVariantConfigurationMethodRefPageExample');
open_system('slexVariantManagement');

The toolstrip is at the top. The Configurations pane and Constraints pane is on the left. The Getting Started pane is on the right. The model hierarchy table is in the middle. The Diagnostics pane is at the bottom.

  • 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.

Variant manager window with custom layout

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 present 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.

The Variant Parameters tab shows all Simulink.VariantVariable objects present in the base workspace or data dictionaries associated with the model, even if the object is not used in the model hierarchy.

Interact with Model Hierarchy

You can perform these actions from the model hierarchy.

ActionModel 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 expression, the list shows default in addition to the variant control expression. For sim-codegen switching mode, the list shows sim or codegen values. For a variant Simulink Function block, the list shows inherit.

Edit variant parameter objects

In the Variant Parameters tab, you can edit the Simulink.VariantVariable objects available in the base workspace or data dictionaries associated with the model.

SearchUse 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.

Block specific tooltip for a Variant Subsystem block in the model hierarchy.

See context menu

Right-click an element in the table to find these context-specific options:

  • Open and Highlight Block: Opens the selected block in the model and highlights it. This provides traceability to the model.

  • Open Model: Opens the selected model or referenced model.

  • Open As Top Model: Opens the selected referenced model as a top model in a separate window.

  • Open Referenced Subsystem: Opens the selected referenced subsystem in a separate window.

  • Open Block Parameters: Opens the block parameter dialog box for the selected block. You can modify the parameter values.

  • Open Parent Block Parameters: Opens the block parameter dialog box for the parent block of the selected block. You can modify the parameter values.

  • Set as Label Mode Active Choice: Sets the selected choice of Variant Subsystem, Variant Sink, or Variant Source blocks as active choice. This option is available only if the Variant Control mode block parameter is set to label.

  • Edit Simulink.VariantVariable: Open the Simulink.VariantVariable dialog box from where you can edit the selected variant parameter.

  • Open and Highlight Chart: Open the selected Stateflow chart and highlight it in the model.

  • Open and Highlight Transition: Open the Stateflow chart and highlight the selected transition.

  • Open Chart Parameters: Open the Chart properties dialog box of the selected Stateflow chart.

  • Open Parent Chart Parameters: Open the Chart properties dialog box of the parent Stateflow chart for the selected transition.

Block specific context menu for a Variant Subsystem block in the model hierarchy.

Filter variant blocks by their Variant control modeUse the View list in the Blocks tab of the model hierarchy.
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:

  • variable usage — Use the Show previous variable usage and Show next variable usage buttons to select the previous/next rows in the hierarchy that uses the selected variant control variable.

    To enable the buttons, select the required variant configuration from the Configurations tab. In the Control Variables section for that configuration, select the control variable from the table. Click the Show usage of selected control variables button .

  • active — Use the Select previous active and Select next active buttons to select the previous/next rows in the hierarchy that has active variant choices.

  • invalid — Use the Select previous invalid and Select next invalid buttons to select the previous/next rows in the hierarchy that has invalid variant choices.

Identify active variant choices

The inactive choice appears greyed out.

Active and inactive variant choices are shown with different background colors in the model hierarchy.

Identify rows with errors

They are highlighted in red.
Identify type of block by the block iconFor the list of block icons, see Model Hierarchy Table.

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 model configurations (component configurations).

  • 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 detailed steps to create a variant configuration, see Create and Activate Variant Configurations.

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.

Manage 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 base workspace or data dictionary.

    When you export the variant control variables in a variant configuration to the base workspace or data dictionary used by the model or when you activate a variant configuration, the corresponding variant control variables are pushed to the base workspace or data dictionary. 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.

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.

See, Reduce Variant Models Using Variant Reducer.

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

ButtonDescription
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 IconType of Control Variable
Normal MATLAB variable
Simulink.Parameter or AUTOSAR.Parameter
Simulink.VariantControl with value as normal MATLAB variable
Simulink.VariantControl with value as Simulink.Parameter

Control Variables Section

ButtonDescription

Import control variables from the entire model reference hierarchy

Note

Control variables from blocks in Label mode are not imported, as they are not variant control variables.

Add a control variable.

Create a copy of a control variable.

Delete a control variable.

Change the data type of a control variable.

Edit Simulink.Parameter or AUTOSAR.Parameter control variables. This option gets activated when the selected control variable is one of these types.

Note

To specify Simulink.Parameter control variable as an expression, set the Value property of the parameter object by using an equals sign (=) followed by a mathematical expression. For example, = A + B.

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 the base workspace or data dictionary used by the model.
Filter the table based on type of control variables.

Component Configurations Tab

IconPurpose
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

IconElement

Model block with Simulation mode set to Normal

Model block with Simulation mode set to Accelerator

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 update diagram.

Variant Subsystem block with Variant activation time set to update diagram analyze all choices.

Variant Subsystem block with Variant activation time set to code compile.

Variant Subsystem block with Variant activation time set to startup.

Variant Subsystem block with Allow zero active variant controls selected and Variant activation time set to update diagram.

Variant Subsystem block with Allow zero active variant controls selected and Variant activation time set to update diagram analyze all choices.

Variant Subsystem block with Allow zero active variant controls selected and Variant activation time set to code compile.

Variant Subsystem block with Variant control mode set to label and an active variant choice selected from the Label mode active choice option.

Variant Subsystem block with Propagate conditions outside of variant subsystem and Variant activation time set to update diagram.

Variant Subsystem block with Propagate conditions outside of variant subsystem and Variant activation time set to update diagram analyze all choices.

Variant Subsystem block with Propagate conditions outside of variant subsystem and Variant activation time set to code compile.

Variant Subsystem block with Propagate conditions outside of variant subsystem and Variant activation time set to startup.

Variant Subsystem block with Propagate conditions outside of variant subsystem option selected. Also, Variant control mode is set to label and an active variant choice is selected from the Label mode active choice option.

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 label and an active variant choice selected from the Label mode active choice option.

Inline Variants Block (Variant Source and Variant Sink) with Variant activation time set to update diagram.

Inline Variants Block (Variant Source and Variant Sink) with Variant activation time set to update diagram analyze all choices.

Inline Variants Block (Variant Source and Variant Sink) with Variant activation time set to code compile.

Inline Variants Block (Variant Source and Variant Sink) with Variant activation time set to startup.

Inline Variants Block (Variant Source and Variant Sink) with Allow zero active variant control and Variant activation time set to update diagram.

Inline Variants Block (Variant Source and Variant Sink) with Allow zero active variant control and Variant activation time set to update diagram analyze all choices.

Inline Variants Block (Variant Source and Variant Sink) with Allow zero active variant control and Variant activation time set to code compile.

Inline Variants Block (Variant Source and Variant Sink) with Allow zero active variant control and Variant activation time set to startup.

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 code compile.

Stateflow chart with Variant activation time set to update diagram analyze all choices.

Stateflow chart with Variant activation time set to startup.

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 class provides a set of methods 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.

  • Variant Manager does not support variant controls defined in InitFcn callbacks and mask workspaces.

  • The model hierarchy table does not show protected referenced models.

  • 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

| |

Related Topics