-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_fig04.py
156 lines (135 loc) · 4.95 KB
/
gen_fig04.py
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
################################################################
# generate results for LoWo21 Figure 4
# evaulate non-d number Λ as tool to understand raindrop evap
################################################################
import src.fall as fall
from src.planet import Planet
import src.drop_prop as drop_prop
import numpy as np
from scipy.optimize import newton,brentq
import time
dir = 'output/fig04/'
# panels (a) and (b)
# set up Earth-like planetary conditions
X = np.zeros(5) # composition
X[2] = 1. # f_N2 [mol/mol]
T_surf = 300 # [K]
p_surf = 1.01325e5 # [Pa]
RH_surf = 0.75 # [ ]
R_p = 1. # [R_earth]
M_p = 1. # [M_earth]
pl = Planet(R_p,T_surf,p_surf,X,'h2o',RH_surf,M_p)
n_z = 100
zs = np.linspace(0,pl.z_LCL,n_z) # [m]
r_min = np.zeros((n_z-1,2)) # [m]
# calc r_min with integration
t1 = time.time()
for i,z in enumerate(zs[:-1]):
pl.z2x4drdz(pl.z_LCL)
r_min[i,0] = fall.calc_smallest_raindrop(pl,z_end=z,dr=5e-7)[0] # [m]
t2 = time.time()
# calc r_min with non-d number
for i,z in enumerate(zs[:-1]):
ell = pl.z_LCL-z
r_min[i,1] = drop_prop.calc_r_from_Λ(pl,ell,Λ_val=1) # [m]
t3 = time.time()
print('t_int',t2-t1)
print('t_nond',t3-t2)
np.save(dir+'r_min',r_min)
np.save(dir+'zs',zs)
n_r = 200
dr = 1e-6
r0s = np.logspace(-5,-3,n_r) # [m]
ell = pl.z_LCL # [m]
m_frac_evap = np.zeros((n_r,2))
for i,r0 in enumerate(r0s):
# calc m_frac_evap with integration
sol = fall.integrate_fall(pl,r0)
if sol.status==0:
r_end = sol.sol.__call__(0.0)[0] # [m]
else:
r_end = dr
m_frac_evap[i,0] = 1 - r_end**3/r0**3 # [ ]
# calc m_frac_evap with non-d number
m_frac_evap[i,1] = drop_prop.calc_Λ(r0,pl,ell) # [ ]
# m_frac_evap = min{1,Λ} (LoWo21 section 3.3)
m_frac_evap[np.where(m_frac_evap[:,1]>1.),1] = 1.
# save results
np.save(dir+'r0s',r0s)
np.save(dir+'m_frac_evap',m_frac_evap)
# panels (c) and (d)
# set up broad planetary conditions
# n_Xs*n_var*n_var_char = 90 different planetary conditions
X_H2 = np.zeros(5) # composition
X_N2 = np.zeros(5) # composition
X_CO2 = np.zeros(5) # composition
X_H2[0] = 1. # f_H2 [mol/mol]
X_N2[2] = 1. # f_N2 [mol/mol]
X_CO2[4] = 1. # f_CO2 [mol/mol]
T_LCL = 275 # [K]
p_LCL = 7.5e4 # [Pa]
RH = 1. # [ ]
R_p = 1. # [R_earth]
M_p = 1. # [M_earth]
Xs = [X_H2,X_N2,X_CO2] # array of varying atm compositions
n_var = 10
p_LCLs = np.logspace(np.log10(5e3),7,n_var) # [Pa]
T_LCLs = np.linspace(275,400,n_var) # [K]
g = np.linspace(2,25,n_var) # [m/s2]
var_char = np.array([p_LCLs,g,T_LCLs]) # array of varying planetary characteristics
n_ℓ = 3
ℓs = np.array([100,500,1000]) # [m]
r_mins = np.zeros((3,3,n_var,n_ℓ,2)) # [m]
r0s = np.array([0.05,0.1,0.5,1])*1e-3 # [m]
n_r0 = 4
m_frac_evap = np.zeros((3,3,n_var,n_r0,2)) # [ ]
dr = 5e-7 # [m]
for i,X in enumerate(Xs):
for x in range(3):
for j,v in enumerate(var_char[x,:]):
if x==0:
pl = Planet(R_p,T_LCL,v,X,'h2o',RH,M_p)
elif x==1:
pl = Planet(R_p,T_LCL,p_LCL,X,'h2o',RH,M_p,g_force=v)
elif x==2:
pl = Planet(R_p,v,p_LCL,X,'h2o',RH,M_p)
for k,ℓ in enumerate(ℓs):
r_mins[i,x,j,k,0] = fall.calc_smallest_raindrop(pl,z_end=-ℓ,dr=5e-7)[0]
try:
r_mins[i,x,j,k,1] = drop_prop.calc_r_from_Λ(pl,ℓ)
except ValueError: # when Λ not defined
r_mins[i,x,j,k,1] = None
if k==1:
for q,r0 in enumerate(r0s):
# integration
sol = fall.integrate_fall(pl,r0,z_end=-ℓ)
if sol.status==0:
r_end = sol.sol.__call__(-ℓ)[0]
else:
r_end = 0.
m_frac_evap[i,x,j,q,0] = 1 - r_end**3/r0**3
# non-d number
# m_frac_evap = min{1,Λ} (LoWo21 section 3.3)
Λ = drop_prop.calc_Λ(r0,pl,ℓ) # [ ]
if Λ>1:
m_frac_evap[i,x,j,q,1] = 1.
else:
m_frac_evap[i,x,j,q,1] = Λ
percent_err_rmin = (r_mins[:,:,:,:,0] - r_mins[:,:,:,:,1])/r_mins[:,:,:,:,0]
rat_rmin = r_mins[:,:,:,:,1]/r_mins[:,:,:,:,0]
diff_rmin = r_mins[:,:,:,:,1]-r_mins[:,:,:,:,0]
percent_err_fevap = (m_frac_evap[:,:,:,:,0] - m_frac_evap[:,:,:,:,1])/m_frac_evap[:,:,:,:,0]
rat_fevap = m_frac_evap[:,:,:,:,1]/m_frac_evap[:,:,:,:,0]
diff_fevap = m_frac_evap[:,:,:,:,1]-m_frac_evap[:,:,:,:,0]
# save results
np.save(dir+'var_char',var_char)
np.save(dir+'ells_broad',ℓs)
np.save(dir+'r0s_broad',r0s)
np.save(dir+'r_mins_broad',r_mins)
np.save(dir+'percent_err_rmin_broad',percent_err_rmin)
np.save(dir+'rat_rmin_broad',rat_rmin)
np.save(dir+'diff_rmin_broad',diff_rmin)
np.save(dir+'percent_err_fevap_broad',percent_err_fevap)
np.save(dir+'rat_fevap_broad',rat_fevap)
np.save(dir+'diff_fevap_broad',diff_fevap)
np.save(dir+'m_frac_evap_broad',m_frac_evap)