-
Notifications
You must be signed in to change notification settings - Fork 6
/
P3Scheme.jl
670 lines (561 loc) · 20.3 KB
/
P3Scheme.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
"""
Predicted particle properties scheme (P3) for ice, which includes:
- threshold solver
- shape parameters solver
- m(D) regime
- a(D) regime
Implementation of Morrison and Milbrandt 2015 doi: 10.1175/JAS-D-14-0065.1
Note: Particle size is defined as its maximum length (i.e. max dimesion).
"""
module P3Scheme
import SpecialFunctions as SF
import QuadGK as QGK
import RootSolvers as RS
import ClimaParams as CP
import CloudMicrophysics.Parameters as CMP
import CloudMicrophysics.Common as CO
const PSP3 = CMP.ParametersP3
export thresholds, distribution_parameter_solver
"""
α_va_si(p3)
- p3 - a struct with P3 scheme parameters
Returns `α_va` coefficient for the assumed particle mass(size) relation for
large unrimed ice and dense nonspherical ice, in base SI units: kg m^(-β_va).
`β_va` is another coefficient of the mass(size) relation.
From measurements of mass grown by vapor diffusion and aggregation
in midlatitude cirrus by Brown and Francis (1995)
doi: 10.1175/1520-0426(1995)012<0410:IMOTIW>2.0.CO;2
"""
α_va_si(p3::PSP3{FT}) where {FT} = p3.α_va * 10^(6 * p3.β_va - 3)
"""
D_th_helper(p3)
- p3 - a struct with P3 scheme parameters
Returns the critical size separating spherical and nonspherical ice, in meters.
Eq. 8 in Morrison and Milbrandt (2015).
"""
D_th_helper(p3::PSP3{FT}) where {FT} =
(FT(π) * p3.ρ_i / 6 / α_va_si(p3))^(1 / (p3.β_va - 3))
"""
D_cr_helper(p3, F_r, ρ_g)
- p3 - a struct with P3 scheme parameters
- F_r - rime mass fraction (q_rim/q_i) [-]
- ρ_g - is the effective density of a spherical graupel particle [kg/m^3]
Returns the size of equal mass for graupel and partially rimed ice, in meters.
Eq. 14 in Morrison and Milbrandt (2015).
"""
function D_cr_helper(p3::PSP3{FT}, F_r::FT, ρ_g::FT) where {FT}
α_va = α_va_si(p3)
return (1 / (1 - F_r) * 6 * α_va / FT(π) / ρ_g)^(1 / (3 - p3.β_va))
end
"""
D_gr_helper(p3, ρ_g)
- p3 - a struct with P3 scheme parameters
- ρ_g - is the effective density of a spherical graupel particle [kg/m^3]
Returns the size of equal mass for graupel and unrimed ice, in meters.
Eq. 15 in Morrison and Milbrandt (2015).
"""
function D_gr_helper(p3::PSP3{FT}, ρ_g::FT) where {FT}
α_va = α_va_si(p3)
return (6 * α_va / FT(π) / ρ_g)^(1 / (3 - p3.β_va))
end
"""
ρ_g_helper(ρ_r, F_r, ρ_d)
- ρ_r - rime density (q_rim/B_rim) [kg/m^3]
- F_r - rime mass fraction (q_rim/q_i) [-]
- ρ_g - is the effective density of a spherical graupel particle [kg/m^3]
Returns the density of total (deposition + rime) ice mass for graupel, in kg/m3
Eq. 16 in Morrison and Milbrandt (2015).
"""
ρ_g_helper(ρ_r::FT, F_r::FT, ρ_d::FT) where {FT} = F_r * ρ_r + (1 - F_r) * ρ_d
"""
ρ_d_helper(p3, D_cr, D_gr)
- p3 - a struct with P3 scheme parameters
- D_cr - is the size of equal mass for graupel and partially rimed ice, in meters
- D_gr - the size of equal mass for graupel and unrimed ice, in meters
Returns the density of unrimed ice mass, in kg/m3
Eq. 17 in Morrison and Milbrandt (2015).
"""
function ρ_d_helper(p3::PSP3{FT}, D_cr::FT, D_gr::FT) where {FT}
α_va = α_va_si(p3)
β_m2 = p3.β_va - 2
return 6 * α_va * (D_cr^β_m2 - D_gr^β_m2) / FT(π) / β_m2 /
max(D_cr - D_gr, eps(FT))
end
"""
thresholds(p3, ρ_r, F_r)
- p3 - a struct with P3 scheme parameters
- ρ_r - rime density (q_rim/B_rim) [kg/m^3]
- F_r - rime mass fraction (q_rim/q_i) [-]
Solves the nonlinear system consisting of D_cr, D_gr, ρ_g, ρ_d
for a given rime density and rime mass fraction.
Returns a named tuple containing:
- D_cr - is the threshold size separating partially rimed ice and graupel [m],
- D_gr - is the threshold size separating graupel and dense nonspherical ice [m],
- ρ_g - is the effective density of a spherical graupel particle [kg/m3],
- ρ_d - is the density of the unrimed portion of the particle [kg/m3],
"""
function thresholds(p3::PSP3{FT}, ρ_r::FT, F_r::FT) where {FT}
@assert F_r >= FT(0) # rime mass fraction must be positive ...
@assert F_r < FT(1) # ... and there must always be some unrimed part
if F_r == FT(0)
return (; D_cr = FT(0), D_gr = FT(0), ρ_g = FT(0), ρ_d = FT(0))
else
@assert ρ_r > FT(0) # rime density must be positive ...
@assert ρ_r <= p3.ρ_l # ... and as a bulk ice density can't exceed the density of water
P3_problem(ρ_d) =
ρ_d - ρ_d_helper(
p3,
D_cr_helper(p3, F_r, ρ_g_helper(ρ_r, F_r, ρ_d)),
D_gr_helper(p3, ρ_g_helper(ρ_r, F_r, ρ_d)),
)
ρ_d =
RS.find_zero(
P3_problem,
RS.SecantMethod(FT(0), FT(1000)),
RS.CompactSolution(),
).root
ρ_g = ρ_g_helper(ρ_r, F_r, ρ_d)
return (;
D_cr = D_cr_helper(p3, F_r, ρ_g),
D_gr = D_gr_helper(p3, ρ_g),
ρ_g,
ρ_d,
)
end
end
# Some wrappers to cast types from SF.gamma
# (which returns Float64 even when the input is Float32)
Γ(a::FT, z::FT) where {FT <: Real} = FT(SF.gamma(a, z))
Γ(a::FT) where {FT <: Real} = FT(SF.gamma(a))
"""
μ_to_λ(μ)
- μ - parameter for gamma distribution of N′
Returns corresponding λ to given μ value
"""
function μ_to_λ(p3::PSP3, μ::FT) where {FT}
return ((μ + p3.c) / p3.a)^(1 / p3.b)
end
"""
DSD_μ_approx(p3, q, N, ρ_r, F_r)
- p3 - a struct with P3 scheme parameters
- q - mass mixing ratio
- N - total ice number concentration [1/m3]
- ρ_r - rime density (q_rim/B_rim) [kg/m^3]
- F_r - rime mass fraction (q_rim/q_i)
Returns the approximated shape parameter μ for a given q and N value
"""
function DSD_μ_approx(p3::PSP3, q::FT, N::FT, ρ_r::FT, F_r::FT) where {FT}
# Get thresholds for given F_r, ρ_r
th = thresholds(p3, ρ_r, F_r)
# Get min and max lambda values
λ_0 = μ_to_λ(p3, FT(0))
λ_6 = μ_to_λ(p3, p3.μ_max)
# Get corresponding q/N values at given F_r
q_over_N_min = log(q_over_N_gamma(p3, F_r, log(λ_0), FT(0), th))
q_over_N_max = log(q_over_N_gamma(p3, F_r, log(λ_6), p3.μ_max, th))
# Return approximation between them
μ = (p3.μ_max / (q_over_N_max - q_over_N_min)) * (log(q / N) - q_over_N_min)
# Clip approximation between 0 and 6
return min(p3.μ_max, max(FT(0), μ))
end
"""
DSD_μ(p3, λ)
- p3 - a struct with P3 scheme parameters
- λ - slope parameter for gamma distribution of N′ [1/m]
Returns the shape parameter μ for a given λ value
Eq. 3 in Morrison and Milbrandt (2015).
"""
function DSD_μ(p3::PSP3, λ::FT) where {FT}
#@assert λ > FT(0)
return min(p3.μ_max, max(FT(0), p3.a * λ^p3.b - p3.c))
end
"""
DSD_N₀(p3, μ, N, λ)
- p3 - a struct with P3 scheme parameters
- N - total ice number concentration [1/m3]
- μ - shape parameter of N′ gamma distribution
- λ - slope parameter for gamma distribution of N′ [1/m]
Returns the shape parameter N₀ from Eq. 2 in Morrison and Milbrandt (2015).
"""
function DSD_N₀(p3::PSP3, N::FT, λ::FT) where {FT}
μ = DSD_μ(p3, λ)
return N / Γ(1 + μ) * λ^(1 + μ)
end
"""
∫_Γ(x₀, x_end, c1, c2, c3)
- x₀ - lower bound
- x_end - upper bound
- c1, c2, c3 - respective constants
f(D, c1, c2, c3) = c1 * D ^ (c2) * exp(-c3 * D)
Integrates f(D, c1, c2, c3) dD from x₀ to x_end
"""
function ∫_Γ(x₀::FT, x_end::FT, c1::FT, c2::FT, c3::FT) where {FT}
if x_end == Inf
return c1 * c3^(-c2 - 1) * (Γ(1 + c2, x₀ * c3))
elseif x₀ == 0
return c1 * c3^(-c2 - 1) * (Γ(1 + c2) - Γ(1 + c2, x_end * c3))
else
return c1 * c3^(-c2 - 1) * (Γ(1 + c2, x₀ * c3) - Γ(1 + c2, x_end * c3))
end
end
"""
∫_Γ(x₀, xₘ, x_end, c1, c2, c3, c4, c5, c6)
- x₀ - lower bound
- xₘ - switch point
- x_end - upper bound
- c1, c2, c3 - respective constants for the first part of the integral
- c4, c5, c6 - respective constants for the second part of the integral
f(D, c1, c2, c3) = c1 * D ^ (c2) * exp(-c3 * D)
Integrates f(D, c1, c2, c3) dD from x₀ to xₘ and f(D, c4, c5, c6) dD from xₘ to x_end
"""
function ∫_Γ(
x₀::FT,
xₘ::FT,
x_end::FT,
c1::FT,
c2::FT,
c3::FT,
c4::FT,
c5::FT,
c6::FT,
) where {FT}
return ∫_Γ(x₀, xₘ, c1, c2, c3) + ∫_Γ(xₘ, x_end, c4, c5, c6)
end
"""
q_(p3, ρ, F_r, λ, μ, D_min, D_max)
- p3 - a struct with P3 scheme parameters
- ρ - bulk ice density (ρ_i for small ice, ρ_g for graupel) [kg/m^3]
- F_r - rime mass fraction [q_rim/q_i]
- μ - shape parameter of N′ gamma distribution
- λ - slope parameter of N′ gamma distribution
- D_min - minimum bound for regime
- D_max - maximum bound for regime (if not specified, then infinity)
Returns ice mass density for a given m(D) regime
"""
# small, spherical ice or graupel (completely rimed, spherical)
# D_min = 0, D_max = D_th, ρ = ρᵢ
# or
# q_rim > 0 and D_min = D_gr, D_max = D_cr, ρ = ρ_g
function q_s(p3::PSP3, ρ::FT, μ::FT, λ::FT, D_min::FT, D_max::FT) where {FT}
return ∫_Γ(D_min, D_max, FT(π) / 6 * ρ, μ + 3, λ)
end
# q_rim = 0 and D_min = D_th, D_max = inf
function q_rz(p3::PSP3, μ::FT, λ::FT, D_min::FT) where {FT}
return ∫_Γ(D_min, FT(Inf), α_va_si(p3), μ + p3.β_va, λ)
end
# q_rim > 0 and D_min = D_th and D_max = D_gr
function q_n(p3::PSP3, μ::FT, λ::FT, D_min::FT, D_max::FT) where {FT}
return ∫_Γ(D_min, D_max, α_va_si(p3), μ + p3.β_va, λ)
end
# partially rimed ice or large unrimed ice (upper bound on D is infinity)
# q_rim > 0 and D_min = D_cr, D_max = inf
function q_r(p3::PSP3, F_r::FT, μ::FT, λ::FT, D_min::FT) where {FT}
return ∫_Γ(D_min, FT(Inf), α_va_si(p3) / (1 - F_r), μ + p3.β_va, λ)
end
"""
q_over_N_gamma(p3, F_r, λ, th)
- p3 - a struct with P3 scheme parameters
- F_r - rime mass fraction [q_rim/q_i]
- log_λ - logarithm of the slope parameter of N′ gamma distribution
- μ - shape parameter of N′ gamma distribution
- th - thresholds() nonlinear solve output tuple (D_cr, D_gr, ρ_g, ρ_d)
Returns q/N for all values of D (sum over all regimes).
Eq. 5 in Morrison and Milbrandt (2015).
"""
function q_over_N_gamma(
p3::PSP3,
F_r::FT,
log_λ::FT,
μ::FT,
th = (; D_cr = FT(0), D_gr = FT(0), ρ_g = FT(0), ρ_d = FT(0)),
) where {FT}
D_th = D_th_helper(p3)
λ = exp(log_λ)
N = Γ(1 + μ) / (λ^(1 + μ))
return ifelse(
F_r == FT(0),
(q_s(p3, p3.ρ_i, μ, λ, FT(0), D_th) + q_rz(p3, μ, λ, D_th)) / N,
(
q_s(p3, p3.ρ_i, μ, λ, FT(0), D_th) +
q_n(p3, μ, λ, D_th, th.D_gr) +
q_s(p3, th.ρ_g, μ, λ, th.D_gr, th.D_cr) +
q_r(p3, F_r, μ, λ, th.D_cr)
) / N,
)
end
"""
get_bounds(N, q, F_r, p3, th)
- N - ice number concentration [1/m3]
- q - mass mixing ratio
- μ - shape parameter of N′ gamma distribution
- F_r -rime mass fraction [q_rim/q_i]
- p3 - a struct with P3 scheme parameters
- th - thresholds() nonlinear solve output tuple (D_cr, D_gr, ρ_g, ρ_d)
Returns estimated guess for λ from q to be used in distribution_parameter_solver()
"""
function get_bounds(
N::FT,
q::FT,
μ::FT,
F_r::FT,
p3::PSP3,
th = (; D_cr = FT(0), D_gr = FT(0), ρ_g = FT(0), ρ_d = FT(0)),
) where {FT}
goal = q / N
if goal >= 1e-8
left = FT(1)
right = FT(6 * 1e3)
radius = FT(0.2)
elseif goal >= 2 * 1e-9
left = FT(6 * 1e3)
right = FT(3 * 1e4)
radius = FT(-0.1)
else
left = FT(4 * 1e4)
right = FT(1e6)
radius = FT(0.2)
end
ql = q_over_N_gamma(p3, F_r, log(left), μ, th)
qr = q_over_N_gamma(p3, F_r, log(right), μ, th)
guess =
left * (goal / (ql))^((log(right) - log(left)) / (log(qr) - log(ql)))
max = log(guess * exp(radius))
min = log(guess)
return (; min, max)
end
"""
distrbution_parameter_solver()
- p3 - a struct with P3 scheme parameters
- q - mass mixing ratio
- N - number mixing ratio
- ρ_r - rime density (q_rim/B_rim) [kg/m^3]
- F_r - rime mass fraction (q_rim/q_i)
Solves the nonlinear system consisting of N_0 and λ for P3 prognostic variables
Returns a named tuple containing:
- N_0 - intercept size distribution parameter [1/m4]
- λ - slope size distribution parameter [1/m]
"""
function distribution_parameter_solver(
p3::PSP3{FT},
q::FT,
N::FT,
ρ_r::FT,
F_r::FT,
) where {FT}
# Get the thresholds for different particles regimes
th = thresholds(p3, ρ_r, F_r)
# Get μ given q and N
μ = DSD_μ_approx(p3, q, N, ρ_r, F_r)
# To ensure that λ is positive solve for x such that λ = exp(x)
shape_problem(x) = q / N - q_over_N_gamma(p3, F_r, x, μ, th)
# Get intial guess for solver
(; min, max) = get_bounds(N, q, μ, F_r, p3, th)
# Find slope parameter
x =
RS.find_zero(
shape_problem,
RS.SecantMethod(min, max),
RS.CompactSolution(),
RS.RelativeSolutionTolerance(eps(FT)),
5,
).root
return (; λ = exp(x), N_0 = DSD_N₀(p3, N, exp(x)))
end
"""
terminal_velocity(p3, Chen2022, q, N, ρ_r, F_r, ρ_a)
- p3 - a struct with P3 scheme parameters
- Chen2022 - a struch with terminal velocity parameters as in Chen(2022)
- q - mass mixing ratio
- N - number mixing ratio
- ρ_r - rime density (q_rim/B_rim) [kg/m^3]
- F_r - rime mass fraction (q_rim/q_i)
- ρ_a - density of air
Returns the mass and number weighted fall speeds
Eq C10 of Morrison and Milbrandt (2015)
"""
function terminal_velocity(
p3::PSP3,
Chen2022::CMP.Chen2022VelTypeSnowIce,
q::FT,
N::FT,
ρ_r::FT,
F_r::FT,
ρ_a::FT,
) where {FT}
# Get the pree parameters for terminal velocities of small
# and large particles
small = CO.Chen2022_vel_coeffs_small(Chen2022, ρ_a)
large = CO.Chen2022_vel_coeffs_large(Chen2022, ρ_a)
get_p(prs, it) = (prs[1][it], prs[2][it], prs[3][it])
# Get the thresholds for different particles regimes
(; D_cr, D_gr, ρ_g, ρ_d) = thresholds(p3, ρ_r, F_r)
D_th = D_th_helper(p3)
D_ct = FT(0.000625) # TODO add to ClimaParams
# Get the shape parameters of the particle size distribution
(λ, N_0) = distribution_parameter_solver(p3, q, N, ρ_r, F_r)
μ = DSD_μ(p3, λ)
# TODO: Change when each value used depending on type of particle
# TODO: or keep fixed and add to ClimaParams...?
κ = FT(-1 / 6) #FT(1/3)
# Redefine α_va to be in si units
α_va = α_va_si(p3)
aₛ(a) = a * N_0
bₛ(b) = b + μ
cₛ(c) = c + λ
aₛ_m(a) = aₛ(a) * FT(π) / 6 * p3.ρ_i
bₛ_m(b) = bₛ(b) + 3
spheres_n(a, b, c) = (aₛ(a), bₛ(b), cₛ(c))
spheres_m(a, b, c) = (aₛ_m(a), bₛ_m(b), cₛ(c))
aₙₛ(a) = aₛ(a) * (16 * p3.ρ_i^2 * p3.γ^3 / (9 * FT(π) * α_va^2))^κ
bₙₛ(b) = bₛ(b) + κ * (3 * p3.σ - 2 * p3.β_va)
aₙₛ_m(a) = aₙₛ(a) * α_va
bₙₛ_m(b) = bₙₛ(b) + p3.β_va
non_spheres_n(a, b, c) = (aₙₛ(a), bₙₛ(b), cₛ(c))
non_spheres_m(a, b, c) = (aₙₛ_m(a), bₙₛ_m(b), cₛ(c))
aᵣₛ(a) = aₛ(a) * (p3.ρ_i / ρ_g)^(2 * κ)
aᵣₛ_m(a) = aᵣₛ(a) * FT(π) / 6 * ρ_g
rimed_n(a, b, c) = (aᵣₛ(a), bₛ(b), cₛ(c))
rimed_m(a, b, c) = (aᵣₛ_m(a), bₛ_m(b), cₛ(c))
v_n_D_cr(D, a, b, c) =
a *
N_0 *
D^(b + μ) *
exp((-c - λ) * D) *
(
16 * p3.ρ_i^2 * (F_r * π / 4 * D^2 + (1 - F_r) * p3.γ * D^p3.σ)^3 /
(9 * π * (α_va / (1 - F_r) * D^p3.β_va)^2)
)^κ
v_m_D_cr(D, a, b, c) = v_n_D_cr(D, a, b, c) * (α_va / (1 - F_r) * D^p3.β_va)
v_m = 0
v_n = 0
for i in 1:2
if F_r == 0
v_m += ∫_Γ(FT(0), D_th, spheres_m(get_p(small, i)...)...)
v_n += ∫_Γ(FT(0), D_th, spheres_n(get_p(small, i)...)...)
v_m += ∫_Γ(
D_th,
D_ct,
Inf,
non_spheres_m(get_p(small, i)...)...,
non_spheres_m(get_p(large, i)...)...,
)
v_n += ∫_Γ(
D_th,
D_ct,
Inf,
non_spheres_n(get_p(small, i)...)...,
non_spheres_n(get_p(large, i)...)...,
)
else
# Velocity coefficients for small particles
v_m += ∫_Γ(FT(0), D_th, spheres_m(get_p(small, i)...)...)
v_n += ∫_Γ(FT(0), D_th, spheres_n(get_p(small, i)...)...)
is_large = false
# D_th to D_gr
if !is_large && D_gr > D_ct
v_m += ∫_Γ(
D_th,
D_ct,
D_gr,
non_spheres_m(get_p(small, i)...)...,
non_spheres_m(get_p(large, i)...)...,
)
v_n += ∫_Γ(
D_th,
D_ct,
D_gr,
non_spheres_n(get_p(small, i)...)...,
non_spheres_n(get_p(large, i)...)...,
)
# Switch to large particles
is_large = true
else
v_m += ∫_Γ(D_th, D_gr, non_spheres_m(get_p(small, i)...)...)
v_n += ∫_Γ(D_th, D_gr, non_spheres_n(get_p(small, i)...)...)
end
# D_gr to D_cr
if !is_large && D_cr > D_ct
v_m += ∫_Γ(
D_gr,
D_ct,
D_cr,
rimed_m(get_p(small, i)...)...,
rimed_m(get_p(large, i)...)...,
)
v_n += ∫_Γ(
D_gr,
D_ct,
D_cr,
rimed_n(get_p(small, i)...)...,
rimed_n(get_p(large, i)...)...,
)
# Switch to large particles
is_large = true
elseif is_large
v_m += ∫_Γ(D_gr, D_cr, rimed_m(get_p(large, i)...)...)
v_n += ∫_Γ(D_gr, D_cr, rimed_n(get_p(large, i)...)...)
else
v_m += ∫_Γ(D_gr, D_cr, rimed_m(get_p(small, i)...)...)
v_n += ∫_Γ(D_gr, D_cr, rimed_n(get_p(small, i)...)...)
end
# D_cr to Infinity
if !is_large
(Im, em) =
QGK.quadgk(D -> v_m_D_cr(D, get_p(small, i)...), D_cr, D_ct)
(In, en) =
QGK.quadgk(D -> v_n_D_cr(D, get_p(small, i)...), D_cr, D_ct)
v_m += Im
v_n += In
# Switch to large particles
(Im, em) =
QGK.quadgk(D -> v_m_D_cr(D, get_p(large, i)...), D_ct, Inf)
(In, en) =
QGK.quadgk(D -> v_n_D_cr(D, get_p(large, i)...), D_ct, Inf)
v_m += Im
v_n += In
else
# TODO - check if it should be large or small
(Im, em) =
QGK.quadgk(D -> v_m_D_cr(D, get_p(large, i)...), D_cr, Inf)
(In, en) =
QGK.quadgk(D -> v_n_D_cr(D, get_p(large, i)...), D_cr, Inf)
v_m += Im
v_n += In
end
end
end
return (v_n / N, v_m / q)
end
"""
D_m (p3, q, N, ρ_r, F_r)
- p3 - a struct with P3 scheme parameters
- q - mass mixing ratio
- N - number mixing ratio
- ρ_r - rime density (q_rim/B_rim) [kg/m^3]
- F_r - rime mass fraction (q_rim/q_i)
Return the mass weighted mean particle size [m]
"""
function D_m(p3::PSP3, q::FT, N::FT, ρ_r::FT, F_r::FT) where {FT}
# Get the thresholds for different particles regimes
th = thresholds(p3, ρ_r, F_r)
D_th = D_th_helper(p3)
# Get the shape parameters
(λ, N_0) = distribution_parameter_solver(p3, q, N, ρ_r, F_r)
μ = DSD_μ(p3, λ)
# Redefine α_va to be in si units
α_va = α_va_si(p3)
# Calculate numerator
n = 0
if F_r == 0
n += ∫_Γ(FT(0), D_th, π / 6 * p3.ρ_i * N_0, μ + 4, λ)
n += ∫_Γ(D_th, Inf, α_va * N_0, μ + p3.β_va + 1, λ)
else
n += ∫_Γ(FT(0), D_th, π / 6 * p3.ρ_i * N_0, μ + 4, λ)
n += ∫_Γ(D_th, th.D_gr, α_va * N_0, μ + p3.β_va + 1, λ)
n += ∫_Γ(th.D_gr, th.D_cr, π / 6 * th.ρ_g * N_0, μ + 4, λ)
n += ∫_Γ(th.D_cr, Inf, α_va / (1 - F_r) * N_0, μ + p3.β_va + 1, λ)
end
# Normalize by q
return n / q
end
end