From 68a3ae1eee46dba51988c6ba20d043e20086f86c Mon Sep 17 00:00:00 2001 From: Joy Zhang Date: Tue, 3 Dec 2024 19:26:16 -0800 Subject: [PATCH] minor update to improve numerical stability --- qsdsan/sanunits/_junction.py | 4 ++++ qsdsan/sanunits/_suspended_growth_bioreactor.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/qsdsan/sanunits/_junction.py b/qsdsan/sanunits/_junction.py index f99809ed..60acce2c 100644 --- a/qsdsan/sanunits/_junction.py +++ b/qsdsan/sanunits/_junction.py @@ -2700,6 +2700,8 @@ def adm1p2masm2d(adm_vals): fraction_dissolve = max(0, min(1, - S_IC / xc_mmp)) asm_vals -= fraction_dissolve * X_CaCO3 * cac_sto asm_vals -= fraction_dissolve * X_MgCO3 * mgc_sto + if asm_vals[8] < 0: + asm_vals[8] = 0 if S_IN < 0: xn_mmp = sum(asm_vals[_mmp_idx] * mmp_in) if xn_mmp > 0: @@ -3022,6 +3024,8 @@ def masm2d2adm1p(asm_vals): fraction_dissolve = max(0, min(1, - S_IC / xc_mmp)) adm_vals -= fraction_dissolve * X_CaCO3 * cac_sto adm_vals -= fraction_dissolve * X_MgCO3 * mgc_sto + if adm_vals[9] < 0: + adm_vals[9] = 0 if S_IN < 0: xn_mmp = sum(adm_vals[_mmp_idx] * mmp_in) if xn_mmp > 0: diff --git a/qsdsan/sanunits/_suspended_growth_bioreactor.py b/qsdsan/sanunits/_suspended_growth_bioreactor.py index 6c5493a9..19c6b2cf 100644 --- a/qsdsan/sanunits/_suspended_growth_bioreactor.py +++ b/qsdsan/sanunits/_suspended_growth_bioreactor.py @@ -1167,7 +1167,7 @@ def _init_state(self): def _update_state(self): out, = self.outs ncol = self._ncol - self._state[self._state < 2.2e-16] = 0. + self._state[self._state < 1e-16] = 0. self._state[self._Qs_idx] = self._Qs if out.state is None: out.state = np.zeros(ncol) out.state[:-1] = self._state[-ncol:-1]