Documentation

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 Operators and Operands in Variant Condition Expressions (Simulink) are supported except for bitwise operations.

Example Model

This example shows how to use the Model Transformer to transform a model into a variant system. The example uses the model rtwdemo_controlflow_opt. 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. In the Command Window, type rtwdemo_controlflow_opt.

  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 3 for the Switch blocks Switch1, Switch2, and Switch3.

  4. Save the model to your working folder.

Identify Blocks That Qualify for Variant Transformation

  1. From the Model Editor, open the Model Transformer by selecting Analysis > Refactor Model > Model Transformer. Or, in the Command Window, type:
    mdltransformer('rtwdemo_controlflow_opt')

  2. Select the folder Transform the model to variant system. If you want to perform the three steps of the transformation at once, you can select Run all, or proceed one step at a time.

  3. Select the first step 1. Identify system constants for use in variant transformation. For the Model Transformer to list a system constant, it must be a Simulink.Parameter object of scalar type.

  4. Select Run This Task. The Model Transformer lists system constants that qualify to be part of condition expressions in Variant Source or Variant Subsystem blocks. For this example, Cond qualifies to part of a condition expression.

  5. Select the second step 2. Identify blocks that qualify for variant transformation.

  6. Select Run This Task. The Model Transformer lists blocks that qualify for a variant transformation. If you do not want one of the transformations to occur, you can clear the check box next to it.

Perform Variant Transformation

  1. Select the third step 3. Convert blocks to variants. This step creates a model with the blocks that you specified for transformation in step 2.

    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. The transformed model is in the folder m2m_rtwdemo_controlflow_opt.

    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_rtwdemo_controlflow_opt.

  2. Select Run This Task. The Model Transformer provides a hyperlink to the transformed model and hyperlinks to the corresponding blocks in the original model and the transformed model.

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

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

Model Transformation Limitations

The Model Transformer tool has these limitations:

  • 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. When you perform the step Convert blocks to variants, 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 protected model reference block.

    • A model contains a Variant Source block with the Analyze all choices during update diagram and generate preprocessor conditionals parameter set to off.

  • After you run one or more tasks, you cannot rerun the tasks because the Run this Task 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

Was this topic helpful?