Timed Callbacks
The following callbacks are designed to help build callbacks with specific timing schemes for when the affect!
is to be detonated.
DiffEqCallbacks.PresetTimeCallback
— FunctionPresetTimeCallback(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 theaffect!
to trigger at.user_affect!
: anaffect!(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.
DiffEqCallbacks.PeriodicCallback
— FunctionPeriodicCallback(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
theaffect!(integrator)
function to be called periodicallyΔt
is the period
Keyword Arguments
phase
is a phase offsetinitial_affect
is whether to apply the affect at the initial time, which defaults tofalse
final_affect
is whether to apply the affect at the final time, which defaults tofalse
kwargs
are keyword arguments accepted by theDiscreteCallback
constructor.
DiffEqCallbacks.IterativeCallback
— FunctionIterativeCallback(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. Ifnothing
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 att=0
which defaults tofalse