Skip to content

Fix convergence failures in VCS constant TP solver#2124

Open
speth wants to merge 3 commits into
Cantera:mainfrom
speth:fix-266-vcs-TP
Open

Fix convergence failures in VCS constant TP solver#2124
speth wants to merge 3 commits into
Cantera:mainfrom
speth:fix-266-vcs-TP

Conversation

@speth
Copy link
Copy Markdown
Member

@speth speth commented May 31, 2026

Changes proposed in this pull request

  • Enforce iteration limit in VCS solver main loop. This prevents an infinite loop that could occur due to oscillating choices of the component basis.
  • Filter VCS non-convergence messages based on log level which were previously printed unconditionally
  • Prevent oscillations in the component basis caused by differing selection criteria at different points in the algorithm. Such cases prevented the solver from ever actually checking whether or not the mixture had reached equilibrium.

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

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.8).

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

speth and others added 3 commits May 30, 2026 22:24
The VCS solver's main loop checked the iteration limit at the top of the
MAIN stage but only set the failure flag (iconv = -1) without exiting the
loop, relying on the subsequent equilibrium-check stage to act on the
limit. That stage is not always reached: a component-basis swap oscillation
can keep the solver cycling through the MAIN stage indefinitely, forcing a
new component calculation on every iteration and never advancing to the
equilibrium check.

Fixed by routing the over-iteration case directly to the cleanup-and-return block.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The optimum-basis check at the end of each VCS iteration can disagree with
the basis that vcs_basopt actually selects: the check ranks a noncomponent
against a component by mole number alone, while vcs_basopt additionally
enforces linear independence and uses slightly different size weighting.
When they disagree, the check forces a component recalculation that re-selects
the same basis, which immediately trips the check again. The solver cycles
through its main loop forcing a new basis every iteration and never reaches
the equilibrium check, so it cannot converge.

Fixed by counting consecutive recalculations forced by this check and stopping
forcing once they clearly exceed what a real basis improvement requires. The
convergence criterion is the same for any equivalent basis, so suppressing
an oscillating swap is safe: it affects only conditioning, not the result.

Add a regression test covering a representative spread of the affected
compositions.

Fixes Cantera#266.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

❌ Patch coverage is 64.86486% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.78%. Comparing base (9f82790) to head (a5ed78d).

Files with missing lines Patch % Lines
src/equil/vcs_solve_TP.cpp 64.86% 9 Missing and 4 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2124   +/-   ##
=======================================
  Coverage   77.78%   77.78%           
=======================================
  Files         452      452           
  Lines       53602    53611    +9     
  Branches     8958     8959    +1     
=======================================
+ Hits        41693    41701    +8     
- Misses       8883     8885    +2     
+ Partials     3026     3025    -1     

☔ 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 31, 2026 14:55
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 VCS multiphase equilibrium solver at constant temperature + pressure

1 participant