Skip to content

Commit

Permalink
Remove output_dir from cache
Browse files Browse the repository at this point in the history
Output dir is constant and is only used for a couple of callbacks
  • Loading branch information
Sbozzolo committed Dec 5, 2024
1 parent 299b8ab commit b7192a9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
7 changes: 1 addition & 6 deletions src/cache/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct AtmosCache{
NETFLUXTOA,
NETFLUXSFC,
CONSCHECK,
OD,
}
"""Timestep of the simulation (in seconds). This is also used by callbacks and tendencies"""
dt::FT
Expand Down Expand Up @@ -84,9 +83,6 @@ struct AtmosCache{

"""Conservation check for prognostic surface temperature"""
conservation_check::CONSCHECK

"""Directory output."""
output_dir::OD
end

# Functions on which the model depends:
Expand All @@ -102,7 +98,7 @@ end
# The model also depends on f_plane_coriolis_frequency(params)
# This is a constant Coriolis frequency that is only used if space is flat
function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
(; dt, t_end, start_date, output_dir) = sim_info
(; dt, t_end, start_date) = sim_info
FT = eltype(params)

ᶜcoord = Fields.local_geometry_field(Y.c).coordinates
Expand Down Expand Up @@ -208,7 +204,6 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
net_energy_flux_toa,
net_energy_flux_sfc,
conservation_check,
output_dir,
)

return AtmosCache{map(typeof, args)...}(args...)
Expand Down
3 changes: 1 addition & 2 deletions src/callbacks/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ simulation will gracefully exit with the integrator.
!!! note
This may not be reliable for MPI jobs.
"""
function maybe_graceful_exit(integrator)
output_dir = integrator.p.output_dir
function maybe_graceful_exit(output_dir, integrator)
file = joinpath(output_dir, "graceful_exit.dat")
if isfile(file)
open(file, "r") do io
Expand Down
20 changes: 15 additions & 5 deletions src/callbacks/get_callbacks.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
function get_diagnostics(parsed_args, atmos_model, Y, p, sim_info, t_start)
function get_diagnostics(
parsed_args,
atmos_model,
Y,
p,
sim_info,
t_start,
output_dir,
)

(; dt, start_date) = sim_info

Expand All @@ -25,7 +33,7 @@ function get_diagnostics(parsed_args, atmos_model, Y, p, sim_info, t_start)
"average" => ((+), CAD.average_pre_output_hook!),
)

hdf5_writer = CAD.HDF5Writer(p.output_dir)
hdf5_writer = CAD.HDF5Writer(output_dir)

if !isnothing(parsed_args["netcdf_interpolation_num_points"])
num_netcdf_points =
Expand All @@ -42,7 +50,7 @@ function get_diagnostics(parsed_args, atmos_model, Y, p, sim_info, t_start)

netcdf_writer = CAD.NetCDFWriter(
axes(Y.c),
p.output_dir,
output_dir,
num_points = num_netcdf_points;
z_sampling_method,
sync_schedule = CAD.EveryStepSchedule(),
Expand Down Expand Up @@ -245,8 +253,10 @@ function get_callbacks(config, sim_info, atmos, params, Y, p, t_start)
call_every_n_steps(
terminate!;
skip_first = true,
condition = (u, t, integrator) ->
maybe_graceful_exit(integrator),
condition = let output_dir = output_dir
(u, t, integrator) ->
maybe_graceful_exit(output_dir, integrator)
end,
),
)

Expand Down
1 change: 1 addition & 0 deletions src/solver/type_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ function get_simulation(config::AtmosConfig)
p,
sim_info,
t_start,
output_dir,
)
end
@info "initializing diagnostics: $s"
Expand Down
1 change: 0 additions & 1 deletion test/coupler_compatibility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ const T2 = 290
p.net_energy_flux_toa,
p.net_energy_flux_sfc,
p.conservation_check,
p.output_dir,
)

# Test that set_precomputed_quantities! can be used to update the surface
Expand Down

0 comments on commit b7192a9

Please sign in to comment.