Variant Subsystem - Template subsystem containing Subsystem blocks as variant choices - Simulink (original) (raw)

Template subsystem containing Subsystem blocks as variant choices

Libraries:
Simulink / Ports & Subsystems
HDL Coder / Ports & Subsystems

Alternative Configurations of Variant Subsystem Block:
Variant Model | Variant Assembly Subsystem

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: 2-cylinder gas, 4-cylinder gas, and 8-cylinder gas. You could implement each engine model as a separate subsystem inside the Variant Subsystem block and then switch between the subsystems based on the Types of Variant Control Modes in Variant Blocks you select. For more information, see Introduction to Variant Controls.

Note

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

Multiple models of an engine inside a 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 how to select the active variant. 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 only Model blocks as choices is called a Variant Model block. For more information, see Implement Variations in Separate Hierarchy Using Variant Subsystems. A Variant Subsystem block with Model orSubsystem Reference blocks as choices that can be added or removed only from external files and not within the block is called a Variant Assembly Subsystem block.

Apart from the variant choices, you can include Inport, control port (Enable, Trigger, Reset, and Function-Call Subsystem), Outport, or Connection Port (Simscape) blocks inside aVariant Subsystem block. There are no drawn connections between the blocks that are inside the Variant Subsystem blocks. The software automatically wires the active variant to the Inport andOutport 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, see Map Input and Output Ports of Variant Choices in Variant Subsystem.

When you load a model with a Variant Subsystem block that has variant choices stored in subsystem files, by default, only the active choice is loaded to optimize the loading time for models. However, if you initialize a model programmatically using the find_system,get_param, or set_param function, inactive choices might get loaded.

Using Variant Subsystem block allows you to:

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, see Variant Badges.

Examples

Ports

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

Input

Output

expand all

Each Subsystem, Model, or Subsystem Reference block contained within a Variant Subsystem represents one variant choice. The variant choices can contain Outport or Connection Port (Simscape) blocks at its output. The variant choices can have output ports that differ in number from the output ports in the parent Variant Subsystem block. However, the conditions described in Map Input and Output Ports of Variant Choices in Variant Subsystem must be met.

The unconnected output ports (inactive output ports) of a Variant Subsystem block 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.

Map Input and Output Ports of Variant Choices in Variant Subsystem

A Variant Subsystem block allows you to use a combination ofSubsystem, Model, or Subsystem Reference blocks as variant choices. The inputs that the Variant Subsystem block receives from upstream model components map to the input and output ports of the variant choices.

The blocks that represent variant choices can have input and output ports that differ in number from the input and output ports in the parent Variant Subsystem block. However, the following conditions must be met:

Parameters

expand all

To access these parameters, right-click the variant badge on the block icon and select . For more information, see Variant Badges.

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

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

Dependencies

The availability of different variant activation times depends on the type of theVariant control mode that you specify. TheVariant activation time parameter determines the time when the software 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 diagram update diagram analyze all choices code compile startup runtime (Variant Subsystem block only)
expression
label x x x x
sim codegen switching x x x

Programmatic Use

Block Parameter: VariantControlMode
Type: character vector
Values: 'expression' | 'label' 'sim codegen switching'
Default: 'expression'

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.

The table compares the different variant activation times based on conditional code, variant switching, handling of states, and fast restart support.

| | update diagram or update diagram analyze all choices | code compile | startup | runtime | | | --------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Generated conditional code | Inactive conditional code is not available. | Conditional code is present inside preprocessor macros. The inactive choice code is eliminated when generated code is compiled. | Conditional code is generated as part of anif-elseif-else statement. The variant control variable value cannot be modified during execution. | Conditional code is generated as part of anif-elseif-else statement. The variant control variable value can be modified during execution. | | Variant switching during simulation or code execution | Not supported. | Not supported. | Supported at startup (before simulation start at_t_ = 0). | Supported. The active variants are switched by changing the variant control variable using the Parameter Writer block. | | Explicit setting of held or reset option for states | Not supported. States are reset for inactive blocks. | Not supported. States are reset for inactive blocks | States cannot be changed during simulation. In the generated code, if you attempt to change the variant, states are in held state. | States are held by default. Reset states explicitly through State Writer blocks. Read blocks with states by using the State Reader block and transfer to another choice by using the State Writer block. | | Executable size | Smaller size. Code is not generated for the inactive variant. | Smaller size. The inactive variant code is removed during compilation. | Comparatively larger size. Both active and inactive variant code is available for startup switching. | Comparatively larger size. Both active and inactive variant code is available for run-time switching. | | Fast restart support | Not supported. | Not supported. | Supported. | Supported. |

Dependencies

Programmatic Use

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

When you specify a variable of type listed in Types of Variant Control Variables (Operands) in Variant Blocks, the software generates variant control expressions for the variant choices of theVariant Assembly Subsystem block. The Variant control variable that you specify here is on the left side and the members of the Variant enumeration choice are on the right side of the generated expressions. Both the sides are related by==.

The variant control variable acts as a switch to change the active variant choice. You specify a value for a variant control variable and run the simulation. During simulation, the software evaluates the variant control expressions to determine the active variant choice. When an expression evaluates to true, the corresponding variant choice is set active. To change the active variant, change the value of the variant control variable such that the corresponding variant control expression evaluates totrue turns active.

Dependencies

This parameter is available only in Variant Assembly Subsystem block. To enable this parameter, set Variant control mode to expression.

Programmatic Use

Block Parameter: VariantControlVariable
Type: character vector
Values: Simulink.VariantControl object, scalar variable,Simulink.Parameter object,struct
Default: ''

To add Model or Subsystem Reference blocks as variant choices to a Variant Assembly Subsystem block, specify an enumeration class name that contains the corresponding model or subsystem filenames as its members. You can then validate the enumeration class using the Refresh button in the Variant choices table. On a successful validation, the members of the enumeration class are added as variant choices to the Variant Assembly Subsystem block. Each choice has a variant control expression with Variant control variable on its left side and the members of theVariant choices enumeration that you specify here on its right side. Both the sides of the expression are related by==. The newly added variant choices and their corresponding control expressions are displayed in the Variant choices table.

To remove variant choices from a Variant Assembly Subsystem block, remove the corresponding members from the enumeration class that you specify here. You cannot manage the variant choices from inside theVariant Assembly Subsystem block.

The enumeration class that you specify must be on the search path of your current MATLAB® session. For information on how to add files or folders to the search path, see addpath.

For more information on how to add choices using the Variant choices enumeration parameter, see Add or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files.

Dependencies

This parameter is available only in Variant Assembly Subsystem block. To enable this parameter, set Variant control mode to expression.

Programmatic Use

Block Parameter: VariantChoicesEnumeration
Type: character vector
Values: enumeration class defined usingclassdef orSimulink.defineIntEnumType
Default: ''

To add Model or Subsystem Reference blocks as variant choices to a Variant Assembly Subsystem block, specify the corresponding model or subsystem filenames. The filenames must be specified as a MATLAB expression that returns a one-dimensional cell array of character vectors when evaluated or an array of strings. You can then validate the expression using the Refresh button in the Variant choices table. On a successful validation, the blocks that correspond to the specified files are added as variant choices to the Variant Assembly Subsystem block. For each choice, a variant control label is generated. The name of the variant control label is same as the name of the choice. The newly added variant choices and their corresponding control labels are displayed in the Variant choices table.

To remove variant choices from a Variant Assembly Subsystem block, modify the expression specified in this parameter. You cannot manage the variant choices of a Variant Assembly Subsystem block from inside the block.

The MATLAB expression that you specify must contain either of these:

For information on how to add files or folders to the search path, see addpath.

For more information on how to specify choices in the Variant choices specifier parameter, see Add or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files.

Dependencies

This parameter is available only in Variant Assembly Subsystem block. To enable this parameter, set Variant control mode to label.

Programmatic Use

Parameter: VariantChoicesSpecifier
Type: character vector
Value: Any MATLAB expression that evaluates to a one-dimensional cell array of filenames or filename patterns.
Default: ''

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. the Create and add a new subsystem choice button
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. the Create and add a new model variant choice button
Delete selected variant choices: Delete variant choices permanently. the Delete selected variant choices button
Create/Edit selected variant object: Create or edit aSimulink.VariantExpression object in the global workspace and specify the variant condition using the Simulink.VariantExpression object parameter dialog box.NoteFor a model that uses the base workspace, this operation creates theSimulink.VariantExpression object in the base workspace and the object is available only for the current MATLAB session. To permanently store the data, save the object in a MAT file or MATLAB script. the Create or Edit selected variant object button
Open selected variant choice block: Open the Subsystem block for the selected row. the Open selected variant choice block button
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. the Refresh dialog information from Variant Subsystem contents button

Dependencies

The Variant Assembly Subsystem block allows you to only open the selected variant choice and refresh the list of variant choices using the buttons in this section. To add new variant choices to theVariant Assembly Subsystem block, see Add or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files.

This parameter is read-only.

This parameter displays the name of the choices. Each choice has a variant control in the form of labels, expressions, or switches. For Variant Assembly Subsystem in thelabel mode, no separate variant control is available. The name of the choice is used as a variant control to set the active choice.

A name for a choice, specified as a string.

Dependencies

To enable this parameter, set Variant control mode tolabel.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: VariantControl
Values: variant control that is associated with the variant choice
Data Types: char

Example: set_param(gcb, 'VariantControl', 'V == 3'), where gcb is the variant choice of the Variant Subsystem block.

Example: get_param(gcb, 'VariantControl'), wheregcb is the variant choice of the Variant Subsystem block.

Specify (sim) to activate the corresponding variant choice during simulation. Specify (codegen) to activate the corresponding variant choice while performing code generation workflows such as SIL, PIL, external mode, and so on.

Dependencies

To enable this parameter, set Variant control mode tosim codegen switching.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Parameter: VariantControl
Values: variant control that is associated with the variant choice
Data Types: char

Example: set_param(gcb, 'VariantControl', '(sim)'), where gcb is the variant choice of the Variant Subsystem block.

Example: get_param(gcb, 'VariantControl'), wheregcb is the variant choice of the Variant Subsystem block.

Specify the condition expression to determine the active choice. When a condition expression evaluates to true, the software activates the corresponding variant choice. When a condition expression evaluates tofalse, the software 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 Blocks and Storage Locations for Variant Control Variables (Operands) in Variant Blocks. For information on operators, see Types of Operators in Variant Blocks for Different Activation Times.

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

In Variant Assembly Subsystem block, this parameter is a list of auto-generated boolean expressions with Variant control variable on the left-hand side and the members of the Variant enumeration choice are on the right-hand side of the expressions. Both the sides of the expressions are connected with ==. This parameter is read-only.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

To get the block parameter value programmatically, use the get_param function.

Variant Subsystem block:

Parameter: VariantControl
Values: variant control that is associated with the variant choice
Data Types: char

Example: set_param(gcb, 'VariantControl', 'V == 3'), wheregcb is the variant choice of the Variant Subsystem block.

Example: get_param(gcb, 'VariantControl'), wheregcb is the variant choice of the Variant Subsystem block.

Variant Source and Variant Sink blocks:

Parameter: VariantControls
Values: variant controls that are associated with variant choices
Data Types: char

Example: set_param(gcb, 'VariantControls', {'A == 1','A == 2'}), where gcb is the Variant Sink or Variant Source block.

Example: get_param(gcb, 'VariantControls'), wheregcb is the Variant Sink or Variant Source block.

This parameter is read-only.

This parameter displays the condition expression specified asSimulink.VariantExpression object. To change or edit the condition expression, use the Simulink.VariantExpression 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 typeSimulink.VariantExpression 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 variant choices. To set an active choice, select a label from the list. The corresponding choice becomes active. Alternatively, to change the active choice in label mode, you can follow the approaches described in Set Active Choices Using Variant Control Labels.

Dependencies

To enable this parameter, set Variant control mode tolabel.

Programmatic Use

Parameter: LabelModeActiveChoice
Type: character vector
Value: If no label mode active choice is specified, the value is empty. If a label mode active choice is specified, the value is the variant control label for the active choice.
Default: ''

For more information, see Manage Variant Components to Pass Specified Values from Inactive Variant Subsystems with No Active Choice (Simulink Coder).

Dependencies

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

Programmatic Use

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

For more information, see Manage Variant Components to Pass Specified Values from Inactive Variant Subsystems with No Active Choice (Simulink Coder).

Dependencies

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

Programmatic Use

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

When you select the Propagate conditions outside of variant subsystem parameter, the software 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 Propagate Variant Conditions to Define Variant Regions Outside Variant Subsystems to Promote Consistency and Reduce Errors and Propagate Variant Conditions to Control Execution of Conditional Subsystems

Variant conditions do not propagate outside a Variant Subsystem block if all variant choices within the block have the same interface.

Programmatic Use

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

Specify whether to make the interface of a variant subsystem flexible.

Programmatic Use

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

Block Characteristics

Data Types Booleana | busa doublea enumerateda fixed pointa halfa integera singlea stringa
Direct Feedthrough no
Multidimensional Signals yesa
Variable-Size Signals yesa
Zero-Crossing Detection no
a Actual data type or capability support depends on block implementation.

Alternative Configurations

expand all

The Variant Model block is a template that containsModel blocks.

Libraries:
Simulink / Ports & Subsystems

Since R2022b

A Variant Assembly Subsystem block enables you to add or remove its variant choices from external sources without modifying the model. A Variant Assembly Subsystem block can contain Model blocks, Subsystem Reference blocks, or both as its variant choices. You specify the source of variant choices in the block parameter dialog box once and then modify the source to add or remove the variant choices from the block. You can also move or resize the Model orSubsystem Reference blocks inside the Variant Assembly Subsystem block. Unlike the Variant Subsystem block, you cannot manage the variant choices from inside the Variant Assembly Subsystem block. Any modifications to add or remove variant choices must be made through the specified source. The attempts to modify variant choices, such as adding or deleting choices, renaming them, or changing the variant controls associated with them, by alternative methods result in an error. For more information, see Add or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files.

To convert a Variant Subsystem block to a Variant Assembly Subsystem block, follow the steps in Convert Variant Subsystem to Variant Assembly Subsystem.

Extended Capabilities

expand all

Actual data type or capability support depends on block implementation.

HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic. Actual data type or capability support depends on block implementation.

HDL Architecture

Architecture Description
Module (default) Generate code for the subsystem and the blocks within the subsystem. HDL Coder generates code for all the variant choices.
BlackBox Generate a black-box interface. That is, the generated HDL code includes only the input/output port definitions for the subsystem. In this way, you can use a subsystem in your model to generate an interface to existing manually written HDL code. The black-box interface generated for subsystems is similar to the interface generated for Model blocks, but without generation of clock signals.
No HDL Remove the subsystem from the generated code. You can use the subsystem in simulation but treat it as a “no-op” in the HDL code.

HDL Block Properties

General
AdaptivePipelining Automatic pipeline insertion based on the synthesis tool, target frequency, and multiplier word-lengths. The default is inherit. See alsoAdaptivePipelining (HDL Coder).
BalanceDelays Detects introduction of new delays along one path and inserts matching delays on the other paths. The default is inherit. See also BalanceDelays (HDL Coder).
ClockRatePipelining Insert pipeline registers at a faster clock rate instead of the slower data rate. The default is inherit. See also ClockRatePipelining (HDL Coder).
ConstrainedOutputPipeline Number of registers to place at the outputs by moving existing delays within your design. Distributed pipelining does not redistribute these registers. The default is0. For more details, see ConstrainedOutputPipeline (HDL Coder).
DistributedPipelining Pipeline register distribution, or register retiming. The default is inherit. See also DistributedPipelining (HDL Coder).
DSPStyle Synthesis attributes for multiplier mapping. The default is none. See also DSPStyle (HDL Coder).
FlattenHierarchy Remove subsystem hierarchy from generated HDL code. The default is inherit. See also FlattenHierarchy (HDL Coder).
InputPipeline Number of input pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is0. For more details, see InputPipeline (HDL Coder).
OutputPipeline Number of output pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is0. For more details, see OutputPipeline (HDL Coder).
SharingFactor Number of functionally equivalent resources to map to a single shared resource. The default is 0. See also Resource Sharing (HDL Coder).
StreamingFactor Number of parallel data paths, or vectors, that are time multiplexed to transform into serial, scalar data paths. The default is 0, which implements fully parallel data paths. See also Streaming (HDL Coder).

Target Specification

This block cannot be the DUT, so the block property settings in the Target Specification tab are ignored.

Restrictions

Actual data type or capability support depends on block implementation.

Version History

Introduced in R2010b

expand all

The callbacks LoadFcn, ContinueFcn,InitFcn, ModelCloseFcn,PauseFcn, PostSaveFcn,PreSaveFcn, StartFcn, andStopFcn do not execute for inactive variant choices in Variant Subsystem blocks with theupdate diagram activation time and for commented blocks. This suppression reduces computational overhead and prevents unnecessary diagnostic messages from the blocks that do not affect the current model iteration. However, these callbacks are not suppressed for blocks within models or subsystem files inside a commented or an inactive Model block or Subsystem Reference block. Also, the mask initialization and mask parameter callbacks are not suppressed. For the list of applicable callbacks, seeAuthor Mask Initialization and Callbacks and Mask Parameters.

The Allow zero active variant controls parameter is now renamed to Built-in empty choice. This new parameter maintains the previous functionality to remove the variant components and output zero when no variant choice is active.

Use the Built-in passthrough choice parameter to bypass variant region and assign input values to the output ports when no variant choice is active.

Starting in R2024b, use the runtime variant activation time in a Variant Subsystem block to change the active variant during simulation or code generation by using the Parameter Writer block. You can model all scenarios where the Parameter Writer block can write to the variant control variable in the global workspace, mask workspace, or model workspace.

Simulink provides options to add missing ports and delete unused ports inVariant Subsystem and Variant Assembly Subsystem blocks to match the ports of the underlying variant choices. During simulation, if Simulink encounters a port mismatch between a Variant Subsystem or Variant Assembly Subsystem block and its variant choices, the resulting error message provides the option of adding missing ports and deleting unused ports to resolve the issue.

You can use adapted rate-based model blocks as variant choices in a Variant Subsystem block. When you add adapted rate-based models as variant choices, the inports in the variant subsystem are matched to the port names of the respective rate-based models.

You can access the mask of the active variant choice of the Variant Subsystem directly without having to navigate inside the Variant Subsystem block.

When you click on the Look under mask badge of a linkedVariant Subsystem block with its active choice as a linked and masked Model Reference block, the Model Reference opens in a separate editor. Additionally, you must performset_param operations on the mask parameters of the active choice block on the active choice, and not on the Variant Subsystem block.

Promotion of the mask of the active choice is limited to its immediate parent. Nested Variant Subsystem mask promotion is not supported.

You can specify Variant choices specifier as an array of strings in Variant Assembly Subsystem block.

Simulink promotes the content preview of the active choice of theVariant Subsystem block automatically. When the active choice is a Model Reference that is not loaded, and when the active choice is a Stateflow chart, the Variant Subsystem is shown as the content preview.

You can navigate directly inside the active variant by double clicking on theVariant Subsystem block. When you select Open in New Tab or Open in New Window from the context menu, the active choice is opened in a new tab or a new window. You can also use theopen_system function to access the variant layer and the active choice.

open_system(vssBlock) open_system(vssBlock,'ActiveChoice','window')

When the active choice has an OpenFcn callback, double-clicking on the Variant Subsystem block does not execute that callback. Additionally, double-clicking on the Variant Subsystem does not navigate into the active choice if the active choice is a referenced model that is not loaded.

Simulink automatically displays the mask icon of the active variant block on the parent Variant Subsystem. Prior to R2021a, you had to provide icon drawing commands on the mask of the Variant Subsystem to display the mask icon of the underlying active variant block.