8000 Fix equilibrium non-convergence between pH 4.2 and 5.05 for chelate mixtures by rafatahmed · Pull Request #58 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

Fix equilibrium non-convergence between pH 4.2 and 5.05 for chelate mixtures - #58

Merged
rafatahmed merged 1 commit into
mainfrom
fix/low-ph-convergence
Oct 20, 2026
Merged

rafatahmed merged 1 commit into
mainfrom
fix/low-ph-convergence

Conversation

@rafatahmed
Copy link
Copy Markdown
Owner

Fixes #52.

Root cause

From the cold start (every free activity at total/1000), Newton crawled toward strongly complexed free ions at low pH (EDTA, DTPA and EDDHA with Fe and Cu; one free-ion log activity near 1e-27), about 0.1 log unit per iteration, until the 150-iteration limit.

Traced at pH 4.5: the residual stalled near 0.036 for 110 iterations. The system is aqueous-only at a prescribed pH, so a unique solution exists; the failure was numerical.

Fix

A solve that raises nonconvergent restarts from a continued-fraction mass-balance estimate (Wigley 1977, as used in the WATEQ/MINTEQ family): each free activity is rescaled by total/sum, damped by its largest stoichiometric coefficient. The restart runs only after a failure, so every converging solve is bit-identical.

Evidence

main This PR
pH 4-9 scan, 3 mixed fixtures (1,503 solves) 215 failures 0
Nitric acid target to pH 5.0 (mixed products) fails 0.9218 mmol/kg, 2.6 s
Worst conservation residual in the scan n/a 2.2e-10 relative
Cost of a rescued solve n/a about 0.37 s (failed attempt plus restart)

Using the estimate as the default start was also measured: 25-40% fewer Newton iterations per solve. But results shift at 1e-11 relative, and the nitric search then needs 23 solves instead of 12 because it works at the solver's noise floor. It is not adopted here.

Tests

  • Convergence across the former failure band (pH 4.2-5.0, two fixtures).
  • A pH 5.0 acid target.
  • A check that converging solves never use the restart.
  • 357 tests pass (1 skipped). PHREEQC is not installed locally; the phreeqc-live CI job will replay it.

…stimate (#52)

From the cold start (every free activity at total/1000), Newton crawled
toward strongly complexed free ions (EDTA, DTPA and EDDHA with Fe and
Cu) at low pH, about 0.1 log unit per iteration, until the 150-iteration
limit. Between pH 4.2 and 5.05 the mixed product solutions could not be
solved at all; an acid target of pH 5.0 failed.

A failed solve now restarts from a continued-fraction mass-balance
estimate (Wigley 1977): each free activity is rescaled by total/sum,
damped by its largest stoichiometric coefficient. A pH 4-9 scan of the
three mixed fixtures (1,503 solves) goes from 215 failures to none, with
conservation residuals below 2.2e-10 relative. The restart runs only
after a failure, so every converging solve is bit-identical.

Using the estimate as the default start was measured too: 25-40% fewer
Newton iterations per solve, but results shift at 1e-11 and the nitric
search then needs 23 solves instead of 12 near its noise floor, so it
is not adopted here.
@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 Flahax | 🛠️ Build #35277935 | 📁 Comparing f74b195 against latest (0aacd27)

  🔍 Preview build  

1 file changed
± changelog.html

@rafatahmed
rafatahmed merged commit 2e9d1d1 into main Oct 20, 2026
6 checks passed
@rafatahmed
rafatahmed deleted the fix/low-ph-convergence branch October 20, 2026 18:31
@rafatahmed rafatahmed self-assigned this Oct 23, 2026
rafatahmed added a commit that referenced this pull request Nov 7, 2026
Fix equilibrium non-convergence between pH 4.2 and 5.05 for chelate mixtures
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.

Equilibrium solver fails to converge between pH 4.2 and 5.05 for chelate-rich mixed solutions

1 participant

0