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) -> Boolaffect!: function(integrator) -> nothing, called whenconditionreturnstrue
Keyword Arguments
initialize: function(cb, u, t, integrator)called at integrator startupfinalize: function(cb, u, t, integrator)called whensolve!finishes
See also CallbackSet, ClimaTimeSteppers.Callbacks.
ClimaTimeSteppers.CallbackSet — Type
CallbackSet(callbacks...)A collection of DiscreteCallbacks applied after each step. Accepts nothing, individual DiscreteCallbacks, or nested CallbackSets.
Pre-Built Callbacks
The ClimaTimeSteppers.Callbacks module provides convenience constructors for common triggering patterns. Import them with:
using ClimaTimeSteppers: Callbacks
using .CallbacksClimaTimeSteppers.Callbacks — Module
ClimaTimeSteppers.CallbacksPre-built DiscreteCallback constructors for common triggering patterns: wall-clock time, simulation time, and step count.
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!: callablef!(integrator)to executeΔwt: wall-clock interval in secondscomm_ctx: aClimaComms.AbstractCommsContext
Keyword Arguments
atinit: iftrue, also trigger at initialization (defaultfalse)
Callbacks.initialize! and Callbacks.finalize! can be extended for typeof(f!) to add setup/teardown behavior.
ClimaTimeSteppers.Callbacks.EveryXSimulationTime — Function
EveryXSimulationTime(f!, Δt; atinit=false)Trigger f!(integrator) every Δt simulation time units.
Arguments
f!: callablef!(integrator)to executeΔt: simulation time interval
Keyword Arguments
atinit: iftrue, also trigger at initialization (defaultfalse)
Callbacks.initialize! and Callbacks.finalize! can be extended for typeof(f!) to add setup/teardown behavior.
ClimaTimeSteppers.Callbacks.EveryXSimulationSteps — Function
EveryXSimulationSteps(f!, Δsteps; atinit=false)Trigger f!(integrator) every Δsteps simulation steps.
Arguments
f!: callablef!(integrator)to executeΔsteps: number of steps between triggers
Keyword Arguments
atinit: iftrue, also trigger at initialization (defaultfalse)
Callbacks.initialize! and Callbacks.finalize! can be extended for typeof(f!) to add setup/teardown behavior.
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.
ClimaTimeSteppers.Callbacks.finalize! — Function
Callbacks.finalize!(f!, integrator)Called when ClimaTimeSteppers.solve! completes. Extend this for your callback type f! to perform teardown (e.g. close files, flush buffers). Default: no-op.