| SimEvents® | ![]() |
| On this page… |
|---|
Overview of Discrete Event Subsystems |
Given the questions raised in Timing Issues in SimEvents Models about the response of time-based blocks to events, this section gives an overview of discrete event subsystems and describes how you can use them to ensure appropriate simulation timing. A discrete event subsystem:
Contains time-based blocks. Examples include:
Constant with a sample time of inf
Sum or Relational Operator with a sample time of -1
Stop Simulation
Cannot contain blocks from the SimEvents libraries, except the Discrete Event Inport, Discrete Event Outport, and Subsystem Configuration blocks.
Note If you want to put blocks that have entity ports into a subsystem as a way to group related blocks or to make a large model more hierarchical, select one or more blocks and use the Edit > Create Subsystem menu option. The result is a virtual subsystem, which does not affect the timing of the simulation but is merely a graphical construct. |
Has two basic forms: a Discrete Event Subsystem block and an appropriately configured Function-Call Subsystem block. A special case of the latter form is called an entity-departure subsystem.
Is executed in response to signal-based events that you specify in the Discrete Event Inport blocks inside the Discrete Event Subsystem window, or in response to function calls in the case of a function-call subsystem.
"Block execution" in this documentation is shorthand for "block methods execution." Methods are functions that the Simulink engine uses to solve a model. Blocks are made up of multiple methods. For details, see Block Methods in the Simulink documentation.
The purpose of a discrete event subsystem is to call the blocks in the subsystem at the exact time of each qualifying event and not at times suggested by the time-based simulation clock. This is an important change in the semantics of the model, not merely an optimization.
When creating a discrete event subsystem, you might need to confirm or manipulate the processing sequence for two or more events, such as:
Signal-based events that execute a Discrete Event Subsystem block
Entity departures that execute an entity-departure subsystem
Function calls that execute a function-call subsystem
Updates in the values of signals that serve as inputs to any kind of discrete event subsystem
Consider the next schematic, which involves a discrete event subsystem. Suppose an entity departure from Block A, an entity arrival at Block C, and updates in all of the signals occur at a given value of the simulation clock.

Typically, the goal is to execute the subsystem:
After the entity departure from Block A, which produces a signal that is an input to the subsystem.
After both Block A and Block B update their output signals at that value of the simulation clock.
Be especially aware of this if you clear the Execute subsystem upon signal-based events option in a Discrete Event Inport block. Because the subsystem uses the most recent value of the signal, make sure that value is up to date, rather than a value from a previous call to the block that creates the signal.
See Example: Detecting Changes from Empty to Nonempty for an example in which the last-updated signal executes the subsystem. See Update Sequence for Output Signals to learn more about when blocks update their output signals.
Before the entity processing at Block C, which uses an output signal from the subsystem. Example: Normalizing a Statistic to Use for Routing shows how storing the entity in a switch before routing the entity to an output port can help produce the correct processing sequence. Another technique is to use an extra server block whose service time is zero; for details and examples, see Interleaving of Block Operations.
For details on processing sequences, see Interleaving of Block Operations, Processing Sequence for Simultaneous Events, and Managing Simultaneous Events.
![]() | Timing Issues in SimEvents Models | Blocks Inside Discrete Event Subsystems | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |