Skip to content

Commit c310fb3

Browse files
authored
Merge pull request #853 from sajjadazimi/condensation_thd_update_option
an option to fix thd in condensation dynamics is added
2 parents 573561e + 96dcfa8 commit c310fb3

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

PySDM/dynamics/condensation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(
2727
dt_cond_range: tuple = DEFAULTS.cond_range,
2828
schedule: str = DEFAULTS.schedule,
2929
max_iters: int = 16,
30+
update_thd: bool = True,
3031
):
3132

3233
self.particulator = None
@@ -47,6 +48,8 @@ def __init__(
4748

4849
self.cell_order = None
4950

51+
self.update_thd = update_thd
52+
5053
def register(self, builder):
5154
self.particulator = builder.particulator
5255

@@ -100,6 +103,10 @@ def __call__(self):
100103
)
101104
if not self.success.all():
102105
raise RuntimeError("Condensation failed")
106+
if not self.update_thd:
107+
self.particulator.environment.get_predicted("thd").ravel(
108+
self.particulator.environment.get_thd()
109+
)
103110
# note: this makes order of dynamics matter
104111
# (e.g., condensation after chemistry or before)
105112
self.particulator.update_TpRH()

test-time-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ ghapi
44
pytest
55

66
# note: if cloning both PySDM and PySDM examples, consider "pip install -e"
7-
PySDM-examples @ git+https://github.com/atmos-cloud-sim-uj/PySDM-examples@050ab12#egg=PySDM-examples
7+
PySDM-examples @ git+https://github.com/sajjadazimi/PySDM-examples@e8797c6#egg=PySDM-examples
88
PyMPDATA @ git+https://github.com/atmos-cloud-sim-uj/PyMPDATA@e7b73a7#egg=PyMPDATA

tests/smoke_tests/shipway_and_hill_2012/test_few_steps.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_few_steps_no_precip(particle_reservoir_depth, plot=False):
2828
)
2929
settings.particle_reservoir_depth = particle_reservoir_depth
3030
settings.t_max = 50 * settings.dt
31+
settings.condensation_update_thd = True
3132
simulation = Simulation(settings)
3233

3334
# Act
@@ -80,3 +81,38 @@ def mean_profile_over_last_steps(var, smooth=True):
8081

8182
assert max(mean_profile_over_last_steps("ripening rate")) > 0
8283
assert max(mean_profile_over_last_steps("deactivating rate")) > 0
84+
85+
86+
def test_fixed_thd():
87+
# Arrange
88+
n_sd_per_gridbox = 128
89+
settings = Settings(
90+
n_sd_per_gridbox=n_sd_per_gridbox,
91+
dt=30 * si.s,
92+
dz=60 * si.m,
93+
precip=False,
94+
rho_times_w_1=2 * si.m / si.s * si.kg / si.m**3,
95+
)
96+
settings.t_max = 50 * settings.dt
97+
settings.condensation_update_thd = False
98+
simulation = Simulation(settings)
99+
100+
# Act
101+
output = simulation.run().products
102+
103+
# Assert
104+
mean_profile_over_last_steps = lambda var: np.mean(
105+
output[var][output["z"] >= 0, -10:], axis=1
106+
)
107+
sd_prof = mean_profile_over_last_steps("super droplet count per gridbox")
108+
assert 0.5 * n_sd_per_gridbox < min(sd_prof) < 1.5 * n_sd_per_gridbox
109+
assert 0.5 * n_sd_per_gridbox < max(sd_prof) < 1.5 * n_sd_per_gridbox
110+
111+
assert 0.01 < max(mean_profile_over_last_steps("peak supersaturation")) < 0.1
112+
assert min(mean_profile_over_last_steps("ql")) < 1e-10
113+
assert 0.6 < max(mean_profile_over_last_steps("ql")) < 0.9
114+
assert max(mean_profile_over_last_steps("activating rate")) == 0
115+
assert max(mean_profile_over_last_steps("ripening rate")) == 0
116+
assert max(mean_profile_over_last_steps("deactivating rate")) == 0
117+
118+
assert sum(np.amin(output["thd"], axis=1)) == sum(np.amax(output["thd"], axis=1))

0 commit comments

Comments
 (0)