Skip to content

Commit

Permalink
fix mADM1-ASM2d charge balances
Browse files Browse the repository at this point in the history
  • Loading branch information
joyxyz1994 committed May 31, 2024
1 parent bef8afd commit 57954af
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions qsdsan/sanunits/_junction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ def madm12asm2d(adm_vals):

# Step 0: snapshot of charged components
# Not sure about charge on X_PP, S_Mg, S_K (PHA and PAO would have zero charge)
# X_PP is charge-neutral
# X_PP in ADM1 is charge neutral
_ions = np.array([S_IN, S_IC, S_IP, S_Mg, S_K, S_ac, S_pro, S_bu, S_va])

# Step 1a: convert biomass and inert particulates into X_S and X_I
Expand Down Expand Up @@ -2322,9 +2322,11 @@ def madm12asm2d(adm_vals):

# _ions = np.array([S_IN, S_IC, S_IP, S_Mg, S_K, S_ac, S_pro, S_bu, S_va])

adm_alphas = np.array([self.alpha_IN, self.alpha_IC, self.alpha_IP, 2, 1, *self.alpha_vfa])
adm_alphas = np.array([self.alpha_IN, self.alpha_IC, self.alpha_IP,
2/24, 1/39, *self.alpha_vfa]) #!!! should be in unit of charge per g
adm_charge = np.dot(_ions, adm_alphas)
S_ALK = (adm_charge - (S_NH4/14 - S_A/64 - S_NO3/14 - 1.5*S_PO4/31))*(-12)
#!!! X_PP in ASM2d has negative charge, to compensate for the absent variables S_K & S_Mg
S_ALK = (adm_charge - (S_NH4/14 - S_A/64 - S_NO3/14 - 1.5*S_PO4/31 - X_PP/31))*(-12)

asm_vals[asm_ions_idx[-1]] = S_ALK

Expand Down Expand Up @@ -2662,7 +2664,7 @@ def asm2d2madm1(asm_vals):
_salk = S_ALK
_spo4 = S_PO4
_sa = S_A
# _xpp = X_PP
_xpp = X_PP

# Step 1: remove any remaining COD demand
O2_coddm = S_O2
Expand Down Expand Up @@ -3063,16 +3065,13 @@ def asm2d2madm1(asm_vals):
adm_vals = f_corr(asm_vals, adm_vals)

# Step 7: charge balance
asm_charge = - _sa/64 + _snh4/14 - _sno3/14 - 1.5*_spo4/31 - _salk# - _xpp/31 #Based on page 84 of IWA ASM handbook
asm_charge = - _sa/64 + _snh4/14 - _sno3/14 - 1.5*_spo4/31 - _salk - _xpp/31 #Based on page 84 of IWA ASM handbook
S_IN, S_IP = adm_vals[adm_ions_idx[:2]]

#!!! charge balance should technically include VFAs, S_K, S_Mg,
# but since their concentrations are assumed zero it is acceptable.

S_IN, S_IP = adm_vals[adm_ions_idx[:2]]

S_IC = (asm_charge - S_IN*self.alpha_IN - S_IP*self.alpha_IP)/self.alpha_IC
proton_charge = 10**(-self.pKa[0]+self.pH) - 10**(-self.pH) # self.pKa[0] is pKw
# proton_charge = (OH)^-1 - (H)^+1
# net_Scat = Scat - San
net_Scat = asm_charge + proton_charge

Expand Down

0 comments on commit 57954af

Please sign in to comment.