Simulate Multiple Referenced Model Instances in Normal Mode

Normal Mode Visibility

All instances of a normal-mode referenced model are part of the simulation. However, Simulink® software displays only one instance in a model window. Normal mode visibility includes the display of Scope blocks and data port values.

Set normal mode visibility by selecting in the top model the Diagram > Subsystem & Model Reference > Model Block Normal Mode Visibility. This setting determines the instance that Simulink software displays. If you do not specify normal mode visibility for a specific instance of a referenced model, Simulink software selects one instance of the referenced model to display.

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.

Example Models with Multiple Referenced Model Instances

The sldemo_mdlref_basic model and the “Visualizing Model Reference Architectures” featured example show the use of models containing multiple instances of a referenced model.

sldemo_mdlref_basic

The sldemo_mdlref_basic model has three Model blocks (CounterA, CounterB, and CounterC) that each reference the sldemo_mdlref_counter model.

If you update the diagram, the sldemo_mdlref_basic displays different icons for each of the three Model blocks that reference sldemo_mdlref_counter.

Model BlockIcon CornersSimulation Mode and Normal Mode Visibility Setting
CounterAWhite Normal mode, with normal mode visibility enabled
CounterBGray cornersNormal mode, with normal mode visibility disabled
CounterCBlack cornerAccelerator mode (normal mode visibility is not applicable)

Open and simulate sldemo_mdlref_basic. Double-click the CounterA model and open the ScopeA block.

That ScopeA block reflects the results of simulating the CounterA Model block, which has normal mode visibility enabled.

If you try to open mdlref_counter model by double-clicking the CounterB Model block, ScopeA in mdlref_counter still shows the results of the CounterA Model block because that block has normal mode visibility enabled.

Visualizing Model Reference Architectures

The featured example Visualizing Model Reference Architectures shows the use of the Model Dependency Viewer for a model (sldemo_mdlref_depgraph) that references multiple instances of a referenced model in normal mode. The example shows how to set up a model with multiple referenced instances in normal mode.

Configure Models with Multiple Referenced Model Instances

  1. Set the Total number of instances allowed per top model parameter to Multiple.

  2. 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.

  3. 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.

Specify the Instance Having Normal Mode Visibility

Determine Which Instance Has Normal Mode Visibility

To determine which instance currently has normal mode visibility:

  1. To apply the normal mode visibility setting, update the diagram and make no other changes to the model.

  2. 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, navigate through the model hierarchy.

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_basic',...
 '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 CompiledModelBlockInstancesBlockPath parameter. For example:

a = get_param('sldemo_mdlref_depgraph',...
 'CompiledModelBlockInstancesBlockPath')
a = 

         sldemo_mdlref_F2C: [1x1 Simulink.BlockPath]
      sldemo_mdlref_heater: [1x1 Simulink.BlockPath]
sldemo_mdlref_outdoor_temp: [1x1 Simulink.BlockPath]

Enable Normal Mode Visibility for an Instance

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:

  1. Navigate to the top model.

  2. In the Simulink Editor, select the Diagram > Subsystem & Model Reference > Model Block 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 block 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.

  3. 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.

  4. 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.

Related Examples

More About