Referenced Model Simulation Modes

Simulation Modes for Referenced Models

Simulink® executes the top model in a model reference hierarchy just as it would if no referenced models existed. All Simulink simulation modes are available to the top model. Simulink can execute a referenced model in any of four modes: Normal, Accelerator, Software-in-the-loop (SIL), or Processor-in-the-loop (PIL).

Normal Mode

Simulink executes a Normal mode referenced model interpretively. Normal mode, compared to other simulation modes:

  • Requires no delay for code generation or compilation

  • Works with more Simulink and Stateflow® tools, supporting tools such as:

    • Scopes, port value display, and other output viewing tools

      • Scopes work with Accelerator mode referenced models, but require using the Signal & Scope Manager and adding test points to signals. Adding or removing a test point necessitates rebuilding the SIM target for a model, which can be time-consuming.

    • Model coverage analysis

    • Stateflow debugging and animation

  • Provides more accurate linearization analysis

  • Supports more S-functions than Accelerator mode does

Normal mode executes slower than Accelerator mode does.

Simulation results for a given model are nearly the same in either Normal or Accelerator mode. Trivial differences can occur due to differences in the optimizations and libraries that you use.

You can use Normal mode with multiple instances of a referenced model. For details, see Using Normal Mode for Multiple Instances of Referenced Models.

Accelerator Mode

Simulink executes an Accelerator mode referenced model by creating a MEX-file (or simulation target) for the referenced model, then running the MEX-file. See Model Reference Simulation Targets for more information. Accelerator mode:

  • Takes time for code generation and code compilation

  • Does not fully support some Simulink tools, such as Model Coverage and the Simulink Debugger.

  • Executes faster than Normal mode

Simulation results for a given model are nearly identical in either Normal or Accelerator mode. Trivial differences can occur due to differences in the optimizations and libraries that you use.

Software-in-the-Loop (SIL) Mode

Simulink executes a SIL-mode referenced model by generating production code using the model reference target for the referenced model. This code is compiled for, and executed on, the host platform.

With SIL mode, you can:

  • Verify generated source code without modifying the original model

  • Reuse test harnesses for the original model with the generated source code

SIL mode provides a convenient alternative to PIL simulation when the target hardware is not available.

This option requires Embedded Coder® software.

For more information, see Numerical Equivalence Testing in the Embedded Coder documentation.

Processor-in-the-Loop (PIL) Mode

Simulink executes a PIL-mode referenced model by generating production code using the model reference target for the referenced model. This code is cross-compiled for, and executed on, a target processor or an equivalent instruction set simulator.

With PIL mode, you can:

  • Verify deployment object code on target processors without modifying the original model

  • Reuse test harnesses for the original model with the generated source code

This option requires Embedded Coder software.

For more information, see Numerical Equivalence Testing in the Embedded Coder documentation.

Specify the Simulation Mode

The Model block for each instance of a referenced model controls its simulation mode. To set or change the simulation mode for a referenced model:

  1. Access the block parameter dialog box for the Model block. (See Navigating a Model Block.)

  2. Set the Simulation mode parameter.

  3. Click OK or Apply.

Mixing Simulation Modes

The following table summarizes the relationship between the simulation mode of the parent model and its referenced models.

Parent Model Simulation ModeReferenced model Simulation Modes
Normal
  • Referenced models can use Normal, Accelerator, SIL, or PIL mode.

  • A referenced model can execute in Normal mode only if every model that is superior to it in the hierarchy also executes in Normal mode. A Normal mode path then extends from the top model through the model reference hierarchy down to the Normal mode referenced model.

Accelerator
  • All subordinate models must also execute in Accelerator mode.

  • When a Normal mode model is subordinate to an Accelerator mode model, Simulink posts a warning and temporarily overrides the Normal mode specification.

  • When a SIL-mode or PIL-mode model is subordinate to an Accelerator mode model, an error occurs.

SIL
  • All subordinate models also execute in SIL mode, provided their simulation modes are Normal, Accelerator, or SIL. Otherwise, an error occurs. See Simulation Mode Override Behavior in Model Reference Hierarchy.

  • The SIL mode Model block uses the model reference targets of the blocks beneath.

  • Multiple Model blocks, starting at the top of a model reference hierarchy, can execute at a time in SIL mode. However, during code coverage or code execution profile, only one Model block can execute at a time in SIL mode.

PIL
  • All subordinate models also execute in PIL mode, provided their simulation modes are Normal, Accelerator, or PIL. Otherwise, an error occurs. See Simulation Mode Override Behavior in Model Reference Hierarchy.

  • The PIL mode Model block uses the model reference targets of the blocks beneath.

  • Only one Model block, starting at the top of a model reference hierarchy, can execute at a time in PIL mode.

For more information about SIL and PIL modes, see in the Embedded Coder documentation:

Using Normal Mode for Multiple Instances of Referenced Models

You can simulate a model that has multiple references in Normal mode.

Normal Mode Visibility

All instances of a Normal mode referenced model are part of the simulation. However, Simulink displays only one instance in a model window; that instance is determined by the Normal Mode Visibility setting. Normal mode visibility includes the display of Scope blocks and data port values.

If you do not set Normal Mode Visibility, Simulink picks one instance of each Normal mode model to display.

After a simulation, if you try to open a referenced model from a Model block that has Normal Mode Visibility set to off, Simulink displays a warning.

For a description of how 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 That Has Normal Mode Visibility.

    Note:   If you change the Normal Mode Visibility setting for a referenced model, you must simulate the top model in the model reference hierarchy to make use of the new setting.

Examples of a Model with Multiple Referenced Instances in Normal Mode

sldemo_mdlref_basic.  The sldemo_mdlref_basicsldemo_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)

If you do the following steps, then the ScopeA block appears as shown below:

  1. Simulate sldemo_mdlref_basic.

  2. Open the sldemo_mdlref_counter model.

  3. 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 from the CounterB Model block (for example, by double-clicking the Model block), ScopeA in mdlref_counter still shows the results of the CounterA Model block, because that is the Model block with Normal Mode Visibility set to on.

sldemo_mdlref_depgraph.  The sldemo_mdlref_depgraphsldemo_mdlref_depgraph model shows the use of the Model Dependency Viewer for a model that has multiple Normal mode instances of a referenced model. The model shows what you need to do to set up a model with multiple referenced instances in Normal mode.

Set Up a Model with Multiple Instances of a Referenced Model in Normal Mode

This section describes how to set up a model to support the use of multiple instances of Normal mode referenced models.

  1. Set the Configuration Parameters > Model Referencing > Total number of instances allowed per top model parameter to Multiple.

    If you cannot use the Multiple setting for your model, because of the requirements described in the Total number of instances allowed per top model parameter documentation, then you can have only one instance of that referenced model be in Normal mode.

  2. For each instance of the referenced model that you want to be in Normal mode, in the block parameters dialog box for the Model block, 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), or 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 have performed the steps in this section, you can specify a non-default instance to have Normal mode visibility. For details, see Specify the Instance That Has Normal Mode Visibility.

Specify the Instance That Has Normal Mode Visibility

This section describes how to specify Normal Mode Visibility for an instance other than the one that an instance that Simulink selects automatically.

You need to:

  1. (Optionally) Determine Which Instance Has Normal Mode Visibility.

  2. Set Normal Mode Visibility.

  3. Simulate the top model to apply the new Normal Mode Visibility settings.

Determine Which Instance Has Normal Mode Visibility.  If you do not already know which instance currently has Normal mode visibility, you can determine that by using one of these approaches:

  • If you update the diagram and have made no other changes to the model, then you can navigate through the model hierarchy to 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, use the ModelReferenceNormalModeVisibilityBlockPath parameter.

    If you use this parameter while editing a model, you must update the diagram before you use this 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 is being simulated 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]

Set Normal Mode Visibility.  To enable Normal Mode Visibility for a different instance of the referenced model than the instance that currently has Normal Mode Visibility, use one of these approaches:

  • Navigate to the top model and select the Diagram > Subsystem & Model Reference > Model Block Normal Mode Visibility menu item.

    The Model Block Normal Mode Visibility dialog box appears. That dialog box includes instructions in the right pane. For additional details about the dialog box, see Model Block Normal Mode Visibility Dialog Box.

  • From the MATLAB® command line, set the ModelReferenceNormalModeVisibility parameter.

    For input, you can specify:

    • 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 strings, with the strings being paths to individual blocks and models. The following example has the same effect as the preceding example (which shows how to specify an array of Simulink.BlockPath objects):

      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.

    Note:   You cannot change Normal Mode Visibility during a simulation.

Model Block Normal Mode Visibility Dialog Box

If you have a model that has multiple instances of a referenced model in Normal mode, you can use the Block Model Normal Mode Visibility dialog box to set Normal Mode Visibility for a specific instance. For a description of Normal mode visibility, see Normal Mode Visibility.

Alternatively, you can set the ModelReferenceNormalModeVisibility parameter. For information about how to specify an instance of a referenced model that is in Normal mode that is different than the instance automatically selected by Simulink, see Specify the Instance That Has Normal Mode Visibility.

Open the Model Block Normal Mode Visibility Dialog Box.  To open the Model Block Normal Mode Visibility dialog box, navigate to the top model and select Diagram > Subsystem & Model Reference > Model Block Normal Mode Visibility.

The dialog box for the sldemo_mdlref_basicsldemo_mdlref_basic model, with the hierarchy pane expanded, looks like this:

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.

Select a Model for Normal Mode Visibility.  

The dialog box shows the complete model block hierarchy for the top model. The Normal mode instances of referenced models have check boxes. Select the check box for the instance of each model that you want to have Normal mode visibility.

When you select a model, Simulink:

  • Selects all ancestors of that model

  • Deselects all other instances of that model

When a model is deselected, Simulink deselects all children of that model.

Opening a Model from the Model Block Normal Mode Visibility Dialog Box.  You can open a model from the Model Block Normal Mode Visibility dialog box by right-clicking the model in the model hierarchy pane and clicking Open.

Refreshing the Model Reference Hierarchy.  To ensure the model hierarchy pane of the Model Block Normal Mode Visibility dialog box reflects the current model hierarchy, click Refresh.

Accelerating a Freestanding or Top Model

You can use Simulink Accelerator mode or Rapid Accelerator mode to achieve faster execution of any Simulink model, including a top model in a model reference hierarchy. For details about Accelerator mode, see the Acceleration documentation. For information about Rapid Accelerator mode, see Rapid Simulations.

When you execute a top model in Simulink Accelerator mode or Rapid Accelerator mode, all referenced models execute in Accelerator mode. For any referenced model that specifies Normal mode, Simulink displays an warning message.

Be careful not confuse Accelerator mode execution of a referenced model with:

  • Accelerator mode execution of a freestanding or top model, as described in Acceleration

  • Rapid Accelerator mode execution of a freestanding or top model, as described in Rapid Simulations

While the different types of acceleration share many capabilities and techniques, they have different implementations, requirements, and limitations.

Was this topic helpful?