This example shows how to view dependencies among referenced models.
|On this page…|
During this example, Simulink® generates files in the current working directory. If you do not want to generate files in this directory, you should change the working directory to a suitable directory before starting this example.
Use the find_mdlrefs utility function to find all Model blocks and all models referenced by a model. Type help find_mdlrefs for more information about this function.
[refMdls, modelBlks] = find_mdlrefs('sldemo_mdlref_depgraph');
find_mdlrefs returns two cell arrays, refMdls and modelBlks. refMdls contains the names of all models that are directly or indirectly referenced by sldemo_mdlref_depgraph. The last element in refMdls is always the name of the input model. modelBlks contains block paths for all Model blocks in the top model and all referenced models.
Double click on the blue box in the example model to view its model reference dependency graph. In general, use the view_mdlrefs utility function or select the menu item Analysis > Model Dependencies > Model Dependency Viewer > Models Only to start the dependency viewer for a specific model.
The next figure shows the dependency graph of sldemo_mdlref_depgraph:
In the dependency graph, the blue nodes represent Simulink models. The directed lines indicate dependencies. For example, in the example model the link from sldemo_mdlref_depgraph to sldemo_mdlref_house indicates that sldemo_mdlref_depgraph references sldemo_mdlref_house. If the model had library links, you could go to the View menu and select Include Libraries to have the dependency viewer show libraries linked to by models in the hierarchy. When Include Libraries is selected, yellow nodes are used to depict libraries.
Left-clicking on a node selects it.
Double-clicking on a node opens the associated model or library.
Pressing the left mouse button on an empty space and then dragging the mouse creates a marquee to select multiple nodes.
Right-clicking on a node brings up a context menu.
Pressing the left mouse button on any selected node and dragging the mouse moves the selected node(s).
The mouse wheel can be used to zoom into and out of the region currently under the mouse pointer.
Pressing the space bar centers the dependency graph and adjusts the zoom so that the dependency graph fits in the available space.
Holding down the space bar activates a navigational mode, where it is possible to pan the view by dragging the mouse with the left button held down.
In the previous dependency graph, only one node exists for each model in the graph and at most one link exists from one node to another node. Therefore, this dependency graph does not show if multiple references exist from one model to another model. Furthermore, this view does not show which models are referenced in Normal mode and which models are referenced in Accelerator mode.
The dependency viewer can show referenced model instances, and this view can be accessed in one of two ways:
From the model, select the menu item Analysis > Model Dependencies > Model Dependency Viewer > Referenced Model Instances
From the model dependency viewer, go to the View menu, select Dependency Type, and then select Referenced Model Instances.
Note that in this view, which we refer to as Instance View, libraries are never shown.
In Instance View, the blue nodes represent Simulink models. The directed lines indicate dependencies. Note: in this view two nodes are labeled sldemo_mdlref_F2C because this model is referenced twice, once by sldemo_mdlref_outdoor_temp and once by sldemo_mdlref_heater. Except for the top model, all nodes have corners that denote the simulation mode of the referenced model. Hollow corners denote a Normal mode reference and filled corners denote an Accelerator mode reference. Thus, sldemo_mdlref_heater makes a Normal mode reference to sldemo_mdlref_F2C and an Accelerator mode reference to sldemo_mdlref_thermostat.
Currently, the reference sldemo_mdlref_outdoor_temp makes to sldemo_mdlref_F2C is an Accelerator mode reference. Hovering the mouse over the node sldemo_mdlref_F2C that sldemo_mdlref_outdoor_temp references displays a tooltip showing the path to the block making the reference to sldemo_mdlref_F2C in sldemo_mdlref_outdoor_temp. Suppose you want to change this to be a Normal mode reference:
Right-click on the node sldemo_mdlref_F2C that sldemo_mdlref_outdoor_temp points to.
Select Highlight Block from the context menu that appears; this opens sldemo_mdlref_outdoor_temp and highlight the corresponding Model block.
Right click on the highlighted block.
Select Block Parameters (ModelReference) from the menu that appears.
Change the Simulation mode to Normal, and click OK.
To see this change in the dependency viewer, go to the dependency viewer and select Refresh from the View menu.
The Instance View dependency graph now looks like this:
The dependency viewer now shows the reference sldemo_mdlref_outdoor_temp makes to sldemo_mdlref_F2C as a Normal mode reference, but it has a yellow triangle on it. This triangle denotes a warning. Hovering the mouse over the node with the triangle displays a tooltip explaining the warning. This warning appears because sldemo_mdlref_F2C is configured to run in Normal mode but its parent, sldemo_mdlref_outdoor_temp, is configured to run in Accelerator mode. Normal mode references from models running in Accelerator mode are not supported, so sldemo_mdlref_F2C will run in Accelerator mode during simulation.
To make this model run in Normal mode, you must configure all of its ancestors to run in Normal mode. To do this, right click on the node sldemo_mdlref_outdoor_temp and select Highlight Block from the context menu that appears; this opens sldemo_mdlref_depgraph and highlights the corresponding Model block. Right click on the highlighted block, select Block Parameters (ModelReference), change the Simulation mode to Normal, and click OK. (If there were more Accelerator mode ancestors of sldemo_mdlref_F2C, these would also need to be changed to Normal mode references.)
To see this change in the dependency viewer, go to the dependency viewer and select Refresh from the View menu:
There are now two models that reference sldemo_mdlref_F2C in Normal mode. After simulating this model, sl_demo_mdlref_heater look likes this:
And sldemo_mdlref_outdoor_temp looks like this:
The Model block that references sldemo_mdlref_F2C in sldemo_mdlref_heater has white corners, while the Model block that references sldemo_mdlref_F2C in sldemo_mdlref_outdoor_temp has gray corners. This is because Model block Normal Mode Visibility is on for the Model block in sldemo_mdlref_heater but is not on for the Model block in sldemo_mdlref_outdoor_temp. Note that only one Normal mode instance of each model will have white corners, the rest will have gray corners. Display blocks (for example, Scopes) will show data for the instance referenced from the Model block with white corners, in this case from the model sldemo_mdlref_heater, but not for any other instance:
To open the Model Block Normal Mode Visibility dialog box, from the top model (sldemo_mdlref_depgraph) select Diagram > Subsystem & Model Reference > Model Block Normal Mode Visibility.... Select the instance of each model that is referenced more than once in Normal mode for which you want to have Normal Mode Visibility on.
Right now, no Model blocks have been selected, which means that during the last simulation, Simulink selected one instance of sldemo_mdlref_F2C to have Normal Mode Visibility set to on, which was indicated by the Model block with white corners. To select the instance referenced by sldemo_mdlref_outdoor_temp, check the box corresponding to that instance, then press OK:
After changing the Normal Mode Visibility setting, simulate the model sldemo_mdlref_depgraph to make use of the new setting.