Convert subsystems to referenced models
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 Choose Among Types of Model Components.
When the conversion encounters an issue, the advisor helps you review and fix the issue. Preparing the contents of a Subsystem block can eliminate or reduce the number of issues that the advisor identifies. Addressing these issues in the model editing environment can be more efficient than switching repeatedly between the advisor and the Simulink® Editor.
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).
In the Simulink Editor, select a Subsystem block. In the Simulink Toolstrip, on the Subsystem Block tab, select Convert > Model Block.
In the MATLAB® command window, use the Simulink.SubSystem.convertToModelReference
function with the
'UseConversionAdvisor'
argument set to
true
.
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.
Input Parameter | Description |
---|---|
New model name | The advisor provides a model name based on the Subsystem block name that is unique in the MATLAB path. The model name cannot exceed 59 characters. For more information, see Model Names. Tip If the advisor generates an error indicating that the target referenced model already exists, then use the New model name parameter to specify a new file name. |
Conversion data file name | The advisor creates a file for storing data created
during the conversion. By default, the advisor uses the
model name at the beginning of the file name and appends
the file name with
You
can save the conversion data in a MAT-file (default) or
a MATLAB file. If you use a Note If the top model uses a data dictionary, you cannot select this option. |
Fix errors automatically (if possible) | 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. If you enable this parameter, the advisor fixes all the conversion errors it can without displaying the Fix button. |
Replace the content of a subsystem with a Model block | 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.
Clear this parameter to have the advisor open a new Simulink Editor window that contains only a Model block that references the newly created referenced model. The advisor does not update the original model in the other Simulink Editor window. |
Copy code mapping information to the new converted model | Copy the code mapping information from the parent model to the new, converted referenced model. By default, this parameter is cleared. 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). |
Model block simulation mode | Simulation mode for the new Model block that references the referenced model.
|
Check simulation results after conversion | Compare top-model simulation results before and after conversion. To use this option, before performing the conversion:
To see the results after the conversion is complete, click View comparison results. The advisor displays the results of the comparison in the Simulation Data Inspector. For more information, see Compare Simulation Results Before and After Conversion. |
Stop time | By default, the advisor uses the stop time of the
top model, unless the stop time of the top model is
To use this option, select Check simulation results after conversion. |
Absolute tolerance | The absolute signal tolerance for the simulation
run comparison. The default is
To use this option, select Check simulation results after conversion. |
Relative tolerance | The relative signal tolerance for the simulation
run comparison. The default is
To use this option, select Check simulation results after conversion. |
Show report after run | After the conversion completes, open a report that summarizes the conversion setup and results. |
The Model Reference Conversion Advisor can step through each check automatically.
After you configure the subsystem conversion options, click Convert.
The Model Reference Conversion Advisor steps through each check automatically.
Address any issues that the advisor reports. The advisor provides a Fix button for any issues it can fix automatically.
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 on conversion input parameters, see Set Subsystem Conversion Options.
In the left pane, select the Check conversion input parameters node.
Click the Run This Task button.
Address any issues that the advisor reports. The advisor provides a Fix button for any issues it can fix automatically.
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.
In the left pane, select the Check model configurations node.
Click the Run This Task button.
Address any issues that the advisor reports. The advisor provides a Fix button for any issues it can fix automatically.
After you address the reported issues, click Continue.
Verify whether the subsystem interface meets model reference requirements.
In the left pane, select the Check subsystem interface node.
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.
Address any issues that the advisor reports. The advisor provides a Fix button for any issues it can fix automatically.
After you address the reported issues, click Continue.
Verify whether the subsystem content meets model reference requirements.
In the left pane, select the Check subsystem content node.
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.
Address any issues that the advisor reports. The advisor provides a Fix button for any issues it can fix automatically.
After you address the reported issues, click Continue.
After all checks run successfully, complete the conversion.
In the left pane, select the Complete conversion node.
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 Simulink Requirements™ 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.
For more information, see Compare Simulation Data.