Skip to contents

ContinuousCallback(condition, affect) fires when condition(u, t, integ) crosses zero; the time is located by root finding on the solver's interpolant. affect runs on upcrossings and affect_neg on downcrossings (by default the same function). A vector valued condition fires per component and the affect receives the component index as its second argument. DiscreteCallback(condition, affect) fires after a step when condition(u, t, integ) is TRUE. PresetTimeCallback(times, affect) fires at given times, and PeriodicCallback(affect, dt) every dt. CallbackSet() combines callbacks. Affects modify the integrator integ in place: integ$u, integ$p, and terminate(integ) stops the integration.

Usage

ContinuousCallback(
  condition,
  affect,
  affect_neg = affect,
  initialize = NULL,
  finalize = NULL,
  rootfind = "left",
  save_positions = c(TRUE, TRUE),
  dtrelax = 1,
  maybe_discontinuity = TRUE
)

VectorContinuousCallback(condition, affect, affect_neg = affect, ...)

DiscreteCallback(
  condition,
  affect,
  initialize = NULL,
  finalize = NULL,
  save_positions = c(TRUE, TRUE)
)

PresetTimeCallback(
  times,
  affect,
  initialize = NULL,
  filter_tstops = TRUE,
  save_positions = c(TRUE, TRUE)
)

PeriodicCallback(
  affect,
  dt,
  phase = 0,
  initial_affect = FALSE,
  final_affect = FALSE,
  initialize = NULL,
  save_positions = c(TRUE, TRUE)
)

CallbackSet(...)

Arguments

condition

A function (u, t, integ).

affect, affect_neg

Functions (integ) (or (integ, idx) for vector conditions); affect_neg = NULL ignores downcrossings.

initialize

A function (integ) called at the start.

finalize

A function (integ) called at the end.

rootfind

How the event time is located: "left" (or TRUE, the default, as SciMLBase's LeftRootFind) applies the affect just before the crossing, "right" just after it, and "none" (or FALSE) at the end of the step.

save_positions

Save the state before and after the affect.

dtrelax

After a continuous event the next step starts from dtrelax times the step that contained the event (DiffEqBase's apply_callback!).

maybe_discontinuity

Whether the event may introduce a discontinuity: only these callbacks take part in the discontinuity detection of solve(..., discontinuity_detection = TRUE).

...

Callbacks.

times

Event times.

filter_tstops

PresetTimeCallback(): with TRUE only the times inside the time span become stops; with FALSE every time is added with add_tstop(), which is an error for a time before the start.

dt

Period.

phase

Time offset of the first event, PeriodicCallback().

initial_affect, final_affect

PeriodicCallback(): also apply the affect at the initial time, or when the integration reaches the final time (which is never a periodic stop).

Value

A callback object.