Skip to content

Commit

Permalink
extended case set to cover both subsaturated and supersaturated condi…
Browse files Browse the repository at this point in the history
…tions, and added assert to ensure these are indeed the conditions
  • Loading branch information
slayoo committed Jan 11, 2025
1 parent b71a6e3 commit 3326280
Showing 1 changed file with 50 additions and 22 deletions.
72 changes: 50 additions & 22 deletions tests/unit_tests/environments/test_moist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,68 @@
import pytest
import numpy as np
from PySDM.environments import Parcel
from PySDM.physics import si
from PySDM.physics import si, constants_defaults
from PySDM import Builder
from PySDM.backends import GPU

COMMON_PARCEL_CTOR_ARGS = {
"mixed_phase": True,
"dt": np.nan,
"mass_of_dry_air": np.nan,
"w": np.nan,
}
T0 = constants_defaults.T0


@pytest.mark.parametrize(
"env",
"env, check",
(
Parcel(
mixed_phase=True,
dt=np.nan,
mass_of_dry_air=np.nan,
p0=1000 * si.hPa,
initial_water_vapour_mixing_ratio=20 * si.g / si.kg,
T0=300 * si.K,
w=np.nan,
(
Parcel(
p0=1000 * si.hPa,
initial_water_vapour_mixing_ratio=20 * si.g / si.kg,
T0=300 * si.K,
**COMMON_PARCEL_CTOR_ARGS,
),
f"_['T']>{T0} and _['RH']<1 and _['RH_ice']<1",
),
(
Parcel(
p0=1000 * si.hPa,
initial_water_vapour_mixing_ratio=25 * si.g / si.kg,
T0=300 * si.K,
**COMMON_PARCEL_CTOR_ARGS,
),
f"_['T']>{T0} and _['RH']>1 and _['RH_ice']<1",
),
(
Parcel(
p0=500 * si.hPa,
initial_water_vapour_mixing_ratio=0.2 * si.g / si.kg,
T0=250 * si.K,
**COMMON_PARCEL_CTOR_ARGS,
),
f"_['T']<{T0} and _['RH']<1 and _['RH_ice']<1",
),
Parcel(
mixed_phase=True,
dt=np.nan,
mass_of_dry_air=np.nan,
p0=500 * si.hPa,
initial_water_vapour_mixing_ratio=0.2 * si.g / si.kg,
T0=250 * si.K,
w=np.nan,
(
Parcel(
p0=500 * si.hPa,
initial_water_vapour_mixing_ratio=1 * si.g / si.kg,
T0=250 * si.K,
**COMMON_PARCEL_CTOR_ARGS,
),
f"_['T']<{T0} and _['RH']<1 and _['RH_ice']>1",
),
),
)
def test_ice_properties(backend_instance, env):
def test_ice_properties(backend_instance, env, check):
"""checks ice-related values in recalculated thermodynamic state make sense"""
if isinstance(backend_instance, GPU):
pytest.skip("TODO #1495")

# arrange
builder = Builder(n_sd=0, backend=backend_instance, environment=env)
const = builder.particulator.formulae.constants

# act
thermo = {
Expand All @@ -46,10 +73,11 @@ def test_ice_properties(backend_instance, env):
}

# assert
if ( thermo["T"] > 273.16 ):
assert 1 > thermo["RH"] > thermo["RH_ice"] > 0
exec(f"assert {check}", {"_": thermo}) # pylint: disable=exec-used
if thermo["T"] - const.T0 > 0:
assert thermo["RH"] > thermo["RH_ice"] > 0
else:
assert 1 > thermo["RH_ice"] > thermo["RH"] > 0
assert thermo["RH_ice"] > thermo["RH"] > 0
np.testing.assert_approx_equal(
thermo["a_w_ice"] * thermo["RH_ice"], thermo["RH"], significant=10
)

0 comments on commit 3326280

Please sign in to comment.