Main Content

V-Model for System Development with Simulink Variants

Simulink® is often used to model systems that represent a product line. The systems in a product line, although based on the same definition, can differ in several aspects. For example, consider a product line of passenger cars where each variant has different set of features. Instead of designing multiple models to represent all possible variants, you can use Simulink variants to model all the variations in a product line in a single model. Simulink variant capabilities allow you to create flexible models with built-in variabilities to more efficiently manage, configure, and reuse your designs. For information on Simulink variants basics, see What Are Variants and When to Use Them.

The V-model represents a development process. The model demonstrates the relationship between each phase of the development cycle on the left side and its associated validation phase on the right side. Simulink variants supports the V-model development process by providing variant capabilities from the System Level Model phase, down to Code Generation, and up to the Interaction and Test phase. In the System Level Model and Component phases, you can use variant blocks and variant parameters to capture structural and data variations. You can use the Variant Manager for Simulink to prevent invalid variant combinations and reduce the variant model to contain only the selected variants. The generated code contains the variations defined in the model and the components. In the Test phases, you can use the Simulink Design Verifier™ to generate test cases to identify hidden design errors and use Simulink Test™ to execute user-defined tests. Also, you can use Simulink Coverage™ to get coverage for all variants.

Depending on your application and its role in the process, you might focus on one or more of the steps called out in the V-model or repeat steps at several stages of the V-model.

These tables list goals that you might have as you apply variations in your model and guides you on how to meet those goals. You can open and run the examples linked below to apply variants and generate code. For a list of models that show variant capabilities in Simulink, see Simulink Variant Examples.

System-Level Model

You can model variations for any component in a system architecture model. A component may have two or more than two variant options that represent alternate structural decompositions. You can also define a mix of behaviors (defined in a Simulink model) and architectures (defined in a System Composer™ architecture model) as variant choices. For more information on System Composer architecture models, see Compose Architectures Visually (System Composer).

GoalCapabilityExample
Add components with alternative structural designs in architecture model.Variant Component (System Composer)Create Variants (System Composer)
Add or remove variant choices without modifying the model.Variant Assembly Component (System Composer)Add or Remove Variant Choices of Variant Assembly Component Blocks Using External File (System Composer)
Manage systems with variations in structural components.Variant Manager for SimulinkManage, Configure, Reduce, and Analyze System Variants with Variant Manager for Simulink

Components — Create Models with Structural Variations

Once you understand your modeling requirements, you can begin to identify the varying components of the system. Identifying components and their relationships within a top-level structure help build a potentially complex model systematically. With variant blocks in Simulink you can design multiple design alternatives of a system in a single model. Each design choice is incorporated into the model as a variant choice. You can choose to activate or deactivate the variant choices as per your requirement during simulation. For more information, see What Are Variants and When to Use Them.

This section covers:

Implement Structural Variabilities for Components

You can implement structural variabilities in all domains, including controls logic, state machines, flow charts, and physical plants by using variant blocks in your model. For more information on variant blocks, see Variant Blocks in Simulink.

GoalCapability Example

Encapsulate variations of a component in a separate in your model. You can encapsulate subsystem (virtual and non-virtual) blocks, model blocks, and subsystem reference blocks to conditionally execute them.

Variant Subsystem, Variant ModelImplement Variations in Separate Hierarchy Using Variant Subsystems
  • Represent all variations of a component at the same level in your model.

  • Represent components with variations in source or destination signals.

Variant Source and Variant Sink
Represent components that have a fixed common structure, but varying input and output interfaces.Variant Subsystem, Variant ModelAdaptive Interface for Variant Subsystems
Represent variations at the same level in your model and toggle between the variant choices using a simple toggle switch mechanism.Manual Variant Source and Manual Variant SinkProvide Variation in Signal Source and Destination Using Manual Variant Source and Manual Variant Sink Blocks

Conditionally execute event-driven functions on a model initialize, reset, and terminate events.

Initialize Function, Reset Function, and Terminate FunctionConditionally Execute Custom Initialize, Reinitialize, Reset, and Terminate Routines

Conditionally execute trigger-driven functions (execution is controlled by external signal).

Enabled Subsystem, Triggered Subsystem, Enabled and Triggered Subsystem, and Using Function-Call SubsystemsPropagate Variant Conditions to Control Execution of Conditional Subsystems
Conditionally execute Simulink functions (analogous to a function in procedural programming language).Simulink FunctionConditionally Execute Simulink Functions
Encapsulate Simulink models or subsystem files as variant choices and execute them conditionally.Variant Subsystem, Variant ModelPropagate Variant Conditions to Enable or Disable Model or Subsystem References in Hierarchy
Add or remove variant choices without modifying the model.Variant Assembly SubsystemAdd or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files

Implement variations in real physical components.

Variant Connector (Simscape)
  • Active variant is fixed before the simulation starts and does not change during intermediate stage of simulation.

  • Switch between active variants using strings with minimal data management.

Use label Mode in Variant BlocksSwitch Between Choices Using Labels in Variant Blocks
Create branches in your model that apply only to simulation or only to code generation.Use sim codegen switching Mode in Variant BlocksSwitch Between Choices for Simulation and Code Generation Workflows Without Using Control Variables in Variant Blocks

Propagate Conditions from Variant Blocks Upstream and Downstream

You can expand the variability control to any region of your model by automatically propagating variant conditions from variant blocks to other blocks upstream and downstream. Variant conditions can propagate through signal lines, buses, and function calls to reach blocks in a model affected by variant selection. For more information, see Propagate Variant Conditions to Define Variant Regions with Variant Blocks.

GoalCapabilityExample
Improve accuracy of the model and avoid manual computation of variant conditions to assign to the dependent blocks by propagating the state of the underlying blocks outside of the parent variant block.Variant Subsystem, Variant ModelPropagate Variant Conditions to Define Variant Regions Outside Variant Subsystems
Improve accuracy of the model and avoid manual computation of variant conditions to assign to the dependent blocks by propagating the state of the variant blocks to all its connected blocks. Propagate Variant Conditions to Define Variant Regions Using Variant Source and Variant Sink Blocks
Remove variant region completely from model execution when no variant is active.Allow zero active variant controlsPropagate Variant Conditions to Define Variant Regions Outside Variant Subsystems
Reduce visual complexity by propagating variant elements in composite signals.

Control Visibility of Variant Regions

You can control the visibility of variant regions by defining the variant control in appropriate workspaces as per your requirement. Limiting the scope helps avoid name conflicts and establish clear ownership of the variant controls between the blocks. It also enables you to use same names for variant controls in different scopes. For more information, see Storage Locations for Variant Control Variables (Operands) in Variant Blocks and Types of Operators in Variant Blocks for Different Activation Times.

GoalCapabilityExample
  • Create custom user interface for variants.

  • Prevent unintended modification of variant controls by encapsulating it behind a mask.

  • Use same names for variant controls in different masks by limiting the scope of controls.

Masking Fundamentals

  • Improve model portability by permanently storing variant controls that is local to the model.

  • Use same names for variant controls in different models by limiting the scope of controls.

Local Data: Model WorkspaceApproaches to Control Active Variant Choice of a Variant Block Using Mask or Model Workspace
Store global variant controls. Create a Simple Variant Model
Set different active variants for multiple instances of custom locked library block.Approaches to Control Active Variant Choice of a Variant Block Using Mask or Model WorkspaceControl Active Choice of Locked Custom Library Variant Subsystem Using Mask Parameter
Define global variant controls for multiple variant regions at different levels of a model.Data Store MemoryVariant Conditions and Data Stores (Model: slexVariantDataStores)

Variant Controls in Structurally Varying Systems

Each variant choice in your model is associated with a variant control. Variant controls determine which variant choice is active. By changing the value of a variant control, you can switch the active variant choice. You can use different types of variant controls variables while implementing variant regions in your model. For more information, see Types of Variant Control Variables (Operands) in Variant Blocks and Storage Locations for Variant Control Variables (Operands) in Variant Blocks.

GoalCapabilityExample
Switch variant choices in related blocks and parameters coherently.Simulink.VariantControlSimulink.VariantControl Variables for Coherent Switching of Choices in Variant Blocks

Rapidly prototype variant controls when you are still building your model.

Scalar variableScalar Variant Control Variables for Rapid Prototyping in Variant Blocks

Reduce complexity of variant controls by encapsulating them.

Simulink.VariantSimulink.VariantExpression Objects for Variant Condition Reuse of Variant Blocks

Improve readability by representing variant controls as meaningful names instead of integers.

Simulink EnumerationsRepresent Variant Conditions of Enumerated Type in Generated Code (Simulink Coder)

Improve readability by grouping related variant controls in a structure.

structStructures to Group Related Variant Control Variables of Variant Blocks

Control Variant Activation Times of Structurally Varying Systems

Prior to simulation or code generation, you can check for incompatibilities, such as datatype and dimension mismatches in variants. You can design variants that can be activated in different stages of simulation and code generation workflows. During code generation, you can choose which variabilities to include in the generated code and activate them at different stages based on the requirements and the target platform. You can also check for incompatibilities, such as datatype and dimension mismatches in variants. For more information, see Activate Variant During Different Stages of Simulation and Code Generation Workflow.

Goal CapabilityExample

Retain active variant and remove inactive variant early in the model compilation stage, so that, the variants with incompatible signal attributes coexist in the simulation workflow.

update diagramConsider a scenario where you want to simulate only the active variant. You have installed all the products required to simulate the active variant, but you do not have licenses that are required to simulate inactive variants. In this case, you can use update diagram activation time to remove inactive variants from execution at the beginning of the simulation workflow.
Analyze active and inactive variants for incompatibilities in signal attributes such as dimension and data type prior to the simulation-loop stage.update diagram analyze all choicesActivate Variant During Different Stages of Simulation and Code Generation Workflow

Perform iterative simulations and enhance simulation speed without having to recompile the model or terminating the simulation each time you change the active variant.

startup

Components — Create Models with Parameter Value Variations

You may have a set of requirements where the structure of the model remains the same, but the values of the parameters for each requirement are different. You can create a single model with fixed structure and create parameters with a finite set of values where each value corresponds to different requirements. You can then choose to activate or deactivate the variant choices during simulation. For more information on value variations, see Use Variant Parameters to Reuse Block Parameters with Different Values.

This section covers:

Implement Variabilities in Parameter Values

You can implement value variabilities in all domains, including controls logic, state machines, flow charts, and physical plants by using variant parameters in your model.

Variant Controls for Varying Parameter Values

Variant controls are Simulink.VariantControl objects that associates the Value of a variant control with an ActivationTime. Use the variant control objects to determine the active value of a variant parameter during different stages of simulation and code generation workflow. You can specify different types of values for variant control objects while implementing variant regions in your model. For more information, see Storage Locations for Variant Control Variables (Operands) in Variant Parameters and Types of Variant Control Variables (Operands) in Variant Parameters.

GoalCapabilityExample

Rapidly prototype variant controls when you are still building your model.

Numeric valuesNumeric Variant Control Values for Rapid Prototyping of Variant Parameters

  • Reuse common variant controls across models.

  • Reduce complexity of variant controls by encapsulating them.

Simulink.VariantSimulink.VariantExpression Objects for Variant Condition Reuse of Variant Parameters

Improve readability by representing variant controls as meaningful names instead of integers.

Simulink EnumerationsEnumerated Types to Improve Code Readability of Variant Control Variables of Variant Parameters

Improve readability by representing variant parameter values as meaningful names instead of integers.

Simulink EnumerationsImprove Code Readability of Variant Parameters Using Enumerated Types

Control Variant Activation Times of Varying Parameter Values

Prior to simulation or code generation, you can check for incompatibilities, such as datatype and dimension mismatches in variants. You can design variants that can be activated in different stages of simulation and code generation workflows. During code generation, you can choose which variabilities to include in the generated code and activate them at different stages based on the requirements and the target platform. You can also check for incompatibilities, such as datatype and dimension mismatches in variants. For more information, see Activate Variant During Different Stages of Simulation and Code Generation Workflow.

GoalCapabilityExample

Retain active variant and remove inactive variant early in the model compilation stage, so that, the variants with incompatible signal attributes coexist in the simulation workflow.

update diagramChange Active Values and Activation Time of Variant Parameters
Analyze active and inactive variants for incompatibilities in signal attributes such as dimension and data type prior to the simulation-loop stage.update diagram analyze all choices
Perform iterative simulations without having to recompile the model or terminating the simulation each time you change the active variant.startupRun Iterative Simulations Without Recompiling Model for Variant Systems Using Fast Restart

Components — Create Models with Variations in Transition Paths

You can control the transition to multiple design configurations within the Stateflow® charts using variant transitions.

GoalCapabilityExample
Conditionally execute transition path from source object to destination object.Conditions (Stateflow) andCondition Actions (Stateflow)Control Indicator Lamp Dimmer Using Variant Conditions (Stateflow)

Components — Create Models with Variations in Dimensions

You can use symbolic dimensions to simulate various sets of dimension choices without regenerating code for every set. These symbols propagate throughout the model during simulation, and then go into the generated code.

GoalCapabilityExample
Store dimensions in symbols to flexibly switch between variant choices.Allow symbolic dimension specificationGenerate Code for Variant Subsystem with Child Subsystems of Different Output Signal Dimensions (Embedded Coder)
Create parameters with variants having different dimensions. Symbolic Dimensions in Generated Code (Simulink Coder)Compile Code Conditionally for All Values of Variant Parameters with Same and Different Dimensions

Components — Create Models with Variations in AUTOSAR Interfaces

You can enable or disable AUTOSAR interfaces or implementations in the execution path using variation points in AUTOSAR software components. In Simulink, AUTOSAR system constants serve as inputs to control component variation points. Variation points present a choice between two or more variants. For more information, see Model AUTOSAR Variants (AUTOSAR Blockset).

GoalCapabilityExample
Enable or disable AUTOSAR ports and runnables.Variants for Ports and Runnables (AUTOSAR Blockset)Configure Variants for AUTOSAR Elements (AUTOSAR Blockset)
Vary implementation of AUTOSAR runnable by specifying variant conditions inside the runnable.Variants for Runnable Implementations (AUTOSAR Blockset)Configure Variants for AUTOSAR Runnable Implementations (AUTOSAR Blockset)
Model AUTOSAR calibration data in combination with different types of variant conditions.Export Variation Points for AUTOSAR Calibration Data (AUTOSAR Blockset)
Import variation points in AUTOSAR software components.Predefined Variants and System Constant Value Sets (AUTOSAR Blockset)Control AUTOSAR Variants with Predefined Value Combinations (AUTOSAR Blockset)
Store dimensions of AUTOSAR elements, such as a ports, in symbols to flexibly switch between variation points during code compilation.Variants for Array Sizes (AUTOSAR Blockset)Configure Dimension Variants for AUTOSAR Array Sizes (AUTOSAR Blockset)
Flexibly switch between AUTOSAR components after the code is compiled and deployed on an electronic control unit (ECU).Configure Postbuild Variant Conditions for AUTOSAR Software Components (AUTOSAR Blockset)
Flexibly switch between value combinations for AUTOSAR elements prior to code compile, or after the code is compiled and deployed on an ECU.Configure Variant Parameter Values for AUTOSAR Elements (AUTOSAR Blockset)

Components — Manage Structural Variations in a Model

Variant Manager enables you to visually trace variations, manage variabilities simultaneously, and prevent invalid variant combinations in a system model or variant transitions in a Stateflow chart. You can also simplify a variant model by automatically reducing it to contain only the selected variants. For more information, see Variant Manager for Simulink.

GoalCapabilityExample

Visualize a tree view of a variant model hierarchy and edit properties of variant elements.

Manage Variant Elements

Create Variant Configurations to represent combinations of variant choices across a model hierarchy.

Variant Manager for SimulinkCreate and Activate Variant Configurations

Define constraints for variant configurations to prevent invalid variant combinations.

Constraints on Variant ConfigurationsDefine Constraints for Variant Configurations

Create a variant configuration data object to store, distribute, and reuse variant configurations for a model.

Variant Configuration Data ObjectSave and Reuse Variant Configurations Using Variant Configuration Data Object

Validate and apply a variant configuration to a model early in the update diagram stage.

Activate a Variant ConfigurationCreate and Activate Variant Configurations

Automatically generate a reduced model that contains only selected variant configurations from a parent model with many variants.

Reduce Variant Models Using Variant ReducerReduce Model Containing Variant Blocks

Visualize and compare variant configurations to locate and diagnose potential faults or inconsistencies in the configurations.

Analyze Variant Configurations in Models Containing Variant Blocks

Run single or multiple simulations programmatically for models that have variant configurations defined. (since R2024a)

Run Simulations ProgrammaticallyRun Simulations for Variant Models Using Variant Configurations

Generated Code

You can include variabilities in generated code to reuse and configure the code for different stages of development, such as testing different implementations or providing multifunctional code to third parties.

Generate Code for Structurally Varying Systems

You can specify the variabilities of the variant blocks to be included in the generated code. You can also control the appearance, placement, definition, and declaration of variant controls in the generated code.

GoalCapabilityExample
Generate a code that contains active and inactive variants, and enables you to switch between the variants prior to code compile.code compile

Compile Code Conditionally for Variations of Component Represented Using Variant Block (Simulink Coder)

Generate an executable that contains active and inactive variants, and enables you to switch between the variants at model startup.startup
Share variant controls among multiple blocks, separate values from their data types and other properties, control the appearance, placement, definition, and declaration of variant controls in the generated code.Simulink.ParameterUse Simulink.Parameter Type of Variant Control Variables for Code Generation in Variant Blocks (Simulink Coder)

Improve code readability by representing variant controls as meaningful names instead of integers in generated code.

Simulink Enumerations

Generate Code for Varying Parameter Values

You can specify the variabilities of the variant parameters to be included in the generated code. You can also control the appearance, placement, definition, and declaration of variant controls and variant parameters in the generated code. For more information, see Options to Represent Variant Parameters in Generated Code (Embedded Coder).

GoalCapabilityExample
Generate a code that contains all variants and enables you to switch between the variants prior to code compile.code compileCompile Code Conditionally for All Values of Variant Parameters with Same and Different Dimensions
Generate an executable that contains all variants and enables you to switch between the variants at model startup.startupRun Executable for Different Variant Parameter Values Without Recompiling Code

Generate code that groups variant parameters with the same variant conditions into a structure called variant parameter bank and uses a pointer variable to switch the set of active parameter values.

Simulink.VariantBankGroup Variant Parameter Values and Conditionally Switch Active Value Sets in Generated Code

Specify code generation properties for a variant parameter bank.

Simulink.VariantBankCoderInfoGroup Variant Parameter Values and Conditionally Switch Active Value Sets in Generated Code
Share variant controls among multiple blocks, separate values from their data types and other properties, control the appearance, placement, definition, and declaration of variant controls in the generated code. Simulink.Parameter Type of Variant Control Variables for Code Generation of Variant Parameters

Improve code readability by representing variant controls as meaningful names instead of integers.

Simulink EnumerationsEnumerated Types to Improve Code Readability of Variant Control Variables of Variant Parameters

Improve code readability by representing variant parameter values as meaningful names instead of integers.

Simulink EnumerationsImprove Code Readability of Variant Parameters Using Enumerated Types

Generate Code for Varying Transition Paths

You can use variant transitions to create Stateflow charts in Simulink models that generate code to be used in a variety of different software situations. Variant transitions allow you to model a full subset of variations within one Stateflow chart so that you can choose which variation you want when you generate code or when you compile the generated code.

GoalCapabilityExample
Generate code that only contains the data members needed to execute the currently selected software configuration.Generate C or C++ Code from Stateflow Blocks (Stateflow)Control Indicator Lamp Dimmer Using Variant Conditions (Stateflow)

Generate Code for Varying Dimensions

You can use symbolic dimensions to simulate various sets of dimension choices without regenerating code for every set. These symbols propagate throughout the model during simulation, and then go into the generated code.

GoalCapabilityExample
Store dimensions in symbols to flexibly switch between variants during code compilation.Allow symbolic dimension specificationGenerate Code for Variant Subsystem with Child Subsystems of Different Output Signal Dimensions (Simulink Coder)
Store dimensions in automatically generated symbols to flexibly switch between variant parameter values during code compilation.Symbolic Dimensions in Generated Code (Simulink Coder)Compile Code Conditionally for All Values of Variant Parameters with Same and Different Dimensions
Store dimensions of AUTOSAR elements, such as a ports, in symbols to flexibly switch between variation points during code compilation.Variants for Array Sizes (AUTOSAR Blockset)Configure Dimension Variants for AUTOSAR Array Sizes (AUTOSAR Blockset)

Component Tests and System-Level Tests

You can identify hidden design errors and detect model constructs in variants that result in integer overflow, dead logic, array access violations, and division by zero by generating test cases using Simulink Design Verifier. For more information, see About Systematic Model Verification Using Simulink Design Verifier (Simulink Design Verifier).

You can further execute user-defined tests on both active and inactive variants in a model by using Simulink Test. If your model has variant configurations defined using Variant Manager for Simulink, you can use the configurations to run tests programmatically for variant paths in the model.

GoalCapability Example
Analyze active variant to detect design errors and requirement violations by generating test cases for debugging.code compileSee SLDV Run workflow in Verify and Validate Variant Models with Code Compile Activation Time

Analyze active and inactive variants to detect design errors and requirement violations by generating test cases for debugging.

startupSee SLDV Run workflow in Verify and Validate Variant Models with Startup Activation Time

Analyze only active variant and re-run the tests to analyze all variants.

code compileSee Simulink Test Manager workflow in Verify and Validate Variant Models with Code Compile Activation Time

Run iterative tests on active and inactive variants without recompiling the model for each variant.

startupSee Simulink Test Manager workflow in Verify and Validate Variant Models with Startup Activation Time

Run iterative tests programmatically for models that have defined variant configurations (since R2024a)

Create and Run Test Case Iterations (Simulink Test)Run Tests for Variant Models Using Variant Configurations

Related Topics