Skip to content

Commit 8c4b13f

Browse files
committed
RHS changes for the working fluid
1 parent 098e794 commit 8c4b13f

14 files changed

+301
-279
lines changed

config/longrun_configs/longrun_moist_baroclinic_wave.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ dt_save_state_to_disk: "10days"
1010
toml: [toml/longrun_baroclinic_wave.toml]
1111
diagnostics:
1212
- short_name: [pfull, wa, va, ua, ta, rhoa, rv, hus, ke, clw, cli]
13-
period: 1days
13+
period: 10days
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
h_elem: 30
2+
z_elem: 43
3+
dz_bottom: 30.0
4+
dt: "60secs"
5+
approximate_linear_solve_iters: 3
6+
max_newton_iters_ode: 1
7+
rayleigh_sponge: true
8+
t_end: "15days"
9+
initial_condition: "MoistBaroclinicWave"
10+
moist: "nonequil"
11+
precip_model: "1M"
12+
dt_save_state_to_disk: "15days"
13+
toml: [toml/longrun_baroclinic_wave_1M.toml]
14+
diagnostics:
15+
- short_name: [pfull, wa, va, ua, ta, rhoa, rv, hus, ke, clw, cli, husra, hussn]
16+
period: 5days

src/cache/cloud_fraction.jl

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import NVTX
22
import StaticArrays as SA
33
import ClimaCore.RecursiveApply: rzero, ,
44

5+
"""
6+
Helper function to populate the cloud diagnostics named tuple
7+
"""
8+
function make_named_tuple(t1, t2, t3)
9+
return NamedTuple{(:cf, :q_liq, :q_ice)}(tuple(t1, t2, t3))
10+
end
11+
512
# TODO: write a test with scalars that are linear with z
613
"""
714
Diagnose horizontal covariances based on vertical gradients
@@ -27,7 +34,7 @@ end
2734
NVTX.@annotate function set_cloud_fraction!(
2835
Y,
2936
p,
30-
::Union{EquilMoistModel, NonEquilMoistModel},
37+
moist_model::Union{EquilMoistModel, NonEquilMoistModel},
3138
::GridScaleCloud,
3239
)
3340
(; params) = p
@@ -48,13 +55,23 @@ NVTX.@annotate function set_cloud_fraction!(
4855
end
4956
compute_gm_mixing_length!(ᶜmixing_length, Y, p)
5057
end
51-
@. cloud_diagnostics_tuple = NamedTuple{(:cf, :q_liq, :q_ice)}(
52-
tuple(
58+
if moist_model isa EquilMoistModel
59+
@. cloud_diagnostics_tuple = make_named_tuple(
5360
ifelse(TD.has_condensate(thermo_params, ᶜts), 1, 0),
5461
TD.PhasePartition(thermo_params, ᶜts).liq,
5562
TD.PhasePartition(thermo_params, ᶜts).ice,
56-
),
57-
)
63+
)
64+
else
65+
@. cloud_diagnostics_tuple = make_named_tuple(
66+
ifelse(
67+
p.precomputed.ᶜspecific.q_liq + p.precomputed.ᶜspecific.q_ice > 0,
68+
1,
69+
0,
70+
),
71+
p.precomputed.ᶜspecific.q_liq,
72+
p.precomputed.ᶜspecific.q_ice,
73+
)
74+
end
5875
end
5976
NVTX.@annotate function set_cloud_fraction!(
6077
Y,

src/cache/precomputed_quantities.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,30 +319,36 @@ function thermo_state(
319319
return get_ts(ρ, p, θ, e_int, q_tot, q_pt)
320320
end
321321

322-
function thermo_vars(moisture_model, specific, K, Φ)
322+
function thermo_vars(moisture_model, precip_model, specific, K, Φ)
323323
energy_var = (; e_int = specific.e_tot - K - Φ)
324324
moisture_var = if moisture_model isa DryModel
325325
(;)
326326
elseif moisture_model isa EquilMoistModel
327327
(; specific.q_tot)
328328
elseif moisture_model isa NonEquilMoistModel
329-
q_pt_args = (specific.q_tot, specific.q_liq, specific.q_ice)
329+
q_pt_args = (
330+
specific.q_tot,
331+
specific.q_liq + specific.q_rai,
332+
specific.q_ice + specific.q_sno,
333+
)
330334
(; q_pt = TD.PhasePartition(q_pt_args...))
331335
end
332336
return (; energy_var..., moisture_var...)
333337
end
334338

335-
ts_gs(thermo_params, moisture_model, specific, K, Φ, ρ) = thermo_state(
336-
thermo_params;
337-
thermo_vars(moisture_model, specific, K, Φ)...,
338-
ρ,
339-
)
339+
ts_gs(thermo_params, moisture_model, precip_model, specific, K, Φ, ρ) =
340+
thermo_state(
341+
thermo_params;
342+
thermo_vars(moisture_model, precip_model, specific, K, Φ)...,
343+
ρ,
344+
)
340345

341-
ts_sgs(thermo_params, moisture_model, specific, K, Φ, p) = thermo_state(
342-
thermo_params;
343-
thermo_vars(moisture_model, specific, K, Φ)...,
344-
p,
345-
)
346+
ts_sgs(thermo_params, moisture_model, precip_model, specific, K, Φ, p) =
347+
thermo_state(
348+
thermo_params;
349+
thermo_vars(moisture_model, precip_model, specific, K, Φ)...,
350+
p,
351+
)
346352

347353
function eddy_diffusivity_coefficient_H(D₀, H, z_sfc, z)
348354
return D₀ * exp(-(z - z_sfc) / H)
@@ -476,7 +482,7 @@ NVTX.@annotate function set_precomputed_quantities!(Y, p, t)
476482
(; call_cloud_diagnostics_per_stage) = p.atmos
477483
thermo_params = CAP.thermodynamics_params(p.params)
478484
n = n_mass_flux_subdomains(turbconv_model)
479-
thermo_args = (thermo_params, moisture_model)
485+
thermo_args = (thermo_params, moisture_model, precip_model)
480486
(; ᶜΦ) = p.core
481487
(; ᶜspecific, ᶜu, ᶠu³, ᶜK, ᶜts, ᶜp) = p.precomputed
482488
ᶠuₕ³ = p.scratch.ᶠtemp_CT3

src/initial_conditions/initial_conditions.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ end
381381
"""
382382
overwrite_initial_conditions!(initial_condition, args...)
383383
384-
Do-nothing fallback method for the operation overwriting initial conditions
385-
(this functionality required in instances where we interpolate initial conditions from NetCDF files).
386-
Future work may revisit this design choice.
384+
Do-nothing fallback method for the operation overwriting initial conditions
385+
(this functionality required in instances where we interpolate initial conditions from NetCDF files).
386+
Future work may revisit this design choice.
387387
"""
388388
function overwrite_initial_conditions!(
389389
initial_condition::InitialCondition,
@@ -419,26 +419,26 @@ function overwrite_initial_conditions!(
419419
@info "Overwriting initial conditions with data from file $(file_path)"
420420
center_space = Fields.axes(Y.c)
421421
face_space = Fields.axes(Y.f)
422-
# Using surface pressure, air temperature and specific humidity
423-
# from the dataset, compute air pressure.
422+
# Using surface pressure, air temperature and specific humidity
423+
# from the dataset, compute air pressure.
424424
p_sfc = Fields.level(
425425
SpaceVaryingInputs.SpaceVaryingInput(file_path, "p", face_space),
426426
Fields.half,
427427
)
428428
ᶜT = SpaceVaryingInputs.SpaceVaryingInput(file_path, "t", center_space)
429429
ᶜq_tot = SpaceVaryingInputs.SpaceVaryingInput(file_path, "q", center_space)
430430

431-
# With the known temperature (ᶜT) and moisture (ᶜq_tot) profile,
431+
# With the known temperature (ᶜT) and moisture (ᶜq_tot) profile,
432432
# recompute the pressure levels assuming hydrostatic balance is maintained.
433-
# Uses the ClimaCore `column_integral_indefinite!` function to solve
433+
# Uses the ClimaCore `column_integral_indefinite!` function to solve
434434
# ∂(ln𝑝)/∂z = -g/(Rₘ(q)T), where
435435
# p is the local pressure
436436
# g is the gravitational constant
437437
# q is the specific humidity
438438
# Rₘ is the gas constant for moist air
439439
# T is the air temperature
440440
# p is then updated with the integral result, given p_sfc,
441-
# following which the thermodynamic state is constructed.
441+
# following which the thermodynamic state is constructed.
442442
ᶜ∂lnp∂z = @. -thermo_params.grav /
443443
(TD.gas_constant_air(thermo_params, TD.PhasePartition(ᶜq_tot)) * ᶜT)
444444
ᶠlnp_over_psfc = zeros(face_space)
@@ -1261,7 +1261,7 @@ function (initial_condition::PrecipitatingColumn)(params)
12611261
thermo_params,
12621262
p(z),
12631263
θ(z),
1264-
TD.PhasePartition(q_tot(z), qₗ(z), qᵢ(z)),
1264+
TD.PhasePartition(q_tot(z), qₗ(z) + qᵣ(z), qᵢ(z) + qₛ(z)),
12651265
)
12661266
return LocalState(;
12671267
params,

src/parameterized_tendencies/microphysics/cloud_condensate.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ function cloud_condensate_tendency!(
2727
)
2828
(; ᶜts) = p.precomputed
2929
(; params, dt) = p
30+
(; q_rai, q_sno) = p.precomputed.ᶜspecific
31+
FT = eltype(params)
3032
thp = CAP.thermodynamics_params(params)
3133
cmc = CAP.microphysics_cloud_params(params)
3234

33-
@. Yₜ.c.ρq_liq += cloud_sources(cmc.liquid, thp, ᶜts, dt)
34-
@. Yₜ.c.ρq_ice += cloud_sources(cmc.ice, thp, ᶜts, dt)
35+
@. Yₜ.c.ρq_liq += cloud_sources(cmc.liquid, thp, ᶜts, q_rai, dt)
36+
@. Yₜ.c.ρq_ice += cloud_sources(cmc.ice, thp, ᶜts, q_sno, dt)
3537
end

0 commit comments

Comments
 (0)