Main Content

Variant Subsystem, Variant Model

Template subsystem containing Subsystem, Model, or Subsystem Reference blocks as Variant choices

  • Library:
  • Simulink / Ports & Subsystems

    HDL Coder / Ports & Subsystems

  • Variant Subsystem, Variant Model block

Description

The Variant Subsystem block enables you to include multiple implementations of a component in a separate hierarchy.

For example, suppose you want to simulate a model that represents a vehicle with three possible engine configurations: 4-cylinder gas, 6-cylinder gas, and 8-cylinder gas. You could implement each engine model as a separate subsystem inside the Variant Subsystem and then switch between the subsystems based on the Variant control mode you select. For more information, see Introduction to Variant Controls.

Note

Only one implementation of a Variant Subsystem is active during simulation.

Multiple implementations of a single system using Variant Subsystem block

The Variant Subsystem block is a template preconfigured to contain two or more blocks to use as Variant choices. These choices represent multiple implementations of a system. Only one child block is active during model execution. The active child block is referred to as the active variant.

Each variant choice inside the Variant Subsystem block is associated with a Variant control mode and a Variant activation time. The variant control mode determines which variant choice is active. The variant activation time determines a time to activate the choices and to decide whether to include only the active choice or both active and inactive choices in the generated code.

A Variant Subsystem block can contain a mixture of Subsystem blocks, Model blocks, or Subsystem Reference blocks as variant choices. A Variant Subsystem block with Model blocks as choices is called a Variant Model block. For more information on these blocks, see Create Subsystems, Model, and Subsystem Reference.

Apart from the variant choices, you can include Inport, Outport, and Connection Port (Simscape) blocks inside a Variant Subsystem block. There are no drawn connections between the blocks that are inside the Variant Subsystem blocks. Simulink® automatically wires the active variant to the Inport and Outport blocks of the Variant Subsystem during model compilation. The blocks representing variant choices can have input and output ports that differ in number from the input and output ports in the parent Variant Subsystem block. For more information, Mapping Inports and Outports of Variant Choices in a Variant Subsystem.

Using Variant Subsystem block allows you to:

  • Mix Subsystem, Model, and Subsystem Reference blocks as variant choices.

  • Model components that do not have similar interface. You can have different numbers of inports and outports for multiple variant choices inside a Variant Subsystem.

  • Establish a hierarchical block diagram, where the Variant Subsystem block is on one layer and the variant choices are on another layer.

  • Keeps functionally related blocks together.

  • Reduce the complexity of your model.

The color and icon of the variant badge on the block icon changes depending on the values of the Variant activation time, Variant control mode, and Propagate conditions outside of variant subsystem parameters set on the block. For more information, seeVariant Badges.

Ports

During simulation, Simulink disables the inactive ports in a Variant Subsystem block.

Input

expand all

Each Subsystem, Model, or Subsystem Reference block contained within a Variant Subsystem represents one variant choice. The variant choices can have same set or a subset of inports as the Variant Subsystem container block.

Output

expand all

Each Subsystem, Model, or Subsystem Reference block contained within a Variant Subsystem represents one variant choice. The variant choices can have same set or a subset of outports as the Variant Subsystem container block or it can be a subset of ports on the container block.

Note

The unconnected outports (inactive outports) of a Variant Subsystem outputs a ground value. To output a value other than ground, select the Specify output when source is unconnected parameter of the Outport block and specify a value.

Parameters

expand all

The variant control that determines the active variant choice can be any of these types.

  • expression — In expression mode, Simulink chooses the active variant based on the evaluation of the variant conditions. When a condition expression evaluates to true, the corresponding variant choice becomes active. When a condition expression evaluates to false, the corresponding variant choice becomes inactive. See Switch Between Choices Using Condition Expressions in Variant Blocks and Variant Parameters.

  • label — In label mode, Simulink chooses the active variant based on the name of the variant. The variant control is a string and does not require you to create variable in any workspaces. See Switch Between Choices Using Labels in Variant Blocks.

  • sim codegen switching — To automatically switch between the variants for simulation and code generation workflows without creating any workspace variable, use sim codegen switching mode. When you simulate a model, Simulink automatically chooses the sim branch as the active choice. Similarly, when you do a Software-in-the-loop (SIL) or Processor-In-Loop (PIL) simulation, generate code, or use external mode, Simulink automatically chooses the codegen branch. See Switch Between Choices For Simulation And Code Generation Workflows in Variant Blocks.

For more information on variant control mode, see Introduction to Variant Controls. For comparison between different types of variant control mode, see Compare Different Types of Variant Control Modes.

Dependencies

The availability of different variant activation times depends on the type of the Variant control mode that you specify. The Variant activation time parameter determines the time when Simulink sets the active choice. The parameter also determines which variability to include in the generated code. This table explains the variant activation time supported by each variant control mode.

Variant activation time
Variant control modeupdate diagramupdate diagram analyze all choicescode compilestartup
expression
labelxxx
sim codegen switchingxx

This parameter determines which variability to include in the simulation and code generation workflows. For more information, see Activate Variant During Different Stages of Simulation and Code Generation Workflow.

You can set the Variant activation time parameter as:

  • update diagram — When you execute the model, only the active choice is included in the simulation and the code generation workflow. Generated code contains only the active choice.

  • update diagram analyze all choices — When you execute the model, both active and inactive choices are analyzed for consistency across the model. However, only the active choice is included in the simulation and the code generation workflow. Generated code contains only the active choice.

  • code compile — When you execute the model, both active and inactive choices are analyzed for consistency across the model, and all choices are included in the simulation and the code generation workflow. Generated code contains both the active and inactive choices enclosed in the preprocessor conditionals #if and #elif. However, the executable built from the generated code contains only active choice.

  • startup — When you execute the model, both active and inactive choices are analyzed for consistency across the model, and all choices are included in the simulation and the code generation workflow. With this option, you can improve the speed of iterative simulations using fast restart. For more information, see How Fast Restart Improves Iterative Simulations. Code generated from the model contains both the active and inactive choices that are enclosed in regular if conditions. The executable built from the generated code also contains both active and inactive choices.

Dependencies

The availability of different variant activation times depends on the type of the variant control mode that you specify. The Variant activation time parameter determines when Simulink sets the active choice. The parameter also determines which variability to include in the generated code. This table explains the variant activation time supported by each variant control mode.

Variant activation time
Variant control mode update diagramupdate diagram analyze all choicescode compilestartup
expression
labelxxx
sim codegen switchingxx

Programmatic Use

Block Parameter: VariantActivationTime
Type: character vector
Values: update diagram | update diagram analyze all choices | code compile | startup
Default: update diagram

The table has a row for each variant choice contained in the Variant Subsystem. If there are no variant choices, the table is empty.

You can use buttons to the left of the Variant choices table to modify the elements in the table.

To...Click...
Create and add a new subsystem choice: Create a new Subsystem block as a variant choice and add an entry for the new choice in the table.Create and add a new subsystem choice
Create and add a new model variant choice: Create a new Model block as a variant choice and add an entry for the new choice in the table.Create and add a new model variant choice
Create/Edit selected variant object: Create or edit a Simulink.Variant object in the global workspace and specify the variant condition using the Simulink.Variant object parameter dialog box.Create/Edit selected variant object
Open selected variant choice block: Open the Subsystem block for the selected row.Open selected variant choice block
Refresh dialog information from Variant Subsystem contents: Update the Variant choices table according to the variant choices and values of the variant control in the global workspace.Refresh dialog information from Variant Subsystem contents

This read-only field displays the name of the blocks contained in the Variant Subsystem.

A name for a choice, specified as a string.

Dependency

To enable this parameter, set Variant control mode to label.

Specify the condition expression to determine the active choice inside the Variant Subsystem. When a condition expression evaluates to true, Simulink activates the corresponding variant choice. When a condition expression evaluates to false, Simulink deactivates the corresponding variant choice.

The variant controls can be:

Here, A and B are operands called as variant control variables. +, ==, and && are operators in the condition expression. The condition expression can contain one or more such variant control variables and operators. For information on supported types and storage location of variant control variables, see Types of Variant Control Variables (Operands) in Variant Condition Expressions and Storage Locations for Variant Control Variables (Operands) in Variant Condition Expressions. For information on operators, see Operators in Variant Condition Expressions.

For more information, see Switch Between Choices Using Condition Expressions in Variant Blocks and Variant Parameters.

Programmatic Use

Structure field: Represented by the read-only variant.Name field in the Variant parameter structure
Type: character vector
Value: variant control that is associated with the variant choice
Default: 'variant'

This read-only field displays the condition expression specified as Simulink.Variant object. To change or edit the condition expression, use the Simulink.Variant parameter dialog box that appears when you double-click the object in the workspace.

Note

The operands that you specify in a condition expression of type Simulink.Variant must be defined in the base workspace or a data dictionary. Specifying operands that are defined in the mask or model workspace is not supported.

This list contains the labels of all the choices inside the Variant Subsystem. To set an active choice, select a label from the list. The corresponding choice turns active. Alternatively, you can follow the approaches described in Variant control mode to change the active choice in label mode.

Dependencies

To enable this parameter, set the Variant control mode parameter to label.

Programmatic Use

Parameter: LabelModeActivechoice
Type: character vector
Value: if no label mode active choice is specified, the value is empty. If label mode active choice is specified, the value is the name of the label mode active choice.
Default: ''

When you select this option and if there is no active variant choice, Simulink simulates the model without any active variant choice in the Variant Subsystem. Simulink disconnects all the blocks connected to the input and output stream ofVariant Subsystem block, thus removing the variant regions completely from the model. The inactive outports of the Subsystem output a ground value. To output a value other than ground, select the Specify output when source is unconnected parameter of the Outport block and specify a value of your choice.

If you do not select this option, Simulink generates an error when there is no active variant choice.

Dependencies

This parameter is available only if there are no default variant choices in the Variant Subsystem and when if you set Variant control mode to expression.

Programmatic Use

Parameter: AllowZeroVariantControls
Type: character vector
Value: 'off' | 'on'
Default: 'off'

When you select the Propagate conditions outside of variant subsystem parameter, Simulink propagates the variant condition of the underlying blocks to the Variant Subsystem container block so the subsystem can adapt its interface to the state of the underlying blocks. Ports that are mapped to the ports on the active choice becomes active. Ports that are not mapped to the ports on the inactive choice becomes inactive. Selecting this option ensures that the components outside of the Variant Subsystem are aware of the active and inactive state of blocks within the Variant Subsystem block. For more information, see Adaptive Interface for Variant Subsystems.

The propagation of variant conditions outside of Variant Subsystem may improve the accuracy of the model and may simplify model construction because you are not required to manually compute the variant condition to assign to dependent blocks. For more information, see Propagate Variant Conditions Outside a Variant Subsystem Block and Use Variant Subsystem Blocks with Conditionally Executed Subsystems

Programmatic Use

Parameter: PropagateVariantConditions
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Block Characteristics

Data Types

Boolean[a] | bus[a] | double[a] | enumerated[a] | fixed point[a] | half[a] | integer[a] | single[a] | string[a]

Direct Feedthrough

no

Multidimensional Signals

limited[a]

Variable-Size Signals

limited[a]

Zero-Crossing Detection

no

[a] Actual data type or capability support depends on block implementation.

Extended Capabilities

Introduced in R2010b