Main Content

Reduce Models Containing Variant Blocks

Note

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

Overview of Variant Configurations

A model hierarchy may contain several variant blocks, each with many variant choices. You must associate each variant choice in a model with a variant control that is used to determine if the choice is active or inactive. A combination of these variant choices represents a specific implementation of the system being modeled. It also corresponds to a specific variant path in the model.

A variant configuration is used to represent such a combination of variant choices. It contains a set of variant control variables and their values, using which you can activate a specific variant path in the model. The number of variant configurations for a model can be high depending on the number of variant control variables used in the model. You can use Variant Manager to create and manage such variant configurations.

Variant Reducer

You can use the Variant Reducer tool in Variant Manager to automatically generate a simplified, standalone model that contains only the selected variant paths from the input model — the generated model is referred to as a reduced model.

The reduced model retains the variant configurations that you choose from the parent variant model. The tool has a Reduction mode that provides multiple ways to specify the configurations to be retained. You can choose configurations based on:

  • Current values of variant control variables in the global workspace.

  • Named variant configurations created for the model.

  • Specified values of variant control variables.

You can choose to compile the input model in simulation or code generation mode as part of the reduction process using the Compile Mode option.

The tool performs these actions:

  • Removes the model components in the inactive variant paths for the variant configurations that you choose to retain in the reduced model.

  • Removes or modifies model components such as blocks, masks, model references, subsystem references, libraries, dependent files such as MAT or .sldd files, and variables in the input model to create the reduced model. For more information, see Considerations and Limitations.

  • Packages the reduced artifacts into a user-specified output folder.

  • Generates a detailed summary of the reduction process that helps to analyze these changes.

An example use case for the tool is for vendor-supplier workflows.

Consider a model with a Variant Source and Variant Subsystem block with two variant choices having conditions, V==1 and V==2, respectively. The image shows the reduced model for the variant configuration corresponding to V=1.

Example of reducing a model with a Variant Source and Variant Subsystem block

Reduce a Variant Model Using Variant Manager

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

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, slexVariantReducer_config.

Model with Variant Source, Variant Sink, and Variant Subsystem.

To reduce the model, perform these steps:

  1. Open Variant Manager. On the Modeling tab, open the Design section and click Variant Manager. Alternatively, right-click the variant badge on any variant block and select Open in Variant Manager.

    variant badge on variant block

    The Variant Manager opens and displays the predefined configurations.

    Variant Manager window.

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

    Variant reducer dialog box.

  3. In the Reduction mode section, select:

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

      Variant Reducer dialog box with reduction mode selected as current variant control values.

    • Specify variant configurations: To reduce the model for the Named configurations defined in a variant configuration data object associated with the model.

      Variant Reducer dialog box with reduction mode selected as specify variant configurations.

      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 by specifying values for the variant control variables. You can create multiple variable groups that correspond to the different variant configurations to be retained in the reduced model. In each variable group you must specify the variant control variables and the values to be considered for each variable.

      Click New variable group. You can either specify a variant control value or select Full-range or Ignored from the Values list.

      Specifying a variant control value as a vector 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, Variant activation time in the block parameters dialog of the blocks which uses that Variant control variable must be set to code compile.

      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.

      Variant Reducer dialog box with reduction mode selected as specify variant control values.

  4. From Compile mode, select sim to compile the model for simulation or codegen to compile the model in the code generation mode as part of reducing the model. If the model contains variant blocks with the Variant control mode parameter set to sim codegen switching, you can select codegen to retain the code generation branches of the blocks in the reduced model. For the default value sim, Variant Reducer compiles and retains the simulation branches in the top-level model.

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

  6. 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. For more information, see Generate Variant Reducer Summary.

    Note

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

  7. 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, the suffix is _r.

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

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

    Reduced model

Generate Variant Reducer Summary

Variant Reducer provides an option to generate a detailed report of the reduction process as an HTML file. The report is saved in the output folder where reduced artifacts are saved.

Note

A Simulink Report Generator™ license is required to generate a Variant Reducer summary.

The Variant Reducer summary can be used to:

  • Verify the input and output options used for reduction, for example, the input variant configuration and the output folder location.

  • Analyze the differences between the original model and the reduced model, for example:

    • Blocks that have been inserted, deleted, or modified.

    • Masks that have been modified.

    • Dependent data files or Simulink cache files that have been modified.

  • Identify any warnings.

  • Identify if the model is reduced for the code generation branch.

  • Identify components that were not reduced and determine the manual updates that may be required, for example, callback code and Stateflow® variant transitions.

  • Navigate the interactive views of the original and reduced models.

To generate the report from the Variant Reducer dialog box, select the Generate detailed summary check box during reduction. To generate the report while reducing the model programmatically, set the 'GenerateSummary' name-value argument to true. For example, this command generates the summary and saves it to the path L:\Models\variantReducerRpt.

addpath(fullfile(matlabroot,'examples','simulink_variants','main'));
open_system('slexVariantReducer');
Simulink.VariantManager.reduceModel...
('slexVariantReducer','NamedConfigurations', {'config1'},'GenerateSummary',true,'OutputFolder','L:\Models');

variant reducer summary

Variant Conditions on Simulink Function Blocks After Reduction

If a model that contains a Simulink Function block is reduced for any or a combination of the available variant conditions on the block, the Simulink Function block in the reduced model becomes unconditional.

Consider a variant model that contains a Simulink Function block with the Variant control parameter value set to V==1 || V==2 || V==3 || V==4. If the model is reduced for the variant control values V=1, V=2, and V=3, the Simulink Function block in the reduced model is unconditional. if the model is reduced for the variant control values 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 control value.

Reduce a 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 based on named variant configurations:

    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 a model programmatically, see reduceModel.

Considerations and Limitations

  • Reduction of models that contain the Variant Connector block is not supported.

  • Reduction of models that contain variant blocks with the Variant activation time parameter set to startup is not supported.

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

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

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

  • Signal attributes such as data type, complexity, or dimensions coming from the inactive elements in Stateflow charts may not be retained in the reduced model.

Model Components That Are Not Reduced

These model components are not reduced automatically and may require manual intervention. To identify such artifacts, generate the Variant Reducer summary by selecting the Generate detailed summary check box in the Variant Reducer dialog box during model reduction.

  • Callback code:

    • Callbacks such as InitFcn, PreLoad, PostLoad, mask initialization code, and mask parameter callback code must be modified manually.

    • Callback code in the inactive variant components are removed. This can cause unexpected behavior in the reduced model.

  • During model reduction, elements in the Stateflow canvas, including variant transitions are not modified.

  • If a model has dependencies on files that are located under matlabroot (Simulink libraries, .m files, .mat files, or .sldd files), they are not modified or copied to the output folder during model reduction.

  • Variant parameter objects (instance of the Simulink.VariantVariable class) are not reduced.

See Also

Related Examples

More About