Skip to content

Commit 476701b

Browse files
fixed dry-air molar mass (number vs. mass weighting), l_tri as a computed derived value; bib-script enhancements; Trivia.K2C and C2K; introducing XFAIL for R&S example on Windows (to be addressed in subsequent PR) (#1507)
Co-authored-by: Sylwester Arabas <[email protected]>
1 parent 4ff7b64 commit 476701b

File tree

10 files changed

+62
-21
lines changed

10 files changed

+62
-21
lines changed

.github/workflows/tests.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,12 @@ jobs:
267267
pvpython --version
268268
pvpython -c "from paraview import simple"
269269
270-
- env:
271-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
272-
run: |
270+
- run: |
273271
python -m pytest --durations=10 -v -p no:unraisableexception -We tests/examples_tests/test_tests_completeness.py
274-
python -m pytest --durations=10 -v -p no:unraisableexception -We tests/examples_tests/test_run* --suite ${{ matrix.test-suite }}
272+
273+
# TODO #1207
274+
- if: startsWith(matrix.platform, 'windows-')
275+
run: python -m pytest --durations=10 -v -p no:unraisableexception -We tests/examples_tests/test_run* -k "not Rozanski_and_Sonntag_1982" --suite ${{ matrix.test-suite }}
276+
277+
- if: ( ! startsWith(matrix.platform, 'windows-') )
278+
run: python -m pytest --durations=10 -v -p no:unraisableexception -We tests/examples_tests/test_run* --suite ${{ matrix.test-suite }}

PySDM/physics/constants_defaults.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""
77

88
import numpy as np
9-
from chempy import Substance
109
from scipy import constants as sci
1110

1211
from .constants import ( # pylint: disable=unused-import
@@ -29,14 +28,11 @@
2928
)
3029
from .trivia import Trivia
3130

32-
# https://physics.nist.gov/cgi-bin/Star/compos.pl?matno=104
33-
# TODO #1507
34-
Md = (
35-
0.755267 * Substance.from_formula("N2").mass * si.gram / si.mole
36-
+ 0.231781 * Substance.from_formula("O2").mass * si.gram / si.mole
37-
+ 0.012827 * Substance.from_formula("Ar").mass * si.gram / si.mole
38-
+ 0.000124 * Substance.from_formula("C").mass * si.gram / si.mole
39-
)
31+
Md = 28.966 * si.g / si.mole
32+
"""
33+
A "twenty-first century" value of dry-air molar mass recommended in
34+
[Gatley et al. 2008](https://doi.org/10.1080/10789669.2008.10391032)
35+
"""
4036

4137
VSMOW_R_2H = 155.76 * PPM
4238
"""
@@ -194,8 +190,8 @@
194190
[Murphy & Koop 2005](https://doi.org/10.1256/qj.04.94) """
195191
T_tri = 273.16 * si.kelvin
196192
""" 〃 """
197-
198-
l_tri = 2.5e6 * si.joule / si.kilogram
193+
L_tri = 45051.0 * si.joule / si.mol
194+
""" 〃 """
199195

200196
l_l19_a = 0.167 * si.dimensionless
201197
""" [Seinfeld and Pandis](https://archive.org/details/0237-pdf-atmospheric-chemistry-and-physics-2nd-ed-j.-seinfeld-s.-pandis-wiley-2006-ww)
@@ -687,3 +683,5 @@ def compute_derived_values(c: dict):
687683
c["water_molar_volume"] = c["Mv"] / c["rho_w"]
688684
c["rho_STP"] = c["p_STP"] / c["Rd"] / c["T_STP"]
689685
c["H_u"] = c["M"] / c["p_STP"]
686+
687+
c["l_tri"] = c["L_tri"] / c["Mv"]

PySDM/physics/trivia.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ def air_schmidt_number(dynamic_viscosity, diffusivity, density):
138138
def sqrt_re_times_cbrt_sc(const, Re, Sc):
139139
return np.power(Re, const.ONE_HALF) * np.power(Sc, const.ONE_THIRD)
140140

141+
@staticmethod
142+
def K2C(const, TK):
143+
return TK - const.T0
144+
145+
@staticmethod
146+
def C2K(const, TC):
147+
return TC + const.T0
148+
141149
@staticmethod
142150
def poissonian_avoidance_function(r, dt):
143151
"""cumulative probability of zero events occurring within time `dt`

docs/bibliography.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,11 @@
719719
"title": "Vapor Pressure Formulation for Water in Range 0 to 100 °C. A Revision",
720720
"label": "Wexler 1976 (J. Res. NBS A Phys. Ch. 80A)"
721721
},
722+
"https://doi.org/10.1080/10789669.2008.10391032": {
723+
"usages": ["PySDM/physics/constants_defaults.py"],
724+
"title": "A Twenty-First Century Molar Mass for Dry Air",
725+
"label": "Gatley et al. 2008 (HVAC&R Res. 14)"
726+
},
722727
"https://archive.org/details/shortcourseinclo0000roge_m3k2": {
723728
"usages": ["PySDM/physics/constants_defaults.py", "PySDM/physics/terminal_velocity/rogers_yau.py"],
724729
"title": "A short course in clouds physics",

examples/PySDM_examples/Rozanski_and_Sonntag_1982/multibox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(
4646

4747
def advance_parcel_vars(self):
4848
"""explicit Euler integration of isotope-ratio time derivative"""
49+
assert self.delta_liquid_water_mixing_ratio >= 0
4950
self._recalculate_temperature_pressure_relative_humidity(self._tmp)
5051

5152
alpha_old = {}
@@ -67,7 +68,6 @@ def advance_parcel_vars(self):
6768
d_n_vapour=-self.delta_liquid_water_mixing_ratio / self.dt,
6869
n_liquid=self.autoconversion_mixrat_threshold, # TODO #1207
6970
)
70-
assert dRv__dt[isotope] <= 0
7171

7272
super().advance_parcel_vars()
7373

tests/smoke_tests/parcel_d/rozanski_and_sonntag_1982/test_figs_4_5_6.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""tests ensuring values on plots match those in the paper"""
22

33
from pathlib import Path
4+
import platform
45

56
import numpy as np
67
import pytest
@@ -20,6 +21,7 @@ def variables_fixture():
2021
)
2122

2223

24+
@pytest.mark.xfail(platform.system() == "Windows", strict=True, reason="TODO #1207")
2325
class TestFigs456:
2426
@staticmethod
2527
def test_fig_5_vapour_asymptote(variables):

tests/unit_tests/backends/test_physics_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_temperature_pressure_rh(backend_instance):
3535
# Assert
3636
assert 282 * si.K < T.amin() < 283 * si.K
3737
assert 810 * si.hPa < p.amin() < 830 * si.hPa
38-
assert 1.12 < RH.amin() < 1.13
38+
assert 1.10 < RH.amin() < 1.11
3939

4040
@staticmethod
4141
@pytest.mark.parametrize("variant", ("LiquidSpheres", "MixedPhaseSpheres"))

tests/unit_tests/physics/test_drop_growth.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import numpy as np
66

77
from PySDM.formulae import _choices, Formulae
8-
from PySDM.physics import drop_growth, constants_defaults, si, in_unit
8+
from PySDM.physics import drop_growth
9+
from PySDM.physics.constants import PER_CENT, si, in_unit
910
from PySDM.physics.dimensional_analysis import DimensionalAnalysis
1011

1112

@@ -39,7 +40,7 @@ def test_mason_1971_vs_1951_difference_vs_temperature(plot=False):
3940
"""checks the relative difference between Mason's 1951 and 1971 formulae
4041
for a range of temperatures"""
4142
# arrange
42-
temperatures = constants_defaults.T0 + np.linspace(-10, 40) * si.K
43+
temperatures = Formulae().trivia.C2K(np.linspace(-10, 40) * si.K)
4344
papers = ("Mason1951", "Mason1971")
4445

4546
# act
@@ -60,7 +61,7 @@ def test_mason_1971_vs_1951_difference_vs_temperature(plot=False):
6061
relative_error = r_dr_dt["Mason1971"] / r_dr_dt["Mason1951"] - 1
6162

6263
# plot
63-
pyplot.plot(temperatures, in_unit(relative_error, constants_defaults.PER_CENT))
64+
pyplot.plot(temperatures, in_unit(relative_error, PER_CENT))
6465
pyplot.title("")
6566
pyplot.xlabel("temperature [K]")
6667
pyplot.ylabel("r dr/dt relative difference (1971 vs. 1951) [%]")

tests/unit_tests/physics/test_latent_heat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ def test_latent_heats(plot=False):
1212
formulae = {k: Formulae(latent_heat=k) for k in ("Kirchhoff", "Lowe2019")}
1313
const = Formulae().constants
1414
temperature = np.linspace(-20, 20) + const.T_tri
15-
1615
# Plot
1716
pyplot.axhline(const.l_tri, label="triple point", color="red")
1817
pyplot.axvline(const.T_tri, color="red")

tests/unit_tests/physics/test_trivia.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,27 @@ def test_poissonian_avoidance_function():
8989

9090
# Assert
9191
assert prob.check(si.dimensionless)
92+
93+
@staticmethod
94+
def test_kelvin_to_celsius():
95+
# arrange
96+
formulae = Formulae()
97+
temperature_in_kelvin = 44
98+
99+
# act
100+
temperature_in_celsius = formulae.trivia.K2C(temperature_in_kelvin)
101+
102+
# assert
103+
assert temperature_in_celsius == temperature_in_kelvin - 273.15
104+
105+
@staticmethod
106+
def test_celsius_to_kelvin():
107+
# arrange
108+
formulae = Formulae()
109+
temperature_in_celsius = 666
110+
111+
# act
112+
temperature_in_kelvin = formulae.trivia.C2K(temperature_in_celsius)
113+
114+
# assert
115+
assert temperature_in_kelvin == temperature_in_celsius + 273.15

0 commit comments

Comments
 (0)