Model reference offers benefits 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.
The Model Reference Conversion Advisor does not support conversion for some types of subsystems.
Subsystem blocks with Simscape™ Multibody™ components that cross the subsystem boundary
Masked Subsystem blocks — To convert masked
Subsystem blocks to Model blocks, use the
function.Simulink.SubSystem.convertToModelReference
Asynchronous subsystems — To convert asynchronous subsystems to referenced models that accept asynchronous function calls, see Asynchronous Support Limitations (Simulink Coder).
The Model Reference Conversion Advisor helps you review and fix issues. 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.
To convert the Subsystem block without preparing its contents, see Convert Subsystem Blocks to Model Blocks. Otherwise, take these steps to prepare Subsystem block contents:
Set the Signal
resolution parameter to Explicit
only
or None
.
You can use the Model Reference Conversion Advisor Fix option to address this issue.
Configure the Subsystem block interface.
Subsystem Block Interface | What to Look For | Model Modification |
---|---|---|
Goto or From blocks | Goto or From blocks crossing the subsystem boundary | Replace From blocks that have a corresponding Goto block that crosses the subsystem boundary with an Inport block. Replace each Goto block that has corresponding From blocks that cross the subsystem boundary with an Outport block. Connect the Inport and Outport blocks to the corresponding subsystem ports. You can use the Model Reference Conversion Advisor Fix option to address this issue. |
Data stores | Data Store Memory blocks accessed by Data Store Read or Data Store Write blocks from outside of the subsystem | Replace the Data Store Memory block with a
global data store. Define a global data store using a
You can use the Model Reference Conversion Advisor Fix option to address this issue. |
Tunable parameters | Global tunable parameters in the dialog box opened using the Configuration Parameters > Code Generation > Optimization > Configure button | To create a The
For more information, see Parameterize Instances of a Reusable Referenced Model and Tunable Parameters. You can use the Model Reference Conversion Advisor Fix option to address this issue. |
Configure the Subsystem block contents.
Subsystem Configuration | What to Look For | Model Modification |
---|---|---|
Function calls | Function-call signals that cross virtual subsystem boundaries | Move the Function-Call Generator block into the subsystem that you want to convert. NoteIf you convert an export-function subsystem, then you do not need to move the Function-Call Generator block. |
Function-call outputs | Change the function-call outputs to data triggers. | |
Wide function-call ports | Eliminate wide signals for function-call subsystems. | |
Sample times | An Inport block sample time that does not match the sample time of the block driving the Inport block | Insert Rate Transition blocks where appropriate. |
Inport blocks | Merged Inport blocks | Configure the model to avoid merged Inport blocks. See the Merge block documentation. |
Constant blocks | Constant blocks that provide input for subsystems | Move Constant blocks into the subsystem. |
Buses | Bus signals that enter and exit a subsystem | Match signal names and bus element names for blocks inside the subsystem. To find signal names that do not match bus element names, use the Signal label mismatch diagnostic. |
Duplicate signal names in buses | Make signal names of bus elements unique. | |
Signal names that are not valid MATLAB® identifiers. A valid identifier is a character vector that meets these conditions:
| Change any invalid signal names to be valid MATLAB identifiers. |
To convert a Subsystem block to a Model block, use the Model Reference Conversion Advisor.
Make sure that the model containing the subsystem that you want to convert compiles successfully.
For improved conversion performance, close any open Scope block windows.
To open the Model Reference Conversion Advisor, right-click the Subsystem block and select Subsystem & Model Reference > Convert to > Referenced Model.
Review the default settings under Input Parameters. Modify the parameters as needed, then click Apply.
The advisor can fix some conversion issues automatically. Select Fix errors automatically (if possible). This option can make the conversion process faster, but you do not control the fixes that the advisor makes.
The advisor can leave the Subsystem block in place and create a separate model from the contents of the Subsystem block. Clear Replace the content of a subsystem with a Model block.
The advisor can compare top-model simulation results before and after conversion. To compare simulation results:
Enable signal logging for output signals of interest
Select Check simulation results after conversion and Replace the content of a subsystem with a Model block
Set the Stop time, Absolute tolerance, and Relative tolerance
Set the Model block simulation mode option in the advisor to the same simulation mode as the original model
Click Convert. For information about the checks, right-click the check (such as Check conversion input parameters) and select What's This?
Address any issues that the advisor reports. For some issues, the advisor provides a Fix button to address an issue.
After you address each issue, click Continue until the advisor reports no remaining issues.
Alternatively, you can use the Simulink.SubSystem.convertToModelReference
function. You can convert
multiple Subsystem blocks using one
Simulink.SubSystem.convertToModelReference
command. However, you
cannot convert a parent subsystem and a child of that subsystem at the same time.
After the Model Reference Conversion Advisor runs all checks successfully, it:
Creates a referenced model from the subsystem.
Creates the bus objects, signal objects, and tunable parameters that the referenced model requires.
By default, replaces the Subsystem block with a Model block that contains the referenced 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 it copies.
Optionally checks the consistency of simulation results before and after conversion.
The advisor 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.
The Model Reference Conversion Advisor can compare simulation results before and after the conversion. After you successfully run the Complete conversion check, select 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 about the Simulation Data Inspector, see View and Analyze Simulation Results.
If you are not satisfied with the conversion results, you can restore the model to its initial state. Use one of these approaches:
At any point during the conversion, select File > Load Restore Point.
After you successfully run the Complete conversion check, select Click here to restore the original model.
After you complete the conversion, update the model as necessary to meet your modeling requirements. For example, you can manually replace a Subsystem block with a Model block that references the created referenced model.
If you want to simulate the model with external data, check that the root Inport blocks in the new referenced model have the appropriate Interpolate data parameter setting. See the documentation for the Interpolate data parameter of the Inport block.