Skip to content

Commit

Permalink
Merge pull request #3448 from CliMA/ck/elim_cache2
Browse files Browse the repository at this point in the history
Eliminate subsidence cache
  • Loading branch information
charleskawczynski authored Nov 21, 2024
2 parents 6fa62ee + 5e53f8d commit fd0dbb6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
4 changes: 0 additions & 4 deletions src/cache/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ struct AtmosCache{
RS,
VS,
PR,
SUB,
LSAD,
EXTFORCING,
EDMFCOR,
Expand Down Expand Up @@ -80,7 +79,6 @@ struct AtmosCache{
rayleigh_sponge::RS
viscous_sponge::VS
precipitation::PR
subsidence::SUB
large_scale_advection::LSAD
external_forcing::EXTFORCING
edmf_coriolis::EDMFCOR
Expand Down Expand Up @@ -188,7 +186,6 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
rayleigh_sponge = rayleigh_sponge_cache(Y, atmos)
viscous_sponge = viscous_sponge_cache(Y, atmos)
precipitation = precipitation_cache(Y, atmos)
subsidence = subsidence_cache(Y, atmos)
large_scale_advection = large_scale_advection_cache(Y, atmos)
external_forcing = external_forcing_cache(Y, atmos, params)
edmf_coriolis = edmf_coriolis_cache(Y, atmos)
Expand Down Expand Up @@ -217,7 +214,6 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
rayleigh_sponge,
viscous_sponge,
precipitation,
subsidence,
large_scale_advection,
external_forcing,
edmf_coriolis,
Expand Down
17 changes: 3 additions & 14 deletions src/prognostic_equations/forcing/subsidence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,16 @@ import ClimaCore.Spaces as Spaces
import ClimaCore.Fields as Fields
import ClimaCore.Operators as Operators

subsidence_cache(Y, atmos::AtmosModel) = subsidence_cache(Y, atmos.subsidence)

#####
##### No subsidence
#####

subsidence_cache(Y, ::Nothing) = (;)
subsidence_tendency!(Yₜ, Y, p, t, ::Nothing) = nothing

#####
##### Subsidence
#####

function subsidence_cache(Y, ::Subsidence)
FT = Spaces.undertype(axes(Y.f))
return (;
ᶠsubsidence = similar(Y.f, FT), # TODO: fix types
)
end

subsidence!(ᶜρχₜ, ᶜρ, ᶠu³, ᶜχ, ::Val{:none}) =
@. ᶜρχₜ -= ᶜρ * (ᶜsubdivᵥ(ᶠu³ * ᶠinterp(ᶜχ)) - ᶜχ * ᶜsubdivᵥ(ᶠu³))
subsidence!(ᶜρχₜ, ᶜρ, ᶠu³, ᶜχ, ::Val{:first_order}) =
Expand All @@ -37,14 +27,13 @@ subsidence!(ᶜρχₜ, ᶜρ, ᶠu³, ᶜχ, ::Val{:third_order}) =
function subsidence_tendency!(Yₜ, Y, p, t, ::Subsidence)
(; moisture_model) = p.atmos
subsidence_profile = p.atmos.subsidence.prof
(; ᶠsubsidence) = p.subsidence
(; ᶜh_tot, ᶜspecific) = p.precomputed

ᶠz = Fields.coordinate_field(axes(ᶠsubsidence)).z
ᶠz = Fields.coordinate_field(axes(Y.f)).z
ᶠlg = Fields.local_geometry_field(Y.f)
@. ᶠsubsidence = subsidence_profile(ᶠz)
ᶠsubsidence³ = p.scratch.ᶠtemp_CT3
@. ᶠsubsidence³ = ᶠsubsidence * CT3(unit_basis_vector_data(CT3, ᶠlg))
@. ᶠsubsidence³ =
subsidence_profile(ᶠz) * CT3(unit_basis_vector_data(CT3, ᶠlg))

# LS Subsidence
subsidence!(Yₜ.c.ρe_tot, Y.c.ρ, ᶠsubsidence³, ᶜh_tot, Val{:first_order}())
Expand Down
1 change: 0 additions & 1 deletion test/coupler_compatibility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ const T2 = 290
p.rayleigh_sponge,
p.viscous_sponge,
p.precipitation,
p.subsidence,
p.large_scale_advection,
p.external_forcing,
p.edmf_coriolis,
Expand Down

0 comments on commit fd0dbb6

Please sign in to comment.