Skip to content

Fix more failure modes in MultiPhaseEquil constant TP algorithm #2122

Merged
ischoegl merged 3 commits into
Cantera:mainfrom
speth:fix-issue265
May 30, 2026
Merged

Fix more failure modes in MultiPhaseEquil constant TP algorithm #2122
ischoegl merged 3 commits into
Cantera:mainfrom
speth:fix-issue265

Conversation

@speth
Copy link
Copy Markdown
Member

@speth speth commented May 30, 2026

Changes proposed in this pull request

  • Fix trace-phase handling in MultiPhaseEquil::stepComposition
  • Use consistent default max_steps for equilibrate
  • Fix component basis reselection in MultiPhaseEquil::computeN

If applicable, fill in the issue number this pull request is fixing

Closes #265

AI Statement (required)

  • Extensive use of generative AI. Significant portions of code or documentation were generated with AI, including logic and implementation decisions. All generated code and documentation were reviewed and understood by the contributor. Implemented using Claude Code (Opus 4.7).

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • AI Statement is included
  • The pull request is ready for review

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>
speth and others added 2 commits May 29, 2026 22:37
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
Copy link
Copy Markdown

codecov Bot commented May 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.78%. Comparing base (44732e7) to head (a9c0eff).
⚠️ Report is 9 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@speth speth marked this pull request as ready for review May 30, 2026 04:01
Copy link
Copy Markdown
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @speth!

@ischoegl ischoegl merged commit 9f82790 into Cantera:main May 30, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failures in Gibbs multiphase equilibrium solver at constant temperature + pressure

2 participants