Skip to content

Commit 0a1d8d0

Browse files
committed
more working tests in CI
1 parent 3282ef9 commit 0a1d8d0

10 files changed

+114
-102
lines changed

.buildkite/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ steps:
349349
slurm_mem: 20GB
350350
slurm_constraint: icelake|cascadelake|skylake|epyc
351351

352-
- label: ":computer: aquaplanet (ρe_tot) nonequilmoist allsky radiation monin_obukhov varying insolation high top 1-moment"
352+
- label: ":umbrella: aquaplanet (ρe_tot) nonequilmoist allsky radiation monin_obukhov varying insolation high top 1-moment"
353353
command: >
354354
julia --color=yes --project=examples examples/hybrid/driver.jl
355355
--config_file $CONFIG_PATH/sphere_aquaplanet_rhoe_nonequilmoist_allsky.yml

config/model_configs/diagnostic_edmfx_dycoms_rf02_box.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ edmfx_sgs_mass_flux: true
1515
edmfx_sgs_diffusive_flux: true
1616
moist: equil
1717
cloud_model: "quadrature_sgs"
18-
precip_model: "1M"
18+
precip_model: "0M"
1919
call_cloud_diagnostics_per_stage: true
2020
config: box
2121
x_max: 1e8
@@ -35,6 +35,4 @@ diagnostics:
3535
period: 10mins
3636
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
3737
period: 10mins
38-
- short_name: [husra, hussn]
39-
period: 10mins
4038
ode_algo: ARS343

config/model_configs/diagnostic_edmfx_rico_box.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ edmfx_sgs_mass_flux: true
1414
edmfx_sgs_diffusive_flux: true
1515
moist: equil
1616
cloud_model: "quadrature_sgs"
17-
precip_model: "1M"
17+
precip_model: "0M"
1818
call_cloud_diagnostics_per_stage: true
1919
config: box
2020
x_max: 1e8
@@ -34,6 +34,4 @@ diagnostics:
3434
period: 10mins
3535
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
3636
period: 10mins
37-
- short_name: [husra, hussn]
38-
period: 10mins
3937
ode_algo: ARS343

config/model_configs/diagnostic_edmfx_trmm_box.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ moist: equil
1515
cloud_model: "quadrature_sgs"
1616
call_cloud_diagnostics_per_stage: true
1717
apply_limiter: false
18-
precip_model: "1M"
18+
precip_model: "0M"
1919
config: box
2020
x_max: 1e8
2121
y_max: 1e8
@@ -35,6 +35,4 @@ diagnostics:
3535
period: 10mins
3636
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
3737
period: 10mins
38-
- short_name: [husra, hussn]
39-
period: 10mins
4038
ode_algo: ARS343

config/model_configs/diagnostic_edmfx_trmm_stretched_box.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ edmfx_sgs_diffusive_flux: true
1515
moist: equil
1616
cloud_model: "quadrature_sgs"
1717
call_cloud_diagnostics_per_stage: true
18-
precip_model: "1M"
18+
precip_model: "0M"
1919
override_precip_timescale: false
2020
config: box
2121
x_max: 1e8
@@ -36,6 +36,4 @@ diagnostics:
3636
period: 10mins
3737
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
3838
period: 10mins
39-
- short_name: [husra, hussn]
40-
period: 10mins
4139
ode_algo: ARS343

config/model_configs/sphere_aquaplanet_rhoe_nonequilmoist_allsky.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ implicit_diffusion: true
99
approximate_linear_solve_iters: 2
1010
cloud_model: "grid_scale"
1111
moist: "nonequil"
12-
precip_model: "nothing"
12+
precip_model: "1M"
1313
rad: "allskywithclear"
1414
insolation: "timevarying"
1515
rayleigh_sponge: true

src/cache/cloud_fraction.jl

Lines changed: 47 additions & 50 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
@@ -24,6 +31,7 @@ NVTX.@annotate function set_cloud_fraction!(Y, p, ::DryModel, _)
2431
p.precomputed.cloud_diagnostics_tuple .=
2532
((; cf = FT(0), q_liq = FT(0), q_ice = FT(0)),)
2633
end
34+
2735
NVTX.@annotate function set_cloud_fraction!(
2836
Y,
2937
p,
@@ -48,28 +56,24 @@ NVTX.@annotate function set_cloud_fraction!(
4856
end
4957
compute_gm_mixing_length!(ᶜmixing_length, Y, p)
5058
end
51-
@. cloud_diagnostics_tuple = ifelse(
52-
moist_model isa EquilMoistModel,
53-
NamedTuple{(:cf, :q_liq, :q_ice)}(
54-
tuple(
55-
ifelse(TD.has_condensate(thermo_params, ᶜts), 1, 0),
56-
TD.PhasePartition(thermo_params, ᶜts).liq,
57-
TD.PhasePartition(thermo_params, ᶜts).ice,
58-
),
59-
),
60-
NamedTuple{(:cf, :q_liq, :q_ice)}(
61-
tuple(
62-
ifelse(
63-
p.precomputed.ᶜspecific.q_liq +
64-
p.precomputed.ᶜspecific.q_ice > 0,
65-
1,
66-
0,
67-
),
68-
p.precomputed.ᶜspecific.q_liq,
69-
p.precomputed.ᶜspecific.q_ice,
59+
60+
if moist_model isa EquilMoistModel
61+
@. cloud_diagnostics_tuple = make_named_tuple(
62+
ifelse(TD.has_condensate(thermo_params, ᶜts), 1, 0),
63+
TD.PhasePartition(thermo_params, ᶜts).liq,
64+
TD.PhasePartition(thermo_params, ᶜts).ice,
65+
)
66+
else
67+
@. cloud_diagnostics_tuple = make_named_tuple(
68+
ifelse(
69+
p.precomputed.ᶜspecific.q_liq + p.precomputed.ᶜspecific.q_ice > 0,
70+
1,
71+
0,
7072
),
71-
),
72-
)
73+
p.precomputed.ᶜspecific.q_liq,
74+
p.precomputed.ᶜspecific.q_ice,
75+
)
76+
end
7377
end
7478
NVTX.@annotate function set_cloud_fraction!(
7579
Y,
@@ -161,21 +165,18 @@ NVTX.@annotate function set_cloud_fraction!(
161165
n = n_mass_flux_subdomains(turbconv_model)
162166

163167
for j in 1:n
164-
@. cloud_diagnostics_tuple += NamedTuple{(:cf, :q_liq, :q_ice)}(
165-
tuple(
166-
ifelse(
167-
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
168-
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)),
169-
0,
170-
),
171-
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
172-
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
173-
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
174-
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
168+
@. cloud_diagnostics_tuple += make_named_tuple(
169+
ifelse(
170+
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
171+
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)),
172+
0,
175173
),
174+
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
175+
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
176+
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
177+
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
176178
)
177179
end
178-
179180
end
180181

181182
NVTX.@annotate function set_cloud_fraction!(
@@ -210,29 +211,25 @@ NVTX.@annotate function set_cloud_fraction!(
210211
)
211212

212213
# weight cloud diagnostics by environmental area
213-
@. cloud_diagnostics_tuple *= NamedTuple{(:cf, :q_liq, :q_ice)}(
214-
tuple(
215-
draft_area(ᶜρa⁰, ᶜρ⁰),
216-
draft_area(ᶜρa⁰, ᶜρ⁰),
217-
draft_area(ᶜρa⁰, ᶜρ⁰),
218-
),
214+
@. cloud_diagnostics_tuple *= make_named_tuple(
215+
draft_area(ᶜρa⁰, ᶜρ⁰),
216+
draft_area(ᶜρa⁰, ᶜρ⁰),
217+
draft_area(ᶜρa⁰, ᶜρ⁰),
219218
)
220219
# updrafts
221220
n = n_mass_flux_subdomains(turbconv_model)
222221

223222
for j in 1:n
224-
@. cloud_diagnostics_tuple += NamedTuple{(:cf, :q_liq, :q_ice)}(
225-
tuple(
226-
ifelse(
227-
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
228-
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
229-
0,
230-
),
231-
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
232-
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
233-
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
234-
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
223+
@. cloud_diagnostics_tuple += make_named_tuple(
224+
ifelse(
225+
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
226+
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
227+
0,
235228
),
229+
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
230+
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
231+
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
232+
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
236233
)
237234
end
238235
end

test/parameterized_tendencies/microphysics/precipitation.jl

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,34 @@ import CloudMicrophysics as CM
99

1010
include("../../test_helpers.jl")
1111

12-
### Common Objects ###
13-
@testset begin
14-
"Precipitation tendency functions"
12+
import Test
13+
14+
@testset "Equilibrium Moisture + 0-moment precipitation RHS terms" begin
15+
1516
### Boilerplate default integrator objects
1617
config = CA.AtmosConfig(
1718
Dict(
18-
"initial_condition" => "PrecipitatingColumn",
19-
"moist" => "nonequil",
19+
"initial_condition" => "DYCOMS_RF02",
20+
"moist" => "equil",
2021
"precip_model" => "0M",
2122
"config" => "column",
2223
"output_default_diagnostics" => false,
2324
),
24-
job_id = "precipitation1",
25+
job_id = "equil_0M",
2526
)
2627
(; Y, p, params) = generate_test_simulation(config)
2728

2829
FT = eltype(Y)
2930
ᶜYₜ = zero(Y)
30-
### Component test begins here
3131

32-
@info "0M Scheme"
33-
### 0-Moment Scheme
34-
precip_model = CA.Microphysics0Moment()
35-
precip_cache = CA.precipitation_cache(Y, precip_model)
32+
# Set all model choices
33+
(; turbconv_model, moisture_model, precip_model) = p.atmos
34+
3635
# Test cache to verify expected variables exist in tendency function
36+
precip_cache = CA.precipitation_cache(Y, precip_model)
3737
test_varnames = (
3838
:ᶜS_ρq_tot,
39+
:ᶜS_ρe_tot,
3940
:ᶜ3d_rain,
4041
:ᶜ3d_snow,
4142
:surface_rain_flux,
@@ -44,25 +45,38 @@ include("../../test_helpers.jl")
4445
for var_name in test_varnames
4546
@test var_name propertynames(precip_cache)
4647
end
47-
turbconv_model = nothing # Extend to other turbulence convection models
48+
49+
# No NaNs in cache
4850
CA.compute_precipitation_cache!(Y, p, precip_model, turbconv_model)
4951
@test maximum(abs.(p.precipitation.ᶜS_ρq_tot)) <= sqrt(eps(FT))
5052

5153
# Test that tendencies result in correct water-mass budget,
5254
# and that the tendency modification corresponds exactly to the
5355
# cached source term.
54-
CA.precipitation_tendency!(ᶜYₜ, Y, p, FT(0), precip_model, turbconv_model)
56+
CA.precipitation_tendency!(
57+
ᶜYₜ,
58+
Y,
59+
p,
60+
FT(0),
61+
moisture_model,
62+
precip_model,
63+
turbconv_model,
64+
)
5565
@test ᶜYₜ.c.ρ == ᶜYₜ.c.ρq_tot
5666
@test ᶜYₜ.c.ρ == p.precipitation.ᶜS_ρq_tot
5767

58-
# test nonequilibrium cloud condensate
59-
moist_model = CA.NonEquilMoistModel()
60-
CA.cloud_condensate_tendency!(ᶜYₜ, p, moist_model)
61-
@assert !any(isnan, ᶜYₜ.c.ρq_liq)
62-
@assert !any(isnan, ᶜYₜ.c.ρq_ice)
68+
# No cloud condensation tendency for the equilibrium model
69+
@test CA.cloud_condensate_tendency!(
70+
ᶜYₜ,
71+
p,
72+
moisture_model,
73+
precip_model,
74+
) isa Nothing
75+
end
6376

64-
### 1-Moment Scheme
65-
@info "1M Scheme"
77+
@testset "NonEquilibrium Moisture + 1-moment precipitation RHS terms" begin
78+
79+
### Boilerplate default integrator objects
6680
config = CA.AtmosConfig(
6781
Dict(
6882
"initial_condition" => "PrecipitatingColumn",
@@ -74,51 +88,60 @@ include("../../test_helpers.jl")
7488
job_id = "precipitation2",
7589
)
7690
(; Y, p, params) = generate_test_simulation(config)
77-
precip_model = CA.Microphysics1Moment()
78-
(; turbconv_model) = p.atmos
91+
92+
FT = eltype(Y)
93+
ᶜYₜ = zero(Y)
94+
95+
# Set all model choices
96+
(; turbconv_model, moisture_model, precip_model) = p.atmos
97+
98+
# Test cache to verify expected variables exist in tendency function
7999
precip_cache = CA.precipitation_cache(Y, precip_model)
80-
ᶜYₜ = Y .* FT(0)
81100
test_varnames =
82-
(:ᶜSqₜᵖ, :ᶜSqᵣᵖ, :ᶜSqₛᵖ, :ᶜSeₜᵖ, :surface_rain_flux, :surface_snow_flux)
101+
(:ᶜSqₗᵖ, :ᶜSqᵢᵖ, :ᶜSqᵣᵖ, :ᶜSqₛᵖ, :surface_rain_flux, :surface_snow_flux)
83102
for var_name in test_varnames
84103
@test var_name propertynames(precip_cache)
85104
end
86105

87106
# test helper functions
88-
@test CA.qₚ(FT(10), FT(2)) == FT(5)
89-
@test CA.qₚ(FT(-10), FT(2)) == FT(0)
90107
@test CA.limit(FT(10), FT(2), 5) == FT(1)
91108

92109
# compute source terms based on the last model state
93-
CA.precipitation_tendency!(ᶜYₜ, Y, p, FT(0), precip_model, turbconv_model)
110+
CA.precipitation_tendency!(
111+
ᶜYₜ,
112+
Y,
113+
p,
114+
FT(0),
115+
moisture_model,
116+
precip_model,
117+
turbconv_model,
118+
)
94119

95120
# check for nans
96121
@assert !any(isnan, ᶜYₜ.c.ρ)
97122
@assert !any(isnan, ᶜYₜ.c.ρq_tot)
98123
@assert !any(isnan, ᶜYₜ.c.ρe_tot)
124+
@assert !any(isnan, ᶜYₜ.c.ρq_liq)
125+
@assert !any(isnan, ᶜYₜ.c.ρq_ice)
99126
@assert !any(isnan, ᶜYₜ.c.ρq_rai)
100127
@assert !any(isnan, ᶜYₜ.c.ρq_sno)
128+
@assert !any(isnan, p.precomputed.ᶜwₗ)
129+
@assert !any(isnan, p.precomputed.ᶜwᵢ)
101130
@assert !any(isnan, p.precomputed.ᶜwᵣ)
102131
@assert !any(isnan, p.precomputed.ᶜwₛ)
103132

104133
# test water budget
105134
@test ᶜYₜ.c.ρ == ᶜYₜ.c.ρq_tot
106-
@test ᶜYₜ.c.ρ == Y.c.ρ .* p.precipitation.ᶜSqₜᵖ
107-
@test all(
108-
isapprox(
109-
.-p.precipitation.ᶜSqₛᵖ .- p.precipitation.ᶜSqᵣᵖ,
110-
p.precipitation.ᶜSqᵣᵖ,
111-
atol = eps(FT),
112-
),
113-
)
135+
@assert iszero(ᶜYₜ.c.ρ)
114136

115137
# test nonequilibrium cloud condensate
116-
moist_model = CA.NonEquilMoistModel()
117-
CA.cloud_condensate_tendency!(ᶜYₜ, p, moist_model)
138+
CA.cloud_condensate_tendency!(ᶜYₜ, p, moisture_model, precip_model)
118139
@assert !any(isnan, ᶜYₜ.c.ρq_liq)
119140
@assert !any(isnan, ᶜYₜ.c.ρq_ice)
120141

121142
# test if terminal velocity is positive
143+
@test minimum(p.precomputed.ᶜwₗ) >= FT(0)
144+
@test minimum(p.precomputed.ᶜwᵢ) >= FT(0)
122145
@test minimum(p.precomputed.ᶜwᵣ) >= FT(0)
123146
@test minimum(p.precomputed.ᶜwₛ) >= FT(0)
124147

0 commit comments

Comments
 (0)