Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed dry-air molar mass (number vs. mass weighting), l_tri as a computed derived value; bib-script enhancements #1507

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,27 @@ jobs:
needs: [nojit_and_codecov]
strategy:
matrix:
platform: [ubuntu-24.04, macos-13, macos-14, windows-latest]
platform: [windows-latest]
# platform: [ubuntu-24.04, macos-13, macos-14, windows-latest]
python-version: ["3.9", "3.12"]
test-suite: ["unit_tests/!(dynamics)", "unit_tests/dynamics/!(collisions)", "unit_tests/dynamics/collisions", "smoke_tests/no_env", "smoke_tests/box", "smoke_tests/parcel_a", "smoke_tests/parcel_b", "smoke_tests/parcel_c", "smoke_tests/parcel_d", "smoke_tests/kinematic_1d", "smoke_tests/kinematic_2d", "tutorials_tests"]
exclude:
- platform: "macos-14"
python-version: "3.9"
- test-suite: "devops_tests"
python-version: "3.9"
# TODO #1406
- platform: "macos-14"
test-suite: "smoke_tests/box"
- platform: "macos-14"
test-suite: "smoke_tests/parcel_a"
- platform: "macos-14"
test-suite: "smoke_tests/parcel_d"
- platform: "macos-14"
test-suite: "smoke_tests/kinematic_2d"
- platform: "macos-14"
test-suite: "unit_tests/!(dynamics)"
# test-suite: ["unit_tests/!(dynamics)", "unit_tests/dynamics/!(collisions)", "unit_tests/dynamics/collisions", "smoke_tests/no_env", "smoke_tests/box", "smoke_tests/parcel_a", "smoke_tests/parcel_b", "smoke_tests/parcel_c", "smoke_tests/parcel_d", "smoke_tests/kinematic_1d", "smoke_tests/kinematic_2d", "tutorials_tests"]
test-suite: ["smoke_tests/parcel_d"]
# exclude:
# - platform: "macos-14"
# python-version: "3.9"
# - test-suite: "devops_tests"
# python-version: "3.9"
# # TODO #1406
# - platform: "macos-14"
# test-suite: "smoke_tests/box"
# - platform: "macos-14"
# test-suite: "smoke_tests/parcel_a"
# - platform: "macos-14"
# test-suite: "smoke_tests/parcel_d"
# - platform: "macos-14"
# test-suite: "smoke_tests/kinematic_2d"
# - platform: "macos-14"
# test-suite: "unit_tests/!(dynamics)"
fail-fast: false
runs-on: ${{ matrix.platform }}
timeout-minutes: ${{ startsWith(matrix.platform, 'windows-') && 35 || 30 }}
Expand Down Expand Up @@ -172,7 +174,7 @@ jobs:
# limit-access-to-actor: true

examples-setup:
needs: [nojit_and_codecov]
needs: [tests] # only for debug [nojit_and_codecov]
strategy:
matrix:
platform: [ubuntu-24.04, macos-13, windows-latest]
Expand Down
32 changes: 15 additions & 17 deletions PySDM/physics/constants_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import numpy as np
from chempy import Substance
from scipy import constants as sci

from .constants import ( # pylint: disable=unused-import
Expand All @@ -29,14 +28,11 @@
)
from .trivia import Trivia

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

VSMOW_R_2H = 155.76 * PPM
"""
Expand Down Expand Up @@ -194,8 +190,8 @@
[Murphy & Koop 2005](https://doi.org/10.1256/qj.04.94) """
T_tri = 273.16 * si.kelvin
""" 〃 """

l_tri = 2.5e6 * si.joule / si.kilogram
L_tri = 45051.0 * si.joule / si.mol
""" 〃 """

l_l19_a = 0.167 * si.dimensionless
""" [Seinfeld and Pandis](https://archive.org/details/0237-pdf-atmospheric-chemistry-and-physics-2nd-ed-j.-seinfeld-s.-pandis-wiley-2006-ww)
Expand Down Expand Up @@ -552,7 +548,7 @@
ROGERS_YAU_TERM_VEL_SMALL_R_LIMIT = 35 * si.um
""" 〃 """
ROGERS_YAU_TERM_VEL_MEDIUM_R_LIMIT = 600 * si.um
""" 〃 """


W76W_G0 = -2.9912729e3 * si.K**2
""" [Wexler 1976](https://doi.org/10.6028/jres.080A.071) saturation vapour pressure """
Expand Down Expand Up @@ -654,23 +650,23 @@ def compute_derived_values(c: dict):

c["Mv"] = (
(
1
1.0
- 2 * Trivia.mixing_ratio_to_specific_content(c["VSMOW_R_2H"])
- 2 * Trivia.mixing_ratio_to_specific_content(c["VSMOW_R_3H"])
- 1 * Trivia.mixing_ratio_to_specific_content(c["VSMOW_R_17O"])
- 1 * Trivia.mixing_ratio_to_specific_content(c["VSMOW_R_18O"])
)
* (c["M_1H"] * 2 + c["M_16O"])
+ 2
+ 2.0
* Trivia.mixing_ratio_to_specific_content(c["VSMOW_R_2H"])
* (c["M_2H"] + c["M_1H"] + c["M_16O"])
+ 2
+ 2.0
* Trivia.mixing_ratio_to_specific_content(c["VSMOW_R_3H"])
* (c["M_3H"] + c["M_1H"] + c["M_16O"])
+ 1
+ 1.0
* Trivia.mixing_ratio_to_specific_content(c["VSMOW_R_17O"])
* (c["M_1H"] * 2 + c["M_17O"])
+ 1
+ 1.0
* Trivia.mixing_ratio_to_specific_content(c["VSMOW_R_18O"])
* (c["M_1H"] * 2 + c["M_18O"])
)
Expand All @@ -684,3 +680,5 @@ def compute_derived_values(c: dict):
c["water_molar_volume"] = c["Mv"] / c["rho_w"]
c["rho_STP"] = c["p_STP"] / c["Rd"] / c["T_STP"]
c["H_u"] = c["M"] / c["p_STP"]

c["l_tri"] = c["L_tri"] / c["Mv"] # 2.5e6 * si.joule / si.kilogram
8 changes: 8 additions & 0 deletions PySDM/physics/trivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,11 @@ def air_schmidt_number(dynamic_viscosity, diffusivity, density):
@staticmethod
def sqrt_re_times_cbrt_sc(const, Re, Sc):
return np.power(Re, const.ONE_HALF) * np.power(Sc, const.ONE_THIRD)

@staticmethod
def K2C(const, TK):
return TK - const.T0

@staticmethod
def C2K(const, TC):
return TC + const.T0
5 changes: 5 additions & 0 deletions docs/bibliography.json
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@
"title": "Vapor Pressure Formulation for Water in Range 0 to 100 °C. A Revision",
"label": "Wexler 1976 (J. Res. NBS A Phys. Ch. 80A)"
},
"https://doi.org/10.1080/10789669.2008.10391032": {
"usages": ["PySDM/physics/constants_defaults.py"],
"title": "A Twenty-First Century Molar Mass for Dry Air",
"label": "Gatley et al. 2008 (HVAC&R Res. 14)"
},
"https://archive.org/details/shortcourseinclo0000roge_m3k2": {
"usages": ["PySDM/physics/constants_defaults.py", "PySDM/physics/terminal_velocity/rogers_yau.py"],
"title": "A short course in clouds physics",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
" - 1\n",
" ),\n",
" 'T0': FIG4_CAPTION_PARAMS['T_init'],\n",
" 'mass_of_dry_air': 1 * si.kg,\n",
" 'mass_of_dry_air': 1.0 * si.kg,\n",
"}\n",
"ARBITRARY_PARAMS['INIT_ATTRIBUTES'] = Builder(\n",
" n_sd=ARBITRARY_PARAMS['N_SUPER_DROPLETS'],\n",
Expand Down Expand Up @@ -166,7 +166,7 @@
" alpha_old[isotope] = alpha_fun(self[\"T\"][0])\n",
" alpha_new = alpha_fun(self._tmp[\"T\"][0])\n",
" \n",
" dRv__dt[isotope] = self[f'Rv_{isotope}'][0] * self.formulae.isotope_ratio_evolution.d_Rv_over_Rv(\n",
" dRv__dt[isotope] = self[f'Rv_{isotope}'][0] * formulae.isotope_ratio_evolution.d_Rv_over_Rv(\n",
" alpha=alpha_old[isotope],\n",
" d_alpha=(alpha_new - alpha_old[isotope]) / self.dt,\n",
" n_vapour=self['water_vapour_mixing_ratio'][0],\n",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/backends/test_physics_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_temperature_pressure_rh(backend_instance):
# Assert
assert 282 * si.K < T.amin() < 283 * si.K
assert 810 * si.hPa < p.amin() < 830 * si.hPa
assert 1.12 < RH.amin() < 1.13
assert 1.10 < RH.amin() < 1.11

@staticmethod
@pytest.mark.parametrize("variant", ("LiquidSpheres", "MixedPhaseSpheres"))
Expand Down
7 changes: 4 additions & 3 deletions tests/unit_tests/physics/test_drop_growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import numpy as np

from PySDM.formulae import _choices, Formulae
from PySDM.physics import drop_growth, constants_defaults, si, in_unit
from PySDM.physics import drop_growth
from PySDM.physics.constants import PER_CENT, si, in_unit
from PySDM.physics.dimensional_analysis import DimensionalAnalysis


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

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

# plot
pyplot.plot(temperatures, in_unit(relative_error, constants_defaults.PER_CENT))
pyplot.plot(temperatures, in_unit(relative_error, PER_CENT))
pyplot.title("")
pyplot.xlabel("temperature [K]")
pyplot.ylabel("r dr/dt relative difference (1971 vs. 1951) [%]")
Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/physics/test_latent_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def test_latent_heats(plot=False):
formulae = {k: Formulae(latent_heat=k) for k in ("Kirchhoff", "Lowe2019")}
const = Formulae().constants
temperature = np.linspace(-20, 20) + const.T_tri

# Plot
pyplot.axhline(const.l_tri, label="triple point", color="red")
pyplot.axvline(const.T_tri, color="red")
Expand Down
Loading