-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move diagnostics preparation into callbacks
- Loading branch information
1 parent
cd1ca39
commit 12b65e4
Showing
7 changed files
with
392 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
function get_callbacks( | ||
Y, | ||
p, | ||
t_start, | ||
parsed_args, | ||
sim_info, | ||
atmos, | ||
params, | ||
comms_ctx, | ||
spaces, | ||
) | ||
FT = eltype(params) | ||
(; dt, output_dir) = sim_info | ||
|
||
callbacks = () | ||
callbacks = ( | ||
callbacks..., | ||
call_every_n_steps( | ||
terminate!; | ||
skip_first = true, | ||
condition = (u, t, integrator) -> | ||
maybe_graceful_exit(integrator), | ||
), | ||
) | ||
|
||
dt_save_state_to_disk = | ||
time_to_seconds(parsed_args["dt_save_state_to_disk"]) | ||
if !(dt_save_state_to_disk == Inf) | ||
callbacks = ( | ||
callbacks..., | ||
call_every_dt( | ||
(integrator) -> | ||
save_state_to_disk_func(integrator, output_dir), | ||
dt_save_state_to_disk; | ||
skip_first = sim_info.restart, | ||
), | ||
) | ||
end | ||
|
||
if is_distributed(comms_ctx) | ||
callbacks = ( | ||
callbacks..., | ||
call_every_n_steps( | ||
gc_func, | ||
parse(Int, get(ENV, "CLIMAATMOS_GC_NSTEPS", "1000")), | ||
skip_first = true, | ||
), | ||
) | ||
end | ||
|
||
if parsed_args["check_conservation"] | ||
callbacks = ( | ||
callbacks..., | ||
call_every_n_steps( | ||
flux_accumulation!; | ||
skip_first = true, | ||
call_at_end = true, | ||
), | ||
) | ||
end | ||
|
||
# get_diagnostics_cb returns an empty tuple if diagnostics are empty | ||
callbacks = ( | ||
callbacks..., | ||
get_diagnostics_cb( | ||
Y, | ||
p, | ||
t_start, | ||
parsed_args, | ||
sim_info, | ||
atmos, | ||
params, | ||
comms_ctx, | ||
spaces, | ||
)..., | ||
) | ||
|
||
if atmos.radiation_mode isa RRTMGPI.AbstractRRTMGPMode | ||
# TODO: better if-else criteria? | ||
dt_rad = if parsed_args["config"] == "column" | ||
dt | ||
else | ||
FT(time_to_seconds(parsed_args["dt_rad"])) | ||
end | ||
callbacks = | ||
(callbacks..., call_every_dt(rrtmgp_model_callback!, dt_rad)) | ||
end | ||
|
||
dt_cf = FT(time_to_seconds(parsed_args["dt_cloud_fraction"])) | ||
callbacks = | ||
(callbacks..., call_every_dt(cloud_fraction_model_callback!, dt_cf)) | ||
|
||
if parsed_args["log_progress"] && !sim_info.restart | ||
@info "Progress logging enabled." | ||
callbacks = ( | ||
callbacks..., | ||
call_every_n_steps( | ||
(integrator) -> print_walltime_estimate(integrator); | ||
skip_first = true, | ||
), | ||
) | ||
end | ||
|
||
return callbacks | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.