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.
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 totrue
.
Examples
Set Subsystem Conversion Options
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.
Automatically Convert Subsystem to Referenced Model
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.
Check Conversion Input Parameters
Verify that all conversion input parameters are valid.
For information about specific parameters, see Parameters.
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.
Check Model Configurations
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.
Check Subsystem Interface
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.
Check Subsystem Content
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.
Complete Conversion
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 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.
Compare Simulation Results Before and After Conversion
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.
Related Examples
Parameters
New model name
— Unique name for model file
text
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.
Conversion data file name
— Unique name for conversion data file
text
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.
Fix errors automatically (if possible)
— Option to apply available fixes
off
(default) | on
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.
Replace the content of a subsystem with a Model block
— Option to replace subsystem with referenced model
on
(default) | off
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.
Copy code mappings
— Option to copy code mapping information to new model
off
(default) | on
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).
Model block simulation mode
— Simulation mode for model reference instance
Normal
(default) | Accelerator
| Software-in-the-loop (SIL)
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.
Check simulation results after conversion
— Comparison of top-model simulation results before and after conversion
off
(default) | on
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.
Stop time
— Simulation stop time
positive scalar
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.
Absolute tolerance
— Absolute tolerance for simulation comparison
1e-06
(default) | positive scalar
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.
Relative tolerance
— Relative tolerance for simulation comparison
0.001
(default) | positive scalar
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.
Show report after run
— Option to open conversion report upon completion
off
(default) | on
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 R2014aR2023a: Copy service interface code mappings from parent model to referenced model
Service interface code mappings were introduced in R2022b. Starting in R2023a, you can copy service interface code mappings from the parent model to the newly created referenced model. To copy the mappings, select the Copy code mappings parameter in the Model Reference Conversion Advisor. To learn more about service interface code mappings, see C Service Interfaces (Embedded Coder). To learn more about code mapping configurations, see Define Service Interfaces, Storage Classes, Memory Sections, and Function Templates for Software Architecture (Embedded Coder).
R2020b: Copy code mappings from parent model to referenced model
Starting in R2020b, you can copy code mappings from the parent model to the newly created referenced model. To copy the code mappings, select the Copy code mappings parameter in the Model Reference Conversion Advisor.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other bat365 country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)