Skip to content

Commit c23e782

Browse files
committed
buoyancy gradient
1 parent 785bc48 commit c23e782

File tree

6 files changed

+70
-37
lines changed

6 files changed

+70
-37
lines changed

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
13401340
t,
13411341
)
13421342
(; params) = p
1343-
(; ᶜu, ᶜts, ᶠu³) = p.precomputed
1343+
(; ᶜu, ᶜT, ᶜq_liq_rai, ᶜq_ice_sno, ᶠu³) = p.precomputed
13441344
(; ustar) = p.precomputed.sfc_conditions
13451345
(; ᶜlinear_buoygrad, ᶜstrain_rate_norm) = p.precomputed
13461346
(; ρtke_flux) = p.precomputed
@@ -1353,10 +1353,15 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
13531353
@. ᶜu⁰ = C123(Y.c.uₕ) + ᶜinterp(C123(ᶠu³⁰))
13541354
end # Set here, but used in a different function
13551355

1356+
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
13561357
@. ᶜlinear_buoygrad = buoyancy_gradients(
13571358
BuoyGradMean(),
13581359
thermo_params,
1359-
ᶜts,
1360+
ᶜT,
1361+
Y.c.ρ,
1362+
ᶜq_tot,
1363+
ᶜq_liq_rai,
1364+
ᶜq_ice_sno,
13601365
p.precomputed.cloud_diagnostics_tuple.cf,
13611366
C3,
13621367
p.precomputed.ᶜgradᵥ_q_tot,

src/cache/prognostic_edmf_precomputed_quantities.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
175175
FT = eltype(params)
176176
n = n_mass_flux_subdomains(turbconv_model)
177177

178-
(; ᶜu, ᶜp, ᶠu³, ᶜts, ᶠu³⁰, ᶜts⁰) = p.precomputed
178+
(; ᶜu, ᶜp, ᶠu³, ᶜT, ᶜq_liq_rai, ᶜq_ice_sno, ᶠu³⁰, ᶜts⁰) = p.precomputed
179179
(; ᶜlinear_buoygrad, ᶜstrain_rate_norm, ρtke_flux) = p.precomputed
180180
(;
181181
ᶜuʲs,
@@ -301,10 +301,15 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
301301

302302
(; ᶜgradᵥ_q_tot, ᶜgradᵥ_θ_liq_ice, cloud_diagnostics_tuple) =
303303
p.precomputed
304+
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
304305
@. ᶜlinear_buoygrad = buoyancy_gradients( # TODO - do we need to modify buoyancy gradients based on NonEq + 1M tracers?
305306
BuoyGradMean(),
306307
thermo_params,
307-
ᶜts,
308+
ᶜT,
309+
Y.c.ρ,
310+
ᶜq_tot,
311+
ᶜq_liq_rai,
312+
ᶜq_ice_sno,
308313
cloud_diagnostics_tuple.cf,
309314
C3,
310315
ᶜgradᵥ_q_tot,

src/parameterized_tendencies/radiation/radiation.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,21 +462,19 @@ function radiation_tendency!(Yₜ, Y, p, t, radiation_mode::RadiationDYCOMS)
462462
(; params) = p
463463
(; ᶜκρq, ∫_0_∞_κρq, ᶠ∫_0_z_κρq, isoline_z_ρ_ρq, ᶠradiation_flux) =
464464
p.radiation
465-
(; ᶜts) = p.precomputed
465+
(; ᶜts, ᶜq_liq_rai) = p.precomputed
466466
thermo_params = CAP.thermodynamics_params(params)
467467
cp_d = CAP.cp_d(params)
468468
FT = Spaces.undertype(axes(Y.c))
469469
NT = NamedTuple{(:z, , :ρq_tot), NTuple{3, FT}}
470470
ᶜz = Fields.coordinate_field(Y.c).z
471471
ᶠz = Fields.coordinate_field(Y.f).z
472472

473-
# TODO: According to the paper, we should replace liquid_specific_humidity
473+
# TODO: According to the paper, we should replace ᶜq_liq_rai
474474
# with TD.mixing_ratios(thermo_params, ᶜts).liq, but this wouldn't
475475
# match the original code from TurbulenceConvection.
476476
@. ᶜκρq =
477-
radiation_mode.kappa *
478-
Y.c.ρ *
479-
TD.liquid_specific_humidity(thermo_params, ᶜts)
477+
radiation_mode.kappa * Y.c.ρ * ᶜq_liq_rai
480478

481479
Operators.column_integral_definite!(∫_0_∞_κρq, ᶜκρq)
482480

@@ -555,11 +553,11 @@ radiation_model_cache(Y, radiation_mode::RadiationISDAC; args...) = (;) # Don't
555553
function radiation_tendency!(Yₜ, Y, p, t, radiation_mode::RadiationISDAC)
556554
(; F₀, F₁, κ) = radiation_mode
557555
(; params, precomputed) = p
558-
(; ᶜts) = precomputed
556+
(; ᶜts, ᶜq_liq_rai) = precomputed
559557
thermo_params = CAP.thermodynamics_params(params)
560558

561559
ᶜρq = p.scratch.ᶜtemp_scalar
562-
@. ᶜρq = Y.c.ρ * TD.liquid_specific_humidity(thermo_params, ᶜts)
560+
@. ᶜρq = Y.c.ρ * ᶜq_liq_rai
563561

564562
LWP_zₜ = p.scratch.temp_field_level # column integral of LWP (zₜ = top-of-domain)
565563
Operators.column_integral_definite!(LWP_zₜ, ᶜρq)

src/prognostic_equations/eddy_diffusion_closures.jl

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import SurfaceFluxes.UniversalFunctions as UF
1414
thermo_params,
1515
1616
# Arguments for the first method (most commonly called):
17-
ts::TD.ThermodynamicState,
17+
T, # Air temperature [K]
18+
ρ, # Air density [kg/m³]
19+
q_tot, # Total specific humidity [kg/kg]
20+
q_liq, # Liquid specific humidity [kg/kg]
21+
q_ice, # Ice specific humidity [kg/kg]
22+
cf, # Cloud fraction
1823
::Type{C3}, # Covariant3 vector type, for projecting gradients
1924
∂qt∂z::AbstractField, # Vertical gradient of total specific humidity
2025
∂θli∂z::AbstractField, # Vertical gradient of liquid-ice potential temperature
@@ -36,23 +41,22 @@ fraction. The calculation involves:
3641
thermodynamic variables (`∂θᵥ/∂z`, `∂θₗᵢ/∂z`, `∂qₜ/∂z`), obtained from
3742
the input fields after projection.
3843
3. Blending the resulting unsaturated and saturated buoyancy gradients based on
39-
the environmental cloud fraction derived from the thermodynamic state `ts`.
40-
41-
The dispatch on `EnvBuoyGradVars` (used internally by the first method after
42-
constructing it from `ts` and projected gradients) occurs during its construction.
43-
The analytical solutions employed are consistent for both mean fields and
44-
conditional fields derived from assumed distributions over conserved thermodynamic
45-
variables.
44+
the environmental cloud fraction.
4645
4746
Arguments:
4847
- `closure`: The environmental buoyancy gradient closure type (e.g., `BuoyGradMean`).
4948
- `thermo_params`: Thermodynamic parameters from `CLIMAParameters`.
50-
- `ts`: Center-level thermodynamic state of the environment.
49+
- `T`: Air temperature [K]
50+
- `ρ`: Air density [kg/m³]
51+
- `q_tot`: Total specific humidity [kg/kg]
52+
- `q_liq`: Liquid specific humidity [kg/kg]
53+
- `q_ice`: Ice specific humidity [kg/kg]
54+
- `cf`: Cloud fraction
5155
- `C3`: The `ClimaCore.Geometry.Covariant3Vector` type, used for projecting input vertical gradients.
5256
- `∂qt∂z`: Field of vertical gradients of total specific humidity.
5357
- `∂θli∂z`: Field of vertical gradients of liquid-ice potential temperature.
5458
- `local_geometry`: Field of local geometry at cell centers, used for gradient projection.
55-
The second method takes a precomputed `EnvBuoyGradVars` object instead of `ts` and gradient fields.
59+
The second method takes a precomputed `EnvBuoyGradVars` object instead of T, ρ, q_tot, q_liq, q_ice and gradient fields.
5660
5761
Returns:
5862
- `∂b∂z`: The mean vertical buoyancy gradient [s⁻²], as a field of scalars.
@@ -62,7 +66,11 @@ function buoyancy_gradients end
6266
function buoyancy_gradients(
6367
ebgc::AbstractEnvBuoyGradClosure,
6468
thermo_params,
65-
ts,
69+
T,
70+
ρ,
71+
q_tot,
72+
q_liq,
73+
q_ice,
6674
cf,
6775
::Type{C3},
6876
∂qt∂z,
@@ -73,7 +81,11 @@ function buoyancy_gradients(
7381
ebgc,
7482
thermo_params,
7583
EnvBuoyGradVars(
76-
ts,
84+
T,
85+
ρ,
86+
q_tot,
87+
q_liq,
88+
q_ice,
7789
cf,
7890
projected_vector_buoy_grad_vars(
7991
C3,
@@ -96,18 +108,18 @@ function buoyancy_gradients(
96108
Rv_over_Rd = TDP.Rv_over_Rd(thermo_params)
97109
R_v = TDP.R_v(thermo_params)
98110

99-
ts = bg_model.ts
100-
∂b∂θv = g / TD.virtual_pottemp(thermo_params, ts)
111+
(; T, ρ, q_tot, q_liq, q_ice) = bg_model
112+
∂b∂θv = g / TD.virtual_pottemp(thermo_params, T, ρ, q_tot, q_liq, q_ice)
101113

102-
T = TD.air_temperature(thermo_params, ts)
103-
λ = TD.liquid_fraction(thermo_params, ts)
114+
# TODO: is this correct for equilmoist?
115+
λ = TD.liquid_fraction(thermo_params, T, q_liq, q_ice)
104116
lh =
105117
λ * TD.latent_heat_vapor(thermo_params, T) +
106118
(1 - λ) * TD.latent_heat_sublim(thermo_params, T)
107-
cp_m = TD.cp_m(thermo_params, ts)
108-
q_sat = TD.q_vap_saturation(thermo_params, ts)
109-
q_tot = TD.total_specific_humidity(thermo_params, ts)
110-
θ = TD.dry_pottemp(thermo_params, ts)
119+
cp_m = TD.cp_m(thermo_params, q_tot, q_liq, q_ice)
120+
# TODO: is this correct for equilmoist?
121+
q_sat = TD.q_vap_saturation(thermo_params, T, ρ, q_liq, q_ice)
122+
θ = TD.potential_temperature(thermo_params, T, ρ, q_tot, q_liq, q_ice)
111123
∂b∂θli_unsat = ∂b∂θv * (1 + (Rv_over_Rd - 1) * q_tot)
112124
∂b∂qt_unsat = ∂b∂θv * (Rv_over_Rd - 1) * θ
113125
∂b∂θli_sat = (

src/prognostic_equations/gm_sgs_closures.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,18 @@ NVTX.@annotate function compute_gm_mixing_length(Y, p)
6767

6868
ᶜdz = Fields.Δz_field(axes(Y.c))
6969
ᶜlg = Fields.local_geometry_field(Y.c)
70-
(; ᶜts, ᶠu³, ᶜlinear_buoygrad, ᶜstrain_rate_norm, cloud_diagnostics_tuple) =
70+
(; ᶜT, ᶜq_liq_rai, ᶜq_ice_sno, ᶠu³, ᶜlinear_buoygrad, ᶜstrain_rate_norm, cloud_diagnostics_tuple) =
7171
p.precomputed
7272

73+
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
7374
@. ᶜlinear_buoygrad = buoyancy_gradients(
7475
BuoyGradMean(),
7576
thermo_params,
76-
ᶜts,
77+
ᶜT,
78+
Y.c.ρ,
79+
ᶜq_tot,
80+
ᶜq_liq_rai,
81+
ᶜq_ice_sno,
7782
cloud_diagnostics_tuple.cf,
7883
C3,
7984
p.precomputed.ᶜgradᵥ_q_tot,

src/solver/types.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,20 +318,28 @@ Base.broadcastable(x::BuoyGradMean) = tuple(x)
318318
319319
Variables used in the environmental buoyancy gradient computation.
320320
"""
321-
Base.@kwdef struct EnvBuoyGradVars{FT, TS}
322-
ts::TS
321+
Base.@kwdef struct EnvBuoyGradVars{FT}
322+
T::FT
323+
ρ::FT
324+
q_tot::FT
325+
q_liq::FT
326+
q_ice::FT
323327
cf::FT
324328
∂qt∂z::FT
325329
∂θli∂z::FT
326330
end
327331

328332
function EnvBuoyGradVars(
329-
ts::TD.ThermodynamicState,
333+
T,
334+
ρ,
335+
q_tot,
336+
q_liq,
337+
q_ice,
330338
cf,
331339
∂qt∂z_∂θli∂z,
332340
)
333341
(; ∂qt∂z, ∂θli∂z) = ∂qt∂z_∂θli∂z
334-
return EnvBuoyGradVars(ts, cf, ∂qt∂z, ∂θli∂z)
342+
return EnvBuoyGradVars(T, ρ, q_tot, q_liq, q_ice, cf, ∂qt∂z, ∂θli∂z)
335343
end
336344

337345
Base.eltype(::EnvBuoyGradVars{FT}) where {FT} = FT

0 commit comments

Comments
 (0)