Main Content

Model Reference Conversion Advisor

Convert subsystems to referenced models

Description

The Model Reference Conversion Advisor converts subsystems, including conditional and referenced subsystems, to referenced models.

Converting subsystems to referenced models is beneficial for modeling large, complex systems and for team-based development. Many large models use a combination of subsystems and referenced models. To decide whether to convert a subsystem to a referenced model, see Explore Types of Model Components.

When the conversion encounters an issue, the Model Reference Conversion Advisor helps you review and fix the issue. Preparing the contents of a Subsystem block can eliminate or reduce the number of issues. Addressing these issues in the model editing environment can be more efficient than switching repeatedly between the Model Reference Conversion Advisor and the Simulink® Editor.

The Model Reference Conversion Advisor window.

Open the Model Reference Conversion Advisor

  • In the Simulink Editor, select a Subsystem block. In the Simulink Toolstrip, perform one of these actions.

    • On the Subsystem Block tab, select Convert > Model Block.

    • On the Modeling tab, in the Component gallery, select Convert to Model Block.

  • In the MATLAB® Command Window, use the Simulink.SubSystem.convertToModelReference function with the 'UseConversionAdvisor' argument set to true.

Examples

expand all

Specify input parameters that determine the output of the conversion and control whether the advisor automatically attempts to fix conversion errors.

When you open the advisor, in the left pane, the top node is selected. This node identifies the Subsystem block that the advisor will convert to a referenced model and provides conversion input parameters. You can use the default parameter values or change the values to customize the conversion.

For information about specific parameters, see Parameters.

The Model Reference Conversion Advisor can step through each check automatically.

  1. After you configure the subsystem conversion options, click Convert.

    The Model Reference Conversion Advisor steps through each check automatically.

  2. Address any issues that the advisor reports. The advisor provides a Fix button for any issues it can fix automatically.

  3. After you address the reported issues, click Continue.

After the Model Reference Conversion Advisor successfully runs all checks, it completes the conversion.

Verify that all conversion input parameters are valid.

For information about specific parameters, see Parameters.

  1. In the left pane, select the Check conversion input parameters node.

  2. Click the Run This Task button.

  3. Address any issues that the advisor reports. The advisor provides a Fix button for any issues it can fix automatically.

  4. After you address the reported issues, click Continue.

Verify that the model configurations meet model referencing requirements. This check identifies model configuration parameter settings that are not valid for model references.

  1. In the left pane, select the Check model configurations node.

  2. Click the Run This Task button.

  3. Address any issues that the advisor reports. The advisor provides a Fix button for any issues it can fix automatically.

  4. After you address the reported issues, click Continue.

Verify whether the subsystem interface meets model reference requirements.

  1. In the left pane, select the Check subsystem interface node.

  2. Click the Run This Task button.

    The advisor verifies that the type of subsystem is one that the advisor can convert. Then, it verifies that the interfaces to specific types of subsystems, such as masked subsystems, meet conversion requirements.

  3. Address any issues that the advisor reports. The advisor provides a Fix button for any issues it can fix automatically.

  4. After you address the reported issues, click Continue.

Verify whether the subsystem content meets model reference requirements.

  1. In the left pane, select the Check subsystem content node.

  2. Click the Run This Task button.

    The advisor checks whether the model compiles successfully. Upon successful compilation, the advisor checks whether the blocks in the subsystem meet the requirements for conversion.

  3. Address any issues that the advisor reports. The advisor provides a Fix button for any issues it can fix automatically.

  4. After you address the reported issues, click Continue.

After all checks run successfully, complete the conversion.

  1. In the left pane, select the Complete conversion node.

  2. Click the Run This Task button.

    The Model Reference Conversion Advisor:

    • Creates a referenced model from the subsystem.

    • Creates the Simulink.Bus objects, Simulink.Signal objects, and tunable parameters that the referenced model requires.

    • By default, replaces the Subsystem block with a Model block that references the new model.

    • Inserts the Model block in a Subsystem block if the automatic fixes added ports to the Model block interface.

    • Creates an HTML conversion summary report in the slprj folder. This report summarizes the results of the conversion process, including the results of the fixes that the advisor performed. This report also describes the elements that the advisor copies.

    • Optionally checks the consistency of simulation results before and after conversion.

    • Copies the following elements from the original model to the new referenced model.

      • Configuration set — If the parent model uses:

        • A configuration set that is not a referenced configuration set, the advisor copies the entire configuration set to the referenced model

        • A referenced configuration set, then both the parent and referenced models use the same referenced configuration set

      • Variables — The advisor copies only the model workspace variables that the subsystem used in the original model to the model workspace of the referenced model. If the model that contained the subsystem uses a data dictionary, then the referenced model uses the same data dictionary.

      • Requirements links — The advisor copies requirements links created with Requirements Toolbox™ software to the Model block from the original Subsystem block.

If you are not satisfied with the conversion results, you can restore the model to its initial state. After you successfully run the Complete conversion check, use the Click here to restore the original model link.

If you selected Check simulation results after conversion, you can view the results by using the Click here to view the comparison results link.

If you selected Check simulation results after conversion, the Model Reference Conversion Advisor provides a comparison of top-model simulation results before and after conversion.

After you successfully run the Complete conversion check, click Click here to view the comparison results. The results display in the Simulation Data Inspector. A green check mark indicates that simulation results are within tolerance between the baseline model and the model with the new referenced model.

The Simulation Data Inspector compares a logged signal before and after conversion.

For more information, see Compare Simulation Data.

Related Examples

Parameters

expand all

The default new model name is a unique name on the MATLAB path that is based on the Subsystem block name.

The model name cannot exceed 59 characters. For more information, see Choose Valid Model File Names.

Tips

If you receive an error that the referenced model exists, use this parameter to specify a new model name.

The conversion data file stores any variables or objects created during the conversion.

By default, the filename begins with the model name and ends with _conversion_data.mat. For example, for a subsystem in a model named myModel, the default conversion filename is myModel_conversion_data.mat.

You can save the conversion data in a MAT file (.mat) or a script (.m). If you use a .m file extension, the file serializes all variables.

Dependencies

To enable this parameter, the top model must not use a data dictionary.

By default, if an advisor check finds an error that the advisor can fix, the advisor provides a Fix button. Click it to have the advisor fix the issue.

Select this parameter to have the advisor fix all the conversion errors it can without displaying the Fix button.

By default, the advisor updates the original model by inserting a Model block. The advisor action depends on whether you use the automatic fix options.

  • If you use the automatic fixes, then the advisor replaces the Subsystem block with a Model block unless the automatic fixes change the input or output ports. If the ports change, the advisor includes the contents of the subsystem in a Model block and inserts it into the Subsystem block.

  • If you do not use the automatic fixes, then the advisor replaces the Subsystem block with a Model block.

Clear this parameter to have the advisor open a new Simulink Editor window that contains only a Model block that references the newly created model. The advisor does not update the original model in the other Simulink Editor window.

Select this parameter to copy the code mapping information from the parent model to the new, converted referenced model.

Code mapping information includes configurations of model data elements for code generation. This parameter does not affect simulation.

For more information, see Convert Subsystem to Referenced Model and Generate Code (Simulink Coder).

The Model block simulation mode controls the simulation mode for the corresponding instance of the referenced model. Another Model block that references the same model can specify a different simulation mode for its instance of the referenced model.

  • Normal — Execute the referenced model interpretively, as if the referenced model is an atomic subsystem implemented directly within the parent model.

  • Accelerator — Create a MEX file for the referenced model. Then, execute the referenced model by running the S-function.

  • Software-in-the-loop (SIL) — This option requires an Embedded Coder® license. Generate production code based on the Model block Code interface parameter setting. The code is compiled for and executed on the host platform.

The corners of the Model block indicate the simulation mode of the Model block. For normal mode, the corners have empty triangles. For accelerator mode, the corner triangles are filled in. For SIL mode, the corners are filled in and the word (SIL) appears on the block icon.

The simulation mode of a parent model can override the simulation mode of a Model block. For more information, see Choose Simulation Modes for Model Hierarchies.

Select this parameter to compare top-model simulation results before and after conversion.

To see the results after the conversion is complete, click View comparison results. The Simulation Data Inspector displays the results of the comparison.

For more information, see Compare Simulation Results Before and After Conversion.

Tips

Before you perform the conversion:

  • Enable signal logging for the subsystem output signals of interest.

  • Set the Model block simulation mode option in the advisor to the same simulation mode as the original model.

  • Specify the Stop time, Absolute tolerance, and Relative tolerance.

Dependencies

To enable this option, select Replace the content of a subsystem with a Model block.

By default, the advisor uses the stop time of the top model, unless the stop time of the top model is inf. If the stop time of the top model is inf, the advisor uses a default stop time of 10.

Dependencies

To enable this parameter, select Check simulation results after conversion.

The absolute tolerance is the largest acceptable solver error, as the value of the measured signal approaches zero. The simulation results before conversion establish the baseline. The simulation results after conversion must be within the tolerance.

Dependencies

To enable this parameter, select Check simulation results after conversion.

The relative tolerance is the largest acceptable solver error, relative to the size of each signal during each time step. The simulation results before conversion establish the baseline. The simulation results after conversion must be within the tolerance.

The default value (0.001) means that the compared signal is accurate to within 0.1% of the baseline signal.

Dependencies

To enable this parameter, select Check simulation results after conversion.

After the conversion completes, the HTML conversion summary report appears in the slprj folder. This report summarizes the conversion setup and results, including the results of the fixes that the advisor performed. This report also describes the elements that the advisor copies.

Select this parameter to open the conversion report after the conversion completes.

Limitations

The Model Reference Conversion Advisor does not support conversion for some types of subsystems. For example:

  • Subsystem blocks with Simscape™ Multibody™ components that cross the subsystem boundary

  • Asynchronous subsystems — To convert asynchronous subsystems to referenced models that accept asynchronous function calls, see Asynchronous Support Limitations (Simulink Coder).

Version History

Introduced in R2014a

expand all