Skip to content

Commit b3dd081

Browse files
authored
Merge pull request #4120 from CliMA/he/rft-clean-surface-code
rft: clean up surface code
2 parents 79e7695 + 2cd60e3 commit b3dd081

15 files changed

+71
-252
lines changed

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,13 +496,8 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
496496

497497
# integral
498498
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
499-
ᶜh_tot = @. lazy(
500-
TD.total_specific_enthalpy(
501-
thermo_params,
502-
ᶜts,
503-
specific(Y.c.ρe_tot, Y.c.ρ),
504-
),
505-
)
499+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
500+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
506501

507502
ᶜtke⁰ = @. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))
508503

src/parameterized_tendencies/les_sgs_models/anisotropic_minimum_dissipation.jl

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,8 @@ function horizontal_amd_tendency!(Yₜ, Y, p, t, les::AnisotropicMinimumDissipat
129129
@. Yₜ.f.u₃ -= C3(wdivₕ(ᶠρ * ᶠτ_amd) / ᶠρ)
130130

131131
## Total energy tendency
132-
ᶜh_tot = @. lazy(
133-
TD.total_specific_enthalpy(
134-
thermo_params,
135-
ᶜts,
136-
specific(Y.c.ρe_tot, Y.c.ρ),
137-
),
138-
)
132+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
133+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
139134
∇h_tot = @. lazy(Geometry.project(axis_uvw, gradₕ(ᶜh_tot)))
140135
∂̂h_tot = @. lazy(Δ_h * ∇h_tot)
141136
ᶜD_amd = @. ᶜtemp_scalar = max(
@@ -311,13 +306,8 @@ function vertical_amd_tendency!(Yₜ, Y, p, t, les::AnisotropicMinimumDissipatio
311306
@. Yₜ.f.u₃ -= C3(ᶠdivᵥ(Y.c.ρ * ᶜτ_amd) / ᶠρ)
312307

313308
## Total energy tendency
314-
ᶜh_tot = @. lazy(
315-
TD.total_specific_enthalpy(
316-
thermo_params,
317-
ᶜts,
318-
specific(Y.c.ρe_tot, Y.c.ρ),
319-
),
320-
)
309+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
310+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
321311
# TODO: Fix @lazy broadcast (components access)
322312
∇h_tot = @. lazy(Geometry.project(axis_uvw, ᶠgradᵥ_scalar(ᶜh_tot)))
323313
∂̂h_tot = @. lazy(ᶠΔ_z * ∇h_tot)

src/prognostic_equations/advection.jl

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@ NVTX.@annotate function horizontal_dynamics_tendency!(Yₜ, Y, p, t)
5252
end
5353
end
5454

55-
ᶜh_tot = @. lazy(
56-
TD.total_specific_enthalpy(
57-
thermo_params,
58-
ᶜts,
59-
specific(Y.c.ρe_tot, Y.c.ρ),
60-
),
61-
)
55+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
56+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
6257
@. Yₜ.c.ρe_tot -= wdivₕ(Y.c.ρ * ᶜh_tot * ᶜu)
6358

6459
if p.atmos.turbconv_model isa PrognosticEDMFX
@@ -297,13 +292,8 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
297292
# ... and upwinding correction of energy and total water.
298293
# (The central advection of energy and total water is done implicitly.)
299294
if energy_q_tot_upwinding != Val(:none)
300-
ᶜh_tot = @. lazy(
301-
TD.total_specific_enthalpy(
302-
thermo_params,
303-
ᶜts,
304-
specific(Y.c.ρe_tot, Y.c.ρ),
305-
),
306-
)
295+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
296+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
307297
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜh_tot, dt, energy_q_tot_upwinding)
308298
vtt_central = vertical_transport(ᶜρ, ᶠu³, ᶜh_tot, dt, Val(:none))
309299
@. Yₜ.c.ρe_tot += vtt - vtt_central

src/prognostic_equations/edmfx_entr_detr.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -637,13 +637,8 @@ function edmfx_first_interior_entr_tendency!(
637637
Fields.local_geometry_field(Fields.level(Y.f, Fields.half)),
638638
)
639639

640-
ᶜh_tot = @. lazy(
641-
TD.total_specific_enthalpy(
642-
thermo_params,
643-
ᶜts,
644-
specific(Y.c.ρe_tot, Y.c.ρ),
645-
),
646-
)
640+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
641+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
647642
ᶜh_tot_int_val = Fields.field_values(Fields.level(ᶜh_tot, 1))
648643
ᶜK_int_val = Fields.field_values(Fields.level(ᶜK, 1))
649644
ᶜmse⁰ = ᶜspecific_env_mse(Y, p)

src/prognostic_equations/edmfx_sgs_flux.jl

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,8 @@ function edmfx_sgs_mass_flux_tendency!(
5757
# [best after removal of precomputed quantities]
5858
ᶠu³_diff = p.scratch.ᶠtemp_CT3
5959
ᶜa_scalar = p.scratch.ᶜtemp_scalar
60-
ᶜh_tot = @. lazy(
61-
TD.total_specific_enthalpy(
62-
thermo_params,
63-
ᶜts,
64-
specific(Y.c.ρe_tot, Y.c.ρ),
65-
),
66-
)
60+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
61+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
6762
for j in 1:n
6863
@. ᶠu³_diff = ᶠu³ʲs.:($$j) - ᶠu³
6964
@. ᶜa_scalar =
@@ -202,13 +197,8 @@ function edmfx_sgs_mass_flux_tendency!(
202197
if p.atmos.edmfx_model.sgs_mass_flux isa Val{true}
203198
thermo_params = CAP.thermodynamics_params(p.params)
204199
# energy
205-
ᶜh_tot = @. lazy(
206-
TD.total_specific_enthalpy(
207-
thermo_params,
208-
ᶜts,
209-
specific(Y.c.ρe_tot, Y.c.ρ),
210-
),
211-
)
200+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
201+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
212202
ᶠu³_diff = p.scratch.ᶠtemp_CT3
213203
ᶜa_scalar = p.scratch.ᶜtemp_scalar
214204
for j in 1:n
@@ -422,13 +412,8 @@ function edmfx_sgs_diffusive_flux_tendency!(
422412
top = Operators.SetValue(C3(FT(0))),
423413
bottom = Operators.SetValue(C3(FT(0))),
424414
)
425-
ᶜh_tot = @. lazy(
426-
TD.total_specific_enthalpy(
427-
thermo_params,
428-
ᶜts,
429-
specific(Y.c.ρe_tot, Y.c.ρ),
430-
),
431-
)
415+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
416+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
432417
@. Yₜ.c.ρe_tot -= ᶜdivᵥ_ρe_tot(-(ᶠρaK_h * ᶠgradᵥ(ᶜh_tot)))
433418

434419
if use_prognostic_tke(turbconv_model)

src/prognostic_equations/forcing/external_forcing.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,8 @@ function external_forcing_tendency!(
354354
@. ᶜuₕ_nudge = C12(Geometry.UVVector(ᶜu_nudge, ᶜv_nudge), ᶜlg)
355355
@. Yₜ.c.uₕ -= (Y.c.uₕ - ᶜuₕ_nudge) * ᶜinv_τ_wind
356356

357-
ᶜh_tot = @. lazy(
358-
TD.total_specific_enthalpy(
359-
thermo_params,
360-
ᶜts,
361-
specific(Y.c.ρe_tot, Y.c.ρ),
362-
),
363-
)
357+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
358+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
364359
# nudging tendency
365360
ᶜdTdt_nudging = p.scratch.ᶜtemp_scalar
366361
ᶜdqtdt_nudging = p.scratch.ᶜtemp_scalar_2

src/prognostic_equations/forcing/subsidence.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,8 @@ function subsidence_tendency!(Yₜ, Y, p, t, ::Subsidence)
9999
subsidence_profile(ᶠz) * CT3(unit_basis_vector_data(CT3, ᶠlg))
100100

101101
# LS Subsidence
102-
ᶜh_tot = @. lazy(
103-
TD.total_specific_enthalpy(
104-
thermo_params,
105-
ᶜts,
106-
specific(Y.c.ρe_tot, Y.c.ρ),
107-
),
108-
)
102+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
103+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
109104
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
110105
subsidence!(Yₜ.c.ρe_tot, Y.c.ρ, ᶠsubsidence³, ᶜh_tot, Val{:first_order}())
111106
subsidence!(Yₜ.c.ρq_tot, Y.c.ρ, ᶠsubsidence³, ᶜq_tot, Val{:first_order}())

src/prognostic_equations/implicit/implicit_tendency.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,8 @@ function implicit_vertical_advection_tendency!(Yₜ, Y, p, t)
115115
(; ᶠu³, ᶜp, ᶜts) = p.precomputed
116116
thermo_params = CAP.thermodynamics_params(params)
117117
cp_d = CAP.cp_d(params)
118-
ᶜh_tot = @. lazy(
119-
TD.total_specific_enthalpy(
120-
thermo_params,
121-
ᶜts,
122-
specific(Y.c.ρe_tot, Y.c.ρ),
123-
),
124-
)
118+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
119+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
125120

126121
@. Yₜ.c.ρ -= ᶜdivᵥ(ᶠinterp(Y.c.ρ * ᶜJ) / ᶠJ * ᶠu³)
127122

src/prognostic_equations/implicit/manual_sparse_jacobian.jl

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,8 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
447447
# minus ∂e_int_∂q_tot
448448
∂e_int_∂q_tot = T_0 * (Δcv_v - R_d) - e_int_v0
449449
thermo_params = CAP.thermodynamics_params(params)
450-
ᶜh_tot = @. lazy(
451-
TD.total_specific_enthalpy(
452-
thermo_params,
453-
ᶜts,
454-
specific(Y.c.ρe_tot, Y.c.ρ),
455-
),
456-
)
450+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
451+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
457452

458453
ᶜρ = Y.c.ρ
459454
ᶜuₕ = Y.c.uₕ
@@ -502,17 +497,7 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
502497

503498
MatrixFields.unrolled_foreach(tracer_info) do ρχ_name
504499
MatrixFields.has_field(Y, ρχ_name) || return
505-
ᶜχ = if ρχ_name === @name(c.ρe_tot)
506-
@. lazy(
507-
TD.total_specific_enthalpy(
508-
thermo_params,
509-
ᶜts,
510-
specific(Y.c.ρe_tot, Y.c.ρ),
511-
),
512-
)
513-
else
514-
@. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
515-
end
500+
ᶜχ = ρχ_name === @name(c.ρe_tot) ? ᶜh_tot : (@. lazy(specific(Y.c.ρq_tot, Y.c.ρ)))
516501

517502
if use_derivative(topography_flag)
518503
∂ᶜρχ_err_∂ᶜuₕ = matrix[ρχ_name, @name(c.uₕ)]
@@ -545,7 +530,6 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
545530
ᶠinterp_matrix()
546531
)
547532
@. ∂ᶠu₃_err_∂ᶜρe_tot = dtγ * ᶠp_grad_matrix DiagonalMatrixRow(ᶜkappa_m)
548-
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
549533

550534
if MatrixFields.has_field(Y, @name(c.ρq_tot))
551535
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))

src/prognostic_equations/remaining_tendency.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,8 @@ NVTX.@annotate function additional_tendency!(Yₜ, Y, p, t)
147147
thermo_params = CAP.thermodynamics_params(params)
148148
(; ᶜp, sfc_conditions, ᶜts, ᶜK) = p.precomputed
149149

150-
ᶜh_tot = @. lazy(
151-
TD.total_specific_enthalpy(
152-
thermo_params,
153-
ᶜts,
154-
specific(Y.c.ρe_tot, Y.c.ρ),
155-
),
156-
)
150+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
151+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
157152
vst_uₕ = viscous_sponge_tendency_uₕ(ᶜuₕ, viscous_sponge)
158153
vst_u₃ = viscous_sponge_tendency_u₃(ᶠu₃, viscous_sponge)
159154
vst_ρe_tot = viscous_sponge_tendency_ρe_tot(ᶜρ, ᶜh_tot, viscous_sponge)

0 commit comments

Comments
 (0)