Multiphase equilibrium solver fixes#2116
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2116 +/- ##
==========================================
- Coverage 77.69% 77.68% -0.01%
==========================================
Files 452 452
Lines 53203 53253 +50
Branches 8864 8880 +16
==========================================
+ Hits 41335 41370 +35
- Misses 8867 8876 +9
- Partials 3001 3007 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Trace species were intended to be ignored in the convergence error metric, but that branch was being overwritten by the following if/else. This fix allows two tests previously marked as "xfail" to pass. Fixes Cantera#130. Fixes Cantera#425. Co-authored-by: OpenAI Codex <codex@openai.com>
…siton For constant TP equilibrium, the initial composition is usually only used to determine the element abundances, so which phases these species come from doesn't matter. Partially addresses Cantera#160 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes Cantera#160 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
One of the terms here is supposed to be (sum_k nu_k)^2, not sum_k nu_k^2. Partially fixes Cantera#1023 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…eEquil::step When a minor non-component species uses the exponential update formula (moles_new = |m_moles[k]| * exp(-dG/RT), capped at 10x growth) instead of the Newton step, the change in moles differs from what the component update above assumed (omega*deltaN[k]). For modestly-trace species the resulting element-balance error is O(m_moles[k]) and absorbed by subsequent iterations without ill effect, but for catastrophic cases — when the Newton step expects a large change but the exponential formula caps the actual change at a small fraction — the imbalance can produce wildly wrong final compositions. The catastrophic case showed up most clearly when one phase has effectively zero total moles: chemical potentials in that phase are dominated by numerical artifacts in the ratios of trace amounts, making other species in the same phase look favorable to form. The Newton step would then debit a large amount from the component (e.g., N2 in the first phase), while the exponential formula left the trace noncomponent unchanged, draining the component. Fixed by correcting the components by m_N(n, j) * excess when the excess is catastrophic (|excess| > 10*|moles_new - m_moles[k]|). Applying the correction routinely destabilizes convergence by perturbing trace components, so the gating threshold is essential. Partially fixes Cantera#1023 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…reactions MultiPhaseEquil checks every formation reaction's |dG/RT| against the convergence tolerance, regardless of how much the reaction could affect the composition. For trace minor species whose mole fraction is dominated by floating-point noise, |dG/RT| can be pinned at a small but nonzero value (e.g., 1e-5) indefinitely, preventing convergence even though no further composition change is possible. For an unfavorable formation reaction (dG/RT > 0), the maximum extent in a single step is bounded by the noncomponent's own moles plus the moles of any component the reaction would produce (m_N(n,j) > 0). When this maximum extent times |dG/RT| is far below the mixture scale, the reaction's contribution to the Gibbs free energy is below floating-point significance, and it should not block convergence. The bound is not applied to favorable reactions (dG/RT < 0), since those can still meaningfully grow a species from trace levels via the exponential update formula's 10x-per-step growth, even when the current extent is small. This fixes pre-existing convergence failures at higher temperatures where minor species like H, O, OH have to be resolved. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sweeps parametrized cases for a two-phase mixture where one phase is the full h2o2 mechanism initially defined as a stoichiometric H2/O2 mixture with some N2 and the second is an ideal-gas phase containing a subset of the mechanism's species, starting with zero moles. The combinations and conditions are chosen to exercise the problematic regimes that were originally reported in issue Cantera#1023. To verify equilibrium, the chemical potential of each species must satisfy mu_k = sum_e n_{e,k} lambda_e for some element potentials lambda_e. We solve for lambda by weighted least squares (weighting by moles so trace species do not dominate) and require the per-species residual to be below 1e-6 of RT for all species with non-trivial moles. Element conservation between initial and final states is checked separately. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…a#425) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ments Fixes Cantera#245 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ischoegl
approved these changes
May 16, 2026
ischoegl
reviewed
May 16, 2026
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.
Changes proposed in this pull request
This PR fixes the known issues with constant TP equilibrium solves using the
MultiPhaseEquilsolver (that is, the one used when callingmix.equilibrate("TP", solver="gibbs").MultiPhaseEquil::step. This requires some thresholds depending on the direction of the step (for favorable or unfavorable trace species) and depending on the amount of the trace species present.AI Statement (required)
Checklist
scons build&scons test) and unit tests address code coverage