Skip to content

Commit

Permalink
troubleshoot adm1p
Browse files Browse the repository at this point in the history
  • Loading branch information
joyxyz1994 committed Dec 4, 2024
1 parent c43e979 commit 2155dd8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions qsdsan/processes/_adm1_p_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -1048,14 +1048,15 @@ 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]
K_h2 = params['half_sat_coeffs'][7]
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']

Expand All @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions qsdsan/sanunits/_anaerobic_reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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):
Expand Down

0 comments on commit 2155dd8

Please sign in to comment.