Fix more failure modes in MultiPhaseEquil constant TP algorithm #2122
Merged
Conversation
Before computing the step, drop trace stoichiometric phases that are being consumed (zero their moles and their formation reaction's dxi, so element balance is preserved). Partially fixes Cantera#265 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The Python interface only allowed 1000 steps by default, while the C++ interface allowed 50000.
Previously, computeN only reselected the basis when the most-abundant species per element wasn't a component. It never noticed when a component itself became depleted. So a radical sitting in the basis at ~8e-10 mol could stay in the basis and throttle every reaction that must consume it, since the step is bounded by moles/|Δmoles|. The solver then settles into a limit cycle and never converges, This is fixed by forcing component reselection when any component drops below a threshold of 1e-3 * total_moles. This is safe because getComponents is idempotent-optimal; it re-selects the same species if it's genuinely the best linearly-independent choice. Otherwise, it swaps in a more abundant species. Fixes Cantera#265 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2122 +/- ##
==========================================
+ Coverage 77.71% 77.78% +0.07%
==========================================
Files 452 452
Lines 53316 53602 +286
Branches 8894 8958 +64
==========================================
+ Hits 41432 41693 +261
- Misses 8870 8883 +13
- Partials 3014 3026 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ischoegl
approved these changes
May 30, 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
MultiPhaseEquil::stepCompositionmax_stepsforequilibrateMultiPhaseEquil::computeNIf applicable, fill in the issue number this pull request is fixing
Closes #265
AI Statement (required)
Checklist
scons build&scons test) and unit tests address code coverage