diff --git a/src/MicrophysicsNonEq.jl b/src/MicrophysicsNonEq.jl index 5f14a826d..4e95ebfab 100644 --- a/src/MicrophysicsNonEq.jl +++ b/src/MicrophysicsNonEq.jl @@ -144,8 +144,8 @@ function conv_q_vap_to_q_liq_ice_MM2015_timeintegrator( w::FT, p_air::FT, const_dt::FT, - type::String, -) where {FT} + ::Val{type}, +) where {FT, type} cₚ_air = TD.cp_m(tps, q) Lₛ = TD.latent_heat_sublim(tps, T) @@ -184,19 +184,21 @@ function conv_q_vap_to_q_liq_ice_MM2015_timeintegrator( δ_0 = qᵥ - qᵥ_sat_liq - if type == "condensation" + if type == :condensation cond_rate = A_c * τ / (liquid.τ_relax * Γₗ) + (δ_0 - A_c * τ) * τ / (const_dt * liquid.τ_relax * Γₗ) * (FT(1) - exp(-const_dt / τ)) return cond_rate - elseif type == "deposition" + elseif type == :deposition dep_rate = A_c * τ / (ice.τ_relax * Γᵢ) + (δ_0 - A_c * τ) * τ / (const_dt * ice.τ_relax * Γᵢ) * (FT(1) - exp(-const_dt / τ)) + (qᵥ_sat_liq - qᵥ_sat_ice) / (ice.τ_relax * Γᵢ) return dep_rate + else + error("please specify condensation or deposition") end end diff --git a/test/gpu_tests.jl b/test/gpu_tests.jl index bda618dcb..99d2b8574 100644 --- a/test/gpu_tests.jl +++ b/test/gpu_tests.jl @@ -136,7 +136,7 @@ end w[i], p[i], const_dt[i], - "deposition", + Val(:condensation), ) output[3, i] = CMN.conv_q_vap_to_q_liq_ice( ice, diff --git a/test/microphysics_noneq_tests.jl b/test/microphysics_noneq_tests.jl index 09fa54213..dc91b5d41 100644 --- a/test/microphysics_noneq_tests.jl +++ b/test/microphysics_noneq_tests.jl @@ -106,22 +106,22 @@ function test_microphysics_noneq(FT) #! format: off # test sign - TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(0.5 * qᵥ_sl)), ρ, T, w, p_air, const_dt, "condensation") < FT(0) - TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.5 * qᵥ_sl)), ρ, T, w, p_air, const_dt, "condensation") > FT(0) + TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(0.5 * qᵥ_sl)), ρ, T, w, p_air, const_dt, Val(:condensation)) < FT(0) + TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.5 * qᵥ_sl)), ρ, T, w, p_air, const_dt, Val(:condensation)) > FT(0) # wouldnt be zero as a result of WBF #TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ( qᵥ_sl), ρ, T, FT(0), p_air, const_dt, "condensation") ≈ FT(0) rtol = 1e-6 - TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(0.5 * qᵥ_si)), ρ, T, w, p_air, const_dt, "deposition") < FT(0) - TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.5 * qᵥ_si)), ρ, T, w, p_air, const_dt, "deposition") > FT(0) + TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(0.5 * qᵥ_si)), ρ, T, w, p_air, const_dt, Val(:deposition)) < FT(0) + TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.5 * qᵥ_si)), ρ, T, w, p_air, const_dt, Val(:deposition)) > FT(0) #TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ( qᵥ_si), ρ, T, FT(0), p_air, const_dt, "deposition") ≈ FT(0) rtol = 1e-6 # smoke test for values - TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.2 * qᵥ_sl)), ρ, T, w, p_air, const_dt, "condensation") ≈ 3.7177455e-5 rtol = 5e-6 - TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.2 * qᵥ_si)), ρ, T, w, p_air, const_dt, "deposition") ≈ 3.2125972e-5 rtol = 1e-6 + TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.2 * qᵥ_sl)), ρ, T, w, p_air, const_dt, Val(:condensation)) ≈ 3.7177455e-5 rtol = 5e-6 + TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.2 * qᵥ_si)), ρ, T, w, p_air, const_dt, Val(:deposition)) ≈ 3.2125972e-5 rtol = 1e-6 # ice grows faster than liquid - TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.2 * qᵥ_sl)), ρ, T, w, p_air, const_dt, "condensation") < - CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.2 * qᵥ_sl)), ρ, T, w, p_air, const_dt, "deposition") + TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.2 * qᵥ_sl)), ρ, T, w, p_air, const_dt, Val(:condensation)) < + CMNe.conv_q_vap_to_q_liq_ice_MM2015_timeintegrator(liquid, ice, tps, qₚ(FT(1.2 * qᵥ_sl)), ρ, T, w, p_air, const_dt, Val(:deposition)) #! format: on end