Skip to content

Commit 002b4f3

Browse files
Merge pull request #3449 from CliMA/ck/elim_cache3
Eliminate forcing cache
2 parents 00082c0 + 7210833 commit 002b4f3

File tree

3 files changed

+102
-43
lines changed

3 files changed

+102
-43
lines changed

src/cache/cache.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct AtmosCache{
1818
LSAD,
1919
EXTFORCING,
2020
EDMFCOR,
21-
FOR,
2221
NONGW,
2322
ORGW,
2423
RAD,
@@ -78,7 +77,6 @@ struct AtmosCache{
7877
large_scale_advection::LSAD
7978
external_forcing::EXTFORCING
8079
edmf_coriolis::EDMFCOR
81-
forcing::FOR
8280
non_orographic_gravity_wave::NONGW
8381
orographic_gravity_wave::ORGW
8482
radiation::RAD
@@ -183,7 +181,6 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
183181
large_scale_advection = large_scale_advection_cache(Y, atmos)
184182
external_forcing = external_forcing_cache(Y, atmos, params)
185183
edmf_coriolis = edmf_coriolis_cache(Y, atmos)
186-
forcing = forcing_cache(Y, atmos)
187184
non_orographic_gravity_wave = non_orographic_gravity_wave_cache(Y, atmos)
188185
orographic_gravity_wave = orographic_gravity_wave_cache(Y, atmos)
189186
radiation = radiation_model_cache(Y, atmos, radiation_args...)
@@ -209,7 +206,6 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
209206
large_scale_advection,
210207
external_forcing,
211208
edmf_coriolis,
212-
forcing,
213209
non_orographic_gravity_wave,
214210
orographic_gravity_wave,
215211
radiation,

src/parameterized_tendencies/radiation/held_suarez.jl

Lines changed: 102 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,21 @@
22
##### Held-Suarez
33
#####
44

5+
import Thermodynamics as TD
6+
import Thermodynamics.Parameters as TDP
57
import ClimaCore.Spaces as Spaces
68
import ClimaCore.Fields as Fields
79

8-
forcing_cache(Y, atmos::AtmosModel) = forcing_cache(Y, atmos.forcing_type)
9-
1010
#####
1111
##### No forcing
1212
#####
1313

14-
forcing_cache(Y, forcing_type::Nothing) = (;)
1514
forcing_tendency!(Yₜ, Y, p, t, ::Nothing) = nothing
1615

1716
#####
1817
##### Held-Suarez forcing
1918
#####
2019

21-
function forcing_cache(Y, forcing_type::HeldSuarezForcing)
22-
FT = Spaces.undertype(axes(Y.c))
23-
return (;
24-
ᶜσ = similar(Y.c, FT),
25-
ᶜheight_factor = similar(Y.c, FT),
26-
ᶜΔρT = similar(Y.c, FT),
27-
ᶜφ = deg2rad.(Fields.coordinate_field(Y.c).lat),
28-
)
29-
end
30-
3120
function held_suarez_ΔT_y_T_equator(params, moisture_model::DryModel)
3221
FT = eltype(params)
3322
ΔT_y = FT(CAP.ΔT_y_dry(params))
@@ -45,10 +34,76 @@ function held_suarez_ΔT_y_T_equator(
4534
return ΔT_y, T_equator
4635
end
4736

37+
struct HeldSuarezForcingParams{FT}
38+
ΔT_y::FT
39+
day::FT
40+
σ_b::FT
41+
R_d::FT
42+
T_min::FT
43+
T_equator::FT
44+
Δθ_z::FT
45+
p_ref_theta::FT
46+
κ_d::FT
47+
grav::FT
48+
MSLP::FT
49+
end
50+
Base.Broadcast.broadcastable(x::HeldSuarezForcingParams) = tuple(x)
51+
52+
function compute_ΔρT(
53+
thermo_params::TDP.ThermodynamicsParameters,
54+
ts_surf::TD.ThermodynamicState,
55+
ρ::FT,
56+
p::FT,
57+
lat::FT,
58+
z_surface::FT,
59+
s::HeldSuarezForcingParams,
60+
) where {FT}
61+
σ = compute_σ(thermo_params, z_surface, p, ts_surf, s)
62+
k_a = 1 / (40 * s.day)
63+
k_s = 1 / (4 * s.day)
64+
65+
φ = deg2rad(lat)
66+
return (k_a + (k_s - k_a) * height_factor(σ, s.σ_b) * abs2(abs2(cos(φ)))) *
67+
ρ *
68+
( # ᶜT - ᶜT_equil
69+
p /* s.R_d) - max(
70+
s.T_min,
71+
(
72+
s.T_equator - s.ΔT_y * abs2(sin(φ)) -
73+
s.Δθ_z * log(p / s.p_ref_theta) * abs2(cos(φ))
74+
) * fast_pow(p / s.p_ref_theta, s.κ_d),
75+
)
76+
)
77+
end
78+
79+
function compute_σ(
80+
thermo_params::TDP.ThermodynamicsParameters,
81+
z_surface::FT,
82+
p::FT,
83+
ts_surf::TD.ThermodynamicState,
84+
s::HeldSuarezForcingParams,
85+
) where {FT}
86+
p / (
87+
s.MSLP * exp(
88+
-s.grav * z_surface / s.R_d /
89+
TD.air_temperature(thermo_params, ts_surf),
90+
)
91+
)
92+
end
93+
94+
height_factor::FT, σ_b::FT) where {FT} = max(0, (σ - σ_b) / (1 - σ_b))
95+
height_factor(
96+
thermo_params::TDP.ThermodynamicsParameters,
97+
z_surface::FT,
98+
p::FT,
99+
ts_surf::TD.ThermodynamicState,
100+
s::HeldSuarezForcingParams,
101+
) where {FT} =
102+
height_factor(compute_σ(thermo_params, z_surface, p, ts_surf, s), s.σ_b)
103+
48104
function forcing_tendency!(Yₜ, Y, p, t, ::HeldSuarezForcing)
49105
(; params) = p
50106
(; ᶜp, sfc_conditions) = p.precomputed
51-
(; ᶜσ, ᶜheight_factor, ᶜΔρT, ᶜφ) = p.forcing
52107

53108
# TODO: Don't need to enforce FT here, it should be done at param creation.
54109
FT = Spaces.undertype(axes(Y.c))
@@ -63,37 +118,46 @@ function forcing_tendency!(Yₜ, Y, p, t, ::HeldSuarezForcing)
63118
T_min = FT(CAP.T_min_hs(params))
64119
thermo_params = CAP.thermodynamics_params(params)
65120
σ_b = CAP.σ_b(params)
66-
k_a = 1 / (40 * day)
67-
k_s = 1 / (4 * day)
68121
k_f = 1 / day
69122

70123
z_surface = Fields.level(Fields.coordinate_field(Y.f).z, Fields.half)
71124

72125
ΔT_y, T_equator = held_suarez_ΔT_y_T_equator(params, p.atmos.moisture_model)
73126

74-
@. ᶜσ =
75-
ᶜp / (
76-
MSLP * exp(
77-
-grav * z_surface / R_d /
78-
TD.air_temperature(thermo_params, sfc_conditions.ts),
79-
)
80-
)
127+
hs_params = HeldSuarezForcingParams{FT}(
128+
ΔT_y,
129+
day,
130+
σ_b,
131+
R_d,
132+
T_min,
133+
T_equator,
134+
Δθ_z,
135+
p_ref_theta,
136+
κ_d,
137+
grav,
138+
MSLP,
139+
)
81140

82-
@. ᶜheight_factor = max(0, (ᶜσ - σ_b) / (1 - σ_b))
83-
@. ᶜΔρT =
84-
(k_a + (k_s - k_a) * ᶜheight_factor * abs2(abs2(cos(ᶜφ)))) *
85-
Y.c.ρ *
86-
( # ᶜT - ᶜT_equil
87-
ᶜp / (Y.c.ρ * R_d) - max(
88-
T_min,
89-
(
90-
T_equator - ΔT_y * abs2(sin(ᶜφ)) -
91-
Δθ_z * log(ᶜp / p_ref_theta) * abs2(cos(ᶜφ))
92-
) * fast_pow(ᶜp / p_ref_theta, κ_d),
141+
lat = Fields.coordinate_field(Y.c).lat
142+
@. Yₜ.c.uₕ -=
143+
(
144+
k_f * height_factor(
145+
thermo_params,
146+
z_surface,
147+
ᶜp,
148+
sfc_conditions.ts,
149+
hs_params,
93150
)
94-
)
95-
96-
@. Yₜ.c.uₕ -= (k_f * ᶜheight_factor) * Y.c.uₕ
97-
@. Yₜ.c.ρe_tot -= ᶜΔρT * cv_d
151+
) * Y.c.uₕ
152+
@. Yₜ.c.ρe_tot -=
153+
compute_ΔρT(
154+
thermo_params,
155+
sfc_conditions.ts,
156+
Y.c.ρ,
157+
ᶜp,
158+
lat,
159+
z_surface,
160+
hs_params,
161+
) * cv_d
98162
return nothing
99163
end

test/coupler_compatibility.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ const T2 = 290
8484
p.large_scale_advection,
8585
p.external_forcing,
8686
p.edmf_coriolis,
87-
p.forcing,
8887
p.non_orographic_gravity_wave,
8988
p.orographic_gravity_wave,
9089
p.radiation,

0 commit comments

Comments
 (0)