-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalytic_blk_1m_pytest.py
40 lines (31 loc) · 1.13 KB
/
analytic_blk_1m_pytest.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
import numpy as np
import math
from constants_pytest import es0, T0, Rv, Rd, cp, L, p0
#in Pa (4.23 C&W)
def press_sat(T, es_ref=es0, T_ref=T0):
return es_ref * math.exp(-L/Rv * (1./T - 1./T_ref))
# in 1 (4.37 C&W)
def mixrat_sat(T, p, es_ref=es0, T_ref=T0):
es = press_sat(T)
return Rd/Rv * es / (p-es)
def pot_temp(T,p):
return T * (p0 / p)**(Rd/cp)
def density_dry(rv, press, T):
return press / T / Rd / (1. + rv * Rv/Rd)
def pottemp_dry(rv, press, T):
return T * (p0 / press * (1. + rv * Rv/Rd))**(Rd/cp)
#linearization of: r_v - \delta r_v = r_vs(\theta + \delta \theta) and
# \delta \theta = L/c_p * \theta/T
def delta_r(rv, rc, T, p, es_ref=es0, T_ref=T0):
rvs = mixrat_sat(T,p)
if rv < rvs:
return max((rv - rvs) / (1. + rvs / T**2 * L**2 / Rv / cp), -rc)
else:
return (rv - rvs) / (1. + rvs / T**2 * L**2 / Rv / cp)
if __name__ == "__main__":
# print mixrat_sat(283.15, 900.e2)
# print pot_temp(283.15, 900.e2)
# print press_sat(283.15, 1227., 283.15)
print delta_r(10.e-3, 283.15, 900.e2)
print delta_r(8.e-3, 283.15, 900.e2)
print delta_r(9.e-3, 283.15, 900.e2)