Documentation

What Are Variants and When to Use Them

What Are Variants?

In Simulink®, you can use the variant blocks to create a single model that caters to multiple variant requirements. Such models have a fixed common structure and a finite set of variable components. The variable components are activated depending on the variant choice that you select. Thus, the resultant active model is a combination of the fixed structure and the variable components based on the variant choice.

The use of variant blocks in a model helps in reusability of the model for different conditional expressions called variant choices. This approach helps you to meet diverse customer requirements based on application, cost, or operational considerations.

You can use these variants blocks depending on the model design:

    Note:   You can convert a Subsystem block available in a model to a Variant Subsystem block. To do so, right-click the Subsystem block, in the context menu, click Subsystem & Model Reference > Convert Subsystem to > Variant Subsystem.

Suppose you want to simulate a model that represents an automobile with several configurations. These configurations, although similar in several aspects, can differ in properties such as fuel consumption, engine size, or emission standard. Instead of designing multiple models that together represent all possible configurations, you can use variants to model only the varying configurations. This approach keeps the common components fixed.

This model contains two variant choices inside a single Variant Subsystem block. Variant choices are two or more configurations of a component in your model.

Advantages of Using Variants

Using variants in Model-Based Design provides several advantages:

  • Variants provide you a way to design one model for many systems.

  • You can rapidly prototype design possibilities as variants without having to comment out sections of your model.

  • Variants help you develop modular design platforms that facilitate reuse and customization. This approach improves workflow speed by reducing complexity.

  • If a model component has several alternative configurations, you can efficiently explore these varying alternatives without altering the fixed, unvarying components.

  • You can use different variant configurations for simulation or code generation from the same model.

  • You can simulate every design possibility in a combinatorial fashion for a given test suite.

  • If you are working with large-scale designs, you can distribute the process of testing these designs on a cluster of multicore computers. Alternatively, you can map different test suites to design alternatives for efficiently managing design-specific tests.

  • Yo can generate a reduced model with a subject of configuration from a master model with many variants.

When to Use Variants

Variants help you specify multiple implementations of a model in a single, unified block diagram. Here are three scenarios where you can use variants:

  • Models that represent multiple simulation, code generation, or testing workflows.

  • Models that contain multiple design choices at the component level.

    Subsystem blocks representing variant choices can have inports and outports that differ in number from the inports and outports in the parent Variant Subsystem block. See Mapping Inports and Outports of Variant Choices.

  • Models that are mostly similar but have slight variations, such as in cases where you want to separate a test model from a debugging model.

    The test model on the left has a fixed design. On the right, the same test model includes a variant that is introduced for debugging purposes.

Simulink selects the active variant during update diagram time and during code compile time.

Options for Representing Variants in Simulink

You can represent one or more variants as variant choices inside these blocks.

 

Variant Source and Variant Sink blocks

Variant Subsystem block

Model Variant block

Variant choice representation

Number of ports

Subsystem or Model block

Only Model block

Allows choice hierarchy

No

Yes

Yes

Mismatched number of inports and outports among variant choices

Simulink disables inactive ports

Simulink disables inactive ports

Requires manual resolution of disconnected signal lines

Option to specify default variant

Yes

Yes

No

Supports control ports

No

No

Yes

Can be saved as standalone file

No

No

Yes

Supports physical modeling connection ports

No

Partially

No

Comment choice

Yes

No

No

In addition, you can represent variant choices using Variant Source and Variant Sink block. These blocks enable the propagation of variant conditions and they allow you to visualize variant choices in a single layer of your model.

You can create variants at several levels inside your model hierarchy.

Mapping Inports and Outports of Variant Choices

A Variant Subsystem is a container of variants choices that are represented as Subsystem or Model blocks. The inputs that the Variant Subsystem block receives from upstream models components map to the inports and outports of the variant choices.

Subsystem and Model blocks representing variant choices can have inports and outports that differ in number from the inports and outports in the parent Variant Subsystem block. However, the following conditions must be satisfied:

  • The names of the inports of a variant choice are a subset of the inport names used by the parent variant subsystem.

  • The names of the outports of a variant choice are a subset of the outport names used by the parent variant subsystem.

During simulation, Simulink disables the inactive ports in a Variant Subsystem block. If you are specifying variant choices in a Model Variant block, resolve any disconnected signal lines manually when you switch between choices.

Related Examples

More About

Was this topic helpful?