Documentation

Model

Include multiple model implementations as block in another model

  • Library:
  • Ports & Subsystems

Description

The Model block allows you to include a model as a block in another model. The included model is called a referenced model, and the model containing it (using the Model block) is called the parent model.

The Model block displays input and output ports corresponding to the top-level input and output ports of the referenced model. Using these ports allow you to connect the referenced model to other blocks in the parent model. See Model Referencing for more information.

As an alternative to specifying a particular referenced model in the Main tab, you can dynamically reference one of several model variants, depending on a model workspace value. A variant describes one possible mode in which a Model block can operate. Each variant of the Model block references a specific model with optional model-specific arguments. Only one variant is active for simulation. To create model variants, click Enable Variants button, which opens a dialog box for implementing model variants. For more information about how to specify a referenced model for multiple specifications, see Set up Model Variants Using a Model Block.

Note

For new models, use a Model block for model variants only if you need to use variants that are conditionally executed models (models with control ports). Model variants are supported for backward compatibility. However, support for model variants will be removed in a future release. Use of a Variant Subsystem block provides these advantages:

  • Allows you to mix Model and Subsystem blocks as variant systems

  • Supports flexible I/O, so that all variants do not need to have the same number of input and output ports

To convert a Model block that contains variant models to a Variant Subsystem block that contains Model blocks that reference the variant models, right-click the Model block and select Subsystems & Model Reference > Convert to > Variant Subsystem. Alternatively, you can use the Simulink.VariantManager.convertToVariant function. Specify the Model block path or block handle. The converted model produces the same results as the original model.

Alternatively, to set up model variants for a new model, you can use the Variant Model block, which is a subsystem variant template block that contains two Model blocks that you can use for variants.

By default, the contents of a referenced model are user-visible by double-clicking the Model block. However, you can hide the contents of a referenced model by making the model a protected model.

Depending on whether you want to reference a single model or variant models, and whether you want to use model arguments, you need to use different parts of the Model block interface.

Modeling GoalModel Block Interface to Use
Reference a single model (nonvariant model)Use the Main tab.
Reference variant modelsOn the Main tab, click Enable Variants, which opens the model variants dialog box.
Specify values for model arguments

For a nonvariant model reference, use the Arguments tab.

For variant models, use the variant dialog box.

To manage various variants that are modeled using variant blocks in a model, in the model variants dialog box click Open block in Variant Manager link.

Ports

Input

expand all

The Model block has an input port for each root-level Inport, Enable, or Trigger block in the referenced model. The name of the Model block port matches the name of the corresponding referenced model input block. The Model block input signals must be valid for the corresponding referenced model input blocks. See Define Referenced Model Inputs and Outputs.

Input signals can have real or complex values of any data type supported by Simulink, including bus objects, arrays of buses, fixed-point, and enumerated data types. For details about data types, see Simulink, Data Types Supported by Simulink.

Output

expand all

The Model block has an output port for each root-level Outport block in the referenced model. The name of the Model block port matches the name of the corresponding Outport block. The Model block output signals are the signals from the corresponding referenced model Outport blocks. See Define Referenced Model Inputs and Outputs.

Output signals can have real or complex values of any data type supported by Simulink, including bus objects, arrays of buses, fixed-point, and enumerated data types. For details about data types, see Simulink, Data Types Supported by Simulink.

Parameters

expand all

Main Tab

Path to the referenced model. The file name must be a valid MATLAB® identifier. The extension, for example, .slx, is optional. The file name must contain fewer than 60 characters, exclusive of the .slx or .mdl suffix.

To navigate to the model that you want to reference, click Browse.

To view the model that you specified, click Open Model.

Programmatic Use

Parameter: ModelFile
Type: character vector
Value: '' | '<file name>'
Default: ''

Specify the simulation mode for the referenced model. The simulation mode for models in a model referencing hierarchy do not have to match. For information about model reference simulation modes and precedence of the simulation mode in a hierarchy, see Simulate Model Reference Hierarchies.

  • Accelerator — Create a MEX-file for the referenced model and then executes the referenced model by running the S-function.

  • Normal — Execute the referenced model interpretively, as if the referenced model is an atomic subsystem implemented directly within the parent model.

  • Software-in-the-loop (SIL) — This option requires the Embedded Coder® software. Generate production code based on the Code Interface parameter setting. The code is compiled for, and executed on, the host platform.

  • Processor-in-the-loop (PIL) — This option requires the Embedded Coder software. Generate production code based on the Code Interface parameter setting. This code is compiled for, and executed on, the target platform. A documented target connectivity API supports exchange of data between the host and target at each time step during the PIL simulation.

The corners of the Model block reflect the simulation mode for the referenced model. For normal mode, the corners have empty triangles. For accelerator mode, the corner triangles are filled in. For SIL and PIL modes, the corners are filled in and the word (SIL) or (PIL) appears on the block icon.

Programmatic Use

Parameter: SimulationMode
Type: character vector
Value: 'Normal' | 'Accelerator' | 'Software-in-the-loop' | 'Processor-in-the-loop'
Default: 'Normal'

Specify whether to generate the code from the top model or the referenced model for SIL and PIL simulation modes. To deploy the generated code as part of a larger application that uses the referenced model, specify Model reference. To deploy the generated code as a standalone application, specify Top model.

Model reference

Code generated from referenced model as part of a model reference hierarchy. Code generation uses the slbuild('model', 'ModelReferenceRTWTarget') command.

Top model

Code generated from top model with the standalone code interface. Code generation uses the slbuild('model') command.

Dependencies

To display and enable this parameter, select either Software-in-the-loop (SIL) or Processor-in-the-loop (SIL) from the Simulation mode drop-down list.

Programmatic Use

Parameter: CodeInterface
Type: character vector
Value: 'Model reference' | 'Top model'
Default: 'Model reference'

Control display of initialize event port on the Model block.

off

Remove port.

on

Display model initialize event port.

Programmatic Use

Block parameter: ShowModelInitializePort
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Control display of reset event ports on the Model block.

off

Remove port.

on

Display model reset event ports.

Programmatic Use

Block parameter: ShowModelResetPorts
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Control display of terminate event port on Model block.

off

Remove port.

on

Display model block port.

Programmatic Use

Block parameter: ShowModelTerminatePort
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Control display of periodic event ports on Model block.

off

Hide ports.

on

Display ports for rate-based models. A rate-based model is a model with the Sample time for a connected Inport block specified.

If you want to manually specify the port rates, set the parameter AutoFillPortDiscreteRates to 'off', and then add the port rates to the parameter PortDiscreteRates.

Programmatic Use

Block parameter: ShowModelPeriodicEventPorts
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Opens a dialog box for defining model variants. The dialog box includes a Variant choices table, with a separate row for defining each variant.

Programmatic Use

Block parameter: Variants
Type: array
Value: array of variant structures where each element specifies one variant. The structure fields are:
  • variant.Name (character vector) — The variant control can be a boolean condition expression, or a Simulink.Variant object representing a boolean condition expression. If you want to generate code for your model, you must define the control variables as Simulink.Parameter objects.

  • variant.ModelName (character vector) — The name of the referenced model associated with the specified variant control in the Model block.

  • variant.ParameterArgumentNames (character vector) — Read-only character vector containing the names of the model arguments for which the Model block must supply values.

  • variant.ParameterArgumentValues (character vector) — The values to supply for the model arguments when this variant is the active variant.

  • variant.SimulationMode (character vector) — The execution mode to use when this variant is the active variant. Possible values are 'Accelerator' | 'Normal' | 'Software-in-the-loop (SIL)' | 'Processor-in-the-loop (PIL)'

Arguments Tab

Display model arguments and specify model argument values. Model arguments enable the referenced model to use a different value for a variable used by a referenced model. To specify model argument values, use the Value column in the table. For more information about configuring model arguments in a referenced model and specifying argument values, see Parameterize Instances of a Reusable Referenced Model.

Programmatic Use

Block parameter: ParameterArgumentValues (corresponding to the Value column in the table)
Type: structure
Value: Structure with one field for each model argument that the referenced model defines. Fields of the structure are names of the model arguments. Values are character vector representations of the values.
Default: Structure with no fields

Model Variants Dialog Box

Table containing a row for each variant object in the base workspace. The Variant choices table includes the Model name, associated Variant control, and Condition (read-only) columns. For details, see the descriptions of each of the parameters.

To modify the table, use buttons to the left of the Variant choices table.

FunctionButton
Add a new variant: Add a new, empty row below the currently selected row
Delete selected variant: Delete the currently selected row. Models and objects are not affected.
Create/Edit selected variant object: Creates a Simulink.Variant object in the base workspace and opens the Simulink.Variant object parameter dialog box for specifying the variant Condition. This button is enabled only for valid Simulink.Variant objects.
Move variant up: Move up the currently selected row one slot in the table
Move variant down: Move the currently selected row down one slot in the table

Dependency

Enable variants on the Main tab opens the variant model dialog box that contains this parameter.

Programmatic Use

Block parameter: Variants
Type: array
Value: array of variant structures where each element specifies one variant. The structure fields are:
  • variant.Name (character vector) — The variant control can be a Boolean condition expression, or a Simulink.Variant object representing a Boolean condition expression. To generate code for your model, define the control variables as Simulink.Parameter objects.

  • variant.ModelName (character vector) — The name of the referenced model associated with the specified variant control in the Model block.

  • variant.ParameterArgumentNames (character vector) — Read-only character vector containing the names of the model arguments for which the Model block must supply values.

  • variant.ParameterArgumentValues (character vector) — The values to supply for the model arguments when this variant is the active variant.

  • variant.SimulationMode (character vector) — The execution mode to use when this variant is the active variant.

    • Possible values are 'Accelerator' | 'Normal' | 'Software-in-the-loop (SIL)' | 'Processor-in-the-loop (PIL)'

Path to the variant model, specified as a character vector. The name must be a valid MATLAB identifier. The extension, for example, .slx, is optional. The model name must contain fewer than 60 characters, exclusive of the .slx or .mdl suffix.

To navigate to the model that you want to reference for the selected variant in the table, click Browse.

To view the model that you specified is the model you want to reference, click Open Model.

Dependency

Enable variants on the Main tab opens the variant model dialog box that contains this parameter.

Programmatic Use

Parameter: ModelName
Type: character vector
Value: '' | '<file name>'
Default: ''

The variant control can be a boolean condition expression or a Simulink.Variant object representing a boolean condition expression. If you want to generate code for your model, define control variables as Simulink.Parameter objects.

The variant condition must be a Boolean expression that references at least one base workspace variable or parameter. For example, FUEL== 2 && EMIS == 1. Do not surround the condition with parentheses or single quotes. The expression can include:

  • MATLAB variables defined in the base workspace

  • Simulink parameter objects defined in the base workspace

  • Scalar variables

  • Enumerated values

  • Operators ==, ~=, &&, ||, ~

  • Parentheses for grouping

During model compilation, Simulink evaluates variant objects before calling the InitFcn callback. Therefore, do not modify the condition of the variant object in the InitFcn callback.

Dependency

Enable variants on the Main tab opens the variant model dialog box that contains this parameter.

Programmatic Use

Structure field: Represented by the variant.Name field in the Variants parameter structure
Type: character vector
Value: Variant control associated with the variant
Default: ''

This read-only field displays the condition for the associated model variant in the base workspace. To specify the condition for the selected variant object, click the Edit selected variant object button.

The variant condition must be a Boolean expression that references at least one base workspace variable or parameter. For example, FUEL== 2 && EMIS == 1. Do not surround the condition with parentheses or single quotes. The expression can include:

  • MATLAB variables defined in the base workspace

  • Simulink parameter objects defined in the base workspace

  • Scalar variables

  • Enumerated values

  • Operators ==, ~=, &&, ||, ~

  • Parentheses for grouping

Dependency

Enable variants on the Main tab opens the variant model dialog box that contains this parameter.

By default, Simulink determines the active variant by the value of the variant conditions. To override the variant conditions and set the active variant to the value of the Variant, enable the Override variant conditions and use the following variant parameter.

Dependency

Selecting this parameter, enables the Variant parameter.

Programmatic Use

Parameter: OverrideUsingVariant
Type: character vector
Value: 'off'| 'on'
Default: 'off'

Specify overriding variant.

Dependency

To enable this parameter, select the Override variant conditions and use the following variant parameter.

Programmatic Use

Parameter: ActiveVariant
Type: character vector
Value: '' if no overriding variant control is specified.
Default: ''

Path to the variant model, specified as a character vector. The name must be a valid MATLAB identifier. The extension, for example, .slx, is optional. The model name must contain fewer than 60 characters, exclusive of the .slx or .mdl suffix.

To navigate to the model that you want to reference for the selected variant in the table, click Browse.

To view the model that you specified is the model you want to reference, click Open Model.

Dependency

Enable variants on the Main tab opens the variant model dialog box that contains this parameter.

Display model arguments for the selected referenced model. For more information about configuring model arguments in a referenced model and specifying argument values, see Parameterize Instances of a Reusable Referenced Model.

Dependency

Enable variants enables this parameter.

Programmatic Use

Structure field: Represented by the variant.ParameterArgumentNames field in the Variants parameter structure OneArgName
Type: character vector
Value: Enter model arguments as a comma separated list
Default: ''

Enter the argument values in this parameter as a list, in the same order as the corresponding argument names in the Model arguments parameter. To separate the items in the list, use commas, spaces, or semicolons. For information about valid values, see Set Block Parameter Values.

To define model arguments, see Model Arguments for Model Blocks That Contain Model Variants.

Dependency

Enable variants on the Main tab opens the variant model dialog box that contains this parameter.

Programmatic Use

Structure field: Represented by the variant.ParameterArgumentValues field in the Variants parameter structureOneArgName
Type: character vector
Value: Any valid value
Default: ''

Simulation mode for the highlighted model variant control.

  • Accelerator — Creates a MEX-file for the referenced model and then executes the referenced model by running the S-function.

  • Normal — Executes the referenced model interpretively, as if the referenced model is an atomic subsystem implemented directly within the parent model.

  • Software-in-the-loop (SIL) — This option requires the Embedded Coder software. Generates production code using model reference target for the referenced model. This code is compiled for, and executed on, the host platform.

  • Processor-in-the-loop (PIL) — This option requires the Embedded Coder software. Generates production code using a model reference target for the referenced model. This code is compiled for, and executed on, the target platform. A documented target connectivity API supports exchange of data between the host and target at each time step during the PIL simulation.

When generating code for an ERT target, this parameter determines whether variant choices are enclosed within C preprocessor conditional statements (#if). When you enable this option, Simulink analyzes all variant choices during an update diagram or simulation. This analysis provides early validation of the code generation readiness of all variant choices.

Dependencies

  • The check box is available for generating only ERT targets.

  • Override variant conditions and use following variant is cleared.

Programmatic Use

Parameter: GeneratePreprocessorConditionals
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Disable model reference variants and display the Main tab. The block retains any information you have entered and approved by clicking Apply or OK.

Programmatic Use

Parameter: Variant
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Introduced before R2006a

Was this topic helpful?