Skip to content

Commit 8b3631b

Browse files
aleksandratalpiotrbartmanslayoo
authored
new example: Toon et al. 1980 (hello-world for using PySDM for extraterrestrial clouds, here for Titan); variable-g/constant-T hydrostatics formulae (#142)
Co-authored-by: prbartman <[email protected]> Co-authored-by: Sylwester Arabas <[email protected]>
1 parent eda9921 commit 8b3631b

File tree

20 files changed

+2479
-15
lines changed

20 files changed

+2479
-15
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ jobs:
213213
matrix:
214214
platform: [ubuntu-24.04, macos-13, windows-latest]
215215
python-version: ["3.9", "3.12"]
216-
test-suite: [ "chemistry_freezing", "isotopes", "condensation_a", "condensation_b", "condensation_c", "coagulation", "breakup", "multi-process_a", "multi-process_b", "multi-process_c", "multi-process_d", "multi-process_e"]
216+
test-suite: [ "chemistry_freezing_extraterrestrial", "isotopes", "condensation_a", "condensation_b", "condensation_c", "coagulation", "breakup", "multi-process_a", "multi-process_b", "multi-process_c", "multi-process_d", "multi-process_e"]
217217
fail-fast: false
218218
runs-on: ${{ matrix.platform }}
219219
timeout-minutes: 35

PySDM/environments/parcel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def advance_parcel_vars(self):
114114

115115
# derivative evaluated at p_old, T_old, mixrat_mid, w_mid
116116
drho_dz = formulae.hydrostatics.drho_dz(
117-
g=formulae.constants.g_std,
118117
p=p,
119118
T=T,
120119
water_vapour_mixing_ratio=water_vapour_mixing_ratio,

PySDM/formulae.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__( # pylint: disable=too-many-locals
4141
ventilation: str = "Neglect",
4242
state_variable_triplet: str = "LibcloudphPlusPlus",
4343
particle_advection: str = "ImplicitInSpace",
44-
hydrostatics: str = "Default",
44+
hydrostatics: str = "ConstantGVapourMixingRatioAndThetaStd",
4545
freezing_temperature_spectrum: str = "Null",
4646
heterogeneous_ice_nucleation_rate: str = "Null",
4747
fragmentation_function: str = "AlwaysN",

PySDM/physics/constants_defaults.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@
606606
g_std = sci.g * si.metre / si.second**2
607607
""" standard gravitational acceleration (value from SciPy) """
608608

609+
celestial_body_radius = np.nan
610+
""" radius of the considered celestial body (Earth, Titan, ...) """
611+
609612
bulk_phase_partitioning_T_cold = 235 * si.K
610613
""" [Kaul et al. 2015](https://doi.org/10.1175/MWR-D-14-00319.1) """
611614
bulk_phase_partitioning_T_warm = 273 * si.K

PySDM/physics/hydrostatics/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
Helper routines for hydrostatic pressure and density profiles
33
"""
44

5-
from .default import Default
5+
from .constant_g_vapour_mixing_ratio_and_theta_std import (
6+
ConstantGVapourMixingRatioAndThetaStd,
7+
)
8+
from .variable_g_isothermal import VariableGIsothermal

PySDM/physics/hydrostatics/default.py renamed to PySDM/physics/hydrostatics/constant_g_vapour_mixing_ratio_and_theta_std.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
"""
2-
# TODO #407
2+
hydrostatic profile assuming constant g, constant water vapour mixing ratio
3+
and constant (standard) potential temperature
34
"""
45

56
import numpy as np
67

78

8-
class Default:
9+
class ConstantGVapourMixingRatioAndThetaStd:
910
def __init__(self, _):
1011
pass
1112

1213
# pylint: disable=too-many-arguments
1314
@staticmethod
1415
def drho_dz(
15-
const, g, p, T, water_vapour_mixing_ratio, lv, d_liquid_water_mixing_ratio__dz=0
16+
const, p, T, water_vapour_mixing_ratio, lv, d_liquid_water_mixing_ratio__dz=0
1617
):
1718
Rq = const.Rv / (1 / water_vapour_mixing_ratio + 1) + const.Rd / (
1819
1 + water_vapour_mixing_ratio
@@ -22,21 +23,21 @@ def drho_dz(
2223
)
2324
rho = p / Rq / T
2425
return (
25-
g / T * rho * (Rq / cp - 1)
26+
const.g_std / T * rho * (Rq / cp - 1)
2627
- p * lv / cp / T**2 * d_liquid_water_mixing_ratio__dz
2728
) / Rq
2829

2930
# pylint: disable=too-many-arguments
3031
@staticmethod
3132
def p_of_z_assuming_const_th_and_initial_water_vapour_mixing_ratio(
32-
const, g, p0, thstd, water_vapour_mixing_ratio, z
33+
const, p0, thstd, water_vapour_mixing_ratio, z
3334
):
3435
z0 = 0
3536
Rq = const.Rv / (1 / water_vapour_mixing_ratio + 1) + const.Rd / (
3637
1 + water_vapour_mixing_ratio
3738
)
3839
arg = (
3940
np.power(p0 / const.p1000, const.Rd_over_c_pd)
40-
- (z - z0) * const.Rd_over_c_pd * g / thstd / Rq
41+
- (z - z0) * const.Rd_over_c_pd * const.g_std / thstd / Rq
4142
)
4243
return const.p1000 * np.power(arg, 1 / const.Rd_over_c_pd)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
assuming constant temperature and variable
3+
gravitational acceleration g(z) = g0 * R^2 / (R+z)^2
4+
as in [Toon et al. 1980](https://doi.org/10.1016/0019-1035(80)90173-6)
5+
"""
6+
7+
import numpy as np
8+
from PySDM.physics import constants_defaults
9+
10+
11+
class VariableGIsothermal: # pylint: disable=too-few-public-methods
12+
def __init__(self, const):
13+
assert np.isfinite(const.celestial_body_radius)
14+
assert const.g_std != constants_defaults.g_std
15+
16+
@staticmethod
17+
def pressure(const, z, p0, temperature, molar_mass):
18+
return p0 * np.exp(
19+
-const.g_std
20+
/ const.R_str
21+
* molar_mass
22+
/ temperature
23+
* z
24+
/ (1 + z / const.celestial_body_radius)
25+
)

PySDM/physics/impl/fake_unit_registry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def __init__(self, si):
1616
for unit in (
1717
"bar",
1818
"metre",
19+
"meter",
1920
"gram",
2021
"hertz",
2122
"mole",
@@ -25,6 +26,7 @@ def __init__(self, si):
2526
"minute",
2627
"pascal",
2728
"litre",
29+
"liter",
2830
"hour",
2931
"newton",
3032
"watt",

docs/bibliography.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,5 +755,13 @@
755755
],
756756
"title": "Isotopic Composition and Temperature of Formation of Antarctic Snows",
757757
"label": "Picciotto et al. 1960 (Nature 187)"
758+
},
759+
"https://doi.org/10.1016/0019-1035(80)90173-6": {
760+
"usages": [
761+
"examples/PySDM_examples/Toon_et_al_1980/fig_1.ipynb",
762+
"PySDM/physics/hydrostatics/variable_g_isothermal.py"
763+
],
764+
"title": "A physical model of Titan’s clouds",
765+
"label": "Toon et al. 1980 (Icarus 43)"
758766
}
759767
}

examples/PySDM_examples/Morrison_and_Grabowski_2007/cumulus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __rhod_of_z(self, T_of_z, p_of_z, q_of_z, z_of_p, z_points):
5050
def drhod_dz(z, _):
5151
lv = self.formulae.latent_heat.lv(T_of_z(z))
5252
return self.formulae.hydrostatics.drho_dz(
53-
self.formulae.constants.g_std, p_of_z(z), T_of_z(z), q_of_z(z), lv
53+
p_of_z(z), T_of_z(z), q_of_z(z), lv
5454
)
5555

5656
theta_std0 = self.formulae.trivia.th_std(

0 commit comments

Comments
 (0)