Main Content

Use SimulationObserver Class to Monitor a SimEvents Model

SimulationObserver Class

To create an observer, create a class that derives from the simevents.SimulationObserver object. You can use observers to:

  • Help understand queue impact, visualize entities moving through the model during simulation,

  • Develop presentation tools showing model simulation via an application-oriented interface, such as restaurant queue activity.

  • Debug and examine entity activity.

  • Examine queue contents.

The simevents.SimulationObserver object provides methods that let you:

  • Create observer or animation objects.

  • Identify model blocks for notification of run-time events.

  • Interact with the event calendar.

  • Perform activities when a model pauses, continues after pausing, and terminates.

SimEvents® models call these functions during model simulation.

Custom Visualization Workflow

  1. Create an application file.

    1. Define a class that inherits from the simevents.SimulationObserver class.

    2. Create an observer object that derives from this class.

    3. From the simevents.SimulationObserver methods, implement the functions you want for your application. This application comprises your observer.

  2. Open the model.

  3. Create an instance of your class.

  4. Run the model.

For more information about custom visualization, see Create Custom Visualization.

Create an Application

You can use these methods in your derived class implementation of simevents.SimulationObserver.

ActionMethod

Specify behavior when simulation starts.

simStarted

Specify behavior when simulation pauses.

simPaused

Specify behavior when simulation resumes.

simResumed

Define observer behavior when simulation is terminating.

simTerminating

Specify list of blocks to be notified of entity entry and exit events.

getBlocksToNotify

Specify whether you want notification for all events in the event calendar.

notifyEventCalendarEvents

Specify behavior after an entity enters a block that has entity storage.

postEntry

Specify behavior before an entity exits a block with entity storage.

preExit

Specify behavior before execution of an event.

preExecute

Add block to list of blocks to be notified.

addBlockNotification

Remove block from list of blocks being notified.

removeBlockNotification

Get handles to event calendars.

getEventCalendars

Get list of blocks that store entities.

getAllBlockWithStorages

Return block handle for a given block path.

getHandleToBlock

Return storage handles of specified block.

getHandlesToBlockStorages

  1. In the MATLAB® Command Window, select New > Class.

  2. In the first line of the file, inherit from the simevents.SimulationObserver class. For example:

    classdef seRestaurantAnimator < simevents.SimulationObserver

    seRestaurantAnimator is the name of the new observer object.

  3. In the properties section, enter the properties for your application.

  4. In the methods section, implement the functions for your application.

  5. To construct the observer object, enter a line like the following in the methods section of the file:

    function this = seRestaurantAnimator
                % Constructor
                modelname = 'seCustomVisualization';
                this@simevents.SimulationObserver(modelname);
                this.mModel = modelname;
            end

For more information, see Using Custom Visualization for Entities.

Use the Observer to Monitor the Model

  1. Open the model to observe.

  2. At the MATLAB command prompt, to enable the animator for the model:

    >> obj=seRestaurantAnimator;

  3. Simulate the model.

    When the model starts, the animator is displayed in a figure window. As the model runs, it makes calls into your application to see if you have implemented one of the predefined set of functions. If your model does not contain a SimEvents block, you receive an error.

Note

As a result of the instrumentation to visualize the simulation, the simulation is slower than without the instrumentation.

Stop Simulation and Disconnect the Model

  1. Stop the simulation.

  2. At the MATLAB command prompt, clear the animator from the model. For example:

    clear obj;

See Also

Related Topics