-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmicrophysics.py
More file actions
1722 lines (1471 loc) · 57.7 KB
/
Copy pathmicrophysics.py
File metadata and controls
1722 lines (1471 loc) · 57.7 KB
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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
TROPOS LAGRANGIAN CLOUD MODEL
Super-Droplet method in two-dimensional kinematic framework
(Test Case 1 ICMW 2012)
Author: Jan Bohrer (bohrer@tropos.de)
Further contact: Oswald Knoth (knoth@tropos.de)
MICROPHYSICS:
PARTICLE FORCES, CONDENSATIONAL MASS GROWTH, SATURATATION ADJUSTMENT
basic units:
particle mass, water mass, solute mass in femto gram = 10^-18 kg
particle radius in micro meter ("mu")
all other quantities in SI units
"""
#%% MODULE IMPORTS
import math
import numpy as np
from scipy.optimize import fminbound
from scipy.optimize import brentq
from numba import njit, vectorize
import constants as c
import material_properties as mat
par_sol_dens_NaCl = mat.par_sol_dens_NaCl
par_rho_AS = mat.par_rho_AS
par_wat_act_AS = mat.par_wat_act_AS
par_wat_act_NaCl = mat.par_wat_act_NaCl
par_sigma_AS = mat.par_sigma_AS
par_sigma_NaCl = mat.par_sigma_NaCl
from algebra import compute_polynom
#%% CONVERSIONS
@njit()
def compute_mass_from_radius(radius, density):
"""Compute mass of a rigid sphere, given radius and density
Parameters
----------
radius: float
Sphere radius (microns)
density: float
Mass density (kg/m^3)
Returns
-------
float
Mass (1E-18 kg)
"""
return c.four_pi_over_three * density * radius * radius * radius
@vectorize("float64(float64,float64)")
def compute_mass_from_radius_vec(radius, density):
"""Compute mass of a rigid sphere, given radius and density
Vectorized version with Numba
Parameters
----------
radius: float
Sphere radius (microns)
density: float
Mass density (kg/m^3)
Returns
-------
float
Mass (1E-18 kg)
"""
return c.four_pi_over_three * density * radius * radius * radius
@njit()
def compute_radius_from_mass(mass, density):
"""Compute radius of a rigid sphere, given mass and density
Parameters
----------
mass: float
Sphere mass (1E-18 kg)
density: float
Mass density (kg/m^3)
Returns
-------
float
Radius (microns)
"""
return ( c.four_pi_over_three_inv * mass / density ) ** (c.one_third)
@vectorize("float64(float64,float64)")
def compute_radius_from_mass_vec(mass, density):
"""Compute radius of a rigid sphere, given mass and density
Vectorized version with Numba
Parameters
----------
mass: float
Sphere mass (1E-18 kg)
density: float
Mass density (kg/m^3)
Returns
-------
float
Radius (microns)
"""
return ( c.four_pi_over_three_inv * mass / density ) ** (c.one_third)
@njit()
def compute_mass_fraction_from_molality(molality, molecular_weight):
"""Compute mass fraction from molality for single solute
Molality = n_solute / m_solvent (mol/kg)
Mass fraction = m_solute / m_solution
For single solute = m_solute / (m_solute + m_solvent)
Vectorized version with Numba
Parameters
----------
molality: float
Molality = n_solute / m_solvent (mol/kg)
molecular_weight: float
Molecular weight (kg/mol)
Returns
-------
float
Mass fraction m_solute / m_solution (no unit)
"""
return 1.0 / ( 1.0 + 1.0 / (molality * molecular_weight) )
@njit()
def compute_molality_from_mass_fraction(mass_fraction, molecular_weight):
"""Compute mass fraction from molality for single solute
Molality = n_solute / m_solvent (mol/kg)
Mass fraction = m_solute / m_solution
For single solute = m_solute / (m_solute + m_solvent)
Vectorized version with Numba
Parameters
----------
mass_fraction: float
Mass fraction m_solute / m_solution (no unit)
molecular_weight: float
Molecular weight (kg/mol)
Returns
-------
molality: float
Molality = n_solute / m_solvent (mol/kg)
"""
return mass_fraction / ( (1. - mass_fraction) * molecular_weight )
### FOR CONVENIENCE: RADIUS, MASS FRACTION AND DENSITY
@njit()
def compute_R_p_w_s_rho_p_NaCl(m_w, m_s, T_p):
"""Compute particle radius, mass fraction and density for sodium chloride
Parameters
----------
m_w: float
Particle water mass (1E-18 kg)
m_s: float
Particle solute mass (1E-18 kg)
T_p: float
Particle temperature (K)
Returns
-------
R_p: float
Particle radius (microns)
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
rho_p: float
Mass density (kg/m^3)
"""
m_p = m_w + m_s
w_s = m_s / m_p
rho_p = mat.compute_density_NaCl_solution(w_s, T_p)
return compute_radius_from_mass(m_p, rho_p), w_s, rho_p
@njit()
def compute_R_p_w_s_rho_p_AS(m_w, m_s, T_p):
"""Compute particle radius, mass fraction and density for ammon. sulfate
Parameters
----------
m_w: float
Particle water mass (1E-18 kg)
m_s: float
Particle solute mass (1E-18 kg)
T_p: float
Particle temperature (K)
Returns
-------
R_p: float
Particle radius (microns)
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
rho_p: float
Mass density (kg/m^3)
"""
m_p = m_w + m_s
w_s = m_s / m_p
rho_p = mat.compute_density_AS_solution(w_s, T_p)
return compute_radius_from_mass(m_p, rho_p), w_s, rho_p
@njit()
def compute_R_p_w_s_rho_p(m_w, m_s, T_p, solute_type):
"""Compute particle radius, mass fraction and density for single solute
Parameters
----------
m_w: float
Particle water mass (1E-18 kg)
m_s: float
Particle solute mass (1E-18 kg)
T_p: float
Particle temperature (K)
solute_type: str
Solute material
Either 'AS' (ammonium sulfate) or 'NaCl' (sodium chloride)
Returns
-------
R_p: float
Particle radius (microns)
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
rho_p: float
Mass density (kg/m^3)
"""
if solute_type == 'AS':
return compute_R_p_w_s_rho_p_AS(m_w, m_s, T_p)
elif solute_type == 'NaCl':
return compute_R_p_w_s_rho_p_NaCl(m_w, m_s, T_p)
def compute_particle_radius_from_ws_T_ms_NaCl(mass_fraction_solute,
temperature, dry_mass):
"""Compute particle radius, given mass fraction, temperature and dry mass
Parameters
----------
mass_fraction_solute: float
Mass fraction of solute m_solute / m_solution (no unit)
temperature: float
Particle temperature (K)
dry_mass: float
Particle dry mass (1E-18 kg)
Returns
-------
float
Radius (microns)
"""
Vp = dry_mass\
/ ( mass_fraction_solute \
* mat.compute_density_NaCl_solution(mass_fraction_solute,
temperature) )
return (c.four_pi_over_three_inv * Vp)**(c.one_third)
#%% FORCES
@njit()
def compute_particle_reynolds_number(radius, velocity_dev, fluid_density,
fluid_viscosity):
"""Compute particle Reynolds number
As given in
Crowe et al. 2011: Multiphase Flows with Droplets and Particles,
CRC Press, 2nd Edition (2011)
Parameters
----------
radius: float
Particle radius (microns)
velocity_dev: float
Absolute difference of the velocities of particle and
surrounding fluid: |v_p - u_fluid| (m/s)
fluid_density: float
Fluid mass density (kg/m^3)
fluid_viscosity: float
Dynamic viscosity of the fluid (Pa s)
Returns
-------
float
Particle Reynolds number (-)
"""
return 2.0E-6 * fluid_density * radius * velocity_dev / fluid_viscosity
#%% EQUILIBRIUM SATURATION - KELVIN RAOULT
@njit()
def compute_kelvin_argument(R_p, T_p, rho_p, sigma_p):
"""Compute the argument of the exponential in the Kelvin term
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
R_p: float
Particle radius (microns)
T_p: float
Particle temperature (K)
rho_p: float
Particle density (kg/m^3)
sigma_p: float
Particle surface tension (N/m)
Returns
-------
float
Argument of the exponential in the Kelvin-Term (s.a.) (no unit)
"""
return 2.0E6 * sigma_p \
/ ( c.specific_gas_constant_water_vapor * T_p * rho_p * R_p )
@njit()
def compute_kelvin_term(R_p, T_p, rho_p, sigma_p):
"""Compute the Kelvin term in the equilibrium saturation
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
R_p: float
Particle radius (microns)
T_p: float
Particle temperature (K)
rho_p: float
Particle density (kg/m^3)
sigma_p: float
Particle surface tension (N/m)
Returns
-------
float
Kelvin-Term of the Köhler-equation (s.a.) (no unit)
"""
return np.exp(compute_kelvin_argument(R_p, T_p, rho_p, sigma_p))
@njit()
def compute_kelvin_term_mf(mass_fraction_solute,
temperature,
mass_solute,
mass_density_particle,
surface_tension ):
"""Compute the Kelvin term in the equil. saturation (from mass fract.)
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
mass_fraction_solute: float
Mass fraction of solute m_solute / m_solution (no unit)
temperature: float
Particle temperature (K)
mass_solute: float
Particle solute mass (1E-18 kg)
mass_density_particle: float
Particle mass densit (kg/m^3)
rho_p: float
Particle density (kg/m^3)
surface_tension: float
Particle surface tension (N/m)
Returns
-------
float
Kelvin-Term of the Köhler-equation (s.a.) (no unit)
"""
return np.exp( 2.0 * surface_tension * 1.0E6\
* (mass_fraction_solute / mass_solute)**(c.one_third)
/ ( c.specific_gas_constant_water_vapor
* temperature
* mass_density_particle**(0.66666667)
* c.volume_to_radius) )
@vectorize(
"float64(float64, float64, float64, float64, float64)")
def compute_equilibrium_saturation_NaCl(w_s, R_p, T_p, rho_p, sigma_p):
"""Compute the Köhler equilibrium saturation for sodium chloride
Vectorized with Numba
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p)
Parameters
----------
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
R_p: float
Particle radius (microns)
T_p: float
Particle temperature (K)
rho_p: float
Particle density (kg/m^3)
sigma_p: float
Particle surface tension (N/m)
Returns
-------
float
Equilibrium saturation by Köhler-equation (s.a.) (no unit)
"""
return mat.compute_water_activity_NaCl(w_s)\
* compute_kelvin_term(R_p, T_p, rho_p, sigma_p)
@vectorize(
"float64(float64, float64, float64, float64, float64)")
def compute_equilibrium_saturation_AS(w_s, R_p, T_p, rho_p, sigma_p):
"""Compute the Köhler equilibrium saturation for ammonium sulfate
Vectorized with Numba
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
R_p: float
Particle radius (microns)
T_p: float
Particle temperature (K)
rho_p: float
Particle density (kg/m^3)
sigma_p: float
Particle surface tension (N/m)
Returns
-------
float
Equilibrium saturation by Köhler-equation (s.a.) (no unit)
"""
return mat.compute_water_activity_AS(w_s)\
* compute_kelvin_term(R_p, T_p, rho_p, sigma_p)
# from mass fraction mf
@njit()
def compute_equilibrium_saturation_NaCl_mf(w_s, T_p, m_s):
"""Compute the Köhler equilibrium saturation for sodium chloride
Using the 'mass_fraction' version of 'compute_kelvin_term_mf'
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
T_p: float
Particle temperature (K)
m_s: float
Particle solute mass (1E-18 kg)
Returns
-------
float
Equilibrium saturation by Köhler-equation (s.a.) (no unit)
"""
rho_p = mat.compute_density_NaCl_solution(w_s, T_p)
sigma_p = mat.compute_surface_tension_NaCl(w_s, T_p)
return mat.compute_water_activity_NaCl(w_s) \
* compute_kelvin_term_mf(w_s, T_p, m_s, rho_p, sigma_p)
# from mass fraction mf
@njit()
def compute_equilibrium_saturation_AS_mf(w_s, T_p, m_s):
"""Compute the Köhler equilibrium saturation for ammonium sulfate
Using the 'mass_fraction' version of 'compute_kelvin_term_mf'
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
T_p: float
Particle temperature (K)
m_s: float
Particle solute mass (1E-18 kg)
Returns
-------
float
Equilibrium saturation by Köhler-equation (s.a.) (no unit)
"""
rho_p = mat.compute_density_AS_solution(w_s, T_p)
sigma_p = mat.compute_surface_tension_AS(w_s, T_p)
return mat.compute_water_activity_AS(w_s) \
* compute_kelvin_term_mf(w_s, T_p, m_s, rho_p, sigma_p)
#%% INITIAL MASS FRACTION
### INITIAL MASS FRACTION SODIUM CHLORIDE
@njit()
def compute_equilibrium_saturation_negative_NaCl_mf(w_s, T_p, m_s):
"""Compute negative Köhler equilibrium saturation for sodium chloride
This wrapper function is used to find the maximum of the
equil. sat. wrt. w_s.
Using the 'mass_fraction' version of 'compute_kelvin_term_mf'
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
T_p: float
Particle temperature (K)
m_s: float
Particle solute mass (1E-18 kg)
Returns
-------
float
Negative equilibrium saturation by Köhler-equation (s.a.) (no unit)
"""
return -compute_equilibrium_saturation_NaCl_mf(w_s, T_p, m_s)
def compute_equilibrium_saturation_minus_S_amb_NaCl_mf(w_s, T_p, m_s, S_amb):
"""Compute equilibrium saturation minus ambient sat. (sodium chloride)
This wrapper function is used to find the root of S_eq-S_amb wrt. w_s.
Using the 'mass_fraction' version of 'compute_kelvin_term_mf'.
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
T_p: float
Particle temperature (K)
m_s: float
Particle solute mass (1E-18 kg)
S_amb: float
Ambient saturation S (no unit)
Returns
-------
float
Difference of equilibrium saturation and ambient saturation
by Köhler-equation (s.a.) (no unit)
"""
return -S_amb + compute_equilibrium_saturation_NaCl_mf(w_s, T_p, m_s)
@vectorize( "float64(float64,float64,float64)", forceobj=True )
def compute_initial_mass_fraction_solute_m_s_NaCl(m_s, S_amb, T_amb):
"""Compute initial particle mass fraction in equilibrium with moist air
Solute material = sodium chloride
The particle solute mass fraction w_s is chosen such that the
equilibrium saturation S_eq(w_s) is equal to the ambient saturation.
If the ambient saturation is larger than the maximum of S_eq(w_s),
then w_s is set to the value corresponding to the maximum of S_eq
(which is the activation mass fraction).
The mass fraction w_s is implemented with an upper bound w_s_max,
which marks the interval, where the parametrization of the
surface tension is valid.
1. S_min = S_eq (w_s_max, m_s)
2. if S_a <= S_min : w_s = w_s_max
3. else (S_a > S_min): S_act, w_s_act = max( S(w_s, m_s) )
4a. w_s_act = 1.00001 * w_s_act (numerical stability ->
want to be on branch of high w_s <-> low R_p for cont. fct. S(w_s) )
4b. S_act = S(w_s_act) ( < S_act_real! )
5. if S_a > S_act : w_s_init = w_s_act
6. else (S_a <= S_act) : calc w_s_init from S( w_s_init ) - S_a = 0
Check for convergence at every stage
For sodium chloride: fix an upper bound for w_s: w_s_max = 0.45
w_s cannot get larger than that.
The border is chosen, because the approximation of sigma_NaCl(w_s)
is only given for 0 < w_s < 0.45
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
m_s: float
Particle solute mass (1E-18 kg)
S_amb: float
Ambient saturation S (no unit)
T_amb: float
Ambient temperature (K)
Returns
-------
w_s_init: float
Initial particle solute mass fraction,
Difference of equilibrium saturation and ambient saturation
by Köhler-equation (s.a.) (no unit)
"""
# 1.
S_min = compute_equilibrium_saturation_NaCl_mf(mat.w_s_max_NaCl,
T_amb, m_s)
# 2.
if S_amb <= S_min:
w_s_init = mat.w_s_max_NaCl
else:
# 3.
w_s_act, S_act, flag, nofc = \
fminbound(compute_equilibrium_saturation_negative_NaCl_mf,
x1=1E-8, x2=mat.w_s_max_NaCl,
args=(T_amb, m_s),
xtol = 1.0E-12, full_output=True )
# 4.
# increase w_s_act slightly to avoid numerical problems
# in solving with brentq() below
if flag == 0:
w_s_act *= 1.000001
# set w_s_act (i.e. the min bound for brentq() solve below )
# to deliqu. mass fraction if fminbound does not converge
else:
w_s_act = mat.compute_solubility_NaCl(T_amb)
S_act = compute_equilibrium_saturation_NaCl_mf(w_s_act,
T_amb,
m_s)
# 5.
if S_amb > S_act:
w_s_init = w_s_act
else:
# 6.
solve_result = \
brentq(
compute_equilibrium_saturation_minus_S_amb_NaCl_mf,
w_s_act,
mat.w_s_max_NaCl,
(T_amb, m_s, S_amb),
xtol = 1e-15,
full_output=True)
if solve_result[1].converged:
w_s_init = solve_result[0]
else:
w_s_init = w_s_act
return w_s_init
### INITIAL MASS FRACTION AMMONIUM SULFATE
@njit()
def compute_equilibrium_saturation_negative_AS_mf(w_s, T_p, m_s):
"""Compute negative Köhler equilibrium saturation for ammonium sulfate
This wrapper function is used to find the maximum of the
equil. sat. wrt. w_s.
Using the 'mass_fraction' version of 'compute_kelvin_term_mf'
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
T_p: float
Particle temperature (K)
m_s: float
Particle solute mass (1E-18 kg)
Returns
-------
float
Negative equilibrium saturation by Köhler-equation (s.a.) (no unit)
"""
return -compute_equilibrium_saturation_AS_mf(w_s, T_p, m_s)
def compute_equilibrium_saturation_minus_S_amb_AS_mf(w_s, T_p, m_s, S_amb):
"""Compute equilibrium saturation minus ambient sat. (ammon. sulfate)
This wrapper function is used to find the root of S_eq-S_amb wrt. w_s.
Using the 'mass_fraction' version of 'compute_kelvin_term_mf'.
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
w_s: float
Particle solute mass fraction m_solute / m_solution (no unit)
T_p: float
Particle temperature (K)
m_s: float
Particle solute mass (1E-18 kg)
S_amb: float
Ambient saturation S (no unit)
Returns
-------
float
Difference of equilibrium saturation and ambient saturation
by Köhler-equation (s.a.) (no unit)
"""
return -S_amb \
+ compute_equilibrium_saturation_AS_mf(w_s, T_p, m_s)
@vectorize( "float64(float64,float64,float64)", forceobj=True )
def compute_initial_mass_fraction_solute_m_s_AS(m_s, S_amb, T_amb):
"""Compute initial particle mass fraction in equilibrium with moist air
Solute material = ammonium sulfate
The particle solute mass fraction w_s is chosen such that the
equilibrium saturation S_eq(w_s) is equal to the ambient saturation.
If the ambient saturation is larger than the maximum of S_eq(w_s),
then w_s is set to the value corresponding to the maximum of S_eq
(which is the activation mass fraction).
The mass fraction w_s is implemented with an upper bound w_s_max,
which marks the interval, where the parametrization of the
surface tension is valid.
1. S_min = S_eq (w_s_max, m_s)
2. if S_a <= S_min : w_s = w_s_max
3. else (S_a > S_min): S_act, w_s_act = max( S(w_s, m_s) )
4a. w_s_act = 1.00001 * w_s_act (numerical stability ->
want to be on branch of high w_s <-> low R_p for cont. fct. S(w_s) )
4b. S_act = S(w_s_act) ( < S_act_real! )
5. if S_a > S_act : w_s_init = w_s_act
6. else (S_a <= S_act) : calc w_s_init from S( w_s_init ) - S_a = 0
Check for convergence at every stage
For ammonium sulfate: fix an upper bound for w_s: w_s_max = 0.78
w_s cannot get larger than that.
The border is chosen, because the approximation of sigma_AS(w_s)
is only given for 0 < w_s < 0.78
Saturation S = e/e_s(T)
e = ambient water vapor pressure
e_s = saturation vapor pressure over a flat water surface
Köhler-equation:
Equilibrium saturation over a curved solution surface =
S_eq = e_equi / e_s(T) = a_w * f_Kelvin
e_equi = equilibrium vapor pressure over a curved solution surface
a_w = water activity
f_Kelvin = exp(kelvin_argument)
kelvin_argument = (2 sigma_p) / (R_v * T_p * rho_p * R_p )
Parameters
----------
m_s: float
Particle solute mass (1E-18 kg)
S_amb: float
Ambient saturation S (no unit)
T_amb: float
Ambient temperature (K)
Returns
-------
w_s_init: float
Initial particle solute mass fraction,
Difference of equilibrium saturation and ambient saturation
by Köhler-equation (s.a.) (no unit)
"""
# 1.
S_effl = compute_equilibrium_saturation_AS_mf(mat.w_s_max_AS,
T_amb, m_s)
# 2.
# np.where(S_amb <= S_effl, w_s_init = w_s_effl,)
if S_amb <= S_effl:
w_s_init = mat.w_s_max_AS
else:
# 3.
w_s_act, S_act, flag, nofc = \
fminbound(compute_equilibrium_saturation_negative_AS_mf,
x1=1E-8, x2=mat.w_s_max_AS,
args=(T_amb, m_s),
xtol = 1.0E-12, full_output=True )
# 4.
# increase w_s_act slightly to avoid numerical problems
# in solving with brentq() below
if flag == 0:
w_s_act *= 1.000001
# set w_s_act (i.e. the min bound for brentq() solve below )
# to deliqu. mass fraction if fminbound does not converge
else:
w_s_act = mat.compute_solubility_AS(T_amb)
# update S_act to S_act* < S_act (right branch of S_eq vs w_s curve)
S_act = compute_equilibrium_saturation_AS_mf(w_s_act,
T_amb, m_s)
# 5.
if S_amb > S_act:
w_s_init = w_s_act
else:
# 6.
solve_result = \
brentq(
compute_equilibrium_saturation_minus_S_amb_AS_mf,
w_s_act,
mat.w_s_max_AS,
(T_amb, m_s, S_amb),
xtol = 1e-15,
full_output=True)
if solve_result[1].converged:
w_s_init = solve_result[0]
else:
w_s_init = w_s_act
return w_s_init
#%% CONDENSATION MASS RATE (= "gamma")
### linearization of the size correction functions of Fukuta 1970
accommodation_coeff = 1.0
# adiabatic index = 1.4 = 7/5 -> 1/1.4 = 5/7 = 0.7142857142857143
adiabatic_index_inv = 0.7142857142857143
T_alpha_0 = 289. # K
c_alpha_1 = 1.0E6 * math.sqrt(2.0 * np.pi * c.specific_gas_constant_air_dry
* T_alpha_0 )\
/ ( accommodation_coeff
* ( c.specific_heat_capacity_air_dry_NTP
* adiabatic_index_inv\
+ 0.5 * c.specific_gas_constant_air_dry ) )
c_alpha_2 = 0.5E6\
* math.sqrt(2.0 * np.pi * c.specific_gas_constant_air_dry
/ T_alpha_0 )\
/ ( accommodation_coeff
* (c.specific_heat_capacity_air_dry_NTP * adiabatic_index_inv\
+ 0.5 * c.specific_gas_constant_air_dry) )
@vectorize("float64(float64,float64,float64)")
def compute_l_alpha_lin(T_amb, p_amb, K):
"""Heat-term size correction for the condensation mass rate (linearized)
Particle radius size correction (Knudsen flow) for the heat-term
in the condensation mass rate equation by
Fukuta and Walter 1970, J. Atmos. Sci. 27: 1160
We use accommodation_coefficient = 1.0 after recommendation in
Pruppacher 1997, adiabatic_index = 7/5 and
c_v_air = c_v_air_dry_NTP (normal temperature and pressure)
Parameters