Skip to content

Commit

Permalink
Merge #256
Browse files Browse the repository at this point in the history
256: Update non-eq microphysics to new parameters r=trontrytel a=trontrytel



Co-authored-by: Anna Jaruga <[email protected]>
  • Loading branch information
bors[bot] and trontrytel authored Oct 5, 2023
2 parents 094470a + 9c4a459 commit 8546e18
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/src/Microphysics1M.md
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ const param_set = cloud_microphysics_parameters(toml_dict)
thermo_params = CMP.thermodynamics_params(param_set)
const air_props = CMT.AirProperties(FT)
const liquid = CMT.LiquidType()
const liquid = CMT.LiquidType(FT)
const ice = CMT.IceType(FT)
const rain = CMT.RainType(FT)
const snow = CMT.SnowType(FT)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/Microphysics2M.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ toml_dict = CP.create_toml_dict(FT; dict_type = "alias")
const param_set = cloud_microphysics_parameters(toml_dict)
thermo_params = CMP.thermodynamics_params(param_set)
const liquid = CMT.LiquidType()
const liquid = CMT.LiquidType(FT)
const rain = CMT.RainType(FT)
const KK2000 = CMT.KK2000Type()
Expand Down
2 changes: 1 addition & 1 deletion docs/src/plots/TerminalVelocityComparisons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import CloudMicrophysics.Parameters as CMP
import CloudMicrophysics.Common as CMO

const rain = CMT.RainType(FT)
const liquid = CMT.LiquidType()
const liquid = CMT.LiquidType(FT)
const ice = CMT.IceType(FT)
const snow = CMT.SnowType(FT)
const tv_SB2006 = CMT.TerminalVelocitySB2006(FT)
Expand Down
19 changes: 17 additions & 2 deletions src/CommonTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,20 @@ Base.broadcastable(x::AbstractPrecipType) = tuple(x)
LiquidType
The type for cloud liquid water condensate
# Fields
$(DocStringExtensions.FIELDS)
"""
struct LiquidType <: AbstractCloudType end
struct LiquidType{FT} <: AbstractCloudType
"condensation evaporation non_equil microphysics relaxation timescale [s]"
τ_relax::FT
end

function LiquidType(::Type{FT}, toml_dict = CP.create_toml_dict(FT)) where {FT}
(; data) = toml_dict
τ_relax = FT(data["condensation_evaporation_timescale"]["value"])
return LiquidType(τ_relax)
end
Base.broadcastable(x::LiquidType) = tuple(x)

"""
Expand Down Expand Up @@ -89,6 +101,8 @@ struct IceType{FT} <: AbstractCloudType
m0::FT
"ice snow threshold radius"
r_ice_snow::FT
"deposition sublimation non_equil microphysics relaxation timescale [s]"
τ_relax::FT
end

function IceType(::Type{FT}, toml_dict = CP.create_toml_dict(FT)) where {FT}
Expand All @@ -101,7 +115,8 @@ function IceType(::Type{FT}, toml_dict = CP.create_toml_dict(FT)) where {FT}
n0 = FT(data["cloud_ice_size_distribution_coefficient_n0"]["value"])
m0 = FT(4 / 3) * π * ρ * r0^me
r_ice_snow = FT(data["ice_snow_threshold_radius"]["value"])
return IceType(r0, me, Δm, χm, ρ, n0, m0, r_ice_snow)
τ_relax = FT(data["sublimation_deposition_timescale"]["value"])
return IceType(r0, me, Δm, χm, ρ, n0, m0, r_ice_snow, τ_relax)
end
Base.broadcastable(x::IceType) = tuple(x)

Expand Down
26 changes: 8 additions & 18 deletions src/MicrophysicsNonEq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,22 @@ export τ_relax
export conv_q_vap_to_q_liq_ice

"""
τ_relax(prs, liquid)
τ_relax(prs, ice)
τ_relax(liquid)
τ_relax(ice)
- `prs` - abstract set with Earth parameters
- `liquid` or `ice` - a type for cloud liquid water or ice
Returns the relaxation timescale for condensation and evaporation of
cloud liquid water or the relaxation timescale for sublimation and
deposition of cloud ice.
"""
τ_relax(prs::APS, ::CT.LiquidType) = CMP.τ_cond_evap(prs)
τ_relax(prs::APS, ::CT.IceType) = CMP.τ_sub_dep(prs)
τ_relax(p::CT.LiquidType) = p.τ_relax
τ_relax(p::CT.IceType) = p.τ_relax

"""
conv_q_vap_to_q_liq_ice(prs, liquid, q_sat, q)
conv_q_vap_to_q_liq_ice(prs, ice, q_sat, q)
conv_q_vap_to_q_liq_ice(liquid, q_sat, q)
conv_q_vap_to_q_liq_ice(ice, q_sat, q)
- `prs` - abstract set with Earth parameters
- `liquid` or `ice` - a type for cloud water or ice
- `q_sat` - PhasePartition at equilibrium
- `q` - current PhasePartition
Expand All @@ -45,26 +43,18 @@ The tendency is obtained assuming a relaxation to equilibrium with
a constant timescale.
"""
function conv_q_vap_to_q_liq_ice(
prs::APS,
liquid::CT.LiquidType,
q_sat::TD.PhasePartition{FT},
q::TD.PhasePartition{FT},
) where {FT <: Real}

_τ_cond_evap::FT = τ_relax(prs, liquid)

return (q_sat.liq - q.liq) / _τ_cond_evap
return (q_sat.liq - q.liq) / liquid.τ_relax
end
function conv_q_vap_to_q_liq_ice(
prs::APS,
ice::CT.IceType,
q_sat::TD.PhasePartition{FT},
q::TD.PhasePartition{FT},
) where {FT <: Real}

_τ_sub_dep::FT = τ_relax(prs, ice)

return (q_sat.ice - q.ice) / _τ_sub_dep
return (q_sat.ice - q.ice) / ice.τ_relax
end

end #module MicrophysicsNonEq.jl
2 changes: 1 addition & 1 deletion test/gpu_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ function test_gpu(FT)
)
thermo_params = CMP.thermodynamics_params(prs)

liquid = CMT.LiquidType()
liquid = CMT.LiquidType(FT)
ice = CMT.IceType(FT)
rain = CMT.RainType(FT)
snow = CMT.SnowType(FT)
Expand Down
12 changes: 5 additions & 7 deletions test/microphysics_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import CloudMicrophysics.Microphysics2M as CM2

include(joinpath(pkgdir(CM), "test", "create_parameters.jl"))

const liquid = CMT.LiquidType()
const SB2006 = CMT.SB2006Type()
const KK2000 = CMT.KK2000Type()
const B1994 = CMT.B1994Type()
Expand All @@ -31,6 +30,7 @@ function test_microphysics(FT)
rain = CMT.RainType(FT)
snow = CMT.SnowType(FT)
ice = CMT.IceType(FT)
liquid = CMT.LiquidType(FT)
Ch2022 = CMT.Chen2022Type(FT)
ce = CMT.CollisionEfficiency(FT)
rain_acnv_1m = CMT.Autoconversion1M(FT, rain)
Expand All @@ -56,8 +56,8 @@ function test_microphysics(FT)

TT.@testset "τ_relax" begin

TT.@test CMNe.τ_relax(prs, liquid) FT(10)
TT.@test CMNe.τ_relax(prs, ice) FT(10)
TT.@test CMNe.τ_relax(liquid) FT(10)
TT.@test CMNe.τ_relax(ice) FT(10)

end

Expand Down Expand Up @@ -180,13 +180,12 @@ function test_microphysics(FT)
q_liq_sat = FT(5e-3)
frac = [FT(0), FT(0.5), FT(1), FT(1.5)]

_τ_cond_evap = CMNe.τ_relax(prs, liquid)
_τ_cond_evap = CMNe.τ_relax(liquid)

for fr in frac
q_liq = q_liq_sat * fr

TT.@test CMNe.conv_q_vap_to_q_liq_ice(
prs,
liquid,
TD.PhasePartition(FT(0), q_liq_sat, FT(0)),
TD.PhasePartition(FT(0), q_liq, FT(0)),
Expand All @@ -199,13 +198,12 @@ function test_microphysics(FT)
q_ice_sat = FT(2e-3)
frac = [FT(0), FT(0.5), FT(1), FT(1.5)]

_τ_cond_evap = CMNe.τ_relax(prs, ice)
_τ_cond_evap = CMNe.τ_relax(ice)

for fr in frac
q_ice = q_ice_sat * fr

TT.@test CMNe.conv_q_vap_to_q_liq_ice(
prs,
ice,
TD.PhasePartition(FT(0), FT(0), q_ice_sat),
TD.PhasePartition(FT(0), FT(0), q_ice),
Expand Down
4 changes: 2 additions & 2 deletions test/performance_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function benchmark_test(FT)
toml_dict = CP.create_toml_dict(FT; dict_type = "alias")
prs = cloud_microphysics_parameters(toml_dict)
p3 = CMP.CloudMicrophysicsParametersP3(FT)
liquid = CMT.LiquidType()
liquid = CMT.LiquidType(FT)
rain = CMT.RainType(FT)
sb2006 = CMT.SB2006Type()
sb2006vel = CMT.SB2006VelType()
Expand Down Expand Up @@ -139,7 +139,7 @@ function benchmark_test(FT)
bench_press(CMI_hom.homogeneous_J, (prs, Delta_a_w), 230)

# non-equilibrium
bench_press(CMN.τ_relax, (prs, liquid), 10)
bench_press(CMN.τ_relax, (liquid,), 10)

# 0-moment
bench_press(CM0.remove_precipitation, (prs, q), 10)
Expand Down

0 comments on commit 8546e18

Please sign in to comment.