Skip to content

Commit

Permalink
more working tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
trontrytel committed Jan 23, 2025
1 parent 3282ef9 commit 0a1d8d0
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ steps:
slurm_mem: 20GB
slurm_constraint: icelake|cascadelake|skylake|epyc

- label: ":computer: aquaplanet (ρe_tot) nonequilmoist allsky radiation monin_obukhov varying insolation high top 1-moment"
- label: ":umbrella: aquaplanet (ρe_tot) nonequilmoist allsky radiation monin_obukhov varying insolation high top 1-moment"
command: >
julia --color=yes --project=examples examples/hybrid/driver.jl
--config_file $CONFIG_PATH/sphere_aquaplanet_rhoe_nonequilmoist_allsky.yml
Expand Down
4 changes: 1 addition & 3 deletions config/model_configs/diagnostic_edmfx_dycoms_rf02_box.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edmfx_sgs_mass_flux: true
edmfx_sgs_diffusive_flux: true
moist: equil
cloud_model: "quadrature_sgs"
precip_model: "1M"
precip_model: "0M"
call_cloud_diagnostics_per_stage: true
config: box
x_max: 1e8
Expand All @@ -35,6 +35,4 @@ diagnostics:
period: 10mins
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
period: 10mins
- short_name: [husra, hussn]
period: 10mins
ode_algo: ARS343
4 changes: 1 addition & 3 deletions config/model_configs/diagnostic_edmfx_rico_box.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ edmfx_sgs_mass_flux: true
edmfx_sgs_diffusive_flux: true
moist: equil
cloud_model: "quadrature_sgs"
precip_model: "1M"
precip_model: "0M"
call_cloud_diagnostics_per_stage: true
config: box
x_max: 1e8
Expand All @@ -34,6 +34,4 @@ diagnostics:
period: 10mins
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
period: 10mins
- short_name: [husra, hussn]
period: 10mins
ode_algo: ARS343
4 changes: 1 addition & 3 deletions config/model_configs/diagnostic_edmfx_trmm_box.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ moist: equil
cloud_model: "quadrature_sgs"
call_cloud_diagnostics_per_stage: true
apply_limiter: false
precip_model: "1M"
precip_model: "0M"
config: box
x_max: 1e8
y_max: 1e8
Expand All @@ -35,6 +35,4 @@ diagnostics:
period: 10mins
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
period: 10mins
- short_name: [husra, hussn]
period: 10mins
ode_algo: ARS343
4 changes: 1 addition & 3 deletions config/model_configs/diagnostic_edmfx_trmm_stretched_box.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edmfx_sgs_diffusive_flux: true
moist: equil
cloud_model: "quadrature_sgs"
call_cloud_diagnostics_per_stage: true
precip_model: "1M"
precip_model: "0M"
override_precip_timescale: false
config: box
x_max: 1e8
Expand All @@ -36,6 +36,4 @@ diagnostics:
period: 10mins
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
period: 10mins
- short_name: [husra, hussn]
period: 10mins
ode_algo: ARS343
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ implicit_diffusion: true
approximate_linear_solve_iters: 2
cloud_model: "grid_scale"
moist: "nonequil"
precip_model: "nothing"
precip_model: "1M"
rad: "allskywithclear"
insolation: "timevarying"
rayleigh_sponge: true
Expand Down
97 changes: 47 additions & 50 deletions src/cache/cloud_fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import NVTX
import StaticArrays as SA
import ClimaCore.RecursiveApply: rzero, ,

"""
Helper function to populate the cloud diagnostics named tuple
"""
function make_named_tuple(t1, t2, t3)
return NamedTuple{(:cf, :q_liq, :q_ice)}(tuple(t1, t2, t3))
end

# TODO: write a test with scalars that are linear with z
"""
Diagnose horizontal covariances based on vertical gradients
Expand All @@ -24,6 +31,7 @@ NVTX.@annotate function set_cloud_fraction!(Y, p, ::DryModel, _)
p.precomputed.cloud_diagnostics_tuple .=
((; cf = FT(0), q_liq = FT(0), q_ice = FT(0)),)
end

NVTX.@annotate function set_cloud_fraction!(
Y,
p,
Expand All @@ -48,28 +56,24 @@ NVTX.@annotate function set_cloud_fraction!(
end
compute_gm_mixing_length!(ᶜmixing_length, Y, p)
end
@. cloud_diagnostics_tuple = ifelse(
moist_model isa EquilMoistModel,
NamedTuple{(:cf, :q_liq, :q_ice)}(
tuple(
ifelse(TD.has_condensate(thermo_params, ᶜts), 1, 0),
TD.PhasePartition(thermo_params, ᶜts).liq,
TD.PhasePartition(thermo_params, ᶜts).ice,
),
),
NamedTuple{(:cf, :q_liq, :q_ice)}(
tuple(
ifelse(
p.precomputed.ᶜspecific.q_liq +
p.precomputed.ᶜspecific.q_ice > 0,
1,
0,
),
p.precomputed.ᶜspecific.q_liq,
p.precomputed.ᶜspecific.q_ice,

if moist_model isa EquilMoistModel
@. cloud_diagnostics_tuple = make_named_tuple(
ifelse(TD.has_condensate(thermo_params, ᶜts), 1, 0),
TD.PhasePartition(thermo_params, ᶜts).liq,
TD.PhasePartition(thermo_params, ᶜts).ice,
)
else
@. cloud_diagnostics_tuple = make_named_tuple(
ifelse(
p.precomputed.ᶜspecific.q_liq + p.precomputed.ᶜspecific.q_ice > 0,
1,
0,
),
),
)
p.precomputed.ᶜspecific.q_liq,
p.precomputed.ᶜspecific.q_ice,
)
end
end
NVTX.@annotate function set_cloud_fraction!(
Y,
Expand Down Expand Up @@ -161,21 +165,18 @@ NVTX.@annotate function set_cloud_fraction!(
n = n_mass_flux_subdomains(turbconv_model)

for j in 1:n
@. cloud_diagnostics_tuple += NamedTuple{(:cf, :q_liq, :q_ice)}(
tuple(
ifelse(
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)),
0,
),
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
@. cloud_diagnostics_tuple += make_named_tuple(
ifelse(
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)),
0,
),
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
)
end

end

NVTX.@annotate function set_cloud_fraction!(
Expand Down Expand Up @@ -210,29 +211,25 @@ NVTX.@annotate function set_cloud_fraction!(
)

# weight cloud diagnostics by environmental area
@. cloud_diagnostics_tuple *= NamedTuple{(:cf, :q_liq, :q_ice)}(
tuple(
draft_area(ᶜρa⁰, ᶜρ⁰),
draft_area(ᶜρa⁰, ᶜρ⁰),
draft_area(ᶜρa⁰, ᶜρ⁰),
),
@. cloud_diagnostics_tuple *= make_named_tuple(
draft_area(ᶜρa⁰, ᶜρ⁰),
draft_area(ᶜρa⁰, ᶜρ⁰),
draft_area(ᶜρa⁰, ᶜρ⁰),
)
# updrafts
n = n_mass_flux_subdomains(turbconv_model)

for j in 1:n
@. cloud_diagnostics_tuple += NamedTuple{(:cf, :q_liq, :q_ice)}(
tuple(
ifelse(
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
0,
),
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
@. cloud_diagnostics_tuple += make_named_tuple(
ifelse(
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
0,
),
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
)
end
end
Expand Down
97 changes: 60 additions & 37 deletions test/parameterized_tendencies/microphysics/precipitation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,34 @@ import CloudMicrophysics as CM

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

### Common Objects ###
@testset begin
"Precipitation tendency functions"
import Test

@testset "Equilibrium Moisture + 0-moment precipitation RHS terms" begin

### Boilerplate default integrator objects
config = CA.AtmosConfig(
Dict(
"initial_condition" => "PrecipitatingColumn",
"moist" => "nonequil",
"initial_condition" => "DYCOMS_RF02",
"moist" => "equil",
"precip_model" => "0M",
"config" => "column",
"output_default_diagnostics" => false,
),
job_id = "precipitation1",
job_id = "equil_0M",
)
(; Y, p, params) = generate_test_simulation(config)

FT = eltype(Y)
ᶜYₜ = zero(Y)
### Component test begins here

@info "0M Scheme"
### 0-Moment Scheme
precip_model = CA.Microphysics0Moment()
precip_cache = CA.precipitation_cache(Y, precip_model)
# Set all model choices
(; turbconv_model, moisture_model, precip_model) = p.atmos

# Test cache to verify expected variables exist in tendency function
precip_cache = CA.precipitation_cache(Y, precip_model)
test_varnames = (
:ᶜS_ρq_tot,
:ᶜS_ρe_tot,
:ᶜ3d_rain,
:ᶜ3d_snow,
:surface_rain_flux,
Expand All @@ -44,25 +45,38 @@ include("../../test_helpers.jl")
for var_name in test_varnames
@test var_name propertynames(precip_cache)
end
turbconv_model = nothing # Extend to other turbulence convection models

# No NaNs in cache
CA.compute_precipitation_cache!(Y, p, precip_model, turbconv_model)
@test maximum(abs.(p.precipitation.ᶜS_ρq_tot)) <= sqrt(eps(FT))

# Test that tendencies result in correct water-mass budget,
# and that the tendency modification corresponds exactly to the
# cached source term.
CA.precipitation_tendency!(ᶜYₜ, Y, p, FT(0), precip_model, turbconv_model)
CA.precipitation_tendency!(
ᶜYₜ,
Y,
p,
FT(0),
moisture_model,
precip_model,
turbconv_model,
)
@test ᶜYₜ.c.ρ == ᶜYₜ.c.ρq_tot
@test ᶜYₜ.c.ρ == p.precipitation.ᶜS_ρq_tot

# test nonequilibrium cloud condensate
moist_model = CA.NonEquilMoistModel()
CA.cloud_condensate_tendency!(ᶜYₜ, p, moist_model)
@assert !any(isnan, ᶜYₜ.c.ρq_liq)
@assert !any(isnan, ᶜYₜ.c.ρq_ice)
# No cloud condensation tendency for the equilibrium model
@test CA.cloud_condensate_tendency!(
ᶜYₜ,
p,
moisture_model,
precip_model,
) isa Nothing
end

### 1-Moment Scheme
@info "1M Scheme"
@testset "NonEquilibrium Moisture + 1-moment precipitation RHS terms" begin

### Boilerplate default integrator objects
config = CA.AtmosConfig(
Dict(
"initial_condition" => "PrecipitatingColumn",
Expand All @@ -74,51 +88,60 @@ include("../../test_helpers.jl")
job_id = "precipitation2",
)
(; Y, p, params) = generate_test_simulation(config)
precip_model = CA.Microphysics1Moment()
(; turbconv_model) = p.atmos

FT = eltype(Y)
ᶜYₜ = zero(Y)

# Set all model choices
(; turbconv_model, moisture_model, precip_model) = p.atmos

# Test cache to verify expected variables exist in tendency function
precip_cache = CA.precipitation_cache(Y, precip_model)
ᶜYₜ = Y .* FT(0)
test_varnames =
(:ᶜSqₜᵖ, :ᶜSqᵣᵖ, :ᶜSqₛᵖ, :ᶜSeₜᵖ, :surface_rain_flux, :surface_snow_flux)
(:ᶜSqₗᵖ, :ᶜSqᵢᵖ, :ᶜSqᵣᵖ, :ᶜSqₛᵖ, :surface_rain_flux, :surface_snow_flux)
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)
CA.precipitation_tendency!(
ᶜYₜ,
Y,
p,
FT(0),
moisture_model,
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_liq)
@assert !any(isnan, ᶜYₜ.c.ρq_ice)
@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ᵢ)
@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 all(
isapprox(
.-p.precipitation.ᶜSqₛᵖ .- p.precipitation.ᶜSqᵣᵖ,
p.precipitation.ᶜSqᵣᵖ,
atol = eps(FT),
),
)
@assert iszero(ᶜYₜ.c.ρ)

# test nonequilibrium cloud condensate
moist_model = CA.NonEquilMoistModel()
CA.cloud_condensate_tendency!(ᶜYₜ, p, moist_model)
CA.cloud_condensate_tendency!(ᶜYₜ, p, moisture_model, precip_model)
@assert !any(isnan, ᶜYₜ.c.ρq_liq)
@assert !any(isnan, ᶜYₜ.c.ρq_ice)

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

Expand Down
Loading

0 comments on commit 0a1d8d0

Please sign in to comment.