Main Content

Model Reference Interface and Boundary

AModelblock 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 includeInport,Outport,In Bus Element,Out Bus Element,Trigger, andEnableblocks to get input from the parent model and to provide output to the parent model. The input signals for theModelblock must be valid for the corresponding input blocks of the referenced model. The output signals for theModelblock are the referenced model root-level output block signals.

Insldemo_mdlref_basic, eachModelblock has three inputs: twoConstantblocks and aPulse Generatorblock. EachModelblock has one output signal logged to a scope. Because the input signal from eachPulse Generatorblock uses a different sample time, the output signal from eachModel为每个模型实例块不同。

Each Model block has input ports named upper, input, and lower and one output port named output.

To connect to the parent model, referenced modelsldemo_mdlref_counter包括threeInportblocks (,lower, andinput) and oneOutportblock (output).

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

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

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

Refresh Model Blocks

Refreshing aModelblock 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, refreshing theModelblock updates its ports.

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

  • Opening the parent model

  • Selecting aModelblock

  • Simulating the model hierarchy

  • Generating code for the model hierarchy

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

When these configuration parameters are set toerrorfor a model, theModelblocks in that model do not automatically refresh. To refresh aModelblock when these configuration parameters are set toerror, perform either of these actions:

When these configuration parameters are set towarningornonefor a model, you can manually refresh allModelblocks in the model hierarchy. To do so, perform either of these actions:

信号传播

Signal attributes in a referenced model are independent from the context of theModelblock. For example, signal dimensions and data types do not propagate across theModelblock boundary. To define signal attributes in a referenced model, define block parameters for root-levelInportandIn Bus Elementblocks.

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

For buses at interfaces, useIn Bus ElementandOut Bus Elementblocks instead ofInportandBus Selectorblocks for inputs andOutportandBus Creatorblocks for outputs.In Bus ElementandOut Bus Elementblocks support multirate virtual buses and do not requireSimulink.Busobjects at model interfaces, unlikeInportandOutportblocks. They also provide cleaner bus interfaces. For more information, seeSimplify Subsystem and Model Interfaces with Bus Element Ports.

For an example of a model hierarchy that uses buses withInportblocks, seeInterface Specification Using Bus Objects.

A referenced model can only provide input or get output for user-defined data types that are fixed point or thatSimulink.DataTypeorSimulink.Busobjects define.

Signal Logging 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, seeOverride 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, seeViewing Signals in Model Reference Instances.

Sample Time Requirements

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, useRate Transitionblocks to match input and output sample times, as shown in this 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, eachModelblock 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 aData Store Memoryblock in the model and select theShare across model instancesparameter. For an example, seeShare Data Store Between Instances of a Reusable Algorithm.

  • To allow access to data outside the referenced model, use a global data store, which is aSimulink.Signalobject 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, seeModel Global Data by Creating Data Stores.

See Also

||||

Related Topics