Skip to content

Comp well improvements#7208

Merged
bska merged 5 commits into
OPM:masterfrom
GitPaean:comp_well_improvements
Jul 1, 2026
Merged

Comp well improvements#7208
bska merged 5 commits into
OPM:masterfrom
GitPaean:comp_well_improvements

Conversation

@GitPaean

Copy link
Copy Markdown
Member

No description provided.

@GitPaean GitPaean added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Jun 28, 2026
@GitPaean GitPaean requested a review from Copilot June 28, 2026 21:42
@GitPaean

Copy link
Copy Markdown
Member Author

jenkins build this please

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the compositional well (“CompWell”) robustness and testability by extracting the wellbore flash/mass computations into reusable helpers, tightening handling of singular well Jacobian blocks, and adding targeted unit tests for both the flash derivative chain and the Schur-complement well equation machinery.

Changes:

  • Extracts the wellbore PT-flash and component-mass computation into CompWellFlash.hpp and uses it from CompWell.
  • Makes CompWellEquations::invert() robust across multiple singular-matrix failure modes (exceptions and silent inf/NaN).
  • Adds two new unit tests covering flash AD-derivatives vs finite differences and Schur-complement operations / singular fallbacks.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_compwell_jacobian.cpp New finite-difference vs AD-derivative regression test for wellbore flash/mass-fraction chain.
tests/test_compwell_equations.cpp New unit test for Schur-complement operations and singular inverse fallback behavior.
flowexperimental/comp/wells/CompWellPrimaryVariables_impl.hpp Generalizes clamping/renormalization of mole-fraction primaries.
flowexperimental/comp/wells/CompWellModel.hpp Formatting/indentation cleanup.
flowexperimental/comp/wells/CompWellModel_impl.hpp Clarifies report-step initialization behavior via comments.
flowexperimental/comp/wells/CompWellFlash.hpp New extracted helpers: wellbore flash + per-component wellbore masses.
flowexperimental/comp/wells/CompWellEquations_impl.hpp Detects singular inversion via exceptions and non-finite inverse entries; falls back to identity.
flowexperimental/comp/wells/CompWell.hpp Includes the new CompWellFlash.hpp.
flowexperimental/comp/wells/CompWell_impl.hpp Uses extracted helpers; adds explicit unsupported-case throw in getMobility; adjusts logging level.
CMakeLists_files.cmake Registers the two new test sources in the build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_compwell_jacobian.cpp
Comment thread tests/test_compwell_equations.cpp Outdated
@GitPaean GitPaean force-pushed the comp_well_improvements branch 2 times, most recently from c0a23e1 to 9dd0990 Compare June 30, 2026 12:17
@GitPaean

Copy link
Copy Markdown
Member Author

jenkins build this please

@GitPaean GitPaean force-pushed the comp_well_improvements branch from 9dd0990 to ac00220 Compare June 30, 2026 12:54
@GitPaean

Copy link
Copy Markdown
Member Author

jenkins build this please

@GitPaean GitPaean force-pushed the comp_well_improvements branch 3 times, most recently from 298bb27 to 0b3de1b Compare June 30, 2026 13:45
@GitPaean

GitPaean commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

I think the well code change are good and clear improvements. The tests can be discussed. I am marking the PR as ready for review now.

@GitPaean GitPaean marked this pull request as ready for review June 30, 2026 14:10
@GitPaean

Copy link
Copy Markdown
Member Author

jenkins build this please

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread flowexperimental/comp/wells/CompWellPrimaryVariables_impl.hpp
Comment thread flowexperimental/comp/wells/CompWell_impl.hpp
@GitPaean GitPaean force-pushed the comp_well_improvements branch from 0b3de1b to ca067d7 Compare June 30, 2026 14:43
@GitPaean

Copy link
Copy Markdown
Member Author

jenkins build this please

@GitPaean GitPaean requested review from atgeirr and bska July 1, 2026 08:29

@bska bska left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this looks good for the most part and I appreciate the simplification. Just a couple of surface level remarks from me.

Comment thread flowexperimental/comp/wells/CompWellPrimaryVariables_impl.hpp
Comment thread flowexperimental/comp/wells/CompWellFlash.hpp Outdated
Comment thread flowexperimental/comp/wells/CompWell_impl.hpp
Comment thread flowexperimental/comp/wells/CompWellEquations_impl.hpp Outdated
GitPaean added 4 commits July 1, 2026 13:56
is different from the connection cell's. throw for now, either zero
mobility will be resulted.
Move the wellbore PT flash and the per-component mass computation out of
CompWell into standalone flashWellboreFluidState()/wellboreComponentMasses()
helpers (CompWellFlash.hpp), removing the duplicated mass loops in
calculateExplicitQuantities()/updateTotalMass(). This makes the
composition/pressure derivatives that flow through the flash unit-testable
without instantiating a Simulator.

Add tests/test_compwell_jacobian.cpp, which checks the AD derivatives of the
component masses, mass fractions and fluid density against central finite
differences. They agree to ~1e-7, confirming the previously-doubted
mass-fraction derivatives are in fact correct.
…sizes

CompWellEquations::invert() replaced a singular well matrix with the identity
only when detail::invertMatrix() threw Opm::NumericalProblem, which happens
just for the 4x4 block (three-component wells). For other sizes a singular
matrix either throws Dune::FMatrixError (generic path) or silently produces
inf/NaN (e.g. the 3x3 path used by two-component wells), so the fallback was
bypassed and the Newton update became NaN. Catch both exception types and
additionally detect a non-finite inverse.

Add tests/test_compwell_equations.cpp covering the Schur-complement
solve/recoverSolutionWell/apply against dense references, plus the singular
fallback for both the 4x4 (throws) and 3x3 (silent inf/NaN) paths.
@GitPaean GitPaean force-pushed the comp_well_improvements branch from ca067d7 to 6f6a331 Compare July 1, 2026 12:10
@GitPaean

GitPaean commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

Thanks for the reviewing comments. I believe I have addressed them.

@GitPaean

GitPaean commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

jenkins build this please

@bska bska left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for the updates. This looks good to me now and I'll merge into master.

@bska bska merged commit 062cb19 into OPM:master Jul 1, 2026
2 checks passed
@GitPaean GitPaean deleted the comp_well_improvements branch July 1, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants