You can include one model in another by using Model blocks. Each instance of a Model block represents a reference to another model, called a referenced model. For simulation and code generation, the referenced model effectively replaces the Model block that references it. The model that contains a referenced model is its parent model. A collection of parent and referenced models constitute a model reference hierarchy.
The interface of a referenced model consists of its:
Input and output ports (and control ports, in the case of a conditional referenced model)
A Model block displays inputs and outputs corresponding to the root-level inputs and outputs of the model it references. These ports enable you to incorporate the referenced model into the block diagram of the parent model. The interface of the referenced model, not the context from which the model is referenced, defines the attributes of blocks in the referenced model. For example, attributes such as dimensions and data types do not propagate across Model block boundaries. To set the interface attributes, use the root Inport of the referenced model.
For example, the
sldemo_mdlref_basic model includes Model blocks
that reference three instances of the same referenced model,
A referenced model can itself contain Model blocks and thus reference lower-level models, to any depth. The top model is the topmost model in a hierarchy of referenced models. Where only one level of model reference exists, the parent model and top model are the same. To prevent cyclic inheritance, a Model block cannot refer directly or indirectly to a model that is superior to it in the model reference hierarchy. This figure shows cyclic inheritance.
A parent model can contain multiple Model blocks that reference the same referenced model as long as the referenced model does not define global data. The referenced model can also appear in other parent models at any level. You can parameterize a referenced model to provide tunability for all instances of the model. Also, you can parameterize a referenced model to let different Model blocks specify different values for variables that define the behavior of the referenced model. See Parameterize Instances of a Reusable Referenced Model for details.
To connect the referenced model to other elements of the parent model, use the ports on a Model block. Connecting a signal to a Model block port has the same effect as connecting the signal to the corresponding port in the referenced model. For example, the Model block CounterA has three inputs: two Constant blocks and a Pulse Generator block with a sample time of .1. The Model block CounterB also has three inputs: the same two Constant blocks, and a Pulse Generator block with a sample time of .5. Each Model block has an output to a separate Scope block.
The referenced model includes Inport and Outport blocks
(and possibly Trigger or Enable blocks) to connect to the
parent model. The
sldemo_mdlref_counter model has three Inport
blocks (upper, input, and lower) and one Outport block (output).
If a referenced model does not depend on data that is available only from a higher-level model, you can use a referenced model as a standalone model. An appropriately configured model can function as both a standalone model and a referenced model, without changing the model or any entities derived from it.
Simulink® includes several models that illustrate model referencing.
Managing Data with Model Reference example introduces the basic
concepts and workflow related to managing data with model referencing. To explore these
topics in more detail, select the
Detailed Workflow for Managing Data with
Model Reference example.
In addition, the
sldemo_absbrake model represents a wheel speed calculation as a
Model block within the context of an anti-lock braking system (ABS).
You can simulate a referenced model either interpretively (in normal mode) or by compiling the referenced model to code and executing the code (in accelerator mode). For details, see Simulate Model Reference Hierarchies.
To learn about considerations when generating code for a referenced model, see Referenced Models (Simulink Coder).