Simulate Multiple Referenced Model Instances in Normal Mode
Normal Mode Visibility
All instances of a referenced model that simulate in normal mode are part of the simulation. However, only one normal-mode instance of the referenced model supports all data visualizations. For example, scopes and port value labels display data for only the instance that has normal mode visibility enabled. To view simulation results for all instances of the referenced model, use the Simulation Data Inspector. To view instance-specific data for each instance of the model that simulates in normal mode, use Display blocks in the referenced model.
To set normal mode visibility, in the top model, on the Simulation tab, in the Prepare gallery, under Signal Monitoring, click Normal Mode Visibility. This setting determines the instance that has normal mode visibility enabled. If you do not specify normal mode visibility for an instance of a referenced model, Simulink® software selects which instance of the referenced model has normal mode visibility enabled.
After a simulation, if you try to open a referenced model from a Model block that does not have normal mode visibility, Simulink software displays a warning.
To set up your model to control which instance of a referenced model in normal mode has visibility and to ensure proper simulation of the model, see Specify the Instance Having Normal Mode Visibility.
Examine Models with Multiple Referenced Model Instances
The sldemo_mdlref_basic
model has Model blocks named
CounterA
, CounterB
, and CounterC
that each reference the sldemo_mdlref_counter
model. If you update the
diagram, sldemo_mdlref_basic
displays different icon corners for each of
the Model blocks.
Model Block | Icon Corners | Simulation Mode and Normal Mode Visibility Setting |
---|---|---|
CounterA | White | Normal mode, with normal mode visibility enabled |
CounterB | Gray corners | Normal mode, with normal mode visibility disabled |
CounterC | Black corner | Accelerator mode (normal mode visibility is not applicable) |
Open and simulate sldemo_mdlref_basic
. Double-click the
Model block named CounterA
and open the
Scope block named ScopeA
.
The scope displays the simulation results for the Model block named
CounterA
, which has normal mode visibility enabled.
If you open the sldemo_mdlref_counter
model by double-clicking the
Model block named CounterB
, the scope in
sldemo_mdlref_counter
still shows the results of the
Model block named CounterA
because that block has normal
mode visibility enabled.
For more information on sldemo_mdlref_basic
, see Component-Based Modeling with Model Reference.
For an example that uses the Dependency Analyzer for a model hierarchy that contains multiple instances of a referenced model in normal mode, see Visualize Model Reference Hierarchies.
Configure Models with Multiple Referenced Model Instances
Set the Total number of instances allowed per top model parameter to
Multiple
.Set each instance of the referenced model so that it uses normal mode. In the block parameters dialog box for the Model block that references the instance, set the Simulation Mode parameter to
Normal
. Ensure that all the ancestors in the hierarchy for that Model block are in normal mode.The corners of icons for Model blocks that are in normal mode can be white (empty). The corners turn gray after you update the diagram or simulate the model.
If necessary, modify S-functions used by the model so that they work with multiple instances of referenced models in normal mode. For details, see Supporting the Use of Multiple Instances of Referenced Models That Are in Normal Mode.
By default, Simulink assigns normal mode visibility to one of the instances. After you complete the configuration steps, you can specify a non-default instance to have normal mode visibility.
For more information about encapsulating a reusable algorithm in a referenced model, see Model Reuse.
Determine Which Instance Has Normal Mode Visibility
To determine which instance currently has normal mode visibility enabled:
To apply the normal mode visibility setting, update the diagram and make no other changes to the model.
Examine the Model blocks that reference the model that you are interested in. The Model block that has white corners has normal mode visibility enabled.
When you are editing a model or during compilation, after updating the diagram, use
the ModelReferenceNormalModeVisibilityBlockPath
parameter. The result
is a Simulink.BlockPath
object that is the
block path for the Model block that references the model that has normal
mode visibility enabled. For example:
get_param('sldemo_mdlref_counter',... 'ModelReferenceNormalModeVisibilityBlockPath')
ans = Simulink.BlockPath Package: Simulink Block Path: 'sldemo_mdlref_basic/CounterA'
For a top model that you are simulating or that is in a compiled state, you can use
the CompiledModelBlockNormalModeVisibility
parameter. For example:
a = get_param('sldemo_mdlref_depgraph',... 'CompiledModelBlockNormalModeVisibility')
a = struct with fields: sldemo_mdlref_F2C: [1×1 Simulink.BlockPath] sldemo_mdlref_heater: [1×1 Simulink.BlockPath]
When you create a Simulink.BlockPath
object for specifying normal
mode visibility:
The first character vector must represent a block that is in the top model of the model reference hierarchy.
Character vectors must represent Model blocks that are in normal mode.
Character vectors that represent variant models or variant subsystems must refer to an active variant.
Specify the Instance Having Normal Mode Visibility
Note
You cannot change normal mode visibility during simulation.
To enable normal mode visibility for a different instance of the referenced model than the instance that currently has normal mode visibility:
Navigate to the top model.
On the Simulation tab, in the Prepare section, under Signal Monitoring, select Normal Mode Visibility.
The Model Block Normal Mode Visibility dialog box appears. For example, here is the dialog box for the
sldemo_mdlref_basic
model, with the hierarchy pane expanded:The model hierarchy pane shows a partial model hierarchy for the model from which you opened the dialog box. The hierarchy stops at the first Model block that is not in normal mode. The model hierarchy pane does not display Model blocks that reference protected models.
The dialog box shows the complete model hierarchy for the top model. The normal mode instances of referenced models have check boxes.
Tip
To have the model hierarchy pane of the Model Block Normal Mode Visibility dialog box reflect the current model hierarchy, click Refresh.
Select the instance of the model that you want to have normal mode visibility.
Simulink selects all ancestors of the model and clears all other instances of that model. When a model is cleared, Simulink clears all children of that model.
Tip
To open a model from the Model Block Normal Mode Visibility dialog box, right-click the model in the model hierarchy pane and then click Open.
To apply the normal mode visibility setting, simulate the top model in the model hierarchy.
As an alternative to using
the Model Block Normal Mode Visibility dialog box, at the MATLAB® command line you can use the
ModelBlockNormalModeVisibility
parameter. For input, you can
specify one of these values:
An array of
Simulink.BlockPath
objects. For example:bp1 = Simulink.BlockPath({'mVisibility_top/Model', ... 'mVisibility_mid_A/Model'}); bp2 = Simulink.BlockPath({'mVisibility_top/Model1', ... 'mVisibility_mid_B/Model1'}); bps = [bp1, bp2]; set_param(topMdl,'ModelBlockNormalModeVisibility',bps);
A cell array of cell arrays of character vectors, with the character vectors being paths to individual blocks and models. This example produces the same effect as the object array example:
p1 = {'mVisibility_top/Model','mVisibility_mid_A/Model'}; p2 = {'mVisibility_top/Model1','mVisibility_mid_B/Model1'}; set_param(topMdl,'ModelBlockNormalModeVisibility',{p1, p2});
An empty array, to specify the use of the Simulink default selection of the instance that has normal mode visibility. For example:
set_param(topMdl, 'ModelBlockNormalModeVisibility', []);
Using an empty array is equivalent to clearing all the check boxes in the Model Block Normal Mode Visibility dialog box.