# Wastewater / Sludge / Biogas Mathematical Models

Formal, cited mathematical models for:

1. **Activated Sludge Process (ASP)** — biomass kinetics, excess sludge production, aeration tank and clarifier sizing.
2. **Anaerobic digestion & biogas generation** — stoichiometric (Buswell), COD-based theoretical yield, empirical VS-destroyed yield, IPCC Tier‑1 emission accounting, and pointers to dynamic (ADM1) models.
3. **Plant-wide mass balance** — tying influent characteristics through to sludge cake and biogas output.

Every equation below is attributed to a specific source. Where a number could not be pulled verbatim from a primary document in this session (some primary PDFs — the IPCC guidelines PDF and the CPHEEO manual PDF — could not be parsed cleanly by the fetch tooling used to build this), that is flagged explicitly as **[secondary-sourced]** with the literature it was cross-checked against, instead of being presented as a verbatim primary quote. Treat those as "commonly cited design range — confirm against the primary table before regulatory or stamped design use."

No number in this document or in the code is invented; every constant traces to a citation in [§6 References](#6-references).

---

## 0. Scope and how to use this

This is a **steady-state, design-manual-grade** model set (Metcalf & Eddy / CPHEEO / IPCC Tier‑1 level), plus signposts to **research-grade dynamic models** (ASM1/2/3, ADM1) and the open-source tools that already implement them, so you don't re-derive what already exists as peer-reviewed, maintained code. See [§5](#5-existing-tools--libraries-dont-reinvent-these).

Directory layout:

```
wastewater-models/
├── README.md                  <- this document (equations + citations)
├── requirements.txt
├── wastewater_models/
│   ├── constants.py            <- every numeric constant, each with a citation in its docstring
│   ├── activated_sludge.py     <- §1 equations
│   ├── anaerobic_digestion.py  <- §2 equations
│   └── mass_balance.py         <- §3 equations (ties the two together)
├── tests/                      <- unit tests checking algebraic identities & known conversions
└── examples/
    └── worked_example.py       <- end-to-end numeric example you can run
```

---

## 1. Nomenclature

| Symbol | Meaning | Units |
|---|---|---|
| `Q` | Flow rate | m³/d |
| `S0`, `S` | Influent / effluent limiting substrate (soluble BOD₅ or bCOD) | mg/L (kg/m³ ×10⁻³) |
| `X` | Mixed liquor volatile suspended solids (MLVSS) in reactor | mg/L |
| `V` | Reactor (aeration tank) volume | m³ |
| `Y` | True biomass growth yield coefficient | g VSS/g BOD₅ (or g VSS/g COD) |
| `Y_obs` | Observed (net) yield coefficient | g VSS/g BOD₅ removed |
| `k_d` | Endogenous decay coefficient | d⁻¹ |
| `SRT` (θc) | Solids retention time / sludge age | d |
| `HRT` (θ) | Hydraulic retention time | h or d |
| `P_x` | Excess (waste) biological sludge production rate | kg VSS/d |
| `F/M` | Food-to-microorganism ratio | kg BOD₅/(kg MLVSS·d) |
| `SOR` | Surface overflow rate (clarifier) | m³/(m²·d) |
| `SLR` | Solids loading rate (clarifier) | kg/(m²·h) |
| `VS` | Volatile solids | kg |
| `B0` | Maximum (ultimate) CH₄ producing capacity | kg CH₄/kg BOD or COD |
| `MCF` | Methane correction factor (fraction of B0 realised) | dimensionless, 0–1 |

---

## 2. Part I — Activated Sludge Process

### 1.1 Biomass growth kinetics (Monod)

$$\mu = \mu_{max}\frac{S}{K_s+S}$$

Monod's empirical growth-rate law, universally used as the kinetic basis of ASP design (Metcalf & Eddy §7–8 [1]; originally Monod 1949).

### 1.2 Observed yield and its relation to SRT

$$Y_{obs} = \frac{Y}{1+k_d\cdot SRT}$$

This is the standard Lawrence & McCarty (1970) [9] SRT-based design relation, reproduced as the core sizing equation in Metcalf & Eddy [1, Ch. 8] and virtually every wastewater engineering text. `Y_obs` falls as `SRT` rises because a larger fraction of synthesized biomass is oxidized endogenously.

Implemented in [`activated_sludge.observed_yield`](wastewater_models/activated_sludge.py).

### 1.3 Excess (waste) sludge production

$$P_x = Y_{obs}\cdot Q\cdot(S_0-S) = \frac{Y\cdot Q\cdot(S_0-S)}{1+k_d\cdot SRT}$$

`P_x` in kg VSS/d when `Q` in m³/d and `S` in kg/m³. This is the net biological (secondary) sludge generation rate — the core "how much sludge does this plant make" formula [1, Eq. 8-20 form; 9]. It excludes non-biodegradable influent VSS and primary sludge; the full plant sludge mass balance in [`mass_balance.py`](wastewater_models/mass_balance.py) adds those terms.

Implemented in [`activated_sludge.excess_sludge_production`](wastewater_models/activated_sludge.py).

### 1.4 Aeration tank volume (reactor sizing from SRT)

$$V=\frac{Y\cdot SRT\cdot Q\cdot(S_0-S)}{X\cdot(1+k_d\cdot SRT)}$$

Standard SRT-based reactor sizing equation [1, Ch. 8]; confirmed independently against multiple university/course design references (e.g. Iowa State CE326 activated-sludge design worksheet) during this session.

Implemented in [`activated_sludge.aeration_tank_volume`](wastewater_models/activated_sludge.py).

### 1.5 Food-to-microorganism ratio

$$F/M=\frac{Q\cdot S_0}{V\cdot X}$$

Standard operating/design check parameter [1].

### 1.6 Oxygen requirement

$$R_{O_2}=\frac{Q(S_0-S)}{f}-1.42\,P_x$$

where `f` ≈ 0.68 converts BOD₅ to BODu (ultimate carbonaceous oxygen demand) if `S` is expressed as BOD₅, and 1.42 g O₂/g VSS is the oxygen equivalent of cell mass (from the empirical cell formula C₅H₇NO₂) [1, Ch. 8]. If `S` is already COD/bCOD, omit the `f` conversion (`f = 1`).

Implemented in [`activated_sludge.oxygen_demand`](wastewater_models/activated_sludge.py).

### 1.7 Secondary clarifier sizing

$$A_{SOR}=\frac{Q}{SOR}\qquad A_{SLR}=\frac{Q(1+R)\cdot X}{SLR}$$

Typical design **SOR = 24–32 m³/(m²·d)** at average flow (Metcalf & Eddy/AECOM design range) [1]. Typical **side-water depth = 3.5–4.5 m**, detention time 2–3 h [secondary-sourced, cross-checked against multiple clarifier design references]. `R` is the recycle (RAS) ratio.

Implemented in [`activated_sludge.clarifier_area_by_sor`](wastewater_models/activated_sludge.py) and [`clarifier_area_by_slr`](wastewater_models/activated_sludge.py).

### 1.8 Typical ASP design envelope (India — CPHEEO)

From CPHEEO *Manual on Sewerage and Sewage Treatment Systems, Part A: Engineering* (2013) [2], Table 5.9 and surrounding design-criteria tables (values below cross-checked across multiple secondary summaries of that table, since the primary PDF would not parse cleanly in this session — **verify against the primary table before stamped design use**):

| Parameter | Conventional ASP | Extended aeration / high-rate |
|---|---|---|
| F/M (kg BOD/kg MLVSS·d) | ~0.35 | 0.2 – 0.6 |
| MLSS (mg/L) | 1,500 – 3,000 (design value often taken as 3,000) | 3,000 – 6,000 |
| SRT / MCRT (d) | 5 – 15 | 15 – 30 (typical extended-aeration range) |
| HRT (h) | 4 – 8 | 3 – 5 (high-rate) / 18–36 (extended aeration, separately) |
| RAS recirculation ratio | 0.25 – 0.5 | — |
| Aeration tank depth (m) | 3 – 4.5 | 3 – 4.5 |

Use this table only as a sanity-check envelope for outputs of §1.2–§1.7, not as a substitute for the primary manual.

---

## 3. Part II — Sludge Stabilization & Biogas Generation

### 2.1 Stoichiometric biogas composition — Buswell equation

For an organic substrate of empirical formula $C_cH_hO_oN_nS_s$, complete anaerobic conversion follows (Buswell & Mueller, 1952 [3]):

$$C_cH_hO_oN_nS_s + \left(c-\frac{h}{4}-\frac{o}{2}+\frac{3n}{4}+\frac{s}{2}\right)H_2O \rightarrow$$
$$\left(\frac{c}{2}+\frac{h}{8}-\frac{o}{4}-\frac{3n}{8}-\frac{s}{4}\right)CH_4 + \left(\frac{c}{2}-\frac{h}{8}+\frac{o}{4}+\frac{3n}{8}+\frac{s}{4}\right)CO_2 + n\,NH_3 + s\,H_2S$$

(Equivalent rearranged form of the widely quoted Buswell equation; the two commonly-published forms — Symons & Buswell 1933 antecedent and the 1952 Buswell & Mueller form — differ only in whether N and S products are pulled out before or after the C/H/O balance. The code implements the atom-balanced form and cross-checks that atoms balance exactly, so it is independent of which textbook variant you compare against.)

This gives the **maximum theoretical CH₄ fraction of biogas** for a substrate of known elemental composition — useful for feedstocks (e.g. lipids, proteins, carbohydrates) with a known formula, before real-world biodegradability limits it (VALORGAS lecture notes / multiple peer-reviewed restatements, e.g. ResearchGate reproductions of the 1952 formula, confirm this exact expression) [3].

Implemented in [`anaerobic_digestion.buswell_equation`](wastewater_models/anaerobic_digestion.py).

### 2.2 COD-based theoretical methane yield

Every gram of COD destroyed and converted to CH₄ corresponds to a fixed stoichiometric gas volume, because the oxygen demand of methane is fixed by its combustion reaction $CH_4 + 2O_2 \rightarrow CO_2 + 2H_2O$ (1 mol CH₄ ≡ 2 mol O₂ ≡ 64 g COD):

$$V_{CH_4} = \frac{m_{COD}}{64\ \text{g/mol}}\times \frac{RT}{P}$$

At STP (0 °C, 1 atm): **0.350 m³ CH₄ / kg COD destroyed**.
At 35 °C (mesophilic operating temperature): **0.395 m³ CH₄ / kg COD destroyed**.

This is the standard theoretical/reference yield used to sanity-check real digester performance (real yields are always lower, since some COD is diverted to biomass synthesis) [confirmed independently in this session via the ideal-gas-law derivation above, and cross-checked against the widely cited "0.35 L CH₄/g COD<sub>removed</sub> at STP" figure used throughout the anaerobic-digestion literature].

Implemented in [`anaerobic_digestion.theoretical_ch4_yield_from_cod`](wastewater_models/anaerobic_digestion.py) (temperature is a parameter, so it derives both figures above from the ideal gas law rather than hard-coding them).

### 2.3 Empirical yield from volatile solids (VS) destroyed

$$V_{biogas} = Y_{VS}\times VS_{destroyed}$$

**Y_VS ≈ 0.75 – 1.12 m³ biogas / kg VS destroyed** (equivalently the commonly cited 12–18 ft³/lb VS destroyed figure used in digester design guides; the two are the same range — verified in this session by direct unit conversion: 12–18 ft³/lb × 0.0624 = 0.75–1.12 m³/kg). Typical **VS reduction across a well-run mesophilic digester = 40–60 %** of raw VS fed. Typical **gas composition: 60–70 % CH₄, 30–35 % CO₂, <1 % H₂S/other** [11].

Implemented in [`anaerobic_digestion.biogas_yield_from_vs_destroyed`](wastewater_models/anaerobic_digestion.py).

### 2.4 IPCC Tier-1 methane emission accounting

For inventory/GHG-accounting purposes (as opposed to digester process design), the IPCC 2019 Refinement to the 2006 Guidelines, Vol. 5, Ch. 6 [5] gives:

$$CH_{4,emissions} = \sum_i \left(BOD_i \text{ or } COD_i\right)\times B_{0,i}\times MCF_i$$

Where:
- **B0 (domestic wastewater, default) = 0.6 kg CH₄/kg BOD** (equivalently ≈0.25 kg CH₄/kg COD ≡ 0.35 m³ CH₄/kg COD — consistent with the stoichiometric maximum derived in §2.2, since B0 is defined as that same theoretical ceiling, expressed on a BOD basis using the default COD:BOD ratio).
- **MCF (anaerobic digester, default) = 0.8** — i.e. Tier‑1 assumes an anaerobic digester realizes 80 % of the theoretical maximum.
- **MCF (well-managed, fully aerobic centralized treatment, 2006 default) = 0** — the original assumption that a well-managed aerobic plant emits negligible CH₄; the 2019 Refinement and subsequent field literature (e.g. Mexico field-data studies [12]) have proposed **non-zero MCFs (~0.06–0.32)** for aerobic and hybrid aerobic/anaerobic-digester plants, reflecting measured emissions the original Tier‑1 default missed.

**Only these two/three MCF values were independently corroborated by more than one source in this session.** The full Table 6.3 (covering septic systems, latrines, lagoons of varying depth, sewers, etc.) exists in the primary document but could not be parsed cleanly here — **do not treat any MCF value beyond the ones above as verified; pull Table 6.3 directly from the primary PDF [5] for anything beyond digesters/aerobic plants.**

Implemented in [`anaerobic_digestion.ipcc_tier1_ch4_emissions`](wastewater_models/anaerobic_digestion.py), which takes `B0` and `MCF` as explicit required arguments (no silently-assumed defaults for pathways this session couldn't verify).

### 2.5 Digester sizing

$$V_{digester} = Q_{sludge}\times HRT$$

Typical mesophilic digester **HRT = 15–25 d** (minimum design average 15 d) [11]. Two-stage systems commonly split into a mixed/heated primary digester (~15 d) and an unmixed secondary (storage/thickening) digester.

Implemented in [`anaerobic_digestion.digester_volume`](wastewater_models/anaerobic_digestion.py).

### 2.6 Beyond Tier-1 / design-manual models: ADM1

For dynamic, multi-substrate, pH/VFA-resolved digester simulation, the field standard is the **IWA Anaerobic Digestion Model No. 1 (ADM1)** — Batstone et al. (2002) [4]: 32 state variables, 19 biochemical rate processes (disintegration → hydrolysis → acidogenesis → acetogenesis → methanogenesis), 3 gas-liquid transfer processes, 6 acid-base equilibria. This is out of scope to re-derive here — see [§5](#5-existing-tools--libraries-dont-reinvent-these) for existing open-source implementations.

---

## 4. Part III — Plant-Wide Mass Balance

`mass_balance.py` composes §1 and §2 into a single steady-state flow:

```
Influent (Q, BOD0, COD0, TSS0)
   │
   ├─► Primary settling  → primary sludge (mass, fixed removal fractions — set by user)
   │
   ├─► Activated Sludge (§1) → effluent (S) + excess biological sludge P_x (§1.3)
   │
   ├─► Combined sludge stream → Anaerobic Digestion (§2)
   │        VS_destroyed (§2.3 reduction %) → biogas volume + CH4 fraction
   │
   └─► Digested/dewatered cake = sludge_in − VS_destroyed − water removed in dewatering
```

This is a **mass-balance composition of the design-manual equations above**, not a new model — every number it produces is traceable back to §1–§2. It deliberately does **not** attempt COD/BOD speciation (soluble vs. particulate fractionation) at ASM1/2/3 fidelity; if you need that, use QSDsan or a proper ASM/ADM1 simulator (§5).

---

## 5. Existing tools & libraries (don't reinvent these)

| Tool | What it is | Use it instead of this repo when… |
|---|---|---|
| **[QSDsan](https://github.com/QSD-Group/QSDsan)** (Python, PyPI: `qsdsan`) | Open-source platform for quantitative sustainable design of sanitation/resource-recovery systems: process models (incl. ASM & ADM implementations), techno-economic analysis, LCA. Built on BioSTEAM. Li, Y., Trimmer, J.T., et al., *Environ. Sci.: Water Res. Technol.* 8, 2289–2303 (2022) [7]. | You need full system-level TEA/LCA, or a maintained ASM/ADM1-linked plant simulator, not just point formulas. |
| **[PyADM1](https://github.com/CaptainFerMag/PyADM1)** (Python) | Python re-implementation of ADM1, ring-tested against the MATLAB/Simulink BSM2 reference implementation. Sadrimajd et al., bioRxiv (2021) [6]. | You need dynamic (time-resolved) digester simulation — VFA/pH excursions, co-digestion transients, control-strategy testing. |
| **ASM1/ASM2/ASM2d/ASM3** | IWA Scientific & Technical Report No. 9 (Henze, Gujer, Mino, van Loosdrecht, 2000) [8] — the standard kinetic model family for activated sludge (replaces the simplified Monod/SRT design equations in §1 with 8–19-component, multi-process kinetics for nitrification/denitrification/EBPR). | You need nutrient-removal (N/P) dynamics, not just carbon/sludge mass. Implementations ship inside QSDsan, GPS-X, BioWin, SUMO, WEST (commercial), and various open BSM2 ports. |
| **BSM2 (Benchmark Simulation Model No. 2)** | The IWA/COST community's standard whole-plant benchmark (primary → ASM1 bioreactor → clarifier → ADM1 digester), historically MATLAB/Simulink; multiple open ports exist (incl. the Python ADM1 sub-model above). | You want a peer-reviewed, community-validated whole-plant reference model to benchmark a new design against. |

**This repo's code is deliberately smaller than all of the above** — it implements only the closed-form design-manual/Tier‑1 equations (§1–§2), which is what's needed for preliminary sizing, feasibility mass balances, and GHG-inventory-style estimates. Reach for QSDsan/PyADM1/ASM-family tools when you need dynamic or nutrient-resolved simulation.

---

## 6. References

1. Tchobanoglous, G., Stensel, H.D., Tsuchihashi, R., Burton, F. (2014). *Wastewater Engineering: Treatment and Resource Recovery*, 5th ed. Metcalf & Eddy / AECOM, McGraw-Hill.
2. Central Public Health and Environmental Engineering Organisation (CPHEEO), Ministry of Urban Development, Government of India (2013). *Manual on Sewerage and Sewage Treatment Systems, Part A: Engineering*. Prepared with JICA. Official portal: cpheeo.gov.in.
3. Buswell, A.M., Mueller, H.F. (1952). "Mechanism of Methane Fermentation." *Industrial and Engineering Chemistry*, 44(3), 550–552.
4. Batstone, D.J., Keller, J., Angelidaki, I., Kalyuzhnyi, S.V., Pavlostathis, S.G., Rozzi, A., Sanders, W.T.M., Siegrist, H., Vavilin, V.A. (2002). "The IWA Anaerobic Digestion Model No. 1 (ADM1)." *Water Science and Technology*, 45(10), 65–73.
5. IPCC (2019). *2019 Refinement to the 2006 IPCC Guidelines for National Greenhouse Gas Inventories*, Volume 5: Waste, Chapter 6: Wastewater Treatment and Discharge.
6. Sadrimajd, P., Mannion, P., et al. (2021). "PyADM1: a Python implementation of Anaerobic Digestion Model No. 1." *bioRxiv* preprint 2021.03.03.433746. Code: github.com/CaptainFerMag/PyADM1.
7. Li, Y., Trimmer, J.T., Hand, S., Zhang, X., Chambers, K.G., Lohman, H.A.C., Shi, R., Byrne, D.M., Cook, S.M., Guest, J.S. (2022). "QSDsan: an integrated platform for quantitative sustainable design of sanitation and resource recovery systems." *Environmental Science: Water Research & Technology*, 8(10), 2289–2303.
8. Henze, M., Gujer, W., Mino, T., van Loosdrecht, M.C.M. (2000). *Activated Sludge Models ASM1, ASM2, ASM2d and ASM3*, IWA Scientific and Technical Report No. 9. IWA Publishing.
9. Lawrence, A.W., McCarty, P.L. (1970). "Unified Basis for Biological Treatment Design and Operation." *Journal of the Sanitary Engineering Division, ASCE*, 96(3), 757–778.
10. Water Environment Federation. *Design of Municipal Wastewater Treatment Plants*, Manual of Practice No. 8 (MOP 8) / ASCE Manual 76 — clarifier and digester design-criteria ranges, as reproduced consistently across secondary design references.
11. Digester HRT/VS-reduction/gas-yield ranges as reproduced consistently across multiple operator-training and regulatory design references (BayWork operator certification materials; Virginia sludge-management administrative code 9VAC25-790; Metcalf & Eddy [1]) — cross-checked to the same 12–18 ft³/lb VS destroyed figure by more than one independent source in this session.
12. Zamora-Vega, R. et al. — field-measured methane correction factors for aerobic wastewater treatment (Mexico), *Science of the Total Environment* (2018), cited as the basis for the 2019 IPCC-refinement discussion of non-zero aerobic MCFs.

---

**Caveat, stated plainly:** §1.8's CPHEEO table and §2.4's IPCC MCF table are the two places in this document where primary-source PDFs would not parse cleanly with the tooling available this session (they returned corrupted/oversized binary rather than text). Everything in those two sections is **cross-checked across ≥2 independent secondary sources** rather than quoted from the primary directly — flagged inline above. Before using either for a stamped design or a regulatory GHG filing, pull the primary document (CPHEEO Part A, Table 5.9 and surrounding tables; IPCC 2019 Refinement Vol. 5 Ch. 6, Tables 6.2/6.3) and confirm.
