Reduce Models Containing Variant Blocks

Note

You require a Simulink® Design Verifier™ license to reduce your model.

A variant model can contain multiple variable structures and a single fixed structure. The combination of a variable structure and the fixed structure to create a model depends on different combinations of the variant choices that you select. Each combination of the variant choices can be stored as a variant configuration.

Variant models can be reduced to simplified, standalone model depending on the selected variant configurations. Additionally, all related files and variable dependencies are also reduced. These reduced artifacts are packaged into a user-specified output folder.

Note

Variant model containing a Subsystem Reference block cannot be reduced.

Consider the model Variant Reducer. The model contains a Variant Source block, a Variant Sink block, and a Variant Subsystem block with these variant choices:

  • Variant Source: V==1 and V==2

  • Variant Sink: W==1, W==2, and W==3

  • Variant Subsystem: V==1 and V==2

Assume that the model has two predefined variant configurations, named config1 (V==1 && W==2) and config2 (V==2 && W==2). These configurations are saved in a variant configuration data object, varConfig.

To reduce the model, perform the following steps:

  1. Right-click the variant badge, and select Open in Variant Manager. The Variant Manager opens displaying the predefined configurations.

  2. Click Reduce model. The Variant Reducer dialog box opens.

  3. In the Reduction mode section, select:

    • Current variant control values : To reduce the model based on its variant control variable values in the global workspace.

    • Specify variant configurations: To reduce the model that is associated with a variant configuration data object and configurations to be retained in the reduced model.

      Note

      During reduction, the control variable values from the last selected configuration are stored in the global workspace.

    • Specify variant control values: To reduce the model based on the variant control variable values. You can create multiple variable groups corresponding to different configurations. Click New variable group to set the values for variant control variables. You can either specify a variant control value or select Full-range or Ignored from the drop-down list. Specifying a variant control value as a vector also allows you to reduce a model for all combinations of that variable. For example, if you specify values V = 1 and W = [1,2], then the model is reduced for the configurations {V==1, W==1} and {V==1, W==2}. If you select Full-range as a variant control value, Reference Value column is activated to enter a reference value required for successful model compilation. The model is reduced for all valid values of the specified variant control variable. If you select Ignored as a variant control value, then that variant control variable is not considered while reducing the model.

      Note

      To use a full-range variant control variable, Analyze all choices during update diagram and generate preprocessor conditional option has to be selected in the block parameters dialog of the blocks which uses that Variant control variable.

    Note

    If you invoke variant reduction by specifying variable groups, the reduced model will have the variant configurations corresponding to the variable groups associated with it. This overwrites any existing variant configurations present in the original model.

  4. Select Preserve signal attributes to preserve the compiled signal attributes between the original and reduced model. When this option is selected, the Variant Reducer tries to preserve the compiled signal attributes between the original and reduced models by adding signal specification blocks at appropriate block ports in the reduced model. Compiled signal attributes include signal data types, signal dimensions, compiled sample times, and so on.

  5. Select Generate detailed summary to generate the Variant Reducer summary in the output folder. The Variant Reducer summary contains summary of Variant Reducer Options, Original and Reduced Model Differences, Dependent Artifacts, Callbacks and Warnings.

    The detailed summary can be used to get traceability information between the original and reduced model. It also helps in identifying artifacts which cannot be handled automatically and need manual intervention. For example, callback codes that may need to be modified.

    Note

    To generate detailed summary, you must have Simulink Report Generator license.

  6. Specify a value as the suffix in the Model suffix field. The model suffix value is appended to the reduced models, data dictionaries, and the related artifacts. By default, _r is the suffix.

  7. Specify the output folder to store the reduced model.

    Note

    Selecting the Open reduced model check box changes the current working folder to the output folder.

  8. Click Reduce. The reduced model for the required configurations are now created. If the model contains resolved library links or referenced models, the corresponding parent is reduced for the specified configuration and is referenced in the model. The reduced model, reduced referenced model, and the reduced library get their names from the corresponding model, referenced model, or the library with _r (Model suffix) appended to it.

Consider a Variant model that contains a Simulink Function block with Variant condition on the Simulink Function block as V==1 || V==2 || V==3 || V==4. If the model is reduced for any or a combination of the available Variant conditions, the Simulink Function block in the reduced model is unconditional. For example, if the model is reduced for Variant condition, V=1, V=2, and V=3, the Simulink Function block in the reduced model is unconditional. Whereas, if the model is reduced for Variant condition, V=1, V=2, and V=5, the Simulink Function block in the reduced model remains conditional with V==1 || V==2 as the Variant condition.

Reduce Model Programmatically

To reduce a model programmatically, use the syntax:

Simulink.VariantManager.reduceModel(model,<Name>,<Value>)

For example,

  • To reduce the model based on its variant control variable values in the global workspace.

    Simulink.VariantManager.reduceModel('sldemo_variant_subsystems')
  • To reduce the model based on its variant control variable values in the global workspace to a specified folder.

    Simulink.VariantManager.reduceModel('sldemo_variant_subsystems', 'OutputFolder', 'outdir')
  • To reduce the model that is associated with a variant configuration data object and configurations to be retained in the reduced model.

    Simulink.VariantManager.reduceModel('sldemo_variant_subsystems','NamedConfigurations', {'LinInterStd','NonLinExterHighFid'})
  • To reduce the model by specifying configurations in the form of a structure of variant control variables.

    Simulink.VariantManager.reduceModel('iv_model', 'VariableConfigurations', {'V',1,'W',[1 2]})

    Here, two configurations are specified corresponding to {V=1, W=1} and {V=1, W=2}, respectively.

  • To reduce the model by specifying variant control values where 'w' is a full-range variant control value.

    Simulink.VariantManager.reduceModel('slexVariantReducer','VariableConfigurations',{'V',1},'FullRangeVariables',{'W',1});

    Here, four configurations are computed corresponding to {V==1, W==1}, {V==1, W==2}, {V==1, W==3} and {V==1, W==0} respectively.

For more information on reducing model programmatically, see reduceModel.

Considerations and Limitations

  • The output folder to store the reduced model must not be under matlabroot.

  • If a model has dependencies on files that are located under matlabroot, these files are not modified or copied to the output folder during model reduction. File dependency can include files from the Simulink libraries, .m files, .mat files, .sldd files.

  • If the output folder contains the variant_reducer.log file from the previous model reduction, the reducer overwrites all the files available in that output for any subsequent reduction.

  • Callback code (For example, model callbacks, mask initialization code and mask parameter callback codes) are not modified during model reduction and must be modified manually.

  • Additional blocks are added automatically to the reduced model to ensure consistent simulation semantics. Additional blocks can include Signal Specification blocks for consistent signal attributes (data type, dimensions, complexity) or the Ground and the Terminator blocks for unconnected signals.

  • During model reduction, commented blocks present on the active path are retained while the commented blocks present on an inactive path are deleted.

  • During model reduction, Stateflow charts present on the active path are retained while the Stateflow charts present on an inactive path are deleted. However, they are not reduced.

Related Examples

More About