Skip to content

Commit a105e06

Browse files
committed
move nh pressure drag to implicit closure
1 parent b32883a commit a105e06

File tree

3 files changed

+54
-35
lines changed

3 files changed

+54
-35
lines changed

reproducibility_tests/ref_counter.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
226
1+
227
22

33
# **README**
44
#
@@ -21,6 +21,9 @@
2121

2222
#=
2323
24+
227
25+
- Move nonhydrostatic pressure drag calculation to implicit precomputed quantities
26+
2427
226
2528
- Add updraft rho*a and u_{3,m} jacobian terms
2629

src/cache/precomputed_quantities.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ NVTX.@annotate function set_implicit_precomputed_quantities!(Y, p, t)
483483
if turbconv_model isa PrognosticEDMFX
484484
set_prognostic_edmf_precomputed_quantities_draft!(Y, p, ᶠuₕ³, t)
485485
set_prognostic_edmf_precomputed_quantities_environment!(Y, p, ᶠuₕ³, t)
486+
set_prognostic_edmf_precomputed_quantities_implicit_closures!(Y, p, t)
486487
elseif turbconv_model isa AbstractEDMF
487488
(; ᶜtke⁰) = p.precomputed
488489
@. ᶜtke⁰ = Y.c.sgs⁰.ρatke / Y.c.ρ
@@ -526,7 +527,7 @@ NVTX.@annotate function set_explicit_precomputed_quantities!(Y, p, t)
526527

527528
if turbconv_model isa PrognosticEDMFX
528529
set_prognostic_edmf_precomputed_quantities_bottom_bc!(Y, p, t)
529-
set_prognostic_edmf_precomputed_quantities_closures!(Y, p, t)
530+
set_prognostic_edmf_precomputed_quantities_explicit_closures!(Y, p, t)
530531
set_prognostic_edmf_precomputed_quantities_precipitation!(
531532
Y,
532533
p,

src/cache/prognostic_edmf_precomputed_quantities.jl

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,54 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_bottom_bc!(
309309
end
310310

311311
"""
312-
set_prognostic_edmf_precomputed_quantities_closures!(Y, p, t)
312+
set_prognostic_edmf_precomputed_quantities_implicit_closures!(Y, p, t)
313313
314-
Updates the precomputed quantities stored in `p` for edmfx closures.
314+
Updates the precomputed quantities stored in `p` for edmfx implicit closures.
315315
"""
316-
NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
316+
NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_implicit_closures!(
317+
Y,
318+
p,
319+
t,
320+
)
321+
322+
(; moisture_model, turbconv_model) = p.atmos
323+
@assert !(moisture_model isa DryModel)
324+
325+
(; params) = p
326+
n = n_mass_flux_subdomains(turbconv_model)
327+
328+
(; ᶠgradᵥ_ᶜΦ) = p.core
329+
(; ᶠu₃⁰, ᶜρʲs, ᶠnh_pressure₃ʲs) = p.precomputed
330+
ᶠlg = Fields.local_geometry_field(Y.f)
331+
332+
scale_height = CAP.R_d(params) * CAP.T_surf_ref(params) / CAP.grav(params)
333+
for j in 1:n
334+
# nonhydrostatic pressure drag
335+
for j in 1:n
336+
if p.atmos.edmfx_model.nh_pressure isa Val{true}
337+
@. ᶠnh_pressure₃ʲs.:($$j) = ᶠupdraft_nh_pressure(
338+
params,
339+
ᶠlg,
340+
ᶠbuoyancy(ᶠinterp(Y.c.ρ), ᶠinterp(ᶜρʲs.:($$j)), ᶠgradᵥ_ᶜΦ),
341+
Y.f.sgsʲs.:($$j).u₃,
342+
ᶠu₃⁰,
343+
scale_height,
344+
)
345+
else
346+
@. ᶠnh_pressure₃ʲs.:($$j) = C3(0)
347+
end
348+
end
349+
end
350+
351+
return nothing
352+
end
353+
354+
"""
355+
set_prognostic_edmf_precomputed_quantities_explicit_closures!(Y, p, t)
356+
357+
Updates the precomputed quantities stored in `p` for edmfx explicit closures.
358+
"""
359+
NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_closures!(
317360
Y,
318361
p,
319362
t,
@@ -330,8 +373,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
330373
FT = eltype(params)
331374
n = n_mass_flux_subdomains(turbconv_model)
332375

333-
(; ᶠgradᵥ_ᶜΦ) = p.core
334-
(; ᶜtke⁰, ᶜu, ᶜp, ᶜρa⁰, ᶠu³⁰, ᶠu₃⁰, ᶜts⁰, ᶜq_tot⁰) = p.precomputed
376+
(; ᶜtke⁰, ᶜu, ᶜp, ᶜρa⁰, ᶠu³⁰, ᶜts⁰, ᶜq_tot⁰) = p.precomputed
335377
(;
336378
ᶜmixing_length_tuple,
337379
ᶜmixing_length,
@@ -341,16 +383,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
341383
ᶜK_h,
342384
ρatke_flux,
343385
) = p.precomputed
344-
(;
345-
ᶜuʲs,
346-
ᶜtsʲs,
347-
ᶠu³ʲs,
348-
ᶜρʲs,
349-
ᶜentrʲs,
350-
ᶜdetrʲs,
351-
ᶜturb_entrʲs,
352-
ᶠnh_pressure₃ʲs,
353-
) = p.precomputed
386+
(; ᶜuʲs, ᶜtsʲs, ᶠu³ʲs, ᶜρʲs, ᶜentrʲs, ᶜdetrʲs, ᶜturb_entrʲs) = p.precomputed
354387
(; ustar, obukhov_length) = p.precomputed.sfc_conditions
355388

356389
ᶜz = Fields.coordinate_field(Y.c).z
@@ -428,24 +461,6 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
428461
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
429462
dt,
430463
)
431-
432-
# nonhydrostatic pressure drag
433-
scale_height =
434-
CAP.R_d(params) * CAP.T_surf_ref(params) / CAP.grav(params)
435-
for j in 1:n
436-
if p.atmos.edmfx_model.nh_pressure isa Val{true}
437-
@. ᶠnh_pressure₃ʲs.:($$j) = ᶠupdraft_nh_pressure(
438-
params,
439-
ᶠlg,
440-
ᶠbuoyancy(ᶠinterp(Y.c.ρ), ᶠinterp(ᶜρʲs.:($$j)), ᶠgradᵥ_ᶜΦ),
441-
Y.f.sgsʲs.:($$j).u₃,
442-
ᶠu₃⁰,
443-
scale_height,
444-
)
445-
else
446-
@. ᶠnh_pressure₃ʲs.:($$j) = C3(0)
447-
end
448-
end
449464
end
450465

451466
(; ᶜgradᵥ_θ_virt⁰, ᶜgradᵥ_q_tot⁰, ᶜgradᵥ_θ_liq_ice⁰) = p.precomputed

0 commit comments

Comments
 (0)