Main Content

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.

金宝app®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 howVariant Sourceblocks help you implement variant choices for the input signals to a system. The inactive choice appears faded.

For an example, seeUse Variants to Create One Model for Many Systems.

Variable and fixed components in a model

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.

包含多个设计选择的模型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金宝app

Variant blockshelp 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, seeVariant Blocks in Simulink.

Variant parametershelp you implement design variations that require varying values for block parameters. For more information, seeUse Variant Parameters to Reuse Block Parameters with Different Values.

Variant transitionsallow you to transition to multiple design configurations within the same Stateflow®chart. For more information, seeCode Generation Using Variant Transitions(Stateflow).

Dimension variantsallow you to specify symbolic dimensions that vary based on variant conditions. SeeImplement Dimension Variants for Array Sizes in Generated Code(Embedded Coder).

AUTOSAR variantsenable you to use variant blocks to implement AUTOSAR software components with variation points. SeeModel AUTOSAR Variants(AUTOSAR Blockset).

Tip

For a list of examples that show variant capabilities in Simulink, seeV-Model for System Development with Simulink Variants.

To see definitions for key terms and parameters used with variants, seeVariant Terminology.

For examples that show variant code generation capabilities, seeVariant Systems(Embedded Coder).

Variant Blocks in金宝app

Use these variant blocks depending on the model design:

  • Hierarchical variant blocksto create multiple implementations of a component in a separate hierarchy in the model.

  • Inline variant blocksto represent all variant implementations at the same level in the model.

  • Event-based variantsto use variants to model context-dependent system behaviors.

Type of Variant Variant Block Use
Hierarchical variant blocks Variant Subsystem

TheVariant Subsystemblock is a template preconfigured withSubsystemblocks to represent the variant choices.

TheVariant Subsystemblock allows a combination ofSubsystemblocks,Modelblocks, orSubsystem Referenceblocks as variant choices.

Variant Model

TheVariant Modelblock is a template preconfigured with twoModelblocks to represent the variant choices.

TheVariant Modelblock allows a combination ofSubsystemblocks,Modelblocks, orSubsystem Referenceblocks as variant choices.

Inline variant blocks Variant Source TheVariant Sourceblock 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 TheVariant Sinkblock 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 TheManual Variant Sourceblock is a toggle switch that allows you to define multiple variant choices at its inports.
Manual Variant Sink TheManual Variant Sinkblock is a toggle switch that allows you to define multiple variant choices at its outports.
Variant Connector(Simscape) TheVariant Connectorblock 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 theSimulink Functionblock 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, andTerminate Functionblocks The variant functionality inInitialize,Reset, andTerminateblocks 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.

Feature

Variant SourceandVariant Sinkblocks

Variant SubsystemandVariant Modelblocks

Variant choice representation

Number of ports

Subsystem,Model, orSubsystem Referenceblocks

Allows to implement variant choices in a separate hierarchy

No

Yes

Supports flexible number of inputs and outputs among variant choices (the choices do not have similar interface)

No

Yes, if thePropagate conditions outside of variant subsystemparameter is set toon.

Option to specify default variant

Yes

Yes

Supports control ports

No

Yes

Can be saved as standalone file

No

No

SupportsConnection Portused for modeling physical connection lines

No

Only when theVariant activation timeparameter is set toupdate diagram.

Comment a variant choice (by adding the%symbol before the variant control in the Block Parameters dialog box)

No

Yes

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.

Automobile configurations with different properties

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 aVariant Subsystemblock,Motor Variant Subsystem, that represents the motor of the vehicle. The motor has two possible configurations,GasandElectric, that are represented as variant choices within theVariant Subsystemblock. AVariant Subsystemblock adapts its interface according to the state of the underlying blocks. Here, theElectricmotor does not have anexhaust temperatureinput. When you activate theElectric变体,仿真软件自动金宝app禁用之日sponding port on theMotor Variant Subsystemand any other model components associated with that input.

For theexhaust temperaturesensor for this model, consider the need to switch between five different sensors provided by two vendors. You can useVariant Sourceblocks to represent all the choices in the same model and activate only one choice at a time.

Variant Source blocks used to select a sensor

Working with Variants

Visual Elements in Variant Models

Visual Element Use
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. SeeVisualize Propagated Variant Conditions Using Variant Conditions Legend.

variant condition legend

Variant Badges

Each variant block displays a badge that changes with different parameter values set on the block. SeeVariant Badges.

variant badge on variant block

Variant Fading and Signal Highlighting

The color of inactive variant choices fades by default. You can choose to disable the fading effect by using theVariant Fadingoption in theInformation Overlaysmenu on theDebugtab of the Simulink Editor.

Highlighting a signal that passes through variant blocks highlights the path of the active variant choice. SeeSignal Highlighting in Variant Systems.

Signal highlighting in variant model

Variant Badges

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(forVariant SourceandVariant Sinkblocks)

  • Propagate conditions outside of variant subsystem(forVariant Subsystemblock)

Variant Badges also provide quick access to some variant commands. Right-click the variant badge to access these commands.

Variant Badge Icons for Different Settings on Variant Blocks

Define and Control Variant Choices

You must associate each variant choice in a model with avariant controlthat 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 theVariant control modeparameter. For more information, seeIntroduction to Variant Controls.

Variant control mode and variant activation time in the block parameters dialog box

Automatically Identify Variant Regions Using Variant Condition Propagation

Simulink determines the model components that are active during simulation by the process ofvariant 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. SeeVariant Condition Propagation Overview.

Variant condition propagation

Choose a Variant Activation Time

You can also choose when the active variant choice is determined using theVariant activation timeparameter. This parameter also determines how the active and inactive choices participate in the simulation and code generation workflows. See在不同阶段的Simula激活变体tion and Code Generation Workflow.

Note

You can choose the variant activation time for a variant block only whenVariant control modeis set toexpression.

Manual Variant SourceandManual Variant Sinkblocks do not support variant controls and variant activation time. They determine the active variant choice based on the active inports and outports, respectively.

Variant Connectorblocks 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. SeeVariant Manager Overview.

Create and Activate Variant Configurations:

模型层次结构可以包含几个变种集团ks, 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 theVariant Configuration Analysistool 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 theVariant Reducertool 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 MAT or.slddfiles, and packages all the reduced artifacts in a specified output folder. An example use case for the tool is a vendor-supplier workflow.

Variant Manager

Generate Code from Variant Models

You can useSimulink Coder™or Embedded Coder®to generate code from variant models. SeePrepare Variant-Containing Model for Code Generation.

For examples that show variant code generation capabilities, seeVariant Systems(Embedded Coder).

Related Examples

More About