diff --git a/PySDM/backends/impl_numba/methods/condensation_methods.py b/PySDM/backends/impl_numba/methods/condensation_methods.py index 67c8e1dba1..941a774d14 100644 --- a/PySDM/backends/impl_numba/methods/condensation_methods.py +++ b/PySDM/backends/impl_numba/methods/condensation_methods.py @@ -29,6 +29,7 @@ def condensation( rhod, thd, qv, + RH, dv, prhod, pthd, @@ -36,7 +37,7 @@ def condensation( kappa, f_org, rtol_x, - rtol_thd, + rtol_RH, timestep, counters, cell_order, @@ -58,6 +59,7 @@ def condensation( rhod=rhod.data, thd=thd.data, qv=qv.data, + RH=RH.data, dv_mean=dv, prhod=prhod.data, pthd=pthd.data, @@ -65,7 +67,7 @@ def condensation( kappa=kappa.data, f_org=f_org.data, rtol_x=rtol_x, - rtol_thd=rtol_thd, + rtol_RH=rtol_RH, timestep=timestep, counter_n_substeps=counters["n_substeps"].data, counter_n_activating=counters["n_activating"].data, @@ -92,6 +94,7 @@ def _condensation( rhod, thd, qv, + RH, dv_mean, prhod, pthd, @@ -99,7 +102,7 @@ def _condensation( kappa, f_org, rtol_x, - rtol_thd, + rtol_RH, timestep, counter_n_substeps, counter_n_activating, @@ -145,12 +148,13 @@ def _condensation( thd[cell_id], qv[cell_id], rhod[cell_id], + RH[cell_id], dthd_dt, dqv_dt, drhod_dt, md, rtol_x, - rtol_thd, + rtol_RH, timestep, counter_n_substeps[cell_id], ) @@ -177,7 +181,7 @@ def make_adapt_substeps( n_substeps_min = math.ceil(timestep / dt_range[1]) @numba.njit(**jit_flags) - def adapt_substeps(args, n_substeps, thd, rtol_thd): + def adapt_substeps(args, n_substeps, thd, RH, rtol_RH): n_substeps = np.maximum(n_substeps_min, n_substeps // multiplier) success = False for burnout in range(fuse + 1): @@ -191,24 +195,26 @@ def adapt_substeps(args, n_substeps, thd, rtol_thd): ), return_value=(0, False), ) - thd_new_long, success = step_fake(args, timestep, n_substeps) + _, RH_new_long, success = step_fake(args, timestep, n_substeps) if success: break n_substeps *= multiplier for burnout in range(fuse + 1): if burnout == fuse: return warn("burnout (short)", __file__, return_value=(0, False)) - thd_new_short, success = step_fake( + _, RH_new_short, success = step_fake( args, timestep, n_substeps * multiplier ) if not success: return warn("short failed", __file__, return_value=(0, False)) - dthd_long = thd_new_long - thd - dthd_short = thd_new_short - thd - error_estimate = np.abs(dthd_long - multiplier * dthd_short) - thd_new_long = thd_new_short - if within_tolerance(error_estimate, thd, rtol_thd): + + dRH_long = RH_new_long - RH + dRH_short = RH_new_short - RH + error_estimate = np.abs(dRH_long - multiplier * dRH_short) + RH_new_long = RH_new_short + if within_tolerance(error_estimate, RH, rtol_RH): break + n_substeps *= multiplier if n_substeps > n_substeps_max: break @@ -221,8 +227,8 @@ def make_step_fake(jit_flags, step_impl): @numba.njit(**jit_flags) def step_fake(args, dt, n_substeps): dt /= n_substeps - _, thd_new, _, _, _, _, success = step_impl(*args, dt, 1, True) - return thd_new, success + _, thd_new, RH_new, _, _, _, _, success = step_impl(*args, dt, 1, True) + return thd_new, RH_new, success return step_fake @@ -333,6 +339,7 @@ def step_impl( # pylint: disable=too-many-arguments,too-many-locals return ( qv, thd, + RH, count_activating, count_deactivating, count_ripening, @@ -417,7 +424,7 @@ def calculate_ml_new( # pylint: disable=too-many-arguments,too-many-statements, lambdaK = phys_lambdaK(T, p) lambdaD = phys_lambdaD(DTp, T) for drop in cell_idx: - if v[drop] < 0: + if v[drop] < 0: # TODO #1086: use _unfrozen from freezing_methods.py continue x_old = x(v[drop]) r_old = radius(v[drop]) @@ -666,12 +673,13 @@ def solve( # pylint: disable=too-many-arguments thd, qv, rhod, + RH, dthd_dt, dqv_dt, drhod_dt, m_d, rtol_x, - rtol_thd, + rtol_RH, timestep, n_substeps, ): @@ -694,11 +702,12 @@ def solve( # pylint: disable=too-many-arguments ) success = True if adaptive: - n_substeps, success = adapt_substeps(args, n_substeps, thd, rtol_thd) + n_substeps, success = adapt_substeps(args, n_substeps, thd, RH, rtol_RH) if success: ( qv, thd, + _, n_activating, n_deactivating, n_ripening, diff --git a/PySDM/backends/impl_numba/test_helpers/scipy_ode_condensation_solver.py b/PySDM/backends/impl_numba/test_helpers/scipy_ode_condensation_solver.py index 5da22468cb..13437082ef 100644 --- a/PySDM/backends/impl_numba/test_helpers/scipy_ode_condensation_solver.py +++ b/PySDM/backends/impl_numba/test_helpers/scipy_ode_condensation_solver.py @@ -24,7 +24,7 @@ def patch_particulator(particulator): def _condensation( - particulator, *, rtol_x, rtol_thd, counters, RH_max, success, cell_order + particulator, *, rtol_x, rtol_RH, counters, RH_max, success, cell_order ): func = Numba._condensation if not numba.config.DISABLE_JIT: # pylint: disable=no-member @@ -42,6 +42,7 @@ def _condensation( rhod=particulator.environment["rhod"].data, thd=particulator.environment["thd"].data, qv=particulator.environment["qv"].data, + RH=particulator.environment["RH"].data, dv_mean=particulator.environment.dv, prhod=particulator.environment.get_predicted("rhod").data, pthd=particulator.environment.get_predicted("thd").data, @@ -49,7 +50,7 @@ def _condensation( kappa=particulator.attributes["kappa"].data, f_org=particulator.attributes["dry volume organic fraction"].data, rtol_x=rtol_x, - rtol_thd=rtol_thd, + rtol_RH=rtol_RH, timestep=particulator.dt, counter_n_substeps=counters["n_substeps"], counter_n_activating=counters["n_activating"], @@ -178,14 +179,15 @@ def solve( # pylint: disable=too-many-arguments,too-many-locals thd, qv, rhod, + __, dthd_dt, dqv_dt, drhod_dt, m_d_mean, - __, ___, - dt, ____, + dt, + _____, ): n_sd_in_cell = len(cell_idx) y0 = np.empty(n_sd_in_cell + idx_x) diff --git a/PySDM/backends/impl_thrust_rtc/methods/condensation_methods.py b/PySDM/backends/impl_thrust_rtc/methods/condensation_methods.py index 6a49945810..951421c624 100644 --- a/PySDM/backends/impl_thrust_rtc/methods/condensation_methods.py +++ b/PySDM/backends/impl_thrust_rtc/methods/condensation_methods.py @@ -332,6 +332,7 @@ def condensation( rhod, thd, qv, + RH, dv, prhod, pthd, @@ -339,7 +340,7 @@ def condensation( kappa, f_org, rtol_x, - rtol_thd, + rtol_RH, timestep, counters, cell_order, diff --git a/PySDM/dynamics/condensation.py b/PySDM/dynamics/condensation.py index 2d3dae6460..406cdcbc1d 100644 --- a/PySDM/dynamics/condensation.py +++ b/PySDM/dynamics/condensation.py @@ -8,9 +8,9 @@ from ..physics import si -DEFAULTS = namedtuple("_", ("rtol_x", "rtol_thd", "cond_range", "schedule"))( +DEFAULTS = namedtuple("_", ("rtol_x", "rtol_RH", "cond_range", "schedule"))( rtol_x=1e-6, - rtol_thd=1e-6, + rtol_RH=1e-6, cond_range=(1e-4 * si.second, 1 * si.second), schedule="dynamic", ) @@ -21,7 +21,7 @@ def __init__( self, *, rtol_x=DEFAULTS.rtol_x, - rtol_thd=DEFAULTS.rtol_thd, + rtol_RH=DEFAULTS.rtol_RH, substeps: int = 1, adaptive: bool = True, dt_cond_range: tuple = DEFAULTS.cond_range, @@ -38,7 +38,7 @@ def __init__( self.enable = True self.rtol_x = rtol_x - self.rtol_thd = rtol_thd + self.rtol_RH = rtol_RH self.rh_max = None self.success = None @@ -62,7 +62,7 @@ def register(self, builder): adaptive=self.adaptive, fuse=32, multiplier=2, - RH_rtol=1e-7, + RH_rtol=1e-7, # TODO #868: use rtol_RH? max_iters=self.max_iters, ) builder.request_attribute("critical volume") @@ -99,7 +99,7 @@ def __call__(self): self.particulator.condensation( rtol_x=self.rtol_x, - rtol_thd=self.rtol_thd, + rtol_RH=self.rtol_RH, counters=self.counters, RH_max=self.rh_max, success=self.success, diff --git a/PySDM/particulator.py b/PySDM/particulator.py index b7241610d5..521c2104b9 100644 --- a/PySDM/particulator.py +++ b/PySDM/particulator.py @@ -101,7 +101,7 @@ def update_TpRH(self): RH=self.environment.get_predicted("RH"), ) - def condensation(self, *, rtol_x, rtol_thd, counters, RH_max, success, cell_order): + def condensation(self, *, rtol_x, rtol_RH, counters, RH_max, success, cell_order): """Updates droplet volumes by simulating condensation driven by prior changes in environment thermodynamic state, updates the environment state. In the case of parcel environment, condensation is driven solely by changes in @@ -121,6 +121,7 @@ def condensation(self, *, rtol_x, rtol_thd, counters, RH_max, success, cell_orde rhod=self.environment["rhod"], thd=self.environment["thd"], qv=self.environment["qv"], + RH=self.environment["RH"], dv=self.environment.dv, prhod=self.environment.get_predicted("rhod"), pthd=self.environment.get_predicted("thd"), @@ -128,7 +129,7 @@ def condensation(self, *, rtol_x, rtol_thd, counters, RH_max, success, cell_orde kappa=self.attributes["kappa"], f_org=self.attributes["dry volume organic fraction"], rtol_x=rtol_x, - rtol_thd=rtol_thd, + rtol_RH=rtol_RH, v_cr=self.attributes["critical volume"], timestep=self.dt, counters=counters, diff --git a/examples/PySDM_examples/Arabas_and_Shima_2017/settings.py b/examples/PySDM_examples/Arabas_and_Shima_2017/settings.py index e2ef220425..a4fa31a0e9 100644 --- a/examples/PySDM_examples/Arabas_and_Shima_2017/settings.py +++ b/examples/PySDM_examples/Arabas_and_Shima_2017/settings.py @@ -37,7 +37,7 @@ def __init__( self.n_output = 500 self.rtol_x = condensation.DEFAULTS.rtol_x - self.rtol_thd = condensation.DEFAULTS.rtol_thd + self.rtol_RH = condensation.DEFAULTS.rtol_RH self.coord = "volume logarithm" self.dt_cond_range = condensation.DEFAULTS.cond_range diff --git a/examples/PySDM_examples/Arabas_and_Shima_2017/simulation.py b/examples/PySDM_examples/Arabas_and_Shima_2017/simulation.py index 52f7db4b5e..3e69187862 100644 --- a/examples/PySDM_examples/Arabas_and_Shima_2017/simulation.py +++ b/examples/PySDM_examples/Arabas_and_Shima_2017/simulation.py @@ -34,7 +34,7 @@ def __init__(self, settings, backend=CPU): builder.add_dynamic( Condensation( rtol_x=settings.rtol_x, - rtol_thd=settings.rtol_thd, + rtol_RH=settings.rtol_RH, dt_cond_range=settings.dt_cond_range, ) ) diff --git a/examples/PySDM_examples/Bartman_2020_MasterThesis/fig_5_SCIPY_VS_ADAPTIVE.py b/examples/PySDM_examples/Bartman_2020_MasterThesis/fig_5_SCIPY_VS_ADAPTIVE.py index f87e1cf2df..1436eac3dc 100644 --- a/examples/PySDM_examples/Bartman_2020_MasterThesis/fig_5_SCIPY_VS_ADAPTIVE.py +++ b/examples/PySDM_examples/Bartman_2020_MasterThesis/fig_5_SCIPY_VS_ADAPTIVE.py @@ -34,7 +34,7 @@ def data(n_output, rtols, schemes, setups_num): for settings_idx in range(setups_num): settings = setups[settings_idx] settings.rtol_x = rtol - settings.rtol_thd = rtol + settings.rtol_RH = rtol settings.n_output = n_output simulation = Simulation( settings, backend=CPU if scheme == "CPU" else GPU diff --git a/examples/PySDM_examples/Bartman_et_al_2021/demo.ipynb b/examples/PySDM_examples/Bartman_et_al_2021/demo.ipynb index b5bb39d47b..9f7cf9f1e0 100644 --- a/examples/PySDM_examples/Bartman_et_al_2021/demo.ipynb +++ b/examples/PySDM_examples/Bartman_et_al_2021/demo.ipynb @@ -60,7 +60,7 @@ "settings.simulation_time = .175 * settings.spin_up_time\n", "settings.output_interval = 1 * si.minute\n", "settings.condensation_rtol_x = 1e-6\n", - "settings.condensation_rtol_thd = 5e-7\n", + "settings.condensation_rtol_RH = 5e-7\n", "\n", "settings.condensation_dt_cond_range = (.25*si.s, settings.dt)\n", "settings.coalescence_dt_coal_range = settings.condensation_dt_cond_range\n", diff --git a/examples/PySDM_examples/Bartman_et_al_2021/demo_fig2.ipynb b/examples/PySDM_examples/Bartman_et_al_2021/demo_fig2.ipynb index feefdbd56a..f27f1bbc99 100644 --- a/examples/PySDM_examples/Bartman_et_al_2021/demo_fig2.ipynb +++ b/examples/PySDM_examples/Bartman_et_al_2021/demo_fig2.ipynb @@ -45,10 +45,10 @@ "tol = .5e-6\n", "m = 2\n", "runs = (\n", - " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': True, 'condensation_rtol_thd': tol}},\n", - " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': True, 'condensation_rtol_thd': tol*m}},\n", - " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': True, 'condensation_rtol_thd': tol*m*m}},\n", - " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': True, 'condensation_rtol_thd': tol*m*m*m}},\n", + " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': True, 'condensation_rtol_RH': tol}},\n", + " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': True, 'condensation_rtol_RH': tol*m}},\n", + " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': True, 'condensation_rtol_RH': tol*m*m}},\n", + " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': True, 'condensation_rtol_RH': tol*m*m*m}},\n", " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': False, 'condensation_substeps': 128}},\n", " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': False, 'condensation_substeps': 32}},\n", " {'file': TemporaryFile('.nc'), 'settings': {'condensation_adaptive': False, 'condensation_substeps': 8}},\n", @@ -87,7 +87,7 @@ " settings.simulation_time = settings.spin_up_time * (1 if 'CI' not in os.environ else .1)\n", " settings.output_interval = settings.dt\n", " settings.condensation_rtol_x = 1e-6\n", - " settings.condensation_rtol_thd = -1\n", + " settings.condensation_rtol_RH = -1\n", " settings.condensation_schedule = 'dynamic'\n", " settings.kappa = .8\n", " \n", diff --git a/examples/PySDM_examples/Bartman_et_al_2021/demo_fig3.ipynb b/examples/PySDM_examples/Bartman_et_al_2021/demo_fig3.ipynb index 75d155730c..169b9b3be3 100644 --- a/examples/PySDM_examples/Bartman_et_al_2021/demo_fig3.ipynb +++ b/examples/PySDM_examples/Bartman_et_al_2021/demo_fig3.ipynb @@ -88,7 +88,7 @@ " settings.output_interval = settings.dt\n", " settings.condensation_adaptive = True\n", " settings.condensation_rtol_x = 1e-6\n", - " settings.condensation_rtol_thd = 2e-5/7/7\n", + " settings.condensation_rtol_RH = 2e-5/7/7\n", " settings.condensation_schedule = 'dynamic'\n", " settings.kappa = .8\n", " \n", diff --git a/examples/PySDM_examples/Morrison_and_Grabowski_2007/common.py b/examples/PySDM_examples/Morrison_and_Grabowski_2007/common.py index 7cda18e28f..faa8d2040a 100644 --- a/examples/PySDM_examples/Morrison_and_Grabowski_2007/common.py +++ b/examples/PySDM_examples/Morrison_and_Grabowski_2007/common.py @@ -21,7 +21,7 @@ def __init__(self, formulae: Formulae): const = formulae.constants self.condensation_rtol_x = condensation.DEFAULTS.rtol_x - self.condensation_rtol_thd = condensation.DEFAULTS.rtol_thd + self.condensation_rtol_RH = condensation.DEFAULTS.rtol_RH self.condensation_adaptive = True self.condensation_substeps = -1 self.condensation_dt_cond_range = condensation.DEFAULTS.cond_range diff --git a/examples/PySDM_examples/Pyrcel/simulation.py b/examples/PySDM_examples/Pyrcel/simulation.py index 330936cb26..dd966db8e0 100644 --- a/examples/PySDM_examples/Pyrcel/simulation.py +++ b/examples/PySDM_examples/Pyrcel/simulation.py @@ -13,7 +13,7 @@ class Simulation(BasicSimulation): def __init__( - self, settings, products=None, scipy_solver=False, rtol_thd=1e-10, rtol_x=1e-10 + self, settings, products=None, scipy_solver=False, rtol_RH=1e-6, rtol_x=1e-10 ): env = Parcel( dt=settings.timestep, @@ -27,7 +27,7 @@ def __init__( builder = Builder(n_sd=n_sd, backend=CPU(formulae=settings.formulae)) builder.set_environment(env) builder.add_dynamic(AmbientThermodynamics()) - builder.add_dynamic(Condensation(rtol_thd=rtol_thd, rtol_x=rtol_x)) + builder.add_dynamic(Condensation(rtol_RH=rtol_RH, rtol_x=rtol_x)) volume = env.mass_of_dry_air / settings.initial_air_density attributes = { diff --git a/examples/PySDM_examples/Shipway_and_Hill_2012/settings.py b/examples/PySDM_examples/Shipway_and_Hill_2012/settings.py index 5773dcf62e..e6e881290b 100644 --- a/examples/PySDM_examples/Shipway_and_Hill_2012/settings.py +++ b/examples/PySDM_examples/Shipway_and_Hill_2012/settings.py @@ -127,7 +127,7 @@ def drhod_dz(z_above_reservoir, rhod): self.mpdata_settings = {"n_iters": 3, "iga": True, "fct": True, "tot": True} self.condensation_rtol_x = condensation.DEFAULTS.rtol_x - self.condensation_rtol_thd = condensation.DEFAULTS.rtol_thd + self.condensation_rtol_RH = condensation.DEFAULTS.rtol_RH self.condensation_adaptive = True self.condensation_update_thd = False self.coalescence_adaptive = True diff --git a/examples/PySDM_examples/Shipway_and_Hill_2012/simulation.py b/examples/PySDM_examples/Shipway_and_Hill_2012/simulation.py index 1712e202ca..9d0d70c5a7 100644 --- a/examples/PySDM_examples/Shipway_and_Hill_2012/simulation.py +++ b/examples/PySDM_examples/Shipway_and_Hill_2012/simulation.py @@ -69,7 +69,7 @@ def zZ_to_z_above_reservoir(zZ): self.builder.add_dynamic( Condensation( adaptive=settings.condensation_adaptive, - rtol_thd=settings.condensation_rtol_thd, + rtol_RH=settings.condensation_rtol_RH, rtol_x=settings.condensation_rtol_x, update_thd=settings.condensation_update_thd, ) diff --git a/examples/PySDM_examples/Szumowski_et_al_1998/gui_settings.py b/examples/PySDM_examples/Szumowski_et_al_1998/gui_settings.py index 9487692ac4..1140224812 100644 --- a/examples/PySDM_examples/Szumowski_et_al_1998/gui_settings.py +++ b/examples/PySDM_examples/Szumowski_et_al_1998/gui_settings.py @@ -80,16 +80,16 @@ def __init__(self, settings): description="simulation time $[s]$", ) self.ui_condensation_rtol_x = IntSlider( - value=np.log10(settings.condensation_rtol_thd), - min=-9, - max=-3, + value=np.log10(settings.condensation_rtol_RH), + min=-7, + max=-1, description="log$_{10}$(rtol$_x$)", ) - self.ui_condensation_rtol_thd = IntSlider( - value=np.log10(settings.condensation_rtol_thd), + self.ui_condensation_rtol_RH = IntSlider( + value=np.log10(settings.condensation_rtol_RH), min=-9, max=-3, - description="log$_{10}$(rtol$_\\theta$)", + description="log$_{10}$(rtol$_{RH}$)", ) self.ui_condensation_adaptive = Checkbox( value=settings.condensation_adaptive, @@ -274,8 +274,8 @@ def condensation_rtol_x(self): return 10**self.ui_condensation_rtol_x.value @property - def condensation_rtol_thd(self): - return 10**self.ui_condensation_rtol_thd.value + def condensation_rtol_RH(self): + return 10**self.ui_condensation_rtol_RH.value @property def condensation_adaptive(self): @@ -371,7 +371,7 @@ def box(self): self.ui_dt, self.ui_simulation_time, self.ui_condensation_rtol_x, - self.ui_condensation_rtol_thd, + self.ui_condensation_rtol_RH, self.ui_condensation_adaptive, self.ui_coalescence_adaptive, self.ui_displacement_rtol, diff --git a/examples/PySDM_examples/Szumowski_et_al_1998/simulation.py b/examples/PySDM_examples/Szumowski_et_al_1998/simulation.py index 9596abef9c..68a0b1c6b7 100644 --- a/examples/PySDM_examples/Szumowski_et_al_1998/simulation.py +++ b/examples/PySDM_examples/Szumowski_et_al_1998/simulation.py @@ -58,7 +58,7 @@ def reinit(self, products=None): kwargs["substeps"] = (self.settings.condensation_substeps,) condensation = Condensation( rtol_x=self.settings.condensation_rtol_x, - rtol_thd=self.settings.condensation_rtol_thd, + rtol_RH=self.settings.condensation_rtol_RH, adaptive=self.settings.condensation_adaptive, dt_cond_range=self.settings.condensation_dt_cond_range, schedule=self.settings.condensation_schedule, diff --git a/examples/PySDM_examples/Yang_et_al_2018/fig_2.ipynb b/examples/PySDM_examples/Yang_et_al_2018/fig_2.ipynb index c44be0ac50..6d34a1a516 100644 --- a/examples/PySDM_examples/Yang_et_al_2018/fig_2.ipynb +++ b/examples/PySDM_examples/Yang_et_al_2018/fig_2.ipynb @@ -97,7 +97,7 @@ " result['T'] = np.array(output[\"T\"])\n", " result['n'] = settings.n / (settings.mass_of_dry_air * si.kilogram)\n", " result['dt_max'] = settings.dt_max\n", - " result['rtol_thd'] = settings.rtol_thd\n", + " result['rtol_RH'] = settings.rtol_RH\n", " result['rtol_x'] = settings.rtol_x\n", " result['dt_cond_max'] = output['dt_cond_max']\n", " result['dt_cond_min'] = output['dt_cond_min']\n", @@ -134,8 +134,8 @@ "for i, output in enumerate(outputs):\n", " dt_max = output['dt_max']\n", " rtol_x = output['rtol_x']\n", - " rtol_thd = output['rtol_thd']\n", - " tols = f'rtol_x = {rtol_x}, rtol_thd = {rtol_thd}'\n", + " rtol_RH = output['rtol_RH']\n", + " tols = f'rtol_x = {rtol_x}, rtol_RH = {rtol_RH}'\n", " \n", " ax[i,1].set_title(f'dt_max = {dt_max}, '+tols)\n", " \n", @@ -195,8 +195,8 @@ " tols = f'tolerance = {rtol}'\n", " else:\n", " rtol_x = output['rtol_x']\n", - " rtol_thd = output['rtol_thd']\n", - " tols = f'rtol_x = {rtol_x}, rtol_thd = {rtol_thd}'\n", + " rtol_RH = output['rtol_RH']\n", + " tols = f'rtol_x = {rtol_x}, rtol_RH = {rtol_RH}'\n", " \n", " hist = output['r_bins_values']\n", " hist = (hist[:,0:-1] + hist[:,1:])/2\n", diff --git a/examples/PySDM_examples/Yang_et_al_2018/settings.py b/examples/PySDM_examples/Yang_et_al_2018/settings.py index 98d54216a4..72ea0df5d7 100644 --- a/examples/PySDM_examples/Yang_et_al_2018/settings.py +++ b/examples/PySDM_examples/Yang_et_al_2018/settings.py @@ -44,7 +44,7 @@ def __init__( self.coord = "VolumeLogarithm" self.adaptive = True self.rtol_x = condensation.DEFAULTS.rtol_x - self.rtol_thd = condensation.DEFAULTS.rtol_thd + self.rtol_RH = condensation.DEFAULTS.rtol_RH self.dt_cond_range = condensation.DEFAULTS.cond_range self.T0 = 284.3 * si.kelvin diff --git a/examples/PySDM_examples/Yang_et_al_2018/simulation.py b/examples/PySDM_examples/Yang_et_al_2018/simulation.py index 8c9d77bcb2..be7ec1b7b2 100644 --- a/examples/PySDM_examples/Yang_et_al_2018/simulation.py +++ b/examples/PySDM_examples/Yang_et_al_2018/simulation.py @@ -36,7 +36,7 @@ def __init__(self, settings, backend=CPU): condensation = Condensation( adaptive=settings.adaptive, rtol_x=settings.rtol_x, - rtol_thd=settings.rtol_thd, + rtol_RH=settings.rtol_RH, dt_cond_range=settings.dt_cond_range, ) builder.add_dynamic(condensation) diff --git a/tests/smoke_tests/parcel/abdul_razzak_ghan_2000/test_single_supersaturation_peak.py b/tests/smoke_tests/parcel/abdul_razzak_ghan_2000/test_single_supersaturation_peak.py index f31073ccfa..8c5b5c0999 100644 --- a/tests/smoke_tests/parcel/abdul_razzak_ghan_2000/test_single_supersaturation_peak.py +++ b/tests/smoke_tests/parcel/abdul_razzak_ghan_2000/test_single_supersaturation_peak.py @@ -17,7 +17,7 @@ @pytest.mark.parametrize( - "rtol_thd", + "rtol_RH", ( pytest.param(1e-6, marks=pytest.mark.xfail(strict=True)), 1e-7, @@ -26,11 +26,9 @@ ), ) @pytest.mark.parametrize("rtol_x", (1e-7,)) -@pytest.mark.parametrize("adaptive", (True,)) @pytest.mark.parametrize("scheme", ("PySDM",)) -def test_single_supersaturation_peak( - adaptive, scheme, rtol_x, rtol_thd, plot=False -): # pylint: disable=too-many-locals +def test_single_supersaturation_peak(scheme, rtol_x, rtol_RH, plot=False): + # pylint: disable=too-many-locals # arrange products = ( PySDM_products.WaterMixingRatio(unit="g/kg", name="ql"), @@ -38,28 +36,25 @@ def test_single_supersaturation_peak( PySDM_products.AmbientRelativeHumidity(name="RH"), PySDM_products.ParcelDisplacement(name="z"), ) + dt = 2 * si.s + w = 0.5 * si.m / si.s env = Parcel( - dt=2 * si.s, + dt=dt, mass_of_dry_air=1e3 * si.kg, p0=1000 * si.hPa, q0=22.76 * si.g / si.kg, - w=0.5 * si.m / si.s, + w=w, T0=300 * si.K, ) - n_steps = 70 + z_max = 70 * si.m + n_steps = int(z_max / (w * dt)) n_sd = 2 kappa = 0.4 spectrum = Lognormal(norm_factor=5000 / si.cm**3, m_mode=50.0 * si.nm, s_geom=2.0) builder = Builder(backend=CPU(), n_sd=n_sd) builder.set_environment(env) builder.add_dynamic(AmbientThermodynamics()) - builder.add_dynamic( - Condensation( - adaptive=adaptive, - rtol_x=rtol_x, - rtol_thd=rtol_thd, - ) - ) + builder.add_dynamic(Condensation(adaptive=True, rtol_x=rtol_x, rtol_RH=rtol_RH)) r_dry, concentration = ConstantMultiplicity(spectrum).sample(n_sd) v_dry = builder.formulae.trivia.volume(radius=r_dry) @@ -110,9 +105,11 @@ def test_single_supersaturation_peak( twin.set_xlim(-0.001, 0.0015) pyplot.legend(loc="lower right") pyplot.grid() - pyplot.title(f"rtol_thd={rtol_thd}; rtol_x={rtol_x}") + pyplot.title(f"rtol_RH={rtol_RH}; rtol_x={rtol_x}") if plot: pyplot.show() # assert - assert signal.argrelextrema(np.asarray(output["RH"]), np.greater)[0].shape[0] == 1 + n_max = signal.argrelextrema(np.asarray(output["RH"]), np.greater)[0].shape[0] + n_min = signal.argrelextrema(np.asarray(output["RH"]), np.less)[0].shape[0] + assert n_max == 1 and n_min == 0 diff --git a/tests/smoke_tests/parcel/arabas_and_shima_2017/test_conservation.py b/tests/smoke_tests/parcel/arabas_and_shima_2017/test_conservation.py index 462b1f9a8c..e5d40d4254 100644 --- a/tests/smoke_tests/parcel/arabas_and_shima_2017/test_conservation.py +++ b/tests/smoke_tests/parcel/arabas_and_shima_2017/test_conservation.py @@ -47,7 +47,7 @@ def test_water_mass_conservation(settings_idx, mass_of_dry_air, scheme, coord): # Assert ql = liquid_water_mixing_ratio(simulation) qt = simulation.particulator.environment["qv"].to_ndarray() + ql - significant = 6 if scheme == "GPU" else 14 # TODO #540 + significant = 6 if scheme == "GPU" else 12 # TODO #540 np.testing.assert_approx_equal(qt, qt0, significant) if scheme != "SciPy": assert simulation.particulator.products["S_max"].get() >= output["S"][-1]