Skip to content

Commit 88fcb6e

Browse files
committed
refactor: streamlined dz_dt computation in Parcel class and updated planetary pressure units
1 parent 5ebe373 commit 88fcb6e

File tree

3 files changed

+20
-43
lines changed

3 files changed

+20
-43
lines changed

PySDM/environments/parcel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def advance_parcel_vars(self):
106106
T = self["T"][0]
107107
p = self["p"][0]
108108

109-
dz_dt = self.w((self.particulator.n_steps + 1 / 2) * dt) # "mid-point"
109+
dz_dt = self._compute_dz_dt(dt)
110110
water_vapour_mixing_ratio = (
111111
self["water_vapour_mixing_ratio"][0]
112112
- self.delta_liquid_water_mixing_ratio / 2
@@ -133,6 +133,9 @@ def advance_parcel_vars(self):
133133
(self._tmp["rhod"][0] + self["rhod"][0]) / 2, self.mass_of_dry_air
134134
)
135135

136+
def _compute_dz_dt(self, dt):
137+
self.w((self.particulator.n_steps + 1 / 2) * dt) # "mid-point"
138+
136139
def get_thd(self):
137140
return self["thd"]
138141

examples/PySDM_examples/Loftus_and_Wordsworth_2021/parcel.py

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,5 @@ def __init__(
2525
variables=None,
2626
)
2727

28-
def advance_parcel_vars(self):
29-
"""
30-
Compute new values of displacement, dry-air density and volume,
31-
and write them to self._tmp and self.mesh.dv
32-
"""
33-
dt = self.particulator.dt
34-
formulae = self.particulator.formulae
35-
T = self["T"][0]
36-
p = self["p"][0]
37-
38-
dz_dt = -self.particulator.attributes["terminal velocity"].to_ndarray()[0]
39-
water_vapour_mixing_ratio = (
40-
self["water_vapour_mixing_ratio"][0]
41-
- self.delta_liquid_water_mixing_ratio / 2
42-
)
43-
44-
drho_dz = formulae.hydrostatics.drho_dz(
45-
p=p,
46-
T=T,
47-
water_vapour_mixing_ratio=water_vapour_mixing_ratio,
48-
lv=formulae.latent_heat_vapourisation.lv(T),
49-
d_liquid_water_mixing_ratio__dz=(
50-
self.delta_liquid_water_mixing_ratio / dz_dt / dt
51-
),
52-
)
53-
drhod_dz = drho_dz
54-
55-
self.particulator.backend.explicit_euler(self._tmp["z"], dt, dz_dt)
56-
self.particulator.backend.explicit_euler(
57-
self._tmp["rhod"], dt, dz_dt * drhod_dz
58-
)
59-
60-
self.mesh.dv = formulae.trivia.volume_of_density_mass(
61-
(self._tmp["rhod"][0] + self["rhod"][0]) / 2, self.mass_of_dry_air
62-
)
28+
def _compute_dz_dt(self, dt):
29+
return -self.particulator.attributes["terminal velocity"].to_ndarray()[0]

examples/PySDM_examples/Loftus_and_Wordsworth_2021/planet.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""
2+
Planetary properties used in calculations.
3+
4+
Values are primarily taken from Table 1 of Loftus & Wordsworth (2021), unless otherwise noted.
5+
Each variable represents a physical property or atmospheric composition relevant for cloud microphysics modeling.
6+
"""
7+
18
from PySDM.physics.constants import si
29
from dataclasses import dataclass
310
from typing import Optional, Dict, Any
@@ -24,7 +31,7 @@ def to_dict(self) -> Dict[str, Any]:
2431
class EarthLike(Planet):
2532
g_std: float = 9.82 * si.metre / si.second**2
2633
T_STP: float = 300 * si.kelvin
27-
p_STP: float = 1.01325 * 1e6 * si.pascal
34+
p_STP: float = 1.01325 * 1e5 * si.Pa
2835
RH_zref: float = 0.75
2936
dry_molar_conc_H2: float = 0
3037
dry_molar_conc_He: float = 0
@@ -38,7 +45,7 @@ class EarthLike(Planet):
3845
class Earth(Planet):
3946
g_std: float = 9.82 * si.metre / si.second**2
4047
T_STP: float = 290 * si.kelvin
41-
p_STP: float = 1.01325 * 1e6 * si.pascal
48+
p_STP: float = 1.01325 * 1e5 * si.Pa
4249
RH_zref: float = 0.75
4350
dry_molar_conc_H2: float = 0
4451
dry_molar_conc_He: float = 0
@@ -52,7 +59,7 @@ class Earth(Planet):
5259
class EarlyMars(Planet):
5360
g_std: float = 3.71 * si.metre / si.second**2
5461
T_STP: float = 290 * si.kelvin
55-
p_STP: float = 2 * 1e6 * si.pascal
62+
p_STP: float = 2 * 1e5 * si.Pa
5663
RH_zref: float = 0.75
5764
dry_molar_conc_H2: float = 0
5865
dry_molar_conc_He: float = 0
@@ -66,7 +73,7 @@ class EarlyMars(Planet):
6673
class Jupiter(Planet):
6774
g_std: float = 24.84 * si.metre / si.second**2
6875
T_STP: float = 274 * si.kelvin
69-
p_STP: float = 4.85 * 1e6 * si.pascal
76+
p_STP: float = 4.85 * 1e5 * si.Pa
7077
RH_zref: float = 1
7178
dry_molar_conc_H2: float = 0.864
7279
dry_molar_conc_He: float = 0.136
@@ -80,7 +87,7 @@ class Jupiter(Planet):
8087
class Saturn(Planet):
8188
g_std: float = 10.47 * si.metre / si.second**2
8289
T_STP: float = 284 * si.kelvin
83-
p_STP: float = 10.4 * 1e6 * si.pascal
90+
p_STP: float = 10.4 * 1e5 * si.Pa
8491
RH_zref: float = 1
8592
dry_molar_conc_H2: float = 0.88
8693
dry_molar_conc_He: float = 0.12
@@ -94,7 +101,7 @@ class Saturn(Planet):
94101
class K2_18B(Planet):
95102
g_std: float = 12.44 * si.metre / si.second**2
96103
T_STP: float = 275 * si.kelvin
97-
p_STP: float = 0.1 * 1e6 * si.pascal
104+
p_STP: float = 0.1 * 1e5 * si.Pa
98105
RH_zref: float = 1
99106
dry_molar_conc_H2: float = 0.9
100107
dry_molar_conc_He: float = 0.1
@@ -108,7 +115,7 @@ class K2_18B(Planet):
108115
class CompositeTest(Planet):
109116
g_std: float = 9.82 * si.metre / si.second**2
110117
T_STP: float = 275 * si.kelvin
111-
p_STP: float = 0.75 * 1e6 * si.pascal
118+
p_STP: float = 0.75 * 1e5 * si.Pa
112119
RH_zref: float = 1
113120
dry_molar_conc_H2: float = 0.1
114121
dry_molar_conc_He: float = 0.1

0 commit comments

Comments
 (0)