Skip to content

Commit

Permalink
Named tuple in 2M evaporation, changed aerosol model constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
trontrytel committed May 9, 2024
1 parent a60366d commit b4a8a90
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 103 deletions.
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ CloudMicrophysics.jl Release Notes
main
------
<!--- # Add changes since the most recent release here --->


v0.20.0
------

- API change:
- return a named tuple in 2-moment microphysics rain evaporation
- changed aerosol size distribution constructor
- [#392](https://github.com/CliMA/CloudMicrophysics.jl/pull/392)

- Added AIDA homogeneous ice nucleation data as artifacts ([#388](https://github.com/CliMA/CloudMicrophysics.jl/pull/388))

- Generalize calibration functions in ice_nucleation_2024 ([#380](https://github.com/CliMA/CloudMicrophysics.jl/pull/380))
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CloudMicrophysics"
uuid = "6a9e3e04-43cd-43ba-94b9-e8782df3c71b"
authors = ["Climate Modeling Alliance"]
version = "0.19.0"
version = "0.20.0"

[deps]
ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
Expand Down
21 changes: 0 additions & 21 deletions docs/src/plots/ARGplots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ function make_ARG_figX(X)
if X in (1, 4)
vol_mixing_ratios_1 = (1.0,)
mass_mixing_ratios_1 = (1.0,)
n_components_1 = 1
if v_B
paper_mode_1 = AM.Mode_B(
r_dry_1,
Expand All @@ -81,7 +80,6 @@ function make_ARG_figX(X)
(sulfate.M,),
(sulfate.ν,),
(sulfate.ρ,),
n_components_1,
)
else
paper_mode_1 = AM.Mode_κ(
Expand All @@ -92,15 +90,13 @@ function make_ARG_figX(X)
mass_mixing_ratios_1,
(sulfate.M,),
(sulfate.κ,),
n_components_1,
)
end
end

if X in (2, 3, 5)
vol_mixing_ratios_1 = (1.0, 0.0)
mass_mixing_ratios_1 = (1.0, 0.0)
n_components_1 = 2
if v_B
paper_mode_1 = AM.Mode_B(
r_dry_1,
Expand All @@ -112,7 +108,6 @@ function make_ARG_figX(X)
(sulfate.M, M_insol),
(sulfate.ν, ν_insol),
(sulfate.ρ, ρ_insol),
n_components_1,
)
else
paper_mode_1 = AM.Mode_κ(
Expand All @@ -123,7 +118,6 @@ function make_ARG_figX(X)
mass_mixing_ratios_1,
(sulfate.M, M_insol),
(sulfate.κ, κ_insol),
n_components_1,
)
end
end
Expand All @@ -139,7 +133,6 @@ function make_ARG_figX(X)
w = 0.5 # vertical velocity, m/s
r_dry_2 = 0.05 * 1e-6 # um
N_2 = range(100, stop = 5000, length = len) * 1e6 # 1/m3
n_components_2 = 1 # 1 mode
mass_mixing_ratios_2 = (1.0,) # all sulfate
vol_mixing_ratios_2 = (1.0,) # all sulfate

Expand All @@ -155,7 +148,6 @@ function make_ARG_figX(X)
(sulfate.M,),
(sulfate.ν,),
(sulfate.ρ,),
n_components_2,
)
else
paper_mode_2 = AM.Mode_κ(
Expand All @@ -166,7 +158,6 @@ function make_ARG_figX(X)
mass_mixing_ratios_2,
(sulfate.M,),
(sulfate.κ,),
n_components_2,
)
end
AD = AM.AerosolDistribution((paper_mode_1, paper_mode_2))
Expand Down Expand Up @@ -195,7 +186,6 @@ function make_ARG_figX(X)
w = 0.5 # vertical velocity, m/s
r_dry_2 = 0.05 * 1e-6 # um
N_2 = range(100, stop = 5000, length = len) * 1e6 # 1/m3
n_components_2 = 2 # 2 modes
mass_mixing_ratios_2 = (0.1, 0.9) # 10% sulfate, 90% insoluble
vol_mixing_ratios_2 = mass2vol(mass_mixing_ratios_2)

Expand All @@ -211,7 +201,6 @@ function make_ARG_figX(X)
(sulfate.M, M_insol),
(sulfate.ν, ν_insol),
(sulfate.ρ, ρ_insol),
n_components_2,
)
else
paper_mode_2 = AM.Mode_κ(
Expand All @@ -222,7 +211,6 @@ function make_ARG_figX(X)
mass_mixing_ratios_2,
(sulfate.M, M_insol),
(sulfate.κ, κ_insol),
n_components_2,
)
end
AD = AM.AerosolDistribution((paper_mode_1, paper_mode_2))
Expand Down Expand Up @@ -251,7 +239,6 @@ function make_ARG_figX(X)
w = 0.5 # vertical velocity, m/s
r_dry_2 = 0.05 * 1e-6 # um
N_2 = 100 * 1e6 # 1/m3
n_components_2 = 2 # 2 modes
# ranging from 10% to 100% sulfate, 90% to 0% insoluble
xvar = range(0.1, stop = 1, length = len)
mass_mixing_ratios_2 = [(i, 1 - i) for i in xvar]
Expand All @@ -269,7 +256,6 @@ function make_ARG_figX(X)
(sulfate.M, M_insol),
(sulfate.ν, ν_insol),
(sulfate.ρ, ρ_insol),
n_components_2,
)
else
paper_mode_2 = AM.Mode_κ(
Expand All @@ -280,7 +266,6 @@ function make_ARG_figX(X)
mmr2i,
(sulfate.M, M_insol),
(sulfate.κ, κ_insol),
n_components_2,
)
end
AD = AM.AerosolDistribution((paper_mode_1, paper_mode_2))
Expand Down Expand Up @@ -308,7 +293,6 @@ function make_ARG_figX(X)
w = 0.5 # vertical velocity, m/s
r_dry_2 = range(0.01, stop = 0.5, length = len) * 1e-6 # um
N_2 = 100 * 1e6 # 1/m3
n_components_2 = 1 # 1 mode
mass_mixing_ratios_2 = (1.0,) # all sulfate
vol_mixing_ratios_2 = mass2vol(mass_mixing_ratios_2)

Expand All @@ -324,7 +308,6 @@ function make_ARG_figX(X)
(sulfate.M,),
(sulfate.ν,),
(sulfate.ρ,),
n_components_2,
)
else
paper_mode_2 = AM.Mode_κ(
Expand All @@ -335,7 +318,6 @@ function make_ARG_figX(X)
mass_mixing_ratios_2,
(sulfate.M,),
(sulfate.κ,),
n_components_2,
)
end
AD = AM.AerosolDistribution((paper_mode_1, paper_mode_2))
Expand Down Expand Up @@ -364,7 +346,6 @@ function make_ARG_figX(X)
w = range(0.01, stop = 5, length = len) # vertical velocity, m/s
r_dry_2 = 0.05 * 1e-6 # um
N_2 = 100 * 1e6 # 1/m3
n_components_2 = 2 # 2 modes
mass_mixing_ratios_2 = (0.1, 0.9) # 10% sulfate, 90% insoluble
vol_mixing_ratios_2 = mass2vol(mass_mixing_ratios_2)

Expand All @@ -379,7 +360,6 @@ function make_ARG_figX(X)
(sulfate.M, M_insol),
(sulfate.ν, ν_insol),
(sulfate.ρ, ρ_insol),
n_components_2,
)
else
paper_mode_2 = AM.Mode_κ(
Expand All @@ -390,7 +370,6 @@ function make_ARG_figX(X)
mass_mixing_ratios_2,
(sulfate.M, M_insol),
(sulfate.κ, κ_insol),
n_components_2,
)
end
AD = AM.AerosolDistribution((paper_mode_1, paper_mode_2))
Expand Down
4 changes: 0 additions & 4 deletions docs/src/plots/ARGplots_fig1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ N_1 = 100.0 * 1e6 # 1/m3
# Sulfate - universal parameters
sulfate = CMP.Sulfate(FT)

n_components_1 = 1
mass_fractions_1 = (1.0,)
paper_mode_1_B = AM.Mode_B(
r_dry,
Expand All @@ -49,15 +48,13 @@ paper_mode_1_B = AM.Mode_B(
(sulfate.M,),
(sulfate.ν,),
(sulfate.ρ,),
n_components_1,
)

N_2_range = range(0, stop = 5000 * 1e6, length = 100)
N_act_frac_B = Vector{Float64}(undef, 100)

it = 1
for N_2 in N_2_range
n_components_2 = 1
mass_fractions_2 = (1.0,)
paper_mode_2_B = AM.Mode_B(
r_dry,
Expand All @@ -69,7 +66,6 @@ for N_2 in N_2_range
(sulfate.M,),
(sulfate.ν,),
(sulfate.ρ,),
n_components_2,
)
AD_B = AM.AerosolDistribution((paper_mode_1_B, paper_mode_2_B))
N_act_frac_B[it] =
Expand Down
26 changes: 13 additions & 13 deletions docs/src/plots/RainEvapoartionSB2006.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function rain_evaporation_CPU(SB2006, aps, tps, q, q_rai, ρ, N_rai, T)
evap_rate_1 = min(FT(0), FT(2) * FT(π) * G * S * N_rai * Dr * Fv1 / ρ)
end

return (evap_rate_0, evap_rate_1)
return (; evap_rate_0, evap_rate_1)
end

qᵥ = FT(1e-2)
Expand All @@ -66,21 +66,21 @@ Nᵣ_range = range(1e6, stop = 1e9, length = 1000)
T_range = range(273.15, stop = 273.15 + 50, length = 1000)

#! format: off
evap_qᵣ_0 = [rain_evaporation_CPU(SB2006, aps, tps, q, _qᵣ, ρ, Nᵣ, T)[1] for _qᵣ in qᵣ_range]
evap_Nᵣ_0 = [rain_evaporation_CPU(SB2006, aps, tps, q, qᵣ, ρ, _Nᵣ, T)[1] for _Nᵣ in Nᵣ_range]
evap_T_0 = [rain_evaporation_CPU(SB2006, aps, tps, q, qᵣ, ρ, Nᵣ, _T)[1] for _T in T_range]
evap_qᵣ_0 = [rain_evaporation_CPU(SB2006, aps, tps, q, _qᵣ, ρ, Nᵣ, T).evap_rate_0 for _qᵣ in qᵣ_range]
evap_Nᵣ_0 = [rain_evaporation_CPU(SB2006, aps, tps, q, qᵣ, ρ, _Nᵣ, T).evap_rate_0 for _Nᵣ in Nᵣ_range]
evap_T_0 = [rain_evaporation_CPU(SB2006, aps, tps, q, qᵣ, ρ, Nᵣ, _T).evap_rate_0 for _T in T_range]

evap_qᵣ_0n = [CM2.rain_evaporation(SB2006, aps, tps, q, _qᵣ, ρ, Nᵣ, T)[1] for _qᵣ in qᵣ_range]
evap_Nᵣ_0n = [CM2.rain_evaporation(SB2006, aps, tps, q, qᵣ, ρ, _Nᵣ, T)[1] for _Nᵣ in Nᵣ_range]
evap_T_0n = [CM2.rain_evaporation(SB2006, aps, tps, q, qᵣ, ρ, Nᵣ, _T)[1] for _T in T_range]
evap_qᵣ_0n = [CM2.rain_evaporation(SB2006, aps, tps, q, _qᵣ, ρ, Nᵣ, T).evap_rate_0 for _qᵣ in qᵣ_range]
evap_Nᵣ_0n = [CM2.rain_evaporation(SB2006, aps, tps, q, qᵣ, ρ, _Nᵣ, T).evap_rate_0 for _Nᵣ in Nᵣ_range]
evap_T_0n = [CM2.rain_evaporation(SB2006, aps, tps, q, qᵣ, ρ, Nᵣ, _T).evap_rate_0 for _T in T_range]

evap_qᵣ_3 = [rain_evaporation_CPU(SB2006, aps, tps, q, _qᵣ, ρ, Nᵣ, T)[2] for _qᵣ in qᵣ_range]
evap_Nᵣ_3 = [rain_evaporation_CPU(SB2006, aps, tps, q, qᵣ, ρ, _Nᵣ, T)[2] for _Nᵣ in Nᵣ_range]
evap_T_3 = [rain_evaporation_CPU(SB2006, aps, tps, q, qᵣ, ρ, Nᵣ, _T)[2] for _T in T_range]
evap_qᵣ_3 = [rain_evaporation_CPU(SB2006, aps, tps, q, _qᵣ, ρ, Nᵣ, T).evap_rate_1 for _qᵣ in qᵣ_range]
evap_Nᵣ_3 = [rain_evaporation_CPU(SB2006, aps, tps, q, qᵣ, ρ, _Nᵣ, T).evap_rate_1 for _Nᵣ in Nᵣ_range]
evap_T_3 = [rain_evaporation_CPU(SB2006, aps, tps, q, qᵣ, ρ, Nᵣ, _T).evap_rate_1 for _T in T_range]

evap_qᵣ_3n = [CM2.rain_evaporation(SB2006, aps, tps, q, _qᵣ, ρ, Nᵣ, T)[2] for _qᵣ in qᵣ_range]
evap_Nᵣ_3n = [CM2.rain_evaporation(SB2006, aps, tps, q, qᵣ, ρ, _Nᵣ, T)[2] for _Nᵣ in Nᵣ_range]
evap_T_3n = [CM2.rain_evaporation(SB2006, aps, tps, q, qᵣ, ρ, Nᵣ, _T)[2] for _T in T_range]
evap_qᵣ_3n = [CM2.rain_evaporation(SB2006, aps, tps, q, _qᵣ, ρ, Nᵣ, T).evap_rate_1 for _qᵣ in qᵣ_range]
evap_Nᵣ_3n = [CM2.rain_evaporation(SB2006, aps, tps, q, qᵣ, ρ, _Nᵣ, T).evap_rate_1 for _Nᵣ in Nᵣ_range]
evap_T_3n = [CM2.rain_evaporation(SB2006, aps, tps, q, qᵣ, ρ, Nᵣ, _T).evap_rate_1 for _T in T_range]

fig = MK.Figure(resolution = (800, 600))

Expand Down
6 changes: 2 additions & 4 deletions ext/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function read_aerosol_dataset(
df = filter(row -> row.S_max > 0 && row.S_max < 0.2, initial_data)
selected_columns_X = []
num_modes = get_num_modes(df)
@info(num_modes)
for i in 1:num_modes
append!(
selected_columns_X,
Expand Down Expand Up @@ -97,7 +96,7 @@ function get_ARG_act_frac(
push!(mode_kappas, data_row[Symbol("mode_$(i)_kappa")])
end
ad = AM.AerosolDistribution(
Tuple(
(
AM.Mode_κ(
mode_means[i],
mode_stdevs[i],
Expand All @@ -106,9 +105,8 @@ function get_ARG_act_frac(
FT(1),
FT(0),
FT(mode_kappas[i]),
1,
) for i in 1:num_modes
),
)...,
)
pv0 = TD.saturation_vapor_pressure(tps, FT(T), TD.Liquid())
vapor_mix_ratio = pv0 / TD.Parameters.molmass_ratio(tps) / (p - pv0)
Expand Down
12 changes: 6 additions & 6 deletions src/AerosolActivation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function mean_hygroscopicity_parameter(
) where {N, T <: AM.Mode_B}
return ntuple(Val(AM.n_modes(ad))) do i
FT = eltype(ap)
mode_i = ad.Modes[i]
mode_i = ad.modes[i]

nom = FT(0)
@inbounds for j in 1:(AM.n_components(mode_i))
Expand All @@ -85,7 +85,7 @@ function mean_hygroscopicity_parameter(

return ntuple(Val(AM.n_modes(ad))) do i
FT = eltype(ap)
mode_i = ad.Modes[i]
mode_i = ad.modes[i]

result = FT(0)
@inbounds for j in 1:(AM.n_components(mode_i))
Expand Down Expand Up @@ -114,7 +114,7 @@ function critical_supersaturation(
hygro = mean_hygroscopicity_parameter(ap, ad)

return ntuple(Val(AM.n_modes(ad))) do i
2 / sqrt(hygro[i]) * (A / 3 / ad.Modes[i].r_dry)^FT(3 / 2)
2 / sqrt(hygro[i]) * (A / 3 / ad.modes[i].r_dry)^FT(3 / 2)
end
end

Expand Down Expand Up @@ -163,7 +163,7 @@ function max_supersaturation(
tmp::FT = FT(0)
@inbounds for i in 1:AM.n_modes(ad)

mode_i = ad.Modes[i]
mode_i = ad.modes[i]

f::FT = ap.f1 * exp(ap.f2 * (log(mode_i.stdev))^2)
g::FT = ap.g1 + ap.g2 * log(mode_i.stdev)
Expand Down Expand Up @@ -207,7 +207,7 @@ function N_activated_per_mode(

return ntuple(Val(AM.n_modes(ad))) do i

mode_i = ad.Modes[i]
mode_i = ad.modes[i]
u_i::FT = 2 * log(sm[i] / smax) / 3 / sqrt(2) / log(mode_i.stdev)

mode_i.N * (1 / 2) * (1 - SF.erf(u_i))
Expand Down Expand Up @@ -244,7 +244,7 @@ function M_activated_per_mode(

return ntuple(Val(AM.n_modes(ad))) do i

mode_i = ad.Modes[i]
mode_i = ad.modes[i]

avg_molar_mass_i = FT(0)
@inbounds for j in 1:(AM.n_components(mode_i))
Expand Down
Loading

0 comments on commit b4a8a90

Please sign in to comment.