Skip to content

Commit f6b8255

Browse files
authored
ensure no NaNs are used in parcel env initialisation. closes #1198 (#1301)
1 parent 6128a4e commit f6b8255

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

PySDM/environments/parcel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def register(self, builder):
7171
self["z"][:] = params[3]
7272
self["t"][:] = params[4]
7373

74+
self._tmp["water_vapour_mixing_ratio"][:] = params[0]
7475
self.sync_parcel_vars()
7576
Moist.sync(self)
7677
self.notify()

tests/unit_tests/dynamics/condensation/test_parcel_sanity_checks.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
""" tests ensuring proper condensation solver operation in some parcel-model based cases """
22

3+
import numpy as np
4+
35
import pytest
46
from matplotlib import pyplot
57
from scipy import signal
@@ -177,3 +179,29 @@ def test_how_condensation_modifies_args(backend_class, update_thd, substeps):
177179
assert pred_thd_old != env.get_predicted("thd")[cell_id]
178180
else:
179181
assert pred_thd_old == env.get_predicted("thd")[cell_id]
182+
183+
@staticmethod
184+
def test_zero_initial_delta_liquid_water_mixing_ratio(backend_class):
185+
# arrange
186+
env = Parcel(
187+
dt=1 * si.s,
188+
mass_of_dry_air=np.nan * si.mg,
189+
p0=np.nan * si.hPa,
190+
initial_water_vapour_mixing_ratio=44 * si.g / si.kg,
191+
T0=np.nan * si.K,
192+
w=np.nan * si.m / si.s,
193+
)
194+
builder = Builder(n_sd=1, backend=backend_class(), environment=env)
195+
builder.add_dynamic(AmbientThermodynamics())
196+
builder.add_dynamic(Condensation())
197+
198+
# act
199+
_ = builder.build(
200+
products=(),
201+
attributes=builder.particulator.environment.init_attributes(
202+
kappa=1, r_dry=0.25 * si.um, n_in_dv=1000
203+
),
204+
)
205+
206+
# assert
207+
assert env.delta_liquid_water_mixing_ratio == 0

0 commit comments

Comments
 (0)