fix(alkalinity): count fluoride as a conservative strong-acid anion (#458) - #467
Merged
Conversation
Fluoride (F-) is a strong-acid anion but was missing from the conservative
anion set used by Solution.alkalinity, leaving the conservative alkalinity
of fluoride-bearing waters (e.g. seawater) ~3.4 mg/L as CaCO3 too high
relative to the PHREEQC engine's titration alkalinity. Add ("F", -1.0): -1
to the acid_anions map and document that the conservative and titration
definitions coincide only for a charge-balanced solution.
Refs #458
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #467 +/- ##
==========================================
- Coverage 87.78% 87.77% -0.01%
==========================================
Files 14 14
Lines 1989 1988 -1
Branches 347 346 -1
==========================================
- Hits 1746 1745 -1
Misses 192 192
Partials 51 51 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
Author
|
@jjstickel I'm going to merge this now to address source 1, but let me know your thoughts about the definitional difference:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #458 / #459. While investigating the residual ~9% discrepancy between
Solution.alkalinityand the alkalinity reported by thephreeqc2026engine(
PhrqSol.get_alkalinity()) for seawater, the gap decomposed — via an exact charge-balanceidentity — into two independent causes:
between the conservative (Stumm) alkalinity and PHREEQC's titration alkalinity. (~7 mg/L for the unbalanced seawater preset)
This PR addresses only cause (1), which is unambiguous: F⁻ is a strong-acid anion (like Cl⁻/Br⁻/I⁻)
and must count against the conservative alkalinity. Cause (2) is left as-is by design — subtracting the
charge imbalance would redefine alkalinity for non-electroneutral inputs (and the conservative and
titration definitions already coincide for any charge-balanced solution). The docstring now notes this
explicitly, and the divergence origin is written up in the #458 discussion.
Changes
("F", -1.0): -1to theacid_anionsmap inSolution.alkalinity.charge-balanced solution; non-electroneutral inputs additionally differ by the residual charge imbalance.
test_alkalinity_fluoride_is_conservative: a charge-balanced NaF solution haszero conservative alkalinity (Na⁺ and F⁻ cancel), and adding 1 mmol/L F⁻ lowers alkalinity by ~50 mg/L as CaCO₃.
ifin the engine cross-check (ruff SIM102) and add a CHANGELOG entry.Verification
matching the charge-balanced PHREEQC value.
tests/test_solution.py,tests/test_engine_phreeqc2026.py, andtests/phreeqc/suites pass (796 tests).🤖 Generated with Claude Code