Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edits so noneq can run in climaatmos #451

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/MicrophysicsNonEq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ function conv_q_vap_to_q_liq_ice(
end

"""
conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, q, ρ, T)
conv_q_vap_to_q_liq_ice_MM2015(ice, tps, q, ρ, T)
conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, q_sat, q, T)
conv_q_vap_to_q_liq_ice_MM2015(ice, tps, q_sat, q, T)

- `liquid` or `ice` - a struct with cloud water or ice free parameters
- `tps` - thermodynamics parameters struct
- `q_sat` - PhasePartition of the q_vap values at saturation for liquid and ice
- `q` - current PhasePartition
- `ρ` - air density [kg/m3]
- `T` - air temperature [K]
Expand All @@ -76,42 +77,36 @@ Morrison and Milbrandt 2015
function conv_q_vap_to_q_liq_ice_MM2015(
(; τ_relax)::CMP.CloudLiquid{FT},
tps::TDP.ThermodynamicsParameters{FT},
q_sat::TD.PhasePartition{FT},
q::TD.PhasePartition{FT},
ρ::FT,
T::FT,
) where {FT}
Rᵥ = TD.Parameters.R_v(tps)
cₚ_air = TD.cp_m(tps, q)
Lᵥ = TD.latent_heat_vapor(tps, T)
qᵥ = TD.vapor_specific_humidity(q)

pᵥ_sat_liq = TD.saturation_vapor_pressure(tps, T, TD.Liquid())
qᵥ_sat_liq = TD.q_vap_saturation_from_density(tps, T, ρ, pᵥ_sat_liq)

dqsldT = qᵥ_sat_liq * (Lᵥ / (Rᵥ * T^2) - 1 / T)
dqsldT = q_sat.liq * (Lᵥ / (Rᵥ * T^2) - 1 / T)
Γₗ = FT(1) + (Lᵥ / cₚ_air) * dqsldT

return (qᵥ - qᵥ_sat_liq) / τ_relax * Γₗ
return (qᵥ - q_sat.liq) / (τ_relax * Γₗ)
end
function conv_q_vap_to_q_liq_ice_MM2015(
(; τ_relax)::CMP.CloudIce{FT},
tps::TDP.ThermodynamicsParameters{FT},
q_sat::TD.PhasePartition{FT},
q::TD.PhasePartition{FT},
ρ::FT,
T::FT,
) where {FT}
Rᵥ = TD.Parameters.R_v(tps)
cₚ_air = TD.cp_m(tps, q)
Lₛ = TD.latent_heat_sublim(tps, T)
qᵥ = TD.vapor_specific_humidity(q)

pᵥ_sat_ice = TD.saturation_vapor_pressure(tps, T, TD.Ice())
qᵥ_sat_ice = TD.q_vap_saturation_from_density(tps, T, ρ, pᵥ_sat_ice)

dqsidT = qᵥ_sat_ice * (Lₛ / (Rᵥ * T^2) - 1 / T)
dqsidT = q_sat.ice * (Lₛ / (Rᵥ * T^2) - 1 / T)
Γᵢ = FT(1) + (Lₛ / cₚ_air) * dqsidT

return (qᵥ - qᵥ_sat_ice) / τ_relax * Γᵢ
return (qᵥ - q_sat.ice) / (τ_relax * Γᵢ)
end

end #module MicrophysicsNonEq.jl
24 changes: 13 additions & 11 deletions test/microphysics_noneq_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function test_microphysics_noneq(FT)
end
end

TT.@testset "CondEvap_DepSub_MG2008" begin
TT.@testset "CondEvap_DepSub_MM2015" begin

ρ = FT(0.8)
T = FT(273 - 10)
Expand All @@ -65,25 +65,27 @@ function test_microphysics_noneq(FT)
pᵥ_si = TD.saturation_vapor_pressure(tps, T, TD.Ice())
qᵥ_si = TD.q_vap_saturation_from_density(tps, T, ρ, pᵥ_si)

qᵥ_s = TD.PhasePartition(FT(0), qᵥ_sl, qᵥ_si)

qₚ(qᵥ) = TD.PhasePartition(FT(qᵥ))

#! format: off
# test sign
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, qₚ(FT(0.5 * qᵥ_sl)), ρ, T) < FT(0)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, qₚ(FT(1.5 * qᵥ_sl)), ρ, T) > FT(0)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, qₚ( qᵥ_sl), ρ, T) ≈ FT(0)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, qᵥ_s, qₚ(FT(0.5 * qᵥ_sl)), T) < FT(0)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, qᵥ_s, qₚ(FT(1.5 * qᵥ_sl)), T) > FT(0)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, qᵥ_s, qₚ( qᵥ_sl), T) ≈ FT(0)

TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(ice, tps, qₚ(FT(0.5 * qᵥ_si)), ρ, T) < FT(0)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(ice, tps, qₚ(FT(1.5 * qᵥ_si)), ρ, T) > FT(0)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(ice, tps, qₚ( qᵥ_si), ρ, T) ≈ FT(0)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(ice, tps, qᵥ_s, qₚ(FT(0.5 * qᵥ_si)), T) < FT(0)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(ice, tps, qᵥ_s, qₚ(FT(1.5 * qᵥ_si)), T) > FT(0)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(ice, tps, qᵥ_s, qₚ( qᵥ_si), T) ≈ FT(0)

# smoke test for values
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, qₚ(FT(1.2 * qᵥ_sl)), ρ, T) ≈ 9.0419475e-5 rtol = 1e-6
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(ice, tps, qₚ(FT(1.2 * qᵥ_si)), ρ, T) ≈ 8.627814e-5 rtol = 1e-6
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, qᵥ_s, qₚ(FT(1.2 * qᵥ_sl)), T) ≈ 3.7631f-5 rtol = 1e-6
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(ice, tps, qᵥ_s, qₚ(FT(1.2 * qᵥ_si)), T) ≈ 3.2356777f-5 rtol = 1e-6

# ice grows faster than liquid
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, qₚ(FT(1.2 * qᵥ_sl)), ρ, T) <
CMNe.conv_q_vap_to_q_liq_ice_MM2015(ice, tps, qₚ(FT(1.2 * qᵥ_sl)), ρ, T)
TT.@test CMNe.conv_q_vap_to_q_liq_ice_MM2015(liquid, tps, qᵥ_s, qₚ(FT(1.2 * qᵥ_sl)), T) <
CMNe.conv_q_vap_to_q_liq_ice_MM2015(ice, tps, qᵥ_s, qₚ(FT(1.2 * qᵥ_sl)), T)

#! format: on
end
Expand Down
Loading