Skip to content

Commit

Permalink
Move remaining precipitation tests from driver to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trontrytel committed May 21, 2024
1 parent 3fbb1bc commit da6e134
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 55 deletions.
3 changes: 0 additions & 3 deletions config/default_configs/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,6 @@ regression_test:
check_conservation:
help: "Check conservation of mass and energy [`false` (default), `true`]"
value: false
check_precipitation:
help: "Sanity checks for 1-moment precipitation [`false` (default), `true`]"
value: false
ls_adv:
help: "Large-scale advection [`nothing` (default), `Bomex`, `LifeCycleTan2018`, `Rico`, `ARM_SGP`, `GATE_III`]"
value: ~
Expand Down
1 change: 0 additions & 1 deletion config/model_configs/single_column_precipitation_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ vert_diff: "FriersonDiffusion"
implicit_diffusion: true
approximate_linear_solve_iters: 2
regression_test: false
check_precipitation: true
toml: [toml/single_column_precipitation_test.toml]
diagnostics:
- short_name: [hus, clw, cli, husra, hussn, ta, wa]
Expand Down
51 changes: 0 additions & 51 deletions examples/hybrid/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,57 +167,6 @@ if config.parsed_args["check_conservation"]
end
end

# Precipitation characteristic checks
if config.parsed_args["check_precipitation"]
# run some simple tests based on the output
FT = Spaces.undertype(axes(sol.u[end].c.ρ))
Yₜ = similar(sol.u[end])
@. Yₜ = 0

Yₜ_ρ = similar(Yₜ.c.ρq_rai)
Yₜ_ρqₚ = similar(Yₜ.c.ρq_rai)
Yₜ_ρqₜ = similar(Yₜ.c.ρq_rai)


CA.precipitation_tendency!(
Yₜ,
sol.u[end],
sol.prob.p,
sol.t[end],
sol.prob.p.atmos.precip_model,
sol.prob.p.atmos.turbconv_model,
)
@. Yₜ_ρqₚ = -Yₜ.c.ρq_rai - Yₜ.c.ρq_sno
@. Yₜ_ρqₜ = Yₜ.c.ρq_tot
@. Yₜ_ρ = Yₜ.c.ρ

# no nans
@assert !any(isnan, Yₜ.c.ρ)
@assert !any(isnan, Yₜ.c.ρq_tot)
@assert !any(isnan, Yₜ.c.ρe_tot)
@assert !any(isnan, Yₜ.c.ρq_rai)
@assert !any(isnan, Yₜ.c.ρq_sno)
@assert !any(isnan, sol.prob.p.precomputed.ᶜwᵣ)
@assert !any(isnan, sol.prob.p.precomputed.ᶜwₛ)

# treminal velocity is positive
@test minimum(sol.prob.p.precomputed.ᶜwᵣ) >= FT(0)
@test minimum(sol.prob.p.precomputed.ᶜwₛ) >= FT(0)

# checking for water budget conservation
# in the presence of precipitation sinks
# (This test only works without surface flux of q_tot)
@test all(ClimaCore.isapprox(Yₜ_ρqₜ, Yₜ_ρqₚ, rtol = 1e2 * eps(FT)))

# mass budget consistency
@test all(ClimaCore.isapprox(Yₜ_ρ, Yₜ_ρqₜ, rtol = eps(FT)))

# cloud fraction diagnostics
@assert !any(isnan, sol.prob.p.precomputed.cloud_diagnostics_tuple.cf)
@test minimum(sol.prob.p.precomputed.cloud_diagnostics_tuple.cf) >= FT(0)
@test maximum(sol.prob.p.precomputed.cloud_diagnostics_tuple.cf) <= FT(1)
end

# Visualize the solution
if ClimaComms.iamroot(config.comms_ctx)
include(
Expand Down
25 changes: 25 additions & 0 deletions test/parameterized_tendencies/microphysics/precipitation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,35 @@ include("../../test_helpers.jl")
for var_name in test_varnames
@test var_name propertynames(precip_cache)
end

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

# compute source terms based on the last model state
CA.precipitation_tendency!(ᶜYₜ, Y, p, FT(0), precip_model, turbconv_model)

# check for nans
@assert !any(isnan, ᶜYₜ.c.ρ)
@assert !any(isnan, ᶜYₜ.c.ρq_tot)
@assert !any(isnan, ᶜYₜ.c.ρe_tot)
@assert !any(isnan, ᶜYₜ.c.ρq_rai)
@assert !any(isnan, ᶜYₜ.c.ρq_sno)
@assert !any(isnan, p.precomputed.ᶜwᵣ)
@assert !any(isnan, p.precomputed.ᶜwₛ)

# test water budget
@test ᶜYₜ.c.ρ == ᶜYₜ.c.ρq_tot
@test ᶜYₜ.c.ρ == Y.c.ρ .* p.precipitation.ᶜSqₜᵖ
@test p.precipitation.ᶜSqₜᵖ == .- p.precipitation.ᶜSqᵣᵖ .- p.precipitation.ᶜSqₛᵖ

# test if terminal velocity is positive
@test minimum(p.precomputed.ᶜwᵣ) >= FT(0)
@test minimum(p.precomputed.ᶜwₛ) >= FT(0)

# test if cloud fraction diagnostics make sense
@assert !any(isnan, p.precomputed.cloud_diagnostics_tuple.cf)
@test minimum(p.precomputed.cloud_diagnostics_tuple.cf) >= FT(0)
@test maximum(p.precomputed.cloud_diagnostics_tuple.cf) <= FT(1)
end

0 comments on commit da6e134

Please sign in to comment.