ClimaLand Shared Callbacks
ClimaLand.IntervalBasedCallback
— FunctionIntervalBasedCallback(
period::Dates.Period,
t0::ITime,
dt::Union{ITime, Nothing},
affect!;
initialize = (_, _, _, _) -> nothing,
callback_start::ITime = t0,
)
Returns a SciML DiscreteCallback that calls affect!
every period
. This method is used when the type of period
is a Dates.Period
The returned callback has a condition function that is built on a ClimaDiagnostics EveryCalendarDtSchedule
. The initialize
argument is passed to the DiscreteCallback as keyword arguments. Excluding initialization, the first time the callback will be called is when the simulation is at or past period
+ callback_start
.
IntervalBasedCallback(
period::Union{Number, ITime},
t0::Union{Number, ITime},
dt::Union{Number, ITime, Nothing},
affect!;
initialize = (_, _, _, _) -> nothing,
callback_start::Union{Number, ITime} = t0,
)
Returns a SciML DiscreteCallback that calls affect!
every period
. This method is used when period
is not a Dates.Period
.
The returned callback has a condition function that is built on a ClimaDiagnostics EveryDtSchedule
. The initialize
argument is passed to the DiscreteCallback as keyword arguments. Excluding initialization, the first time the callback will be called is when the simulation is at or past period
+ callback_start
.
ClimaLand.ReportCallback
— FunctionReportCallback(period, t0; dt = nothing)
Return a callback that prints performance and progress summaries every period
ClimaLand.NaNCheckCallback
— FunctionNaNCheckCallback(
nancheck_period::Union{Number, Dates.Period, ITime},
t0;
dt = nothing,
mask = nothing,
)
Constructs a DiscreteCallback which counts the number of NaNs in the state and produces a warning if any are found.
Arguments
nancheck_period
: The interrval between times when the state is checked for NaNs. Can be specified as anITime
, aNumber
, or aDates.Period
.t0
: The start of the simulation.dt
: The timestep of the model (optional), used to check for consistency.mask
: NaNs will not be counted in areas wheremask
is zero
The callback uses ClimaDiagnostics
schedules to determine when to check for NaNs based on the nancheck_period
.
ClimaLand.NonInterpSavingCallback
— FunctionNonInterpSavingCallback(
start_date::Dates.DateTime,
stop_date::Dates.DateTime,
callback_period::Dates.Period;
first_save_date = start_date,
)
Constructs a DiscreteCallback
which saves the time and cache p
at first_save_date
and every callback_period
after. Times are saved as DateTimes, and the saved times and caches are each saved in a vector. They are stored in a NamedTuple
, which is the saved_values
property of the affect!
property of the DiscreteCallback
. For example:
cb = NonInterpSavingCallback(start_date, stop_date, callback_period)
saved_values = cb.affect!.saved_values
saved_times = saved_values.t
- Vector of DateTimes saved_cache = saved_values.saveval
- A vector of caches
Note: This method constructs a callback that uses ITime
for scheduling, and should only be used with simulations that are run with ITime
.
NonInterpSavingCallback(t0, tf, callback_period; t_first_save = t0)
Constructs a DiscreteCallback
which saves the time and cache p
at t_first_save
and every callback_period
after. Times are saved as the same type as t0
, and the saved times and caches are each saved in a vector. They are stored in a NamedTuple
, which is the saved_values
property of the affect!
property of the DiscreteCallback
. For example:
cb = NonInterpSavingCallback(t0, tf, callback_period)
saved_values = cb.affect!.saved_values
saved_times = saved_values.t
- Vector of typeof(t0) saved_cache = saved_values.saveval
- A vector of caches
Note: This method constructs a callback that uses ITime
for scheduling, and should only be used with simulations that are run with ITime
.
ClimaLand.DriverUpdateCallback
— FunctionDriverUpdateCallback(
updatefunc,
update_period,
t0;
dt = nothing,
)
Constructs a DiscreteCallback which updates the cache p.drivers
at each time specified by updateat
, using the function updatefunc
which takes as arguments (p,t). If update_period
is nothing
, then updatefunc
will not be called during the simulation or during intialization. This can be used to disable the driver update for a simulation.
ClimaLand.CheckpointCallback
— FunctionCheckpointCallback(
checkpoint_period::Union{Number, Dates.Period, ITime},
output_dir,
t0;
model,
dt = nothing,
)
Constructs a DiscreteCallback which saves the state to disk with the save_checkpoint
function.
Arguments
checkpoint_period
: The interval between times where checkpoints are saved. Can be specified as a float (in seconds)Dates.Period
, orITime
.output_dir
: The directory where the checkpoint files will be saved.t0
: The start of the simulation.model
: The ClimaLand model object.dt
: The timestep of the model (optional), used to check for consistency.
The callback uses ClimaDiagnostics.EveryCalendarDtSchedule
to determine when to save checkpoints based on the checkpoint_period
. The schedule is initialized with the t0
to ensure that the first checkpoint is saved at the correct time.
The save_checkpoint
function is called with the current state vector u
, the current time t
, and the output_dir
to save the checkpoint to disk.