Repository navigation
Fix equilibrium non-convergence between pH 4.2 and 5.05 for chelate mixtures - #58
Merged
Merged
Conversation
…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.
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
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.
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
nonconvergentrestarts 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
mainUsing 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
phreeqc-liveCI job will replay it.