Skip to content

Commit 97b4024

Browse files
committed
clean up buoyancy gradient
1 parent e000883 commit 97b4024

File tree

1 file changed

+28
-85
lines changed

1 file changed

+28
-85
lines changed

src/prognostic_equations/eddy_diffusion_closures.jl

Lines changed: 28 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,6 @@ import Thermodynamics.Parameters as TDP
77
import ClimaCore.Geometry as Geometry
88
import ClimaCore.Fields as Fields
99

10-
get_t_sat(thermo_params, x::EnvBuoyGradVars) =
11-
TD.air_temperature(thermo_params, x.ts)
12-
get_p(thermo_params, x::EnvBuoyGradVars) = TD.air_pressure(thermo_params, x.ts)
13-
get_ρ(thermo_params, x::EnvBuoyGradVars) = TD.air_density(thermo_params, x.ts)
14-
get_en_cld_frac(thermo_params, x::EnvBuoyGradVars) =
15-
ifelse(TD.has_condensate(thermo_params, x.ts), 1, 0)
16-
get_θ_liq_ice_sat(thermo_params, x::EnvBuoyGradVars) =
17-
TD.liquid_ice_pottemp(thermo_params, x.ts)
18-
get_qt_sat(thermo_params, x::EnvBuoyGradVars) =
19-
TD.total_specific_humidity(thermo_params, x.ts)
20-
get_ql_sat(thermo_params, x::EnvBuoyGradVars) =
21-
TD.liquid_specific_humidity(thermo_params, x.ts)
22-
get_qi_sat(thermo_params, x::EnvBuoyGradVars) =
23-
TD.ice_specific_humidity(thermo_params, x.ts)
24-
get_qv_sat(thermo_params, x::EnvBuoyGradVars) =
25-
TD.vapor_specific_humidity(thermo_params, x.ts)
26-
get_θ_sat(thermo_params, x::EnvBuoyGradVars) =
27-
TD.dry_pottemp(thermo_params, x.ts)
28-
get_∂θli∂z_sat(_, x::EnvBuoyGradVars) = x.∂θli∂z_sat
29-
get_∂qt∂z_sat(_, x::EnvBuoyGradVars) = x.∂qt∂z_sat
30-
get_∂θv∂z_unsat(_, x::EnvBuoyGradVars) = x.∂θv∂z_unsat
31-
3210
"""
3311
buoyancy_gradients(
3412
closure::AbstractEnvBuoyGradClosure,
@@ -124,54 +102,27 @@ function buoyancy_gradients(
124102
R_d = TDP.R_d(thermo_params)
125103
R_v = TDP.R_v(thermo_params)
126104

127-
phase_part = TD.PhasePartition(FT(0), FT(0), FT(0)) # assuming R_m = R_d
128-
p = get_p(thermo_params, bg_model)
129-
Π = TD.exner_given_pressure(thermo_params, p, phase_part)
130-
131-
∂b∂θv = g * (R_d * get_ρ(thermo_params, bg_model) / p) * Π
132-
θ_liq_ice_sat = get_θ_liq_ice_sat(thermo_params, bg_model)
133-
qt_sat = get_qt_sat(thermo_params, bg_model)
134-
135-
if get_en_cld_frac(thermo_params, bg_model) > 0.0
136-
ts_sat = if moisture_model isa DryModel
137-
TD.PhaseDry_pθ(thermo_params, p, θ_liq_ice_sat)
138-
elseif moisture_model isa EquilMoistModel
139-
TD.PhaseEquil_pθq(thermo_params, p, θ_liq_ice_sat, qt_sat)
140-
elseif moisture_model isa NonEquilMoistModel
141-
TD.PhaseNonEquil_pθq(
142-
thermo_params,
143-
p,
144-
θ_liq_ice_sat,
145-
TD.PhasePartition(
146-
qt_sat,
147-
get_ql_sat(thermo_params, bg_model),
148-
get_qi_sat(thermo_params, bg_model),
149-
),
150-
)
151-
else
152-
error("Unsupported moisture model")
153-
end
154-
155-
t_sat = get_t_sat(thermo_params, bg_model)
156-
phase_part = TD.PhasePartition(thermo_params, ts_sat)
157-
λ = TD.liquid_fraction(thermo_params, ts_sat)
158-
lh =
159-
λ * TD.latent_heat_vapor(thermo_params, t_sat) +
160-
(1 - λ) * TD.latent_heat_sublim(thermo_params, t_sat)
161-
cp_m = TD.cp_m(thermo_params, ts_sat)
162-
qv_sat = get_qv_sat(thermo_params, bg_model)
163-
∂b∂θli_sat = (
164-
∂b∂θv *
165-
(1 + Rv_over_Rd * (1 + lh / R_v / t_sat) * qv_sat - qt_sat) /
166-
(1 + lh * lh / cp_m / R_v / t_sat / t_sat * qv_sat)
167-
)
168-
∂b∂qt_sat =
169-
(lh / cp_m / t_sat * ∂b∂θli_sat - ∂b∂θv) *
170-
get_θ_sat(thermo_params, bg_model)
171-
else
172-
∂b∂θli_sat = FT(0)
173-
∂b∂qt_sat = FT(0)
174-
end
105+
ts = bg_model.ts
106+
p = TD.air_pressure(thermo_params, ts)
107+
Π = TD.exner_given_pressure(thermo_params, p)
108+
∂b∂θv = g * (R_d * TD.air_density(thermo_params, ts) / p) * Π
109+
110+
t_sat = TD.air_temperature(thermo_params, ts)
111+
λ = TD.liquid_fraction(thermo_params, ts)
112+
lh =
113+
λ * TD.latent_heat_vapor(thermo_params, t_sat) +
114+
(1 - λ) * TD.latent_heat_sublim(thermo_params, t_sat)
115+
cp_m = TD.cp_m(thermo_params, ts)
116+
qv_sat = TD.vapor_specific_humidity(thermo_params, ts)
117+
qt_sat = TD.total_specific_humidity(thermo_params, ts)
118+
∂b∂θli_sat = (
119+
∂b∂θv *
120+
(1 + Rv_over_Rd * (1 + lh / R_v / t_sat) * qv_sat - qt_sat) /
121+
(1 + lh * lh / cp_m / R_v / t_sat / t_sat * qv_sat)
122+
)
123+
∂b∂qt_sat =
124+
(lh / cp_m / t_sat * ∂b∂θli_sat - ∂b∂θv) *
125+
TD.dry_pottemp(thermo_params, ts)
175126

176127
∂b∂z = buoyancy_gradient_chain_rule(
177128
ebgc,
@@ -203,12 +154,12 @@ This function takes the partial derivatives of buoyancy with respect to:
203154
- total specific humidity (`∂b/∂qₜ,sat`) for the saturated part.
204155
205156
It then multiplies these by the respective vertical gradients of `θᵥ`, `θₗᵢ`, and `qₜ`
206-
(obtained from `bg_model` via `get_∂θv∂z_unsat`, `get_∂θli∂z_sat`, `get_∂qt∂z_sat`)
157+
(obtained from `bg_model`)
207158
to get the buoyancy gradients for the unsaturated (`∂b∂z_unsat`) and saturated
208159
(`∂b∂z_sat`) parts of the environment.
209160
Finally, it returns a single mean buoyancy gradient by linearly combining
210161
`∂b∂z_unsat` and `∂b∂z_sat` weighted by the environmental cloud fraction
211-
(also obtained from `bg_model` via `get_en_cld_frac`).
162+
(also obtained from `bg_model`).
212163
213164
Arguments:
214165
- `closure`: The environmental buoyancy gradient closure type.
@@ -229,21 +180,13 @@ function buoyancy_gradient_chain_rule(
229180
∂b∂θli_sat,
230181
∂b∂qt_sat,
231182
)
232-
FT = eltype(thermo_params)
233-
en_cld_frac = get_en_cld_frac(thermo_params, bg_model)
234-
if en_cld_frac > FT(0)
235-
∂b∂z_θl_sat = ∂b∂θli_sat * get_∂θli∂z_sat(thermo_params, bg_model)
236-
∂b∂z_qt_sat = ∂b∂qt_sat * get_∂qt∂z_sat(thermo_params, bg_model)
237-
else
238-
∂b∂z_θl_sat = FT(0)
239-
∂b∂z_qt_sat = FT(0)
240-
end
241-
242-
∂b∂z_unsat =
243-
en_cld_frac < FT(1) ? ∂b∂θv * get_∂θv∂z_unsat(thermo_params, bg_model) :
244-
FT(0)
183+
en_cld_frac = ifelse(TD.has_condensate(thermo_params, bg_model.ts), 1, 0)
245184

185+
∂b∂z_θl_sat = ∂b∂θli_sat * bg_model.∂θli∂z_sat
186+
∂b∂z_qt_sat = ∂b∂qt_sat * bg_model.∂qt∂z_sat
246187
∂b∂z_sat = ∂b∂z_θl_sat + ∂b∂z_qt_sat
188+
∂b∂z_unsat = ∂b∂θv * bg_model.∂θv∂z_unsat
189+
247190
∂b∂z = (1 - en_cld_frac) * ∂b∂z_unsat + en_cld_frac * ∂b∂z_sat
248191

249192
return ∂b∂z

0 commit comments

Comments
 (0)