Skip to content

Commit 80043a8

Browse files
refactor saturation vapour pressure formulae to avoid using temperatures in Celsius (#1388)
Co-authored-by: Sylwester Arabas <[email protected]>
1 parent 20bed75 commit 80043a8

File tree

34 files changed

+3477
-289
lines changed

34 files changed

+3477
-289
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ repos:
1818
hooks:
1919
- id: trailing-whitespace
2020
- id: end-of-file-fixer
21-
- id: debug-statements
21+
- id: debug-statements

PySDM/backends/impl_numba/methods/condensation_methods.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,7 @@ def step_impl( # pylint: disable=too-many-arguments,too-many-locals
291291
)
292292
pv = formulae.state_variable_triplet__pv(p, water_vapour_mixing_ratio)
293293
lv = formulae.latent_heat__lv(T)
294-
pvs = formulae.saturation_vapour_pressure__pvs_Celsius(
295-
T - formulae.constants.T0
296-
)
294+
pvs = formulae.saturation_vapour_pressure__pvs_water(T)
297295
DTp = formulae.diffusion_thermics__D(T, p)
298296
RH = pv / pvs
299297
Sc = formulae.trivia__air_schmidt_number(

PySDM/backends/impl_numba/methods/physics_methods.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def body(*, rhod, thd, water_vapour_mixing_ratio, T, p, RH):
5959
)
6060
RH[i] = ff.state_variable_triplet__pv(
6161
p[i], water_vapour_mixing_ratio[i]
62-
) / ff.saturation_vapour_pressure__pvs_Celsius(T[i] - ff.constants.T0)
62+
) / ff.saturation_vapour_pressure__pvs_water(T[i])
6363

6464
return body
6565

@@ -82,9 +82,7 @@ def _a_w_ice_body(self):
8282
@numba.njit(**self.default_jit_flags)
8383
def body(*, T_in, p_in, RH_in, water_vapour_mixing_ratio_in, a_w_ice_out):
8484
for i in prange(T_in.shape[0]): # pylint: disable=not-an-iterable
85-
pvi = ff.saturation_vapour_pressure__ice_Celsius(
86-
T_in[i] - ff.constants.T0
87-
)
85+
pvi = ff.saturation_vapour_pressure__pvs_ice(T_in[i])
8886
pv = ff.state_variable_triplet__pv(
8987
p_in[i], water_vapour_mixing_ratio_in[i]
9088
)

PySDM/backends/impl_numba/test_helpers/scipy_ode_condensation_solver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
_CellData,
1919
_Counters,
2020
)
21-
from PySDM.physics.constants_defaults import PI_4_3, T0
21+
from PySDM.physics.constants_defaults import PI_4_3
2222

2323
idx_thd = 0
2424
idx_x = 1
@@ -205,7 +205,7 @@ def _odesys( # pylint: disable=too-many-arguments,too-many-locals
205205
T = jit_formulae.state_variable_triplet__T(rhod, thd)
206206
p = jit_formulae.state_variable_triplet__p(rhod, T, water_vapour_mixing_ratio)
207207
pv = jit_formulae.state_variable_triplet__pv(p, water_vapour_mixing_ratio)
208-
pvs = jit_formulae.saturation_vapour_pressure__pvs_Celsius(T - T0)
208+
pvs = jit_formulae.saturation_vapour_pressure__pvs_water(T)
209209
RH = pv / pvs
210210

211211
dy_dt = np.empty_like(y)

PySDM/backends/impl_thrust_rtc/methods/condensation_methods.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ def __pre(self):
318318
p='p[i]', water_vapour_mixing_ratio='predicted_water_vapour_mixing_ratio[i]')};
319319
lv[i] = {phys.latent_heat.lv.c_inline(
320320
T='T[i]')};
321-
pvs[i] = {phys.saturation_vapour_pressure.pvs_Celsius.c_inline(
322-
T='T[i] - const.T0')};
321+
pvs[i] = {phys.saturation_vapour_pressure.pvs_water.c_inline(
322+
T='T[i]')};
323323
RH[i] = pv[i] / pvs[i];
324324
RH_max[i] = max(RH_max[i], RH[i]);
325325
DTp[i] = {phys.diffusion_thermics.D.c_inline(

PySDM/backends/impl_thrust_rtc/methods/physics_methods.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ def _temperature_pressure_rh_body(self):
2727
)};
2828
RH[i] = {self.formulae.state_variable_triplet.pv.c_inline(
2929
p="p[i]", water_vapour_mixing_ratio="water_vapour_mixing_ratio[i]"
30-
)} / {self.formulae.saturation_vapour_pressure.pvs_Celsius.c_inline(
31-
T="T[i] - const.T0"
32-
)};
30+
)} / {self.formulae.saturation_vapour_pressure.pvs_water.c_inline(T="T[i]")};
3331
""".replace(
3432
"real_type", self._get_c_type()
3533
),

PySDM/physics/saturation_vapour_pressure/august_roche_magnus.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ def __init__(self, _):
1212
pass
1313

1414
@staticmethod
15-
def pvs_Celsius(const, T):
16-
return const.ARM_C1 * np.exp((const.ARM_C2 * T) / (T + const.ARM_C3))
15+
def pvs_water(const, T):
16+
return const.ARM_C1 * np.exp(
17+
(const.ARM_C2 * (T - const.T0)) / ((T - const.T0) + const.ARM_C3)
18+
)
1719

1820
@staticmethod
19-
def ice_Celsius(const, T):
21+
def pvs_ice(const, T):
2022
"""NaN with unit of pressure and correct dimension"""
21-
return np.nan * T / const.ARM_C3 * const.ARM_C1
23+
return np.nan * (T - const.T0) / const.ARM_C3 * const.ARM_C1

PySDM/physics/saturation_vapour_pressure/bolton_1980.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ def __init__(self, _):
1010
pass
1111

1212
@staticmethod
13-
def pvs_Celsius(const, T):
14-
"""valid for -30 <= T <= 35 C, eq (10)"""
15-
return const.B80W_G0 * np.exp((const.B80W_G1 * T) / (T + const.B80W_G2))
13+
def pvs_water(const, T):
14+
"""valid for 243.15(-30) <= T <= 308.15(35) K(C), eq. (10)"""
15+
return const.B80W_G0 * np.exp(
16+
(const.B80W_G1 * (T - const.T0)) / ((T - const.T0) + const.B80W_G2)
17+
)
1618

1719
@staticmethod
18-
def ice_Celsius(const, T):
20+
def pvs_ice(const, T):
1921
"""NaN with unit of pressure and correct dimension"""
20-
return np.nan * T / const.B80W_G2 * const.B80W_G0
22+
return np.nan * (T - const.T0) / const.B80W_G2 * const.B80W_G0

PySDM/physics/saturation_vapour_pressure/flatau_walko_cotton.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,55 @@ def __init__(self, _):
99
pass
1010

1111
@staticmethod
12-
def pvs_Celsius(const, T):
13-
return const.FWC_C0 + T * (
12+
def pvs_water(const, T):
13+
return const.FWC_C0 + (T - const.T0) * (
1414
const.FWC_C1
15-
+ T
15+
+ (T - const.T0)
1616
* (
1717
const.FWC_C2
18-
+ T
18+
+ (T - const.T0)
1919
* (
2020
const.FWC_C3
21-
+ T
21+
+ (T - const.T0)
2222
* (
2323
const.FWC_C4
24-
+ T
24+
+ (T - const.T0)
2525
* (
2626
const.FWC_C5
27-
+ T * (const.FWC_C6 + T * (const.FWC_C7 + T * const.FWC_C8))
27+
+ (T - const.T0)
28+
* (
29+
const.FWC_C6
30+
+ (T - const.T0)
31+
* (const.FWC_C7 + (T - const.T0) * const.FWC_C8)
32+
)
2833
)
2934
)
3035
)
3136
)
3237
)
3338

3439
@staticmethod
35-
def ice_Celsius(const, T):
36-
return const.FWC_I0 + T * (
40+
def pvs_ice(const, T):
41+
return const.FWC_I0 + (T - const.T0) * (
3742
const.FWC_I1
38-
+ T
43+
+ (T - const.T0)
3944
* (
4045
const.FWC_I2
41-
+ T
46+
+ (T - const.T0)
4247
* (
4348
const.FWC_I3
44-
+ T
49+
+ (T - const.T0)
4550
* (
4651
const.FWC_I4
47-
+ T
52+
+ (T - const.T0)
4853
* (
4954
const.FWC_I5
50-
+ T * (const.FWC_I6 + T * (const.FWC_I7 + T * const.FWC_I8))
55+
+ (T - const.T0)
56+
* (
57+
const.FWC_I6
58+
+ (T - const.T0)
59+
* (const.FWC_I7 + (T - const.T0) * const.FWC_I8)
60+
)
5161
)
5262
)
5363
)

PySDM/physics/saturation_vapour_pressure/lowe1977.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,41 @@ def __init__(self, _):
99
pass
1010

1111
@staticmethod
12-
def pvs_Celsius(const, T):
13-
return const.L77W_A0 + T * (
12+
def pvs_water(const, T):
13+
return const.L77W_A0 + (T - const.T0) * (
1414
const.L77W_A1
15-
+ T
15+
+ (T - const.T0)
1616
* (
1717
const.L77W_A2
18-
+ T
18+
+ (T - const.T0)
1919
* (
2020
const.L77W_A3
21-
+ T * (const.L77W_A4 + T * (const.L77W_A5 + T * (const.L77W_A6)))
21+
+ (T - const.T0)
22+
* (
23+
const.L77W_A4
24+
+ (T - const.T0)
25+
* (const.L77W_A5 + (T - const.T0) * (const.L77W_A6))
26+
)
2227
)
2328
)
2429
)
2530

2631
@staticmethod
27-
def ice_Celsius(const, T):
28-
return const.L77I_A0 + T * (
32+
def pvs_ice(const, T):
33+
return const.L77I_A0 + (T - const.T0) * (
2934
const.L77I_A1
30-
+ T
35+
+ (T - const.T0)
3136
* (
3237
const.L77I_A2
33-
+ T
38+
+ (T - const.T0)
3439
* (
3540
const.L77I_A3
36-
+ T * (const.L77I_A4 + T * (const.L77I_A5 + T * (const.L77I_A6)))
41+
+ (T - const.T0)
42+
* (
43+
const.L77I_A4
44+
+ (T - const.T0)
45+
* (const.L77I_A5 + (T - const.T0) * (const.L77I_A6))
46+
)
3747
)
3848
)
3949
)

0 commit comments

Comments
 (0)