Discrete events are sets of equations/statements that are to be executed at specific points in time (instantaneously), or when specific variables cross a threshold (so-called “state” events).  In either case, the discrete even code has to be carefully synchronized with the continuous code.  A time event, for example, may need to take place at a time which is not an even multiple of the simulation’s communication interval; thus, the simulation engine must know how to integrate up to the exact desired time, evaluate the discrete section code without advancing time, and then resume integration.

  • Evaluation of code in a discrete section based on a specific time is accomplished via the SCHEDULE AT statement.  The schedule statement require the name of the target discrete section and the value of time at which the section should be invoked.  The time argument may be an arbitrary mathematical expression.
  • SCHEDULE AT statements may be included in any section except the DERIVATIVE section.
  • Handling of events on state crossings is done with the SCHEDULE XZ/XP/XN statement.  This statement also accepts a section name and footing point expression as arguments.  This type of SCHEDULE statement may only be used in the DERIVATIVE section.
  • INTERVAL statements can be used as an alternative to SCHDULE AT statements when invocation of the discrete section needs to happen only at regular intervals.  In this case the INTERVAL statement is included directly in the DISCRETE section it controls, with the syntax INTERVAL <variable name> = <interval length>.

model ScheduleExample


    schedule on at 0.0
    schedule spike at 2.75
    schedule spike at 5.03
    schedule spike at 7.234



    constant tstop = 10.0
    termt(t >= tstop, 'Stopped on time limit')

end ! derivative

discrete on
    schedule off at t + 0.5
    x = 1

discrete off
    schedule on at t + 0.5
    x = 0

discrete spike
    x = 5

end ! program