Timed Callbacks

The following callbacks are designed to help build callbacks with specific timing schemes for when the affect! is to be detonated.

DiffEqCallbacks.PresetTimeCallbackFunction
PresetTimeCallback(tstops, user_affect!;
    initialize = DiffEqBase.INITIALIZE_DEFAULT,
    filter_tstops = true,
    kwargs...)

A callback that adds callback affect! calls at preset times. No playing around with tstops or anything is required: this callback adds the triggers for you to make it automatic.

Arguments

  • tstops: the times for the affect! to trigger at.
  • user_affect!: an affect!(integrator) function to use at the time points.

Keyword Arguments

  • filter_tstops: Whether to filter out tstops beyond the end of the integration timespan. Defaults to true. If false, then tstops can extend the interval of integration.
source
DiffEqCallbacks.PeriodicCallbackFunction
PeriodicCallback(f, Δt::Number; phase = 0, initial_affect = false,
    final_affect = false,
    kwargs...)

PeriodicCallback can be used when a function should be called periodically in terms of integration time (as opposed to wall time), i.e. at t = tspan[1], t = tspan[1] + Δt, t = tspan[1] + 2Δt, and so on.

If a non-zero phase is provided, the invocations of the callback will be shifted by phase time units, i.e., the calls will occur at t = tspan[1] + phase, t = tspan[1] + phase + Δt, t = tspan[1] + phase + 2Δt, and so on.

This callback can, for example, be used to model a discrete-time controller for a continuous-time system, running at a fixed rate.

Arguments

  • f the affect!(integrator) function to be called periodically
  • Δt is the period

Keyword Arguments

  • phase is a phase offset
  • initial_affect is whether to apply the affect at the initial time, which defaults to false
  • final_affect is whether to apply the affect at the final time, which defaults to false
  • kwargs are keyword arguments accepted by the DiscreteCallback constructor.
source
DiffEqCallbacks.IterativeCallbackFunction
IterativeCallback(time_choice, user_affect!, tType = Float64;
    initial_affect = false, kwargs...)

A callback to be used to iteratively apply some affect. For example, if given the first effect at t₁, you can define t₂ to apply the next effect.

Arguments

  • time_choice(integrator) determines the time of the next callback. If nothing is returned for the time choice, then the iterator ends.
  • user_affect! is the effect applied to the integrator at the stopping points.

Keyword Arguments

  • initial_affect is whether to apply the affect at t=0 which defaults to false
source