Skip to content

Commit

Permalink
fixed gpu type instability
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivia Alcabes committed Sep 16, 2024
1 parent 675fc35 commit ef8a564
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/MicrophysicsNonEq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/gpu_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions test/microphysics_noneq_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef8a564

Please sign in to comment.