Skip to content

Commit 1a15de0

Browse files
authored
isotopes: Rozanski & Sonntag 1982 example (#1209)
1 parent 38b0fa7 commit 1a15de0

File tree

11 files changed

+14984
-72
lines changed

11 files changed

+14984
-72
lines changed

PySDM/dynamics/isotopic_fractionation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ def register(self, builder):
3535
builder.request_attribute(f"moles_{isotope}")
3636

3737
def __call__(self):
38-
self.particulator.isotopic_fractionation()
38+
self.particulator.isotopic_fractionation(self.isotopes)

PySDM/environments/impl/moist.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ def __init__(self, dt, mesh, variables, mixed_phase=False):
1212
variables += ["water_vapour_mixing_ratio", "thd", "T", "p", "RH"]
1313
if mixed_phase:
1414
variables += ["a_w_ice"]
15+
all_vars_unique = len(variables) == len(set(variables))
16+
assert all_vars_unique
17+
1518
self.particulator = None
1619
self.dt = dt
1720
self.mesh = mesh
@@ -57,11 +60,7 @@ def get_predicted(self, index):
5760
)
5861
return self._values["predicted"][index]
5962

60-
def sync(self):
61-
target = self._tmp
62-
target["water_vapour_mixing_ratio"].ravel(self.get_water_vapour_mixing_ratio())
63-
target["thd"].ravel(self.get_thd())
64-
63+
def _recalculate_temperature_pressure_relative_humidity(self, target):
6564
self.particulator.backend.temperature_pressure_rh(
6665
rhod=target["rhod"],
6766
thd=target["thd"],
@@ -70,6 +69,14 @@ def sync(self):
7069
p=target["p"],
7170
RH=target["RH"],
7271
)
72+
73+
def sync(self):
74+
target = self._tmp
75+
target["water_vapour_mixing_ratio"].ravel(self.get_water_vapour_mixing_ratio())
76+
target["thd"].ravel(self.get_thd())
77+
78+
self._recalculate_temperature_pressure_relative_humidity(target)
79+
7380
if "a_w_ice" in self.variables:
7481
self.particulator.backend.a_w_ice(
7582
T=target["T"],

PySDM/environments/parcel.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Zero-dimensional adiabatic parcel framework
33
"""
44

5+
from typing import List, Optional
6+
57
import numpy as np
68

79
from PySDM.environments.impl.moist import Moist
@@ -24,10 +26,10 @@ def __init__(
2426
w: [float, callable],
2527
z0: float = 0,
2628
mixed_phase=False,
29+
variables: Optional[List[str]] = None,
2730
):
28-
super().__init__(
29-
dt, Mesh.mesh_0d(), ["rhod", "z", "t"], mixed_phase=mixed_phase
30-
)
31+
variables = (variables or []) + ["rhod", "z", "t"]
32+
super().__init__(dt, Mesh.mesh_0d(), variables, mixed_phase=mixed_phase)
3133

3234
self.p0 = p0
3335
self.initial_water_vapour_mixing_ratio = initial_water_vapour_mixing_ratio
@@ -38,7 +40,7 @@ def __init__(
3840
self.w = w if callable(w) else lambda _: w
3941

4042
self.formulae = None
41-
self.delta_liquid_water_mixing_ratio = None
43+
self.delta_liquid_water_mixing_ratio = np.nan
4244
self.params = None
4345

4446
@property
@@ -116,6 +118,7 @@ def advance_parcel_vars(self):
116118
- self.delta_liquid_water_mixing_ratio / 2
117119
)
118120

121+
# derivate evaluated at p_old, T_old, mixrat_mid, w_mid
119122
drho_dz = self.formulae.hydrostatics.drho_dz(
120123
g=self.formulae.constants.g_std,
121124
p=p,

PySDM/physics/isotope_ratio_evolution/merlivat_and_jouzel_1979.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
22
see derivation of eq. (12) in [Merlivat and Jouzel 1979](https://doi.org/10.1029/JC084iC08p05029)
3+
(for constant alpha leads to eq. (13) in
4+
[Gedzelman & Arnold 1994](https://doi.org/10.1029/93jd03518))
35
"""
46

57

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""
2+
based on Rozanski and Sonntag 1982 (Tellus)
3+
https://doi.org/10.3402/tellusa.v34i2.10795
4+
"""
5+
6+
# pylint: disable=invalid-name

0 commit comments

Comments
 (0)