Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove output_dir from cache #3465

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/cache/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 @@ -88,9 +87,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 @@ -106,7 +102,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 @@ -213,7 +209,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 @@ -489,8 +489,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, dt, t_start)
function get_diagnostics(
parsed_args,
atmos_model,
Y,
p,
dt,
t_start,
output_dir,
)

FT = Spaces.undertype(axes(Y.c))

Expand All @@ -23,7 +31,7 @@ function get_diagnostics(parsed_args, atmos_model, Y, p, dt, 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 @@ -40,7 +48,7 @@ function get_diagnostics(parsed_args, atmos_model, Y, p, dt, 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 @@ -243,8 +251,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.dt,
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 @@ -91,7 +91,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
Loading