You can generate an event and use it to
Invoke a subsystem, MATLAB Function block, or Stateflow® block
Cause certain events, such as the opening of a gate or the reading of memory in a Signal Latch block
Generate an entity
For most purposes, a function call is an appropriate type of event to generate.
Note: While you can invoke triggered subsystems, MATLAB Function blocks, and Stateflow blocks upon trigger edges, trigger usage has limitations in discrete-event simulations. In particular, you should use function calls instead of triggers if you want the invocations to occur asynchronously, to be prioritized among other simultaneous events, or to occur more than once in a fixed time instant.
The table below indicates which blocks generate function calls when other events occur.
|Event Upon Which to Generate Another Event||Block|
|Entity advancement||Entity-Based Function-Call Event Generator|
|Signal-based event||Signal-Based Function-Call Event Generator|
|Function call||Signal-Based Function-Call Event Generator|
The fragment below, which is part of an example in Use Stateflow Charts to Implement a Failure State, uses entities to represent failures and repairs of a server elsewhere in the model:
A failure of the server is modeled as an entity's arrival at the block labeled Repair Work. When the Repair Work block's #n signal increases to reflect the entity arrival, the Signal-Based Function-Call Event Generator block generates a function call that calls the Stateflow block to change the state of the server from up to down.
A completed repair of the server is modeled as an entity's departure from the Repair Work block. When the Repair Work block's #n signal decreases to reflect the entity departure, the Signal-Based Function-Call Event Generator block generates a function call that calls the Stateflow block to change the state of the server from down to up.
Using function-calls rather than triggers to call a Stateflow block in discrete-event simulations is preferable because an event-based signal can experience a trigger edge due to a zero-duration value that a time-based block does not recognize. The Signal-Based Function-Call Event Generator can detect signal-based events that involve zero-duration values.
To generate events in a time-based manner, use the Time-Based Function-Call Generator block.
When you want to generate events
using intergeneration times from a signal or a statistical distribution,
set the Event generation mode parameter of the Time-Based
Function-Call Generator block to
port. Connect the signal or statistical distribution
to the input port t of the Time-Based
Function-Call Generator block.
When the intergeneration time is constant, set the Event
generation mode parameter of the Time-Based Function-Call
Period from dialog.
In the block dialog box, enter a value for the Period parameter.
The period is the time interval between successive function-call events
that the block generates, in seconds.
The following model (open modelmodel) uses the Time-Based Entity Generator block to generate entities that enter a gated queuing system. In this case, the Time-Based Function-Call Generator block generates function-call events with intergeneration times drawn from a statistical distribution. Each of these function-call events triggers the Release Gate block and an entity advances from the queue.