Skip to content

Commit

Permalink
Cache: define AtmosCache
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbozzolo committed Oct 27, 2023
1 parent eccc800 commit ef41092
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 4 deletions.
85 changes: 83 additions & 2 deletions src/cache/cache.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,84 @@
Base.@kwdef struct AtmosCache{
FT <: Real,
SIM,
AM,
SFC,
COR,
CAP,
GHOST,
ENV,
PREC,
SCRA,
HYPE,
RS,
VS,
PR,
SUB,
LSAD,
EDMFCOR,
FOR,
NONGW,
ORGW,
RAD,
DSS,
NETFLUXTOA,
NETFLUXSFC,
}
"""Timestep of the simulation (in seconds). This is also used by callbacks and tendencies"""
dt::FT

"""NamedTuple with job_id, output_dir (used in post), and start_date (used for insolation)."""
# TODO: Remove simulation
simulation::SIM

"""AtmosModel"""
atmos::AM

"""ClimaAtmosParameters that have to be used"""
params::CAP

"""Variables that are used generally, such as ᶜρ_ref, ᶜΦ"""
core::COR

"""Used by update_surface_conditions! in set_precomputed_quantities! and coupler"""
sfc_setup::SFC

"""Center and face ghost buffers used by DSS"""
ghost_buffer::GHOST

env_thermo_quad::ENV

"""Quantities that are updated with set_precomputed_quantities!"""
precomputed::PREC

"""Pre-allocated areas of memory to store temporary values"""
scratch::SCRA

"""Hyperdiffision quantities for grid and subgrid scale quantities, potentially with
ghost buffers for DSS"""
hyperdiff::HYPE

"""Additional parameters used by the various tendencies"""
rayleigh_sponge::RS
viscous_sponge::VS
precipitation::PR
subsidence::SUB
large_scale_advection::LSAD
edmf_coriolis::EDMFCOR
forcing::FOR
non_orographic_gravity_wave::NONGW
orographic_gravity_wave::ORGW
radiation::RAD

do_dss::DSS

"""Net energy flux coming through top of atmosphere and surface"""
net_energy_flux_toa::NETFLUXTOA
net_energy_flux_sfc::NETFLUXSFC
end

Base.broadcastable(x::AtmosCache) = tuple(x)

# Functions on which the model depends:
# CAP.R_d(params) # dry specific gas constant
# CAP.kappa_d(params) # dry adiabatic exponent
Expand Down Expand Up @@ -86,7 +167,7 @@ function build_cache(Y, atmos, params, surface_setup, simulation)
orographic_gravity_wave = orographic_gravity_wave_cache(Y, atmos)
radiation = radiation_model_cache(Y, atmos, radiation_args...)

p = (;
p = AtmosCache(;
simulation,
atmos,
core,
Expand All @@ -108,7 +189,7 @@ function build_cache(Y, atmos, params, surface_setup, simulation)
radiation,
env_thermo_quad,
ghost_buffer,
dt = simulation.dt,
simulation.dt,
net_energy_flux_toa,
net_energy_flux_sfc,
)
Expand Down
1 change: 1 addition & 0 deletions src/callbacks/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)
t = integrator.t

(; ᶜts, sfc_conditions) = p.precomputed
(; params) = p
(; idealized_insolation, idealized_h2o, idealized_clouds) = p.radiation
(; insolation_tuple, ᶠradiation_flux, radiation_model) = p.radiation

Expand Down
2 changes: 1 addition & 1 deletion src/parameterized_tendencies/sponge/viscous_sponge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ add_viscous_sponge_energy_tendency!(Yₜ, Y, p, t) =

function add_viscous_sponge_energy_tendency!(Yₜ, Y, p, t, ::TotalEnergy)
(; ᶜβ_viscous) = p.viscous_sponge
(; ᶜh_tot) = p
(; ᶜh_tot) = p.precomputed
ᶜρ = Y.c.ρ
@. Yₜ.c.ρe_tot += ᶜβ_viscous * wdivₕ(ᶜρ * gradₕ(ᶜh_tot))
end
Expand Down
27 changes: 26 additions & 1 deletion test/coupler_compatibility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,32 @@ const T2 = 290
)
sfc_setup = similar(Spaces.level(Y.f, half), typeof(surface_state))
@. sfc_setup = (surface_state,)
p_overwritten = merge(p, (; sfc_setup))
p_overwritten = CA.AtmosCache(;
p.simulation,
p.atmos,
p.core,
sfc_setup,
p.params,
p.do_dss,
p.precomputed,
p.scratch,
p.hyperdiff,
p.rayleigh_sponge,
p.viscous_sponge,
p.precipitation,
p.subsidence,
p.large_scale_advection,
p.edmf_coriolis,
p.forcing,
p.non_orographic_gravity_wave,
p.orographic_gravity_wave,
p.radiation,
p.env_thermo_quad,
p.ghost_buffer,
p.simulation.dt,
p.net_energy_flux_toa,
p.net_energy_flux_sfc,
)

# Test that set_precomputed_quantities! can be used to update the surface
# temperature to T1 and then to T2.
Expand Down

0 comments on commit ef41092

Please sign in to comment.