From 2155dd8474647f94f2031f98811bbe444f7a64e4 Mon Sep 17 00:00:00 2001 From: Joy Zhang Date: Wed, 4 Dec 2024 13:14:18 -0800 Subject: [PATCH] troubleshoot adm1p --- qsdsan/processes/_adm1_p_extension.py | 11 ++++++----- qsdsan/sanunits/_anaerobic_reactor.py | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/qsdsan/processes/_adm1_p_extension.py b/qsdsan/processes/_adm1_p_extension.py index 77f6305d..b850db4b 100644 --- a/qsdsan/processes/_adm1_p_extension.py +++ b/qsdsan/processes/_adm1_p_extension.py @@ -1038,7 +1038,7 @@ def __new__(cls, components=None, path=None, KS_IP*P_mw, np.array(k_mmp), Ksp_mass, np.array(K_dis), K_AlOH, K_FeOH])) - def dydt_Sh2_AD(S_h2, state_arr, h, params, f_stoichio, V_liq, S_h2_in): + def adm1p_dydt_Sh2_AD(S_h2, state_arr, h, params, f_stoichio, V_liq, S_h2_in): state_arr[7] = S_h2 Q = state_arr[45] rxn = _rhos_adm1p(state_arr, params, h=h) @@ -1048,7 +1048,7 @@ def dydt_Sh2_AD(S_h2, state_arr, h, params, f_stoichio, V_liq, S_h2_in): grad_rhosp = np.zeros(5) X_biop = np.zeros(5) - def grad_dydt_Sh2_AD(S_h2, state_arr, h, params, f_stoichio, V_liq, S_h2_in): + def adm1p_grad_dydt_Sh2_AD(S_h2, state_arr, h, params, f_stoichio, V_liq, S_h2_in): state_arr[7] = S_h2 ks = params['rate_constants'][[5,6,7,8,10]] Ks = params['half_sat_coeffs'][2:6] @@ -1056,6 +1056,7 @@ def grad_dydt_Sh2_AD(S_h2, state_arr, h, params, f_stoichio, V_liq, S_h2_in): pH_ULs = params['pH_ULs'] pH_LLs = params['pH_LLs'] KS_IN = params['KS_IN'] + KS_IP = params['KS_IP'] KIs_h2 = params['KIs_h2'] kLa = params['kLa'] @@ -1076,12 +1077,12 @@ def grad_dydt_Sh2_AD(S_h2, state_arr, h, params, f_stoichio, V_liq, S_h2_in): stoichio = f_stoichio(state_arr) Q = state_arr[45] - return -Q/V_liq + np.dot(grad_rhos, stoichio[[5,6,7,8,10]]) + kLa*stoichio[-3] + return -Q/V_liq + np.dot(grad_rhosp, stoichio[[5,6,7,8,10]]) + kLa*stoichio[-3] dct['flex_rhos'] = _rhos_adm1p dct['solve_pH'] = adm1p_solve_pH - dct['dydt_Sh2_AD'] = dydt_Sh2_AD - dct['grad_dydt_Sh2_AD'] = grad_dydt_Sh2_AD + dct['dydt_Sh2_AD'] = adm1p_dydt_Sh2_AD + dct['grad_dydt_Sh2_AD'] = adm1p_grad_dydt_Sh2_AD return self def set_half_sat_K(self, K, process): diff --git a/qsdsan/sanunits/_anaerobic_reactor.py b/qsdsan/sanunits/_anaerobic_reactor.py index 496cb061..c800af47 100644 --- a/qsdsan/sanunits/_anaerobic_reactor.py +++ b/qsdsan/sanunits/_anaerobic_reactor.py @@ -583,8 +583,9 @@ def h2_stoichio(state_arr): dydt_Sh2_AD = self.model.dydt_Sh2_AD grad_dydt_Sh2_AD = self.model.grad_dydt_Sh2_AD def solve_h2(QC, S_in, T, h=h): - Ka = params['Ka_base'] * T_correction_factor(params['T_base'], T, params['Ka_dH']) - if h == None: h = solve_pH(QC, Ka, unit_conversion) + if h == None: + Ka = params['Ka_base'] * T_correction_factor(params['T_base'], T, params['Ka_dH']) + h = solve_pH(QC, Ka, unit_conversion) # S_h2_0 = QC[h2_idx] S_h2_0 = 2.8309E-07 S_h2_in = S_in[h2_idx] @@ -596,7 +597,7 @@ def solve_h2(QC, S_in, T, h=h): def update_h2_dstate(dstate): dstate[h2_idx] = 0. else: - solve_h2 = lambda QC, S_ins, T: QC[h2_idx] + solve_h2 = lambda QC, S_in, T: QC[h2_idx] def update_h2_dstate(dstate): pass def dy_dt(t, QC_ins, QC, dQC_ins):