Contenuto principale

Variant Modeling Strategies for System Development with Simulink

The V-model for system development 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.

V-model system development life cycle diagram showing the phases where Simulink variant capabilities apply

Simulink® variants support the V-model development process by providing variant capabilities from the System Level Model phase, down to Code Generation, and up to the System Integration and Test phase. In the System Level Model and Component phases, you can use variant blocks, variant parameters, and symbolic dimensions to capture structural and data variations. The generated code contains the variations defined in the model and its 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 particular phases of the V-model or revisit certain phases multiple times throughout the V-model lifecycle.

This topic describes strategies that you can use for plant and controller design at different phases of the V-model. For a more specific list of goals related to applying variations in your model, along with the guidance on how to achieve those goals, see V-Model for System Development with Simulink Variants.

Design Structural, Value, and Dimension Variations

Using variant blocks, you can conditionally switch between different structural alternatives within a model. With variant parameters, you can design block parameters with different values or dimensions and configure instance-specific values for referenced models. You can also use symbolic dimensions to simulate various sets of dimension choices without regenerating code for every set.

  • Model structural variations — With variant blocks such as Variant Subsystem blocks, you can encapsulate and switch between different component implementations, and with Variant Source and Variant Sink blocks, you can manage alternative signal paths. For external management, Variant Assembly Subsystem blocks allow you to add or remove variant choices without directly modifying the model structure. Additionally, Variant Start and Variant End blocks help you confine and collectively control variations within a specific set of blocks, ensuring that only intended elements are affected. For examples to configure structural variations in your model, see Implement Structural Variabilities for Components.

    When switching between these variations, variant blocks propagate changes to the affected elements within your model, eliminating the need for manual updates. For examples on these techniques, see Propagate Variant Conditions from Variant Blocks Upstream and Downstream.

    Additionally, you can control transitions between multiple design configurations within Stateflow® charts using variant transitions, and manage architectural variations in System Composer™. For AUTOSAR software components, you can enable or disable interfaces or implementations in the execution path using variation points, with AUTOSAR system constants serving as inputs to control these points. For examples, see System-Level Model, Components — Create Models with Variations in Transition Paths, and Components — Create Models with Variations in AUTOSAR Interfaces.

  • Model value variations — With variant parameters, you can design block parameters with different values or dimensions, and configure instance-specific values for referenced models. Each variant parameter defines a set of choices and associates each choice with a variant condition expression. When the conditions are evaluated, the model selects the appropriate parameter value based on the active variant, allowing you to represent multiple design alternatives without changing the model structure. For examples to configure parameter value variations, see Implement Variabilities in Parameter Values.

  • Model dimension variations — With symbolic dimensions, you can define model signals, parameters, and states using symbolic names instead of fixed numeric values. Symbolic dimensions enable you to simulate and generate code for models with varying dimensions, without needing to manually update or regenerate the model for each configuration. For examples to configure signals with symbolic dimensions, see Components — Create Models with Variations in Dimensions.

Enhance Reuse and Prevent Conflicts with Scoped Variant Controls

For variant blocks and variant parameters, each variant choice is linked to a variant control that determines which variant choice is active. Only one variant control of a variant block or a variant parameter can evaluate to true at a time. The variant blocks support expression, label, and sim codegen switching as control modes, while variant parameters support only the expression mode. Select the appropriate control mode based on your project needs. For an introduction to variant controls in variant blocks and variant parameters, see Define, Activate, and Manage Design Alternatives in Simulink Models.

You can encapsulate the variant controls in mask workspaces and model workspaces to localize the control variables to specific blocks or models and manage their visibility. Scoping the variables prevents unintended modifications from outside their intended context and enables you to reuse the same control names in different parts of your design without conflicts. Additionally, mask workspace variables enable each masked block instance to have its own set of variant control values, allowing you to configure blocks independently. Furthermore, if you want each instance of a referenced model to use different variant control values, you can use model arguments to achieve instance-specific variation. This approach supports modularity and improves model portability. For examples on variant control management techniques using workspace variables, see Control Visibility of Variant Regions.

Achieve Configurable and Maintainable Models with Variant Control Variables

A variant control variable is a workspace variable in Boolean expressions of the variant block or variant parameter when the variant control mode set to expression. The value of the variant control variable determines which Boolean expression evaluates to true to activate the corresponding variant choice. By changing the values of variant control variables, you can switch between the variant choices without altering the overall model structure. You can define these variables in various workspaces, such as the base workspace, data dictionary, mask workspace, or model workspace, to control the scope of variant selection locally or global as needed.

For an introduction to variant control variables in variant blocks, see:

To determine the appropriate type of variant control variable to use and the values to assign to them, see the flowcharts in:

Simulate Varying Designs in Plant and Controller Systems

Simulation and code generation for complex models in plant modeling and controller design require design flexibility and execution efficiency.

Plant modeling involves creating a representation of a physical system to predict its behavior, whereas, controller design involves creating logic that adjusts a system’s output to achieve desired performance. For example, modeling a car's braking system to understand how it responds to different road surfaces is an example of plant modeling, while designing an anti-lock braking controller to optimize braking performance under those conditions is an example of controller design.

Features, such as variant control mode, variant activation time, and parallel execution, enable you to manage active variants, minimize simulation overhead, and ensure model consistency.

Optimal Activation of Variations During Simulation

The following table explains how the combinations of variant activation times and variant control modes help address different modeling requirements. For an introduction to variant activation times and variant control modes, see Selectively Check Signal Consistency and Include Variants in Generated Code Using Activation Time and Switch Between Variant Choices Using Variant Controls.

Control designVariant activation timeVariant control modeUse case

Plant modeling

update diagramlabel

Use this combination in applications such as aircraft autopilot modes, vehicle drive profiles, or industrial machine settings, where the desired variant is selected by name before simulation and remains unchanged throughout the simulation.

 Simulate Preconfigured Autopilot Modes Using Variant Labels

Controller designupdate diagramexpression

Use this combination for systems such as industrial robotic arms, where the desired variant is selected by setting specific variables before simulation and these values remain unchanged throughout simulation.

 Simulate Preconfigured Robotic Arm Controllers Using Variant Control Expressions

Controller designupdate diagram analyze all choicesexpression

Use this combination in applications such as automotive systems, where the variant is selected by configuring multiple variables before simulation and remains unchanged, but it is important to verify all variant logics for errors to confirm readiness for future deployment or evolving requirements.

 Simulate Preconfigured ECU Calibration Modes with Variant Control Expressions

Controller designstartupexpression

Use this combination in applications such as advanced vehicle suspension models, where you intend to compile the entire model just once and then select the desired variant before each simulation run based on the value of multiple variables. This setup is ideal for simulation environments that require Fast Restart-based workflows, rapid prototyping, and integrated test and verification environments such as Simulink Test scenarios that override parameters, and Simulink Design Verifier and Simulink Verification and Validation™ workflows that require coverage across all variant paths where maintaining a single precompiled artifact can accelerate the testing cycle. For more information, see Run Iterative Simulations Without Recompiling Model for Variant Systems Using Fast Restart and Simulate Variant Blocks in Accelerator and Rapid Accelerator Modes with Startup Activation Time.

 Simulate Adaptive Suspension Controllers Using Variant Control Expressions

Controller designruntimeexpression

Use this combination in applications such as aircraft flight control systems, where the decision about which variant to execute depends on dynamic simulation-time inputs rather than the predetermined conditions. This setup enables transitions between control strategies during simulation, allowing the system to adapt in real time to changing atmospheric conditions without stopping or recompiling the model. For more information, see Control Active Choice of Variant Subsystem During Simulation or Execution of Generated Code.

 Simulate Dynamic Flight Control Strategies Using Variant Control Expressions

Controller designupdate diagram or update diagram analyze all choicessim codegen switching

Use this combination in applications such as smart home lighting systems to automatically switch between simulation and code generation controllers without manually configuring the model based on whether you are running simulations to test algorithms or generating code for embedded deployment.

 Simulate and Deploy Lighting Controllers Using sim codegen switching

For examples to control which variations to analyze using variant activation times, see Control Variant Activation Times of Structurally Varying Systems and Control Variant Activation Times of Varying Parameter Values.

Parallel Simulation of Variations

In Simulink, the parsim command enables you to perform parallel simulations across available processors or clusters for different variant choices. By using a Simulink.SimulationInput object, you can define multiple variant configurations and run them in parallel, reducing simulation time. For more information, see Simulate Variant Subsystem with Startup Activation Using parsim.

Independent Execution of Variations with Simulink Compiler

With startup variants, you can use Simulink Compiler™ to create a standalone executable that runs simulations independently of the Simulink environment. For more information, see Create Standalone Executables with Variants Using Simulink Compiler.

Generate Code to Conditionally Include Variants

You can include design variations 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. The code can be generated to accommodate structural, value, and dimensional variations, as well as different transition paths, ensuring the code remains adaptable to a wide range of requirements and use cases. For an introduction to code generation with variants, see Variant Systems (Simulink Coder).

  • Generate Code for Structurally Varying and Value-Varying Systems — You can generate code or executables that include both active and inactive variants of variant blocks or variant parameters, enabling you to switch between different system configurations either before code compilation or at model startup. This approach optimizes performance by including only the relevant portions of the model in the executable and, with activation times such as startup, allows for the flexible selection of configurations at execution without needing to regenerate code. For links to example models, see Generate Code for Structurally Varying Systems and Generate Code for Varying Parameter Values.

  • Generate Code for Varying Dimensions — Using symbolic dimensions enable you to define model signals, parameters, and states with symbolic names rather than fixed numeric values. By representing dimensions as symbols, the model can automatically adjust the sizes of signals, parameters, or ports to meet different requirements, eliminating the need for manual updates. As a result, the generated code remains flexible and easily adapts to a variety of system configurations. For examples of how to generate code for models with symbolic dimensions, see Generate Code for Varying Dimensions.

  • Generate Code for Varying Transition Paths — You can use variant transitions to create Stateflow charts in Simulink models that generate code adaptable to a wide range of software scenarios. Variant transitions enable you to represent multiple variations within a single Stateflow chart so that you select the appropriate behavior during code generation or compilation. For examples of how to generate code for Stateflow charts with variant transitions, see Generate Code for Varying Transition Paths.

Organize and Represent Variant Controls to Improve Code Quality

You can improve how variant controls are organized and represented in generated code.

  • Use Simulink.Parameter objects in variant controls to control how these variables are represented in the generated code. For example, you can specify whether the variables appear in header or source files, and configure their definition and declaration scope to enable global access or restrict them to file-level visibility.

  • Use enumerated types to enhance code readability by assigning meaningful names to values instead of integers.

  • Group variant parameters with the same variant conditions into variant parameter banks to switch between parameter sets.

  • Use Code Mappings Editor — C (Simulink Coder) to set instance-specific parameter values.

For examples of how to organize and represent variant controls for better code quality, see Generate Code for Structurally Varying Systems and Generate Code for Varying Parameter Values.

Optimal Inclusion of Variations in Generated Code

Code generation for complex models in controller design requires both design flexibility and execution efficiency. Features such as Variant activation time and Variant control mode allow you to specify which design variations are included in the generated code and at what stage the selection is made either before code generation, at model initialization, or during code execution. The following table shows how different combinations of variant activation times and variant control modes help address different modeling requirements. For an introduction to variant activation times and variant control modes, see Selectively Check Signal Consistency and Include Variants in Generated Code Using Activation Time and Switch Between Variant Choices Using Variant Controls.

Use caseVariant activation timeVariant control modeExample
Controller designcode compileexpression

Use this combination in applications where multiple control strategies must be thoroughly validated during development, while optimizing resource usage in the production system by including only the necessary logic.

 Generate Code for Predefined Automotive Braking Controllers Using Variant Control Expressions

Controller designstartupexpression

Use this combination in applications where multiple control strategies must be thoroughly validated during development, while retaining the flexibility to activate the appropriate variant at system startup, without requiring recompilation.

 Generate Code for Adaptive Firewall Controller Using Variant Control Expressions

Controller designruntimeexpression

Use this combination in applications that require switching between variant choices while the generated code is running, such as adaptive systems and real-time testing scenarios.

 Generate Code for Dynamic Drone Navigators Using Variant Control Expressions

For examples on controlling which variations to include in the generated code using variant activation times, see Generate Code for Structurally Varying Systems and Generate Code for Varying Parameter Values.

Deploy Variant Models for Different Targets

With variant blocks, you can configure the models to deploy on different target platforms:

Systematic Verification and Validation of Variations Through Tests

You can identify hidden design errors and detect model constructs within variants that may result in integer overflow, dead logic, array access violations, and division by zero by generating test cases using Simulink Design Verifier. Additionally, you can 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 the Variant Manager for Simulink support package, you can use the configurations to run tests programmatically for variant paths in the model. For examples of how to perform and automate testing across different variant configurations, see Component Tests and System-Level Tests.