Skip to content

Preserve surface site inventories in VCS TP equilibrium - #2200

Open
Kiril1Shevtsov wants to merge 3 commits into
Cantera:mainfrom
Kiril1Shevtsov:fix-vcs-surface-site-balance
Open

Kiril1Shevtsov wants to merge 3 commits into
Cantera:mainfrom
Kiril1Shevtsov:fix-vcs-surface-site-balance

Conversation

@Kiril1Shevtsov

@Kiril1Shevtsov Kiril1Shevtsov commented Nov 16, 2026 •

Copy link
Copy Markdown

Changes proposed in this pull request

This adds support for conserving surface-site inventories in mixtures with neutral ideal surfaces and equal positive species site sizes. The supported modes are TP with solver="vcs" or auto, and HP or SP with explicit solver="vcs". The existing HP/SP outer loops are unchanged.

  • Add an independent site balance for each supported surface phase.
  • Provide surface activity coefficients consistent with coverage-based activities.
  • Handle vacant-site species with no chemical elements.
  • Reject unsupported surface models, unequal site sizes, charged species, volume-constrained modes and the Gibbs solver explicitly.
  • Add C++ and Python regression tests for conservation, surface activities and rejected inputs.

Addresses #1720. This is deliberately scoped support, not a general solution for every surface model or equilibrium constraint.

Validation

The original TP-only revision was tested against 25c1ab1c397e2991c77560b1ad5154919a12c733:

  • Archived Linux/GCC native run: scons test -j1 -k, 8058 passed, 0 failed, one reused test group.
  • That equilibrium group also ran separately: 42 active tests passed; two pre-existing tests remained disabled.
  • 56 focused Python regressions passed.
  • An independent constrained-Gibbs reference agreed with the supported examples.
  • A separate check of the original consumer example's composition overrides passed all four VCS/auto and amount-scaling cases: 88 checks and two scaling comparisons. Relative atom and site residuals were below 3e-16.

The full native run was performed on 11 November and the original-composition checks on 12 November; neither is claimed as a new run today. Fresh preparation checks verified clean patch application to current main and Python syntax for all three changed Python files. The native build enabled Python and GoogleTest and disabled HDF5 and Fortran.

On the current HP/SP follow-up (db0a8a1), the targeted run passed 79 tests, including 16 new HP/SP cases with and without a gas phase. An independent reference agreed within 3 µK in final temperature. The full native suite was not rerun on this follow-up. Details.

AI Statement (required)

Extensive use of generative AI. Generative AI was used for code review, as well as for writing part of the routine code. All code was reviewed by me personally.

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build/test evidence for the exact patch is described above, including its scope and date
  • Style and formatting follow the contributing guidelines
  • AI Statement is included
  • The pull request is ready for review

Add scoped neutral ideal-surface support and regression tests.
Addresses Cantera#1720.
@speth

speth commented Nov 22, 2026

Copy link
Copy Markdown
Member

I realize this is not marked as ready for review yet, but I had one question about the choice of scoping this to constant TP solves only. Given all the other constraint options for the VCS solver are just loops over constant TP solves, is there a reason not to support those constraints here? Unless I'm missing something, it wouldn't require anything else from the implementation; just perhaps a few additional tests.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.42857% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.53%. Comparing base (25c1ab1) to head (7957345).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/equil/vcs_solve.cpp 85.71% 1 Missing and 2 partials ⚠️
src/equil/vcs_VolPhase.cpp 84.61% 1 Missing and 1 partial ⚠️
src/equil/MultiPhaseEquil.cpp 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2200      +/-   ##
==========================================
- Coverage   78.44%   77.53%   -0.92%     
==========================================
  Files         463      470       +7     
  Lines       55884    57244    +1360     
  Branches     9166     9215      +49     
==========================================
+ Hits        43839    44384     +545     
- Misses       8978     9791     +813     
- Partials     3067     3069       +2     

☔ View full report in Codecov by Harness.
📢 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.

@Kiril1Shevtsov

Copy link
Copy Markdown
Author

Thanks, @speth. You were right about HP and SP. I started with TP to test the site balance in the simplest setting, not because HP or SP needs a different inner solve.

I’ve added HP and SP to this PR for explicit solver="vcs", leaving the outer loops and auto unchanged. The targeted run passed 79 tests, including 16 new HP/SP cases with neutral, equal-site ideal surfaces, both with and without a gas phase. An independent reference agreed to within 3 µK on the final temperature.

I’ve left the volume-constrained modes guarded. The current loop divides by the target volume, which is zero for a surface-only system. One idea is to handle zero volume explicitly and test the existing iteration separately on positive-volume gas–surface mixtures. That part isn’t validated yet.

I’m still getting to know Cantera’s internals, and I hope to contribute more as I learn my way around. Thanks for pointing me in this direction.

Codex assisted with the HP/SP patch and validation; I reviewed the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants