A Model block has input, output, and control ports that correspond to root-level input, output, and control ports of the model it references. A referenced model can include Inport, Outport, In Bus Element, Out Bus Element, Trigger, and Enable blocks to get input from the parent model and to provide output to the parent model. 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 referenced model root-level output block signals.
sldemo_mdlref_basic, each Model block has three
inputs: two Constant blocks and a Pulse Generator block. Each
Model block has one output signal logged to a scope. Because the input
signal from each Pulse Generator block uses a different sample time, the
output signal from each Model block differs for each model instance.
To connect to the parent model, referenced model
includes three Inport blocks (upper,
lower, and input) and one Outport
block (output). If you change the ports in the referenced model, refresh
the Model block to reflect these changes.
To compare the output signals of each Model block, you can use the Simulation Data Inspector. In a referenced model, you can log any signal marked for signal logging.
To set up signal logging, see Export Signal Data Using Signal Logging. To log a subset of the signals marked for logging in a model hierarchy, see Override Signal Logging Settings. For an example that uses the Simulation Data Inspector with referenced models, see Viewing Signals in Model Reference Instances.
Refreshing a Model block updates its internal representation to reflect changes to the interface of the referenced model. For example, when the referenced model gains or loses a port, refresh the Model block to update its ports.
To detect changes in referenced model interfaces that could require refreshing the related Model blocks, use Simulink® diagnostics. These diagnostics include:
If changes to a referenced model interface do not affect how the referenced model interfaces to its parent, you do not need to refresh the Model block.
To refresh a specific Model block, from the context menu of the Model block, select Subsystem & Model Reference > Refresh Selected Model Block.
To refresh all Model blocks in a model (including linked blocks in a library or model), in the Simulink Editor, select Diagram > Refresh Blocks. Simulating or generating code for a model also refreshes all Model blocks in the model.
Signal attributes in a referenced model are independent from the context of the Model block. For example, signal dimensions and data types do not propagate across the Model block boundary. To define signal attributes in a referenced model, define block parameters for root-level Inport and In Bus Element 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.
For virtual buses that cross model reference boundaries, use In Bus Element and Out Bus Element blocks.
For nonvirtual buses that cross model reference boundaries, use Inport and Outport blocks that specify the same bus object as the related buses in the parent model. See Bus Data Crossing Model Reference Boundaries.
For an example of a model hierarchy that uses buses, see
A referenced model can only provide input or get output for user-defined data types
that are fixed point or that
Simulink.Bus objects define.
The first nonvirtual block that connects to a referenced model root-level input or output block 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 diagram.
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.
To restrict access to data so that only the blocks in the referenced model can read from and write to it, use a Data Store Memory block in the model and select the Share across model instances parameter. For an example, see Share Data Store Between Instances of a Reusable Algorithm.
To allow access to data outside the referenced model, use a global data
store, which is a
Simulink.Signal object in the base workspace
or a data dictionary. Data outside the referenced model can be in
the parent model or in other referenced models.
For more information about data stores, see Model Global Data by Creating Data Stores.