Callbacks

Callbacks allow user code to run at specific points during time integration — after every step, at fixed simulation-time intervals, or on a wall-clock schedule. They are passed to init or solve via the callback keyword argument.

Core Types

DiscreteCallback is the primitive: a condition/action pair checked after every integrator step. CallbackSet groups multiple callbacks.

ClimaTimeSteppers.DiscreteCallback — Type
DiscreteCallback(condition, affect!; initialize, finalize)

A callback checked after each integrator step.

Arguments

  • condition: function (u, t, integrator) -> Bool
  • affect!: function (integrator) -> nothing, called when condition returns true

Keyword Arguments

  • initialize: function (cb, u, t, integrator) called at integrator startup
  • finalize: function (cb, u, t, integrator) called when solve! finishes

See also CallbackSet, ClimaTimeSteppers.Callbacks.

source

Pre-Built Callbacks

The ClimaTimeSteppers.Callbacks module provides convenience constructors for common triggering patterns. Import them with:

using ClimaTimeSteppers: Callbacks
using .Callbacks
ClimaTimeSteppers.Callbacks.EveryXWallTimeSeconds — Function
EveryXWallTimeSeconds(f!, Δwt, comm_ctx; atinit=false)

Trigger f!(integrator) every Δwt wall-clock seconds.

Timing is synchronized across all MPI ranks via comm_ctx (ClimaComms context).

Arguments

  • f!: callable f!(integrator) to execute
  • Δwt: wall-clock interval in seconds
  • comm_ctx: a ClimaComms.AbstractCommsContext

Keyword Arguments

  • atinit: if true, also trigger at initialization (default false)

Callbacks.initialize! and Callbacks.finalize! can be extended for typeof(f!) to add setup/teardown behavior.

source

Extension Points

Define methods on initialize! and finalize! for your callback's f! type to run setup/teardown code when the integrator starts and finishes.

ClimaTimeSteppers.Callbacks.initialize! — Function
Callbacks.initialize!(f!, integrator)

Called when the integrator starts. Extend this for your callback type f! to perform setup (e.g. open files, record initial state). Default: no-op.

source