From c5a9a2e6109d6bbaaa300ee945c6e6df503ddd23 Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Thu, 5 Jun 2025 14:52:23 +0200
Subject: [PATCH] Implemented first five stoichiometric equations
---
dependencies/asm3_class.js | 86 ++++++++++++++++++++++++++------------
1 file changed, 59 insertions(+), 27 deletions(-)
diff --git a/dependencies/asm3_class.js b/dependencies/asm3_class.js
index 1b214db..c7aa16f 100644
--- a/dependencies/asm3_class.js
+++ b/dependencies/asm3_class.js
@@ -32,13 +32,17 @@ class ASM3 {
stoi_params = {
// Stoichiometric and composition parameters
- f_S_I: 0., // fraction S_I from hydrolysis [g S_I g-1 X_S]
+ f_SI: 0., // fraction S_I from hydrolysis [g S_I g-1 X_S]
+ f_XI: 0.2, // fraction X_I from decomp X_H [g X_I g-1 X_H]
// Yields
- Y_STO_O: 0.85, // Aerobic yield X_STO per S_S [g X_STO g-1 S_S]
- Y_STO_NO: 0.80, // Anoxic yield X_STO per S_S [g X_STO g-1 S_S]
- Y_H_O: 0.63, // Aerobic yield X_H per X_STO [g X_H g-1 X_STO]
- Y_H_NO: 0.54, // Anoxic yield X_H per X_STO [g X_H g-1 X_STO]
+ Y_STO_O: 0.85, // aerobic yield X_STO per S_S [g X_STO g-1 S_S]
+ Y_STO_NO: 0.80, // anoxic yield X_STO per S_S [g X_STO g-1 S_S]
+ Y_H_O: 0.63, // aerobic yield X_H per X_STO [g X_H g-1 X_STO]
+ Y_H_NO: 0.54, // anoxic yield X_H per X_STO [g X_H g-1 X_STO]
Y_A: 0.24, // anoxic yield X_A per S_NO [g X_A g-1 NO3-N]
+ // Composition (COD via DoR)
+ i_CODN: -1.71, // COD content (DoR) [g COD g-1 N2-N]
+ i_CODNO: -4.57, // COD content (DoR) [g COD g-1 NO3-N]
// Composition (nitrogen)
i_NSI: 0.01, // nitrogen content S_I [g N g-1 S_I]
i_NSS: 0.03, // nitrogen content S_S [g N g-1 S_S]
@@ -46,16 +50,40 @@ class ASM3 {
i_NXS: 0.04, // nitrogen content X_S [g N g-1 X_S]
i_NBM: 0.07, // nitrogen content X_H / X_A [g N g-1 X_H / X_A]
// Composition (TSS)
- i_TS: 0.75, // TSS content X_I [g TS g-1 X_I]
- i_TS: 0.75, // TSS content X_S [g TS g-1 X_S]
- i_TS: 0.90, // TSS content X_H / X_A [g TS g-1 X_H / X_A]
- i_TS: 0.60 // TSS content X_STO (PHB based) [g TS g-1 X_STO]
+ i_TSXI: 0.75, // TSS content X_I [g TS g-1 X_I]
+ i_TSXS: 0.75, // TSS content X_S [g TS g-1 X_S]
+ i_TSBM: 0.90, // TSS content X_H / X_A [g TS g-1 X_H / X_A]
+ i_TSSTO: 0.60, // TSS content X_STO (PHB based) [g TS g-1 X_STO]
+ // Composition (charge)
+ i_cNH: 1/14, // charge per S_NH [mole H+ g-1 NH3-N]
+ i_cNO: -1/14 // charge per S_NO [mole H+ g-1 NO3-N]
}
- // S_O, S_I, S_S, S_NH, S_N2, S_NO, S_HCO, X_I, X_S, X_H, X_STO, X_A, X_TS
- state = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
constructor(state) {
+ // S_O, S_I, S_S, S_NH, S_N2, S_NO, S_HCO, X_I, X_S, X_H, X_STO, X_A, X_TS
this.state = state;
+ this.stoi_matrix = this._initialise_stoi_matrix()
+ }
+
+ _initialise_stoi_matrix(){
+ const { f_SI, f_XI, Y_STO_O, Y_STO_NO, Y_H_O, Y_H_NO, Y_A, i_CODN, i_CODNO, i_NSI, i_NSS, i_NXI, i_NXS, i_NBM, i_TSXI, i_TSXS, i_TSBM, i_TSSTO, i_cNH, i_cNO } = this.stoi_params;
+
+ const stoi_matrix = Array(12);
+ // S_O, S_I, S_S, S_NH, S_N2, S_NO, S_HCO, X_I, X_S, X_H, X_STO, X_A, X_TS
+ stoi_matrix[0] = [0., f_SI, 1.-f_SI, (1.-f_SI)*i_NSS-f_SI*i_NSI+i_NXS, 0., 0., ((1.-f_SI)*i_NSS-f_SI*i_NSI+i_NXS)*i_cNH, 0., 0., -1., 0., 0., 0., -i_TSXS];
+ stoi_matrix[1] = [-(1.-Y_STO_O), 0, -1., i_NSS, 0., 0., i_NSS*i_cNH, 0., 0., 0., Y_STO_O, 0., Y_STO_O*i_TSSTO];
+ stoi_matrix[2] = [0., 0., -1., i_NSS, -(1.-Y_STO_NO)/(i_CODNO-i_CODN), (1.-Y_STO_NO)/(i_CODNO-i_CODN), i_NSS*i_cNH + (1.-Y_STO_NO)/(i_CODNO-i_CODN)*i_cNO, 0., 0., 0., Y_STO_NO, 0., Y_STO_NO*i_TSSTO];
+ stoi_matrix[3] = [-(1.-Y_H_O)/Y_H_O, 0., 0., -i_NBM, 0., 0., -i_NBM*i_cNH, 0., 0., 1., -1./Y_H_O, 0., i_TSBM-i_TSSTO/Y_H_O];
+ stoi_matrix[4] = [0., 0., 0., -i_NBM, -(1.-Y_H_NO)/(Y_H_NO*(i_CODNO-i_CODN)), (1.-Y_H_NO)/(Y_H_NO*(i_CODNO-i_CODN)), -i_NBM*i_cNH+(1.-Y_H_NO)/(Y_H_NO*(i_CODNO-i_CODN))*i_cNO, 0., 0., 1., -1./Y_H_NO, 0., i_TSBM-i_TSSTO/Y_H_NO];
+ stoi_matrix[5] = [-(1-f_XI), 0., 0., i_NBM-f_XI*i_NXI, 0., 0., (i_NBM-f_XI*i_NXI)*i_cNH, f_XI, 0., -1., 0., 0., f_XI*i_TSXI-i_TSBM];
+ stoi_matrix[6] = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.];
+ stoi_matrix[7] = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.];
+ stoi_matrix[8] = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.];
+ stoi_matrix[9] = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.];
+ stoi_matrix[10] = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.];
+ stoi_matrix[11] = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.];
+
+ return _.zip(...stoi_matrix); // transpose matrix
}
_monod(c, K){
@@ -66,28 +94,32 @@ class ASM3 {
return K / (K + c);
}
- compute_rates(state) {
- const rates = new Array(12);
- const [S_O, S_I, S_S, S_NH, S_N2, S_NO, S_HCO, X_I, X_S, X_H, X_STO, X_A, X_TS] = state;
+ compute_rates() {
+ const rates = Array(12);
+ const [S_O, S_I, S_S, S_NH, S_N2, S_NO, S_HCO, X_I, X_S, X_H, X_STO, X_A, X_TS] = this.state;
+ const { k_H, k_STO, nu_NO, K_O, K_NO, K_S, K_STO, mu_H_max, K_NH, K_HCO, b_H_O, b_H_NO, b_STO_O, b_STO_NO, mu_A_max, K_A_NH, K_A_O, K_A_HCO, b_A_O, b_A_NO } = this.kin_params;
// Hydrolysis
- rates[0] = this.kin_params.k_H * this._monod(X_S / X_H, this.kin_params.K_X) * X_H;
+ rates[0] = k_H * this._monod(X_S / X_H, K_X) * X_H;
// Heterotrophs
- rates[1] = this.kin_params.k_STO * this._monod(S_O, this.kin_params.K_O) * this._monod(S_S, this.kin_params.K_S) * X_H;
- rates[2] = this.kin_params.k_STO * this.kin_params.nu_NO * this._inv_monod(S_O, this.kin_params.K_O) * this._monod(S_NO, this.kin_params.K_NO) * this._monod(S_S, this.kin_params.K_S) * X_H;
- rates[3] = this.kin_params.mu_H_max * this._monod(S_O, this.kin_params.K_O) * this._monod(S_NH, this.kin_params.K_NH) * this._monod(S_HCO, this.kin_params.K_HCO) * this._monod(X_STO/X_H, K_STO) * X_H;
- rates[4] = this.kin_params.mu_H_max * this.kin_params.nu_NO * this._inv_monod(S_O, this.kin_params.K_O) * this._monod(S_NO, this.kin_params.NO) * this._monod(S_NH, this.kin_params.K_NH) * this._monod(S_HCO, this.kin_params.K_HCO) * this._monod(X_STO/X_H, this.kin_params.K_STO) * X_H;
- rates[5] = this.kin_params.b_H_O * this._monod(S_O, this.kin_params.K_O) * X_H;
- rates[6] = this.kin_params.b_H_NO * this._inv_monod(S_O, this.kin_params.K_O) * this._monod(S_NO, this.kin_params.K_NO) * X_H;
- rates[7] = this.kin_params.b_STO_O * this._monod(S_O, this.kin_params.K_O) * X_H;
- rates[8] = this.kin_params.b_STO_NO * this._inv_monod(S_O, this.kin_params.K_O) * this._monod(S_NO, this.kin_params.K_NO) * X_STO;
+ rates[1] = k_STO * this._monod(S_O, K_O) * this._monod(S_S, K_S) * X_H;
+ rates[2] = k_STO * nu_NO * this._inv_monod(S_O, K_O) * this._monod(S_NO, K_NO) * this._monod(S_S, K_S) * X_H;
+ rates[3] = mu_H_max * this._monod(S_O, K_O) * this._monod(S_NH, K_NH) * this._monod(S_HCO, K_HCO) * this._monod(X_STO/X_H, K_STO) * X_H;
+ rates[4] = mu_H_max * nu_NO * this._inv_monod(S_O, K_O) * this._monod(S_NO, K_NO) * this._monod(S_NH, K_NH) * this._monod(S_HCO, K_HCO) * this._monod(X_STO/X_H, K_STO) * X_H;
+ rates[5] = b_H_O * this._monod(S_O, K_O) * X_H;
+ rates[6] = b_H_NO * this._inv_monod(S_O, K_O) * this._monod(S_NO, K_NO) * X_H;
+ rates[7] = b_STO_O * this._monod(S_O, K_O) * X_H;
+ rates[8] = b_STO_NO * this._inv_monod(S_O, K_O) * this._monod(S_NO, K_NO) * X_STO;
// Autotrophs
- rates[9] = this.kin_params.mu_A_max * this._monod(S_O, this.kin_params.K_A_O) * this._monod(S_NH, this.kin_params.K_A_NH) * this._monod(S_HCO, this.kin_params.K_A_HCO) * X_A;
- rates[10] = this.kin_params.b_A_O * this._monod(S_O, this.kin_params.K_O) * X_A;
- rates[11] = this.kin_params.b_A_NO * this._inv_monod(S_O, this.kin_params.K_A_O) * this._monod(S_NO, this.kin_params.K_NO) * X_A;
+ rates[9] = mu_A_max * this._monod(S_O, K_A_O) * this._monod(S_NH, K_A_NH) * this._monod(S_HCO, K_A_HCO) * X_A;
+ rates[10] = b_A_O * this._monod(S_O, K_O) * X_A;
+ rates[11] = b_A_NO * this._inv_monod(S_O, K_A_O) * this._monod(S_NO, K_NO) * X_A;
return rates;
}
-}
\ No newline at end of file
+}
+
+const asm3 = new ASM3([0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
+console.log(asm3.compute_rates())
\ No newline at end of file