Skip to content

Add a waste phase to SBRUnit - #1095

Merged
ctdegroot merged 3 commits into
mainfrom
sbr-waste-phase
Dec 4, 2026
Merged

ctdegroot merged 3 commits into
mainfrom
sbr-waste-phase

Conversation

@ctdegroot

Copy link
Copy Markdown
Member

Closes #334

Summary

SBRUnit can waste sludge, which is how an SBR sets its sludge age; without it the solids the clarified decant leaves behind build up cycle after cycle.

  • SBRPhase(waste=True) draws the new waste_flow setting (a plant parameter, "<unit>.waste_flow") out of a waste port (waste_port), at the bottom-of-tank concentration the settling model reports. The tank keeps the rest, so mass is conserved whatever the model reports.
  • SettlingModel gains an abstract waste_multiplier:
    • InterfaceSettling: the blanket below the clarified zone. With c the clarified share of the depth holding particulates at (1 - c) of the bulk, the blanket holds them at (1 - c + c²)/(1 - c) of the bulk, capped by a new max_thickening (default 3, must be ≥ 1). It is the bulk when mixed (c = 0), and the cap keeps a fully clarified tank finite.
    • LayeredSettling: the bottom layer's ratio.
  • A waste phase needs a positive waste_flow, and a waste_flow without a waste phase is refused. The port and the parameter exist only when a phase wastes, so existing SBRs, their parameter vectors and their spec files are unchanged.
  • In the catalogue, the waste port carries when: {setting: waste_flow}. The unit requires the two together, so the port rules agree with the built unit without a new kind of when condition (none that reads a record's field), and the editor needed no change.
  • Docs: a short wasting example in docs/custom_flowsheets.md and a line in docs/plant_files.md / the spec.py docstring. Also a changelog fragment and the when line in .claude/rules/plant-spec.md.

Things a reviewer should know

  • The capped blanket for InterfaceSettling and max_thickening = 3 were the owner's choice. The alternatives were wasting the mixed liquor only, or an uncapped blanket.
  • Six existing tests changed, only to add the new fields. They pin the exact field list or the written dict of an SBRPhase or an InterfaceSettling, so I added waste / "waste": False and max_thickening / 3.0 to them. No assertion was loosened:
    • tests/unit/test_plant_catalog.py: the phases' field list, InterfaceSettling's argument list, and the written phase and settling dicts.
    • tests/integration/test_plant_spec.py: the written phase, _INTERFACE, and the defaults used to shorten a spec.
    • tests/ui/test_forms.py: the phase table's fields, values and blank row.
  • make_small_sbr_plant (in tests/conftest.py) takes phases=, so the waste tests reuse the small decay-model SBR.
  • Wasting does not thin the settling model's state: after a waste draw the clarity (or the layer profile) is kept as the settle left it. A phase after it that mixes resets it.

Testing

  • New tests:
    • On a three-cycle small SBR, against the same cycle decanting those 5 m³ instead (tests/integration/test_sbr.py):
      • the waste port carries waste_flow in the waste phase only, at the capped-blanket ratio for the particulate and the bulk for the soluble;
      • the tank returns to its heel each cycle;
      • the COD balance closes, with sbr.waste among the outlets;
      • the tank ends holding less than 0.9× the solids.
    • jax.grad of the held solids with respect to waste_flow matches a central finite difference (rel=1e-5) and is negative.
    • Each error message, by text.
    • Multiplier values:
      • mass consistency, c·decant + (1 − c)·waste = 1;
      • the cap, including c = 1, with a finite zero gradient;
      • LayeredSettling's bottom layer;
      • the refusal of max_thickening < 1.
    • The catalogue's port rules match check_unit for a wasting SBR.
    • A spec round trip with the same fingerprint.
  • Fast tier, pytest tests/unit tests/integration tests/ui -m "not validation and not slow" -n 4: 5800 passed, 1 failed. The failure, test_plant_identifiability.py::test_rank_forward_and_reverse_agree, is a one-CSTR test that passes alone; it is tracked in test_rank_forward_and_reverse_agree fails intermittently under xdist #1094.
  • After merging main: the SBR, catalogue, spec, form and repository-check tests (381 passed) and ruff.
  • Other checks: scripts/check_types.py passes. The doc examples pass (pytest docs/custom_flowsheets.md docs/plant_files.md: 33 passed, 2 skipped). The strict docs build (sphinx-build -W, offline) is clean.
  • Not run: the slow / validation tiers and the browser tests.

Patch coverage

python scripts/patch_coverage.py: 100.00% of 50 changed lines.

Found on the way, not changed here


Generated by Claude Code

An SBRPhase with waste=True draws waste_flow out of a waste port, at the
bottom-of-tank concentration the settling model reports: the mixed liquor
when mixed, the settled blanket after a settle. InterfaceSettling gives
the mass-consistent blanket, capped by a new max_thickening (default 3);
LayeredSettling wastes its bottom layer. The waste port and waste_flow
exist only when a phase wastes, so existing SBRs are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ctdegroot
ctdegroot added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit c93057a Dec 4, 2026
34 checks passed
@ctdegroot
ctdegroot deleted the sbr-waste-phase branch December 4, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SBRUnit: add sludge wasting (waste phase / draw) to close the long-run solids balance

2 participants