Skip to content

Commit 200302f

Browse files
Use LazyBroadcast in set_velocity_quantities
1 parent af7ca7e commit 200302f

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/cache/precomputed_quantities.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,10 @@ end
240240

241241
# This is used to set the grid-scale velocity quantities ᶜu, ᶠu³, ᶜK based on
242242
# ᶠu₃, and it is also used to set the SGS quantities based on ᶠu₃⁰ and ᶠu₃ʲ.
243-
function set_velocity_quantities!(ᶜu, ᶠu³, ᶜK, ᶠu₃, ᶜuₕ, ᶠuₕ³)
244-
@. ᶜu = C123(ᶜuₕ) + ᶜinterp(C123(ᶠu₃))
245-
@. ᶠu³ = ᶠuₕ³ + CT3(ᶠu₃)
246-
bc_kinetic = compute_kinetic(ᶜuₕ, ᶠu₃)
247-
@. ᶜK = bc_kinetic
248-
return nothing
243+
compute_ᶜu(ᶜuₕ, ᶠu₃) = @lazy @. C123(ᶜuₕ) + ᶜinterp(C123(ᶠu₃))
244+
function compute_ᶠu³(ᶜuₕ, ᶜρ, ᶠu₃)
245+
ᶠuₕ³ = compute_ᶠuₕ³(ᶜuₕ, ᶜρ)
246+
return @lazy @. ᶠuₕ³ + CT3(ᶠu₃)
249247
end
250248

251249
function set_sgs_ᶠu₃!(w_function, ᶠu₃, Y, turbconv_model)
@@ -385,6 +383,7 @@ NVTX.@annotate function set_precomputed_quantities!(Y, p, t)
385383
@. ᶜspecific = specific_gs(Y.c)
386384
ᶜρ = Y.c.ρ
387385
ᶜuₕ = Y.c.uₕ
386+
ᶠu₃ = Y.f.u₃
388387
bc_ᶠuₕ³ = compute_ᶠuₕ³(ᶜuₕ, ᶜρ)
389388
@. ᶠuₕ³ = bc_ᶠuₕ³
390389

@@ -393,7 +392,13 @@ NVTX.@annotate function set_precomputed_quantities!(Y, p, t)
393392
set_velocity_at_surface!(Y, ᶠuₕ³, turbconv_model)
394393
set_velocity_at_top!(Y, turbconv_model)
395394

396-
set_velocity_quantities!(ᶜu, ᶠu³, ᶜK, Y.f.u₃, Y.c.uₕ, ᶠuₕ³)
395+
bc_ᶠu³ = compute_ᶠu³(ᶜuₕ, ᶜρ, ᶠu₃)
396+
bc_ᶜu = compute_ᶜu(ᶜuₕ, ᶠu₃)
397+
bc_ᶜK = compute_kinetic(ᶜuₕ, ᶠu₃)
398+
@. ᶠu³ = bc_ᶠu³
399+
@. ᶜu = bc_ᶜu
400+
@. ᶜK = bc_ᶜK
401+
397402
if n > 0
398403
# TODO: In the following increments to ᶜK, we actually need to add
399404
# quantities of the form ᶜρaχ⁰ / ᶜρ⁰ and ᶜρaχʲ / ᶜρʲ to ᶜK, rather than
@@ -496,8 +501,8 @@ NVTX.@annotate function set_precomputed_quantities!(Y, p, t)
496501
end
497502

498503
if turbconv_model isa PrognosticEDMFX
499-
set_prognostic_edmf_precomputed_quantities_draft_and_bc!(Y, p, ᶠuₕ³, t)
500-
set_prognostic_edmf_precomputed_quantities_environment!(Y, p, ᶠuₕ³, t)
504+
set_prognostic_edmf_precomputed_quantities_draft_and_bc!(Y, p, t)
505+
set_prognostic_edmf_precomputed_quantities_environment!(Y, p, t)
501506
set_prognostic_edmf_precomputed_quantities_closures!(Y, p, t)
502507
set_prognostic_edmf_precomputed_quantities_precipitation!(
503508
Y,

src/cache/prognostic_edmf_precomputed_quantities.jl

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ Updates the edmf environment precomputed quantities stored in `p` for edmfx.
1313
NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_environment!(
1414
Y,
1515
p,
16-
ᶠuₕ³,
1716
t,
1817
)
1918
@assert !(p.atmos.moisture_model isa DryModel)
2019

20+
ᶜuₕ = Y.c.uₕ
21+
ᶠu₃ = Y.f.u₃
22+
ᶜρ = Y.c.ρ
2123
thermo_params = CAP.thermodynamics_params(p.params)
2224
(; turbconv_model) = p.atmos
2325
(; ᶜΦ,) = p.core
@@ -42,29 +44,37 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_environment!(
4244
turbconv_model,
4345
)
4446
set_sgs_ᶠu₃!(u₃⁰, ᶠu₃⁰, Y, turbconv_model)
45-
set_velocity_quantities!(ᶜu⁰, ᶠu³⁰, ᶜK⁰, ᶠu₃⁰, Y.c.uₕ, ᶠuₕ³)
47+
bc_ᶠu³ = compute_ᶠu³(ᶜuₕ, ᶜρ, ᶠu₃)
48+
bc_ᶜu = compute_ᶜu(ᶜuₕ, ᶠu₃⁰)
49+
bc_ᶜK = compute_kinetic(ᶜuₕ, ᶠu₃⁰)
50+
@. ᶠu³⁰ = bc_ᶠu³
51+
@. ᶜu⁰ = bc_ᶜu
52+
@. ᶜK⁰ = bc_ᶜK
53+
4654
# @. ᶜK⁰ += ᶜtke⁰
4755
@. ᶜts⁰ = TD.PhaseEquil_phq(thermo_params, ᶜp, ᶜmse⁰ - ᶜΦ, ᶜq_tot⁰)
4856
@. ᶜρ⁰ = TD.air_density(thermo_params, ᶜts⁰)
4957
return nothing
5058
end
5159

5260
"""
53-
set_prognostic_edmf_precomputed_quantities_draft_and_bc!(Y, p, ᶠuₕ³, t)
61+
set_prognostic_edmf_precomputed_quantities_draft_and_bc!(Y, p, t)
5462
5563
Updates the draft thermo state and boundary conditions
5664
precomputed quantities stored in `p` for edmfx.
5765
"""
5866
NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_draft_and_bc!(
5967
Y,
6068
p,
61-
ᶠuₕ³,
6269
t,
6370
)
6471
(; moisture_model, turbconv_model) = p.atmos
6572
#EDMFX BCs only support total energy as state variable
6673
@assert !(moisture_model isa DryModel)
6774

75+
ᶜuₕ = Y.c.uₕ
76+
ᶠu₃ = Y.f.u₃
77+
ᶜρ = Y.c.ρ
6878
FT = Spaces.undertype(axes(Y.c))
6979
n = n_mass_flux_subdomains(turbconv_model)
7080

@@ -88,7 +98,13 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_draft_and_bc!
8898
ᶜmseʲ = Y.c.sgsʲs.:($j).mse
8999
ᶜq_totʲ = Y.c.sgsʲs.:($j).q_tot
90100

91-
set_velocity_quantities!(ᶜuʲ, ᶠu³ʲ, ᶜKʲ, ᶠu₃ʲ, Y.c.uₕ, ᶠuₕ³)
101+
bc_ᶠu³ʲ = compute_ᶠu³(ᶜuₕ, ᶜρ, ᶠu₃)
102+
bc_ᶜuʲ = compute_ᶜu(ᶜuₕ, ᶠu₃ʲ)
103+
bc_ᶜKʲ = compute_kinetic(ᶜuₕ, ᶠu₃ʲ)
104+
@. ᶠu³ʲ = bc_ᶠu³ʲ
105+
@. ᶜuʲ = bc_ᶜuʲ
106+
@. ᶜKʲ = bc_ᶜKʲ
107+
92108
@. ᶠKᵥʲ = (adjoint(CT3(ᶠu₃ʲ)) * ᶠu₃ʲ) / 2
93109
@. ᶜtsʲ = TD.PhaseEquil_phq(thermo_params, ᶜp, ᶜmseʲ - ᶜΦ, ᶜq_totʲ)
94110
@. ᶜρʲ = TD.air_density(thermo_params, ᶜtsʲ)

0 commit comments

Comments
 (0)