Main Content

Transform Model to Variant System

You can use the Model Transformer tool to improve model componentization by replacing qualifying modeling patterns with Variant Source and Variant Subsystem blocks. The Model Transformer reports the qualifying modeling patterns. You choose which modeling patterns the tool replaces with a Variant Source block or Variant Subsystem block.

The Model Transformer can perform these transformations:

  • If an If block connects to one or more If Action Subsystems and each one has one outport, replace this modeling pattern with a subsystem and a Variant Source block.

  • If an If block connects to an If Action Subsystem that does not have an outport or has two or more outports, replace this modeling pattern with a Variant Subsystem block.

  • If a Switch Case block connects to one or more Switch Case Action Subsystems and each one has one outport, replace this modeling pattern with a subsystem and a Variant Source block.

  • If a Switch Case block connects to a Switch Case Action Subsystem that does not have an outport or has two or more outports, replace this modeling pattern with a Variant Subsystem block.

  • Replace a Switch block with a Variant Source block.

  • Replace a Multiport Switch block that has two or more data ports with a Variant Source block.

For the Model Transformer tool to perform the transformation, the control input to Multiport Switch or Switch blocks and the inputs to If or Switch Case blocks must be either of the following:

  • A Constant block in which the Constant value parameter is a Simulink.Parameter object of scalar type.

  • Constant blocks in which the Constant value parameters are Simulink.Parameter objects of scalar type and some other combination of blocks that form a supported MATLAB® expression. The MATLAB expressions in Types of Operators in Variant Blocks for Different Activation Times are supported except for bitwise operations.

Transform Model to Variant System Using Model Transformer

This example shows how to use the Model Transformer app to transform a model into a variant system. The example uses the model ControlFlowOptimization. This model has three Switch blocks. The control input to these Switch blocks is the Simulink.Parameter cond. The Model Transformer dialog box and this example refer to cond as a system constant.

  1. Open the model ControlFlowOptimization.

  2. Open the Switch1 Block Parameters dialog box. Change the Threshold parameter to 0. The Threshold parameter must be an integer because after the variant transformation it is part of the condition expression in the Variant Source block.

  3. Repeat step 2 for the Switch blocks Switch1, Switch2, and Switch3.

  4. Save the model to your working folder.

Perform Variant Transform on Example Model

  1. In the Apps tab, Open the Model Transformer by selecting Model Transformer. Or, in the Command Window, type:

mdltransformer('ControlFlowOptimization')

2. Select the check Replace Modeling Patterns with Variant Blocks

3. In the Specify system constant cell array field, you can specify a cell array of character vectors consisting of Simulink.Parameters. The base workspace must contain their definitions.

4. In the Prefix of transformed model name field, specify a prefix for the model name. If you do not specify a prefix, the default is gen0_.

5. Select Run This Check. The Model Transformer lists system constants and blocks that qualify to be part of condition expressions in Variant Source or Variant Subsystem blocks. For the Model Transformer to list a system constant, it must be a Simulink.Parameter object of scalar type. For this example, Cond qualifies to part of a condition expression.

6. If you do not want one of the transformations to occur, you can clear the check box next to it.

7. Select Refactor Model. The Model Transformer provides a hyperlink to the transformed model and hyperlinks to the corresponding blocks in the original model and the transformed model. The transformed model or models are in the folder that has the prefix m2m plus the original model name. For this example, the folder name is m2m_ControlFlowOptimization.

8. In the original model ControlFlowOptimization , right-click one of the Switch blocks. In the menu, select Model Transformer > Traceability to Transformed Block. In the transformed model gen0_ControlFlowOptimization, the corresponding Variant Source block is highlighted.

9. In the transformed model gen0_ControlFlowOptimization, right-click one of the Switch blocks. In the menu, select Model Transformer > Traceability to Original Block. In the original model ControlFlowOptimization, the corresponding Switch block is highlighted.

Model Transformation Limitations

The Model Transformer tool has these limitation:

  • In order to run the Model Transformer on a model, you must be able to simulate the model.

  • If an If Action Subsystem block drives a Merge block, and the Merge block has another inport that is either unconnected or driven by another conditional subsystem, the Model Transformer does not add a Variant Source block. This modeling pattern produces a warning and an excluded candidate message.

  • The Model Transformer cannot perform a variant transformation for every modeling pattern. This list contains some exceptions:

    • The model contains a Model block that references a protected model.

    • A model contains a Variant Source block with the Variant activation time parameter set to update diagram.

  • After you run one or more tasks, you cannot rerun the tasks because the Run this Check and Run All buttons are deactivated. If you want to rerun a task, reset the Model Transformer by right-clicking Model Transformer and selecting Reset.

  • Do not change a model in the middle of a transformation. If you want to change the model, close the Model Transformer, modify the model, and then reopen the Model Transformer.

  • For the hyperlinks in the Model Transformer to work, you must have the model to which the links point to open.

Related Topics