Skip to content

Commit

Permalink
merge changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
joyxyz1994 committed Oct 23, 2024
1 parent 75e083b commit 1e1f966
Show file tree
Hide file tree
Showing 7 changed files with 868 additions and 261 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# built documents.
#
# The short X.Y version.
version = '1.3.1'
version = '1.4.0'
# The full version, including alpha/beta/rc tags.
release = version

Expand Down
6 changes: 3 additions & 3 deletions qsdsan/processes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self):
from ._asm2d import *
from ._adm1 import *
from ._adm1_p_extension import *
from ._madm1 import *
# from ._madm1 import *
from ._decay import *
from ._kinetic_reaction import *
from ._pm2 import *
Expand All @@ -74,7 +74,7 @@ def __init__(self):
_asm2d,
_adm1,
_adm1_p_extension,
_madm1,
# _madm1,
_decay,
_kinetic_reaction,
_pm2
Expand All @@ -86,7 +86,7 @@ def __init__(self):
*_asm2d.__all__,
*_adm1.__all__,
*_adm1_p_extension.__all__,
*_madm1.__all__,
# *_madm1.__all__,
*_decay.__all__,
*_kinetic_reaction.__all__,
*_pm2.__all__,
Expand Down
46 changes: 36 additions & 10 deletions qsdsan/processes/_adm1_p_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,6 @@ def acid_base_rxn(h_ion, weak_acids_tot, Kas):
nh3, hpo4, hco3, ac, pro, bu, va = Kas[1:] * weak_acids_tot[4:] / (Kas[1:] + h_ion)
return S_cat + S_K + 2*S_Mg + h_ion + (S_IN - nh3) - S_an - oh_ion - hco3 - ac - pro - bu - va - 2*hpo4 - (S_IP - hpo4)

# The function 'fprime_abr' is not used in the code
def fprime_abr(h_ion, weak_acids_tot, Kas):
# S_cat, S_K, S_Mg, S_an, S_IN, S_IP = weak_acids_tot[:6]
Kw = Kas[0]
doh_ion = - Kw / h_ion ** 2
dnh3, dhpo4, dhco3, dac, dpro, dbu, dva = - Kas[1:] * weak_acids_tot[4:] / (Kas[1:] + h_ion)**2
return 1 + (-dnh3) - doh_ion - dhco3 - dac - dpro - dbu - dva - dhpo4


rhos = np.zeros(28) # 28 kinetic processes (25 as defined in modified ADM1 + 3 for gases)
Cs = np.empty(25) # 25 processes as defined in modified ADM1

Expand Down Expand Up @@ -239,7 +230,6 @@ def _rhos_adm1_p_extension(state_arr, params, h=None):
rhos[9] *= Inh3
rhos[-3:] = kLa * (biogas_S - KH * biogas_p)

# print(rhos)
return rhos

def dydt_Sh2_AD(S_h2, state_arr, h, params, f_stoichio, V_liq, S_h2_in):
Expand Down Expand Up @@ -355,6 +345,42 @@ class ADM1_p_extension(ADM1):
>>> adm1_p.show()
ADM1_p_extension([hydrolysis_carbs, hydrolysis_proteins, hydrolysis_lipids, uptake_sugars, uptake_amino_acids, uptake_LCFA, uptake_valerate, uptake_butyrate, uptake_propionate, uptake_acetate, uptake_h2, decay_Xsu, decay_Xaa, decay_Xfa, decay_Xc4, decay_Xpro, decay_Xac, decay_Xh2, storage_Sva_in_XPHA, storage_Sbu_in_XPHA, storage_Spro_in_XPHA, storage_Sac_in_XPHA, lysis_XPAO, lysis_XPP, lysis_XPHA, h2_transfer, ch4_transfer, IC_transfer])
>>> import numpy as np
>>> state_arr = np.ones(cmps.size + len(adm1_p._biogas_IDs) + 2) # liquid-phase concentrations, gas-phase concentrations, liquid flowrate, and temperature
>>> state_arr[-1] = 273.15+35 # Temperature
>>> rhos = adm1_p.rate_function(state_arr) # reaction rate for each process
>>> for i,j in zip(adm1_p.IDs, rhos):
... print(f'{i}{(40-len(i))*" "}{j:.3g}')
hydrolysis_carbs 10
hydrolysis_proteins 10
hydrolysis_lipids 10
uptake_sugars 20
uptake_amino_acids 38.4
uptake_LCFA 2.14e-05
uptake_valerate 8.32e-05
uptake_butyrate 8.32e-05
uptake_propionate 4.13e-05
uptake_acetate 1.93
uptake_h2 34.9
decay_Xsu 0.02
decay_Xaa 0.02
decay_Xfa 0.02
decay_Xc4 0.02
decay_Xpro 0.02
decay_Xac 0.02
decay_Xh2 0.02
storage_Sva_in_XPHA 0.747
storage_Sbu_in_XPHA 0.747
storage_Spro_in_XPHA 0.747
storage_Sac_in_XPHA 0.747
lysis_XPAO 0.2
lysis_XPP 0.2
lysis_XPHA 0.2
h2_transfer 139
ch4_transfer -181
IC_transfer -1.66e+03
References
----------
[1] Batstone, D. J.; Keller, J.; Angelidaki, I.; Kalyuzhnyi, S. V;
Expand Down
21 changes: 21 additions & 0 deletions qsdsan/processes/_aeration.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ class DiffusedAeration(Process):
[parameters] KLa: 240
DOsat: 8
[dynamic parameters]
>>> aer2 = pc.DiffusedAeration('aer2', 'S_O', KLa_20=100, V=1000, d_submergence=3.7)
>>> aer2.show()
Process: aer2
[stoichiometry] S_O: 1
[reference] S_O
[rate equation] KLa*(DOsat - S_O)
[parameters] KLa: 60
DOsat: 9.87
[dynamic parameters]
>>> aer2.Q_air # doctest: +ELLIPSIS
12470.65...
>>> round(aer2.SOTR / 1000)
1039
>>> aer3 = pc.DiffusedAeration('aer3', 'S_O', Q_air=7600, V=1000, d_submergence=3.7)
>>> aer3.kLa # doctest: +ELLIPSIS
36.56...
"""


Expand Down Expand Up @@ -357,5 +376,7 @@ def DOsat(self):
return self._DOsat
@DOsat.setter
def DOsat(self, DOsat):
if DOsat is not None:
self._DOsat_s20 = DOsat / (self.tau * self._beta * self.Omega * self.delta)
self._DOsat = DOsat or self._calc_DOsat()
self.set_parameters(DOsat = self._DOsat)
46 changes: 43 additions & 3 deletions qsdsan/processes/_asm2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def create_asm2d_cmps(set_thermo=True):

return cmps_asm2d

# create_asm2d_cmps()

def create_masm2d_cmps(set_thermo=True):
c2d = create_asm2d_cmps(False)
ion_kwargs = dict(particle_size='Soluble',
Expand Down Expand Up @@ -433,7 +431,7 @@ class ASM2d(CompiledProcesses):
Examples
--------
>>> from qsdsan import processes as pc, set_thermo
>>> from qsdsan import processes as pc
>>> cmps = pc.create_asm2d_cmps()
>>> asm2d = pc.ASM2d()
>>> asm2d.show()
Expand Down Expand Up @@ -714,6 +712,8 @@ class mASM2d(CompiledProcesses):
electron_acceptor_dependent_decay : bool, optional
Whether biomass decay kinetics is dependent on concentrations of
electron acceptors. The default is True.
pH_ctrl : float or None, optional
Whether to fix pH at a specific value or solve for pH (`None`). The default is 7.0.
k_h : float, optional
Hydrolysis rate constant, in [d^(-1)]. The default is 3.0.
eta_NO3_Hl : float, optional
Expand Down Expand Up @@ -766,6 +766,46 @@ class mASM2d(CompiledProcesses):
>>> asm.show()
mASM2d([aero_hydrolysis, anox_hydrolysis, anae_hydrolysis, hetero_growth_S_F, hetero_growth_S_A, denitri_S_F, denitri_S_A, ferment, hetero_lysis, storage_PHA, aero_storage_PP, anox_storage_PP, PAO_aero_growth_PHA, PAO_anox_growth, PAO_lysis, PP_lysis, PHA_lysis, auto_aero_growth, auto_lysis, CaCO3_precipitation_dissolution, struvite_precipitation_dissolution, newberyite_precipitation_dissolution, ACP_precipitation_dissolution, MgCO3_precipitation_dissolution, AlPO4_precipitation_dissolution, FePO4_precipitation_dissolution])
>>> # Calculate process rate given state variable values and fixed pH.
>>> import numpy as np
>>> state_arr = np.ones(len(cmps))
>>> rhos = asm.rate_function(state_arr) # reaction rate for each process
>>> for i,j in zip(asm.IDs, rhos):
... print(f'{i}{(40-len(i))*" "}{j:.3g}')
aero_hydrolysis 2.27
anox_hydrolysis 0.182
anae_hydrolysis 0.0606
hetero_growth_S_F 0.471
hetero_growth_S_A 0.471
denitri_S_F 0.0503
denitri_S_A 0.0503
ferment 0.0333
hetero_lysis 0.356
storage_PHA 0.594
aero_storage_PP 1.06
anox_storage_PP 0.0851
PAO_aero_growth_PHA 0.778
PAO_anox_growth 0.0622
PAO_lysis 0.174
PP_lysis 0.174
PHA_lysis 0.174
auto_aero_growth 0.33
auto_lysis 0.111
CaCO3_precipitation_dissolution 0
struvite_precipitation_dissolution 0
newberyite_precipitation_dissolution 0
ACP_precipitation_dissolution 0
MgCO3_precipitation_dissolution 0
AlPO4_precipitation_dissolution 1.82e-11
FePO4_precipitation_dissolution 1.82e-11
>>> # Estimate pH given state variable values.
>>> Ka = asm.rate_function.params['Ka']
>>> unit_conversion = asm.rate_function.params['mass2mol']
>>> h_ion = asm.solve_pH(state_arr, Ka, unit_conversion)
>>> pH = -np.log10(h_ion)
>>> print(f'{pH:.2f}')
8.40
References
----------
Expand Down
Loading

0 comments on commit 1e1f966

Please sign in to comment.