Define Model Reference Interfaces - MATLAB & Simulink (original) (raw)

The ports on a Model block correspond to blocks at the top level, or root level, of the referenced model. The ports can be input, output, or control ports.

For example, in the [sldemo_mdlref_basic](https://mdsite.deno.dev/matlab:openExample%28'simulink%5Ffeatures/ComponentBasedModelingUsingModelReferenceExample'%29;openProject%28'ModelReference'%29;) model, each Model block references the sldemo_mdlref_counter model and has:

Each Model block receives three input signals and returns one output signal.

The sldemo_mdlref_counter referenced model has:

Blocks that represent model input and output are part of the block diagram for the model.

When you connect a signal to a Model block port, you connect the signal to the corresponding port of the referenced model. The output of a Model block can differ despite the referenced model being the same.

For example, in sldemo_mdlref_basic, each Model blockinput port receives a signal from a unique Pulse Generator block. Because the input signal from each Pulse Generator block uses a different sample time, the output signal from each Model block differs despite the referenced model being the same.

To view how the output signal for each Model block differs, you can use theSimulation Data Inspector.

Simulation Data Inspector plot of the output signal for each model instance

Add Ports to Model Reference Interface

A model reference interface supports multiple types of ports and port blocks.

This table describes the type of ports and corresponding port blocks that a model reference interface supports.

To add ports to a model reference interface, perform either of these actions:

Note

If the maximum port number in the model exceeds the number of ports in the model, you cannot add ports to the model reference interface. For example, if there are five port blocks in the model, and you change the port number parameter of one of them to10, you cannot add ports to the model reference interface.

To open a referenced model, open the model file or double-click theModel block. Then, add the port blocks to the referenced model.

To add ports to a Model block, pause on an edge of the block. When your pointer turns into a cross, click. A new port, highlighted in blue, appears on the edge you click.

Pause your pointer on the new port. In the action menu that expands, select the type of port you want to create. For example, you can create signal and bus element ports.

An input port is added to a Model block and then deleted.

You can also add ports to a Model block by dragging a signal line from the model element you want to connect to an edge of the Model block.

An input port is added to a Model block by dragging a signal line from a Constant block to the edge of the Model block.

Dragging from a port block creates a new port of the same type. Dragging from aSubsystem or Model block port that represents a port block also creates a new port of the same type as the port block.

The input signals for the Model block must be valid for the corresponding input blocks of the referenced model. The output signals for the Model block are the signals that connect to the corresponding output blocks.

To delete an existing port, select the port and press Delete. To delete multiple ports, press Shift, select the ports, and then pressDelete.

For more information about referenced models with control ports, see Conditionally Execute Referenced Models.

Tip

You can use the same approach to add ports to and delete ports from Reference Component (System Composer) blocks and Component (AUTOSAR Blockset) blocks that are linked to models.

Refresh Model Blocks

Refreshing a Model block updates it to reflect changes to the interface of the referenced model. For example, when the referenced model gains or loses a port, refreshing the Model block updates its ports.

By default, when a referenced model is loaded, the Model blocks that reference it automatically refresh. When a referenced model is not loaded, the correspondingModel blocks refresh when you perform actions such as:

To be notified when Simulink® detects Model blocks that might not match their referenced models, change the default setting for these diagnostic configuration parameters:

When these configuration parameters are set to error for a model, the Model blocks in that model do not automatically refresh. To refresh a Model block when these configuration parameters are set toerror, perform either of these actions:

When these configuration parameters are set to warning ornone for a model, you can manually refresh allModel blocks in the model hierarchy. To do so, perform either of these actions:

Define Signal Attributes

Signal attributes in a referenced model are independent from the context of theModel block. For example, signal dimensions and data types do not propagate across the Model block boundary.

To define the attributes of input to a referenced model, use the parameters of the root-level Inport and In Bus Element blocks. An In Bus Element block can fully specify the hierarchy and attributes of an input bus without a Simulink.Bus object.

In Bus Element and Out Bus Element blocks support multirate virtual buses and do not require Simulink.Bus objects at model interfaces, unlike Inport and Outport blocks.

For signals that connect to Outport blocks to propagate out of a referenced model to the parent model, the signal names must explicitly appear on the signal lines.

A referenced model can only provide input or get output for user-defined data types that are fixed point or that Simulink.DataType or Simulink.Bus objects define.

Use Buses at Model Interfaces

Bus input for a Model block must be consistent with the bus expected by the referenced model.

If you use a bus as an input to or an output from a referenced model:

For cleaner bus interfaces, use:

For more information, see Simplify Subsystem and Model Interfaces with Bus Element Ports.

Log Signals in Referenced Models

In a referenced model, you can log any signal configured for signal logging. Use the Signal Logging Selector to select a subset or all the signals configured for signal logging in a model hierarchy. For details, see Override Signal Logging Settings.

You can use the Simulation Data Inspector to view and analyze signals logged in referenced models. You can view signals on multiple plots, zoom, and use data cursors to understand and evaluate the data. Also, you can compare signal data from multiple simulations. For an example of viewing signals with referenced models, see Viewing Signals in Model Reference Instances.

Configure Sample Times

The first nonvirtual block that connects to a root-level input or output block of a referenced model must have the same sample time as the related port. If the sample times are different, use Rate Transition blocks to match input and output sample times, as shown in this block diagram.

Simple block diagram with one Rate Transition block after the Inport block and another Rate Transition block before the Outport block

Share Data Among Referenced Model Instances

By default, each Model block instance reads from and writes to a separate copy of the signals and block states in the model. Therefore, the instances do not interact with each other through shared signal or state data.

To share a piece of data between all of the instances (for example, an accumulator or a fault indicator), model the data as a data store.

For more information about data stores, see Model Global Data by Creating Data Stores.

See Also

Model | Inport | Outport | In Bus Element | Out Bus Element

Topics