8000 fix: count every proton carrier in the legacy nitric planner by rafatahmed · Pull Request #511 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

fix: count every proton carrier in the legacy nitric planner - #511

Merged
rafatahmed merged 1 commit into
mainfrom
fix/legacy-nitric-alkalinity-507
Dec 5, 2026
Merged

rafatahmed merged 1 commit into
mainfrom
fix/legacy-nitric-alkalinity-507

Conversation

@rafatahmed
Copy link
Copy Markdown
Owner

Summary

_alkalinity, which only plan_legacy_phreeqc_nitric uses, summed part of the protons the reduced model holds.

 Alk = HCO3- + 2 CO3^2- + HPO4^2- + 2 PO4^3-
+    + 2 (CaPO4- + MgPO4-) + CaHPO4 + MgHPO4 + NaHPO4-
+    + NH3 - H3PO4
     + OH- - H+

The complex amounts are recomputed from the result's activities and the module's formation constants. The result record and the public nitric planner (MINTEQ model) are unchanged.

Closes #507
Closes #510

Evidence

PHREEQC 3.8.6, nitric acid in mol/kgw, solution of the reference fixture. The ammonium row adds 1 mmol/kgw ammonium and chloride and uses Amm.dat; the others use phreeqc.dat. These doses were found by iterating a REACTION on HNO3.

Case PHREEQC Before After
pH 7.4 to 6.0 2.0865e-3 1.8780e-3 (-10.00 %) 2.0900e-3 (+0.17 %)
pH 7.4 to 6.0 with ammonium 2.0973e-3 1.8801e-3 (-10.35 %) 2.1006e-3 (+0.16 %)
pH 6.0 to 3.0 2.1977e-3 2.0001e-3 (-8.99 %) 2.1483e-3 (-2.25 %)
  • New test: the dose equals the change in net charge over every species, with literal constants, in the three cases above. Before: three failures. After: pass.
  • The fixture limit for nitric acid goes from 12 % to 0.2 % (1.2 times the measured difference), and a new test rejects the old dose.
  • Local: 25 affected and repository test modules pass, live PHREEQC replay 6 tests pass, a fresh product capture matches the stored one in 58 of 58 files, ruff check and format pass.

Remaining limit

At pH 3 the dose stays 2.25 % (4.9e-5) below PHREEQC. The reduced model has no HSO4-, of which PHREEQC holds 5.3e-5 at that pH. The legacy model also keeps total sodium as free Na+ while forming NaHPO4-.

Checked against earlier work

Merge Danger

Door: two-way

Blast Radius: narrow. Doses from plan_legacy_phreeqc_nitric rise, by about 11 % in the reference case.

The alkalinity sum left out the Ca, Mg and Na phosphate complexes, NH3 and H3PO4. The reference fixture's nitric acid limit goes from 12 % to 0.2 %.
@rafatahmed rafatahmed added the bug Something isn't working label Dec 5, 2026
@rafatahmed rafatahmed self-assigned this Dec 5, 2026
@read-the-docs-community
Copy link
Copy Markdown

📖 1 file modified


Preview · build overview · Flahax · built Dec. 5, 2026, 11:35 a.m. UTC

@codecov
codecov Bot commented Dec 5, 2026 •
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (053c693) to head (e17b5b5).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #511   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          155       155           
  Lines        18417     18421    +4     
  Branches      3723      3723           
=========================================
+ Hits         18417     18421    +4     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rafatahmed
rafatahmed marked this pull request as ready for review December 5, 2026 11:42
@rafatahmed
rafatahmed merged commit 31be384 into main Dec 5, 2026
28 checks passed
@rafatahmed
rafatahmed deleted the fix/legacy-nitric-alkalinity-507 branch December 5, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: the legacy nitric planner leaves NH3 and H3PO4 out of alkalinity bug: the legacy nitric planner leaves the phosphate complexes out of alkalinity

1 participant

0