Skip to content

Commit 7b26a96

Browse files
committed
lazy thermo vars
1 parent 91d4650 commit 7b26a96

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

src/cache/precomputed_quantities.jl

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,29 +373,81 @@ function thermo_state(
373373
return get_ts(ρ, p, θ, e_int, q_tot, q_pt)
374374
end
375375

376+
function ᶜthermo_state(
377+
thermo_params;
378+
ρ = nothing,
379+
p = nothing,
380+
θ = nothing,
381+
e_int = nothing,
382+
q_tot = nothing,
383+
q_pt = nothing,
384+
)
385+
386+
get_ts(ρ, ::Nothing, θ, ::Nothing, ::Nothing, ::Nothing) =
387+
TD.PhaseDry_ρθ(thermo_params, ρ, θ)
388+
get_ts(ρ, ::Nothing, θ, ::Nothing, q_tot, ::Nothing) =
389+
TD.PhaseEquil_ρθq(thermo_params, ρ, θ, q_tot)
390+
get_ts(ρ, ::Nothing, θ, ::Nothing, ::Nothing, q_pt) =
391+
TD.PhaseNonEquil_ρθq(thermo_params, ρ, θ, q_pt)
392+
get_ts(ρ, ::Nothing, ::Nothing, e_int, ::Nothing, ::Nothing) =
393+
TD.PhaseDry_ρe(thermo_params, ρ, e_int)
394+
get_ts(ρ, ::Nothing, ::Nothing, e_int, q_tot, ::Nothing) =
395+
TD.PhaseEquil_ρeq(
396+
thermo_params,
397+
ρ,
398+
e_int,
399+
q_tot,
400+
3,
401+
eltype(thermo_params)(0.003),
402+
)
403+
get_ts(ρ, ::Nothing, ::Nothing, e_int, ::Nothing, q_pt) =
404+
TD.PhaseNonEquil(thermo_params, e_int, ρ, q_pt)
405+
get_ts(::Nothing, p, θ, ::Nothing, ::Nothing, ::Nothing) =
406+
TD.PhaseDry_pθ(thermo_params, p, θ)
407+
get_ts(::Nothing, p, θ, ::Nothing, q_tot, ::Nothing) =
408+
TD.PhaseEquil_pθq(thermo_params, p, θ, q_tot)
409+
get_ts(::Nothing, p, θ, ::Nothing, ::Nothing, q_pt) =
410+
TD.PhaseNonEquil_pθq(thermo_params, p, θ, q_pt)
411+
get_ts(::Nothing, p, ::Nothing, e_int, ::Nothing, ::Nothing) =
412+
TD.PhaseDry_pe(thermo_params, p, e_int)
413+
get_ts(::Nothing, p, ::Nothing, e_int, q_tot, ::Nothing) =
414+
TD.PhaseEquil_peq(thermo_params, p, e_int, q_tot)
415+
get_ts(::Nothing, p, ::Nothing, e_int, ::Nothing, q_pt) =
416+
TD.PhaseNonEquil_peq(thermo_params, p, e_int, q_pt)
417+
418+
return @. lazy(get_ts(ρ, p, θ, e_int, q_tot, q_pt))
419+
end
420+
376421
function thermo_vars(moisture_model, microphysics_model, Y_c, K, Φ)
377-
e_tot = materialize(@. lazy(specific(Y_c.ρe_tot, Y_c.ρ)))
378-
energy_var = (; e_int = e_tot - K - Φ)
422+
e_tot = @. lazy(specific(Y_c.ρe_tot, Y_c.ρ))
423+
energy_var = (; e_int = @. lazy(e_tot - K - Φ))
379424

380425
moisture_var = if moisture_model isa DryModel
381426
(;)
382427
elseif moisture_model isa EquilMoistModel
383-
q_tot = materialize(@. lazy(specific(Y_c.ρq_tot, Y_c.ρ)))
428+
q_tot = @. lazy(specific(Y_c.ρq_tot, Y_c.ρ))
384429
(; q_tot)
385430
elseif moisture_model isa NonEquilMoistModel
386-
q_tot = materialize(@. lazy(specific(Y_c.ρq_tot, Y_c.ρ)))
387-
q_liq = materialize(@. lazy(specific(Y_c.ρq_liq, Y_c.ρ)))
388-
q_ice = materialize(@. lazy(specific(Y_c.ρq_ice, Y_c.ρ)))
389-
q_rai = materialize(@. lazy(specific(Y_c.ρq_rai, Y_c.ρ)))
390-
q_sno = materialize(@. lazy(specific(Y_c.ρq_sno, Y_c.ρ)))
431+
q_tot = @. lazy(specific(Y_c.ρq_tot, Y_c.ρ))
432+
q_liq = @. lazy(specific(Y_c.ρq_liq, Y_c.ρ))
433+
q_ice = @. lazy(specific(Y_c.ρq_ice, Y_c.ρ))
434+
q_rai = @. lazy(specific(Y_c.ρq_rai, Y_c.ρ))
435+
q_sno = @. lazy(specific(Y_c.ρq_sno, Y_c.ρ))
391436
q_pt_args = (q_tot, q_liq + q_rai, q_ice + q_sno)
392437
(; q_pt = TD.PhasePartition(q_pt_args...))
393438
end
394439
return (; energy_var..., moisture_var...)
395440
end
396441

397442
ts_gs(thermo_params, moisture_model, microphysics_model, ᶜY, K, Φ, ρ) =
398-
thermo_state(
443+
ᶜthermo_state(
444+
thermo_params;
445+
thermo_vars(moisture_model, microphysics_model, ᶜY, K, Φ)...,
446+
ρ,
447+
)
448+
449+
ᶜts_gs(thermo_params, moisture_model, microphysics_model, ᶜY, K, Φ, ρ) =
450+
ᶜthermo_state(
399451
thermo_params;
400452
thermo_vars(moisture_model, microphysics_model, ᶜY, K, Φ)...,
401453
ρ,
@@ -467,7 +519,7 @@ NVTX.@annotate function set_implicit_precomputed_quantities!(Y, p, t)
467519
# @. ᶜK += Y.c.sgs⁰.ρatke / Y.c.ρ
468520
# TODO: We should think more about these increments before we use them.
469521
end
470-
@. ᶜts = ts_gs(thermo_args..., Y.c, ᶜK, ᶜΦ, Y.c.ρ)
522+
ᶜts .= ᶜts_gs(thermo_args..., Y.c, ᶜK, ᶜΦ, Y.c.ρ)
471523
@. ᶜp = TD.air_pressure(thermo_params, ᶜts)
472524

473525
if turbconv_model isa PrognosticEDMFX

src/prognostic_equations/advection.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
194194
turbconv_model isa EDOnlyEDMFX ? p.precomputed.ᶠu³ :
195195
p.precomputed.ᶠu³⁰
196196
) : nothing
197-
ᶜρa⁰_vals = advect_tke ? (n > 0 ? (ᶜρa⁰(Y.c, p)) : lazy(Y.c.ρ)) : nothing
197+
ᶜρa⁰_vals = advect_tke ? (n > 0 ? (ᶜρa⁰(Y.c, p)) : @. lazy(Y.c.ρ)) : nothing
198198
ᶜρ⁰ = if advect_tke
199199
if n > 0
200-
(; ᶜts⁰) = p.precomputed.ᶜts⁰
200+
(; ᶜts⁰) = p.precomputed
201201
@. lazy(TD.air_density(thermo_params, ᶜts⁰))
202202
else
203-
lazy(Y.c.ρ)
203+
@. lazy(Y.c.ρ)
204204
end
205205
else
206206
nothing

0 commit comments

Comments
 (0)