Skip to content

Commit 933a3f7

Browse files
committed
refactor: liquid (cloud/rain) terminal velocity
1 parent bb61a3f commit 933a3f7

File tree

4 files changed

+36
-53
lines changed

4 files changed

+36
-53
lines changed

docs/src/plots/TerminalVelocity.jl

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,6 @@ function aspect_ratio_snow_1M_prolate(snow::CMP.Snow, D::FT) where {FT <: Real}
4747
return 16 * ρᵢ^2 * aᵢ^3 / (9 * FT(π) * mᵢ^2)
4848
end
4949

50-
"""
51-
rain_terminal_velocity_individual_Chen(velo_scheme ρₐ, ρᵢ, D_r)
52-
53-
- `velo_scheme` - structs with free parameters
54-
- `ρₐ` - air density
55-
- `ρᵢ` - apparent density of ice particles
56-
- `D` - particle diameter
57-
58-
Returns the fall velocity of a raindrops or ice crystals from Chen et al 2022
59-
"""
60-
function rain_terminal_velocity_individual_Chen(
61-
velo_scheme::CMP.Chen2022VelTypeRain,
62-
ρₐ::FT,
63-
D::FT, #in m
64-
) where {FT <: Real}
65-
ai, bi, ci = CMO.Chen2022_vel_coeffs_B1(velo_scheme, ρₐ)
66-
67-
v = 0
68-
for i in 1:3
69-
v += ai[i] * D^bi[i] * exp(-D * ci[i])
70-
end
71-
return v
72-
end
73-
7450
function ice_terminal_velocity_individual_Chen(
7551
ice::CMP.CloudIce,
7652
velo_scheme::CMP.Chen2022VelTypeSmallIce,
@@ -181,22 +157,23 @@ q_range = range(0, stop = 5 * 1e-3, length = 100)
181157

182158
#! format: off
183159
# velocity values for cloud particle sizes
160+
v_term_rain = CMO.liquid_particle_terminal_velocity(Chen2022.rain, ρ_air)
184161
SB_rain_small = [rain_terminal_velocity_individual_SB(SB2006Vel, ρ_air, D_r) for D_r in D_r_range_small]
185162
M1_rain_small = [terminal_velocity_individual_1M(Blk1MVel.rain, ρ_air, D_r) for D_r in D_r_range_small]
186163
M1_snow_small = [terminal_velocity_individual_1M(Blk1MVel.snow, ρ_air, D_r) for D_r in D_r_range_small]
187-
Ch_liq_small = [rain_terminal_velocity_individual_Chen(Chen2022.rain, ρ_air, D_r) for D_r in D_r_range_small]
164+
Ch_liq_small = v_term_rain.(D_r_range_small)
188165
Ch_ice_small = [ice_terminal_velocity_individual_Chen(ice, Chen2022.small_ice, ρ_air, D_r) for D_r in D_r_range_small]
189-
Ch_rain_small = [rain_terminal_velocity_individual_Chen(Chen2022.rain, ρ_air, D_r) for D_r in D_r_range_small]
166+
Ch_rain_small = v_term_rain.(D_r_range_small)
190167
Ch_snow_small = [snow_terminal_velocity_individual_Chen(snow, Chen2022.large_ice, ρ_air, D_r) for D_r in D_r_range_small]
191168
Ch_snow_small_oblate = [snow_terminal_velocity_individual_Chen_oblate(snow, Chen2022.large_ice, ρ_air, D_r) for D_r in D_r_range_small]
192169
Ch_snow_small_prolate = [snow_terminal_velocity_individual_Chen_prolate(snow, Chen2022.large_ice, ρ_air, D_r) for D_r in D_r_range_small]
193170
# velocity values for precip particle sizes
194171
SB_rain = [rain_terminal_velocity_individual_SB(SB2006Vel, ρ_air, D_r) for D_r in D_r_range]
195172
M1_rain = [terminal_velocity_individual_1M(Blk1MVel.rain, ρ_air, D_r) for D_r in D_r_range]
196173
M1_snow = [terminal_velocity_individual_1M(Blk1MVel.snow, ρ_air, D_r) for D_r in D_r_range]
197-
Ch_liq = [rain_terminal_velocity_individual_Chen(Chen2022.rain, ρ_air, D_r) for D_r in D_r_range]
174+
Ch_liq = v_term_rain.(D_r_range)
198175
Ch_ice = [ice_terminal_velocity_individual_Chen(ice, Chen2022.small_ice, ρ_air, D_r) for D_r in D_r_range]
199-
Ch_rain = [rain_terminal_velocity_individual_Chen(Chen2022.rain, ρ_air, D_r) for D_r in D_r_range]
176+
Ch_rain = v_term_rain.(D_r_range)
200177
Ch_snow = [snow_terminal_velocity_individual_Chen(snow, Chen2022.large_ice, ρ_air, D_r) for D_r in D_r_range]
201178
Ch_snow_oblate = [snow_terminal_velocity_individual_Chen_oblate(snow, Chen2022.large_ice, ρ_air, D_r) for D_r in D_r_range]
202179
Ch_snow_prolate = [snow_terminal_velocity_individual_Chen_prolate(snow, Chen2022.large_ice, ρ_air, D_r) for D_r in D_r_range]

src/Common.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,34 @@ function Chen2022_exponential_pdf(a::FT, b::FT, c::FT, λ_inv::FT, k::Int) where
336336
return a * exp* log(1 / λ_inv) - (b + δ) * log(1 / λ_inv + c)) * SF.gamma(b + δ) / SF.gamma(δ)
337337
end
338338

339+
"""
340+
liquid_particle_terminal_velocity(velocity_params, ρₐ)
341+
342+
Compute the terminal velocity of a liquid particle as a function of its size
343+
(maximum dimension, `D`) using the Chen 2022 parametrization.
344+
345+
# Arguments
346+
- `velocity_params`: a struct with terminal velocity parameters from Chen 2022
347+
- `ρₐ`: air density [kg/m³]
348+
349+
# Returns
350+
- The terminal velocity of a liquid particle as a function of its size (maximum dimension)
351+
following Chen 2022 velocity parametrization.
352+
353+
Needed for numerical integrals in the P3 scheme.
354+
355+
!!! note
356+
We use the same terminal velocity parametrization for cloud and rain water.
357+
"""
358+
function liquid_particle_terminal_velocity(velocity_params::CMP.Chen2022VelTypeRain, ρₐ)
359+
(ai, bi, ci) = Chen2022_vel_coeffs_B1(velocity_params, ρₐ)
360+
v_term(D) = sum(@. sum(ai * D^bi * exp(-ci * D)))
361+
return v_term
362+
end
363+
liquid_particle_terminal_velocity(velocity_params::CMP.Chen2022VelType, ρₐ) =
364+
liquid_particle_terminal_velocity(velocity_params.rain, ρₐ)
365+
366+
339367
"""
340368
volume_sphere_D(D)
341369

src/Microphysics2M.jl

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -590,29 +590,6 @@ function rain_self_collection_and_breakup(
590590
return (; sc, br)
591591
end
592592

593-
"""
594-
rain_particle_terminal_velocity(Chen2022, ρₐ)
595-
596-
Compute the terminal velocity of an individual rain drop as a function of its size
597-
(maximum dimension) following Chen 2022 velocity parametrization.
598-
Needed for numerical integrals in the P3 scheme.
599-
600-
# Arguments
601-
- `Chen2022`: terminal velocity parameters from Chen 2022, [`CMP.Chen2022VelTypeRain`](@ref)
602-
- `ρₐ`: air density
603-
604-
# Returns
605-
- The terminal velocity of an individual rain drop as a function
606-
of its size (maximum dimension) following Chen 2022 velocity parametrization.
607-
Needed for numerical integrals in the P3 scheme.
608-
"""
609-
function rain_particle_terminal_velocity(Chen2022::CMP.Chen2022VelTypeRain, ρₐ)
610-
(ai, bi, ci) = CO.Chen2022_vel_coeffs_B1(Chen2022, ρₐ)
611-
612-
v(D) = sum(@. sum(ai * D^bi * exp(-ci * D)))
613-
return v
614-
end
615-
616593
"""
617594
rain_terminal_velocity(SB2006, vel, q_rai, ρ, N_rai)
618595

test/p3_tests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using Test: @testset, @test, @test_throws, @test_broken
22
import CloudMicrophysics.P3Scheme as P3
33
import CloudMicrophysics.Parameters as CMP
44
import CloudMicrophysics.Microphysics2M as CM2
5+
import CloudMicrophysics.Common as CO
56
import Thermodynamics as TD
67
import ClimaParams as CP
78

@@ -236,9 +237,9 @@ function test_particle_terminal_velocities(FT)
236237
@testset "Smoke tests for cloud/rain particle terminal vel from Chen 2022" begin
237238
Ds = range(FT(1e-6), stop = FT(1e-5), length = 5) # TODO: Add tests for larger sizes
238239
expected = [0.002508, 0.009156, 0.01632, 0.02377, 0.03144]
239-
vel_func = CM2.rain_particle_terminal_velocity(Chen2022.rain, ρ_a)
240+
v_term = CO.liquid_particle_terminal_velocity(Chen2022.rain, ρ_a)
240241
for i in axes(Ds, 1)
241-
vel = vel_func(Ds[i])
242+
vel = v_term(Ds[i])
242243
@test vel >= 0
243244
@test vel expected[i] rtol = 1e-3
244245
end

0 commit comments

Comments
 (0)