Using Submodels

Understanding submodels and how to use them
Submodels are groups of blocks contained within a single block. The behavior of a model containing submodel is mostly the same as an equivalent model where all blocks would be in the same layer.

Creating submodels

  1. 1.
    Given an existing model with various inter-connected blocks, select the blocks you wish to move into a submodel
  2. 2.
    Right-click on the canvas and then select “Create Submodel”
Select a few blocks to move into a new submodel
Right click and select “Create Submodel”
3. Enter the newly created Submodel by double-clicking on it
4. To go back to the main block diagram, you may hit the “↩️ Parent” button.
You may freely create as many layers of nested Submodels as you wish. When clicking the “↩️ Parent” button, you will be brought back one layer up. The “↩️ Parent” button will not be visible when editing the top-level model.

Submodel input and output ports

The block representing a submodel has as many input & output ports as its internal block diagram has “Inport” and “Outport” blocks respectively. You may add or remove input/output ports to a Submodel by entering it (double-click on it) and adding or removing blocks of types Inport or Outport.
Adding new I/O ports
  1. 1.
    Drag and drop an Inport or Outport block onto the canvas
Here, we are dragging an Outport block from the block library onto the canvas
2. Connect the port blocks
3. All Inport and Outport blocks get a corresponding port on the Submodel block
The new port called “Outport_1” may now be connected in the parent layer
You may remove I/O ports by removing their corresponding port block. This may lead to unconnected links that will show up as red lines. These unconnected links will often lead to model compilation failures, so you may need to reconnect or remove these links appropriately.

Submodel parameters

Just like the top-level model has optional model parameters, you may add new parameters at the submodel level, by first selecting a Submodel block and then clicking the + icon next to Submodel parameters in the right-side pane.
Parameters do not get propagated throughout nested layers of submodels, such that parameters defined in parent layers are not visible to blocks within a submodel.
The syntax of model and submodel parameters follows a subset of Python where math and np(alias for numpy) modules are exposed. See Using Model Parameters for more information about parameters (submodel and model parameters follow the same syntax rules).
Parameter name conflicts and inheritance
If the name of a parameter in a Submodel conflicts with any parent Submodel parameter or an existing Model parameter, the value defined at the Submodel level will override the inherited value.
Using submodel parameters
The names defined as submodel parameters can be used by any blocks, just like model parameters. Example for a parameter-defined gain block:
Model parameters can be edited when no block is selected
Model parameters can be edited when no block is selected
Block parameters may be literals or refer to (sub)model parameters