Skip to content

Commit

Permalink
updating climaparameters
Browse files Browse the repository at this point in the history
  • Loading branch information
amylu00 committed Feb 16, 2024
1 parent 4051ac6 commit a35f8c6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 27 deletions.
4 changes: 2 additions & 2 deletions parcel/parcel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function parcel_model(dY, Y, p, t)
end
end
if "P3_Deposition" in ice_nucleation_modes
Nᵢ_depo = CMI_het.P3_deposition_N_i(T)
Nᵢ_depo = CMI_het.P3_deposition_N_i(ip.p3, T)
dN_act_dt_depo = max(FT(0), (Nᵢ_depo - N_ice) / const_dt)
dqi_dt_new_depo = dN_act_dt_depo * 4 / 3 * FT(π) * r_nuc^3 * ρ_ice / ρ_air
end
Expand Down Expand Up @@ -140,7 +140,7 @@ function parcel_model(dY, Y, p, t)
r_l = 2 / λ
end
V_l = FT(4 / 3 * π * r_l^3)
Nᵢ_het = CMI_het.P3_het_N_i(T, N_liq, V_l, const_dt)
Nᵢ_het = CMI_het.P3_het_N_i(ip.p3, T, N_liq, V_l, const_dt)
dN_act_dt_immersion = max(FT(0), (Nᵢ_het - N_ice) / const_dt)
dqi_dt_new_immers = dN_act_dt_immersion * 4 / 3 * FT(π) * r_l^3 * ρ_ice / ρ_air
end
Expand Down
20 changes: 11 additions & 9 deletions src/IceNucleation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,18 @@ function ABIFM_J(
end

"""
P3_deposition_N_i(T)
P3_deposition_N_i(ip, T)
- `ip` - a struct with ice nucleation parameters,
- `T` - air temperature [K].
Returns the number of ice nucleated via deposition nucleation with units of m^-3.
From Thompson et al 2004 eqn 2 as used in Morrison & Milbrandt 2015.
"""
function P3_deposition_N_i(T::FT) where {FT}
function P3_deposition_N_i(ip::CMP.MorrisonMilbrandt2014, T::FT) where {FT}

T₀ = FT(273.15)
T_thres = FT(233)
T₀ = ip.T₀ # 0°C
T_thres = ip.T_dep_thres # cutoff temperature

Nᵢ = ifelse(
T < T_thres,
Expand All @@ -133,8 +134,9 @@ function P3_deposition_N_i(T::FT) where {FT}
end

"""
P3_het_N_i(T, N_l, B, V_l, a, Δt)
P3_het_N_i(ip, T, N_l, B, V_l, a, Δt)
- `ip` - a struct with ice nucleation parameters,
- `T` - air temperature [K],
- `N_l` - number of droplets [m^-3],
- `B` - water-type dependent parameter [cm^-3 s^-1],
Expand All @@ -146,12 +148,12 @@ Returns the number of ice nucleated within Δt via heterogeneous freezing
with units of m^-3. From Pruppacher & Klett 1997 eqn (9-51) as used in
Morrison & Milbrandt 2015.
"""
function P3_het_N_i(T::FT, N_l::FT, V_l::FT, Δt::FT) where {FT}
function P3_het_N_i(ip::CMP.MorrisonMilbrandt2014, T::FT, N_l::FT, V_l::FT, Δt::FT) where {FT}

a = 0.65 # (celcius)^-1
B = 2e-4 # cm^-3 s^-1 for rain water
a = ip.het_a # (celcius)^-1
B = ip.het_b # cm^-3 s^-1 for rain water
V_l_converted = V_l * 1e6 # converted from m^3 to cm^3
Tₛ = FT(273.15) - T
Tₛ = ip.T₀ - T

return N_l * (1 - exp(-B * V_l_converted * Δt * exp(a * Tₛ)))
end
Expand Down
41 changes: 38 additions & 3 deletions src/parameters/IceNucleation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,49 @@ function Koop2000(td::CP.AbstractTOMLDict)
end

"""
IceNucleationParameters{FT, DEP, HOM}
MorrisonMilbrandt2014{FT}
Parameters for ice nucleation from Morrison & Milbrandt 2014
DOI: 10.1175/JAS-D-14-0065.1
# Fields
$(DocStringExtensions.FIELDS)
"""
Base.@kwdef struct MorrisonMilbrandt2014{FT} <: ParametersType{FT}
"deposition nucleation threshold T [K]"
T_dep_thres::FT
"T₀"
T₀::FT
"heterogeneous freezing parameter a [°C^-1]"
het_a::FT
"heterogeneous freezing parameter B [cm^-3 s^-1]"
het_B::FT
end

function MorrisonMilbrandt2014(td::CP.AbstractTOMLDict)
name_map = (;
:Thompson2004_T_threshold_Cooper => :T_dep_thres,
:temperature_water_freeze => :T₀,
:BarklieGokhale1959_a_parameter => :het_a,
:BarklieGokhale1959_B_parameter => :het_B,
)
parameters = CP.get_parameter_values(td, name_map, "CloudMicrophysics")
FT = CP.float_type(td)
return MorrisonMilbrandt2014{FT}(; parameters...)
end

"""
IceNucleationParameters{FT, DEP, HOM, P3_type}
Parameters for ice nucleation
# Fields
$(DocStringExtensions.FIELDS)
"""
struct IceNucleationParameters{FT, DEP, HOM} <: ParametersType{FT}
struct IceNucleationParameters{FT, DEP, HOM, P3_type} <: ParametersType{FT}
deposition::DEP
homogeneous::HOM
p3::P3_type
end

IceNucleationParameters(::Type{FT}) where {FT <: AbstractFloat} =
Expand All @@ -84,10 +117,12 @@ IceNucleationParameters(::Type{FT}) where {FT <: AbstractFloat} =
function IceNucleationParameters(toml_dict::CP.AbstractTOMLDict)
deposition = Mohler2006(toml_dict)
homogeneous = Koop2000(toml_dict)
p3 = MorrisonMilbrandt2014(toml_dict)
DEP = typeof(deposition)
HOM = typeof(homogeneous)
P3_type = typeof(p3)
FT = CP.float_type(toml_dict)
return IceNucleationParameters{FT, DEP, HOM}(deposition, homogeneous)
return IceNucleationParameters{FT, DEP, HOM, P3_type}(deposition, homogeneous, p3)
end


Expand Down
11 changes: 7 additions & 4 deletions test/gpu_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -570,18 +570,20 @@ end

@kernel function IceNucleation_P3_deposition_N_i_kernel!(
output::AbstractArray{FT},
ip,
T,
) where {FT}

i = @index(Group, Linear)

@inbounds begin
output[1] = CMI_het.P3_deposition_N_i(T[1])
output[1] = CMI_het.P3_deposition_N_i(ip, T[1])
end
end

@kernel function IceNucleation_P3_het_N_i_kernel!(
output::AbstractArray{FT},
ip,
T,
N_l,
V_l,
Expand All @@ -591,7 +593,7 @@ end
i = @index(Group, Linear)

@inbounds begin
output[1] = CMI_het.P3_het_N_i(T[1], N_l[1], V_l[1], Δt[1])
output[1] = CMI_het.P3_het_N_i(ip, T[1], N_l[1], V_l[1], Δt[1])
end
end

Expand Down Expand Up @@ -1016,10 +1018,11 @@ function test_gpu(FT)
dims = (1, 1)
(; output, ndrange) = setup_output(dims, FT)

ip_P3 = ip.p3
T = ArrayType([FT(240)])

kernel! = IceNucleation_P3_deposition_N_i_kernel!(backend, work_groups)
kernel!(output, T; ndrange)
kernel!(output, ip_P3, T; ndrange)

# test if P3_deposition_N_i is callable and returns reasonable values
@test Array(output)[1] FT(119018.93920746)
Expand All @@ -1033,7 +1036,7 @@ function test_gpu(FT)
Δt = ArrayType([FT(0.1)])

kernel! = IceNucleation_P3_het_N_i_kernel!(backend, work_groups)
kernel!(output, T, N_l, V_l, Δt; ndrange)
kernel!(output, ip_P3, T, N_l, V_l, Δt; ndrange)

# test if P3_het_N_i is callable and returns reasonable values
@test Array(output)[1] FT(0.0002736160475969029)
Expand Down
12 changes: 6 additions & 6 deletions test/heterogeneous_ice_nucleation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ function test_heterogeneous_ice_nucleation(FT)
T_too_cold = FT(232)

# higher ice concentration at colder temperatures
TT.@test CMI_het.P3_deposition_N_i(T_cold) >
CMI_het.P3_deposition_N_i(T_warm)
TT.@test CMI_het.P3_deposition_N_i(ip.p3, T_cold) >
CMI_het.P3_deposition_N_i(ip.p3, T_warm)

# if colder than threshold T, use threshold T
TT.@test CMI_het.P3_deposition_N_i(T_too_cold) ==
CMI_het.P3_deposition_N_i(FT(233))
TT.@test CMI_het.P3_deposition_N_i(ip.p3, T_too_cold) ==
CMI_het.P3_deposition_N_i(ip.p3, ip.p3.T_dep_thres)
end

TT.@testset "ABIFM J" begin
Expand Down Expand Up @@ -205,8 +205,8 @@ function test_heterogeneous_ice_nucleation(FT)
Δt = FT(0.1)

# higher ice concentration at colder temperatures
TT.@test CMI_het.P3_het_N_i(T_cold, N_liq, V_l, Δt) >
CMI_het.P3_het_N_i(T_warm, N_liq, V_l, Δt)
TT.@test CMI_het.P3_het_N_i(ip.p3, T_cold, N_liq, V_l, Δt) >
CMI_het.P3_het_N_i(ip.p3, T_warm, N_liq, V_l, Δt)
end

TT.@testset "Frostenberg" begin
Expand Down
6 changes: 3 additions & 3 deletions test/performance_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ function benchmark_test(FT)
80,
)
bench_press(CMI_het.deposition_J, (kaolinite, Delta_a_w), 230)
bench_press(CMI_het.P3_deposition_N_i, (T_air_cold), 230)
bench_press(CMI_het.P3_deposition_N_i, (ip.p3, T_air_cold), 230)
bench_press(CMI_het.ABIFM_J, (desert_dust, Delta_a_w), 230)
bench_press(CMI_het.P3_het_N_i, (T_air_cold, N_liq, V_liq, Δt), 230)
bench_press(CMI_het.P3_het_N_i, (ip.p3, T_air_cold, N_liq, V_liq, Δt), 230)
bench_press(
CMI_het.INP_concentration_frequency,
(ip_frostenberg, INPC, T_air_cold),
110,
150,
)
bench_press(CMI_hom.homogeneous_J, (ip.homogeneous, Delta_a_w), 230)

Expand Down

0 comments on commit a35f8c6

Please sign in to comment.