Skip to content

Linear solver for the full (reservoir, well) system#7111

Merged
atgeirr merged 1 commit into
OPM:masterfrom
ElyesAhmed:linear_solver_cpr
Jun 25, 2026
Merged

Linear solver for the full (reservoir, well) system#7111
atgeirr merged 1 commit into
OPM:masterfrom
ElyesAhmed:linear_solver_cpr

Conversation

@ElyesAhmed

Copy link
Copy Markdown
Contributor

We will close #6751 and make a new PR from @jakobtorben and @hnil

Draft PR: Coupled Reservoir–Well Linear Solver (system_cpr)
This PR introduces a prototype for solving the reservoir and well degrees of freedom as a single coupled linear system, rather than handling wells separately through Schur complement elimination.
The preconditioner is functionally equivalent to the existing cpr (not cprw) and serves as a baseline to validate correctness before further tuning.
Features

  • Linear solve operates on the full coupled system (reservoir + well DOFs)
  • The underlying linear solver works with standard sparse matrices — no special well-aware operators required
  • Preconditioner is configurable to reproduce standard CPR behavior exactly
  • Supports an approximate well-block solve; performance impact to be benchmarked
  • The new preconditioner can be used with --linear-solver=system_cpr

@ElyesAhmed ElyesAhmed force-pushed the linear_solver_cpr branch from b1fc160 to 9b2c3ed Compare June 2, 2026 06:40
@ElyesAhmed ElyesAhmed force-pushed the linear_solver_cpr branch 4 times, most recently from 5db1cde to 557bc7d Compare June 15, 2026 09:24
@atgeirr atgeirr added the manual:new-feature This is a new feature and should be described in the manual label Jun 16, 2026
@atgeirr

atgeirr commented Jun 16, 2026

Copy link
Copy Markdown
Member

jenkins build this please

@atgeirr atgeirr 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.

Just started reviewing this, but noticed some surface-level stuff that can be fixed easily while I look at the more important parts.

Comment thread CMakeLists_files.cmake
Comment thread opm/simulators/linalg/system/MultiComm.hpp Outdated
Comment thread opm/simulators/linalg/system/SystemPreconditioner.hpp Outdated
Comment thread opm/simulators/linalg/system/SystemPreconditioner.hpp

@atgeirr atgeirr 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 have now looked at all the new code in the system/ subdirectory. Overall there is a lot of good work, I look forward to merging it!

I have identified some issues that can be worked on while I look at the rest of the code.

Comment thread opm/simulators/linalg/system/ISTLSolverSystem.hpp Outdated
Comment thread opm/simulators/linalg/system/ISTLSolverSystem.hpp
Comment thread opm/simulators/linalg/system/ISTLSolverSystem.hpp
Comment thread flow/flow_blackoil.cpp
Comment thread opm/simulators/linalg/system/ISTLSolverSystem.hpp Outdated
Comment thread opm/simulators/linalg/system/SystemPreconditioner.hpp Outdated
Comment thread opm/simulators/linalg/system/SystemPreconditioner.hpp Outdated
Comment thread opm/simulators/linalg/system/SystemPreconditioner.hpp
Comment thread opm/simulators/linalg/system/SystemPreconditioner.hpp Outdated
Comment thread opm/simulators/linalg/system/SystemPreconditionerFactory.hpp
@atgeirr atgeirr changed the title Linear solver cpr Linear solver for the full (reservoir, well) system Jun 18, 2026

@atgeirr atgeirr 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.

Done with the rest of the code, only minor things except possibly for the addition of direct_solver_needs_update_ as noted below, I do not fully understand yet if it makes a difference.

Comment thread tests/test_WellMatrixMerger.cpp Outdated
Comment thread opm/simulators/linalg/ISTLSolverRuntimeOptionProxy.hpp Outdated
Comment thread opm/simulators/linalg/setupPropertyTree.cpp Outdated
Comment thread opm/simulators/linalg/FlexibleSolver_impl.hpp Outdated
Comment thread opm/simulators/linalg/MatrixMarketSpecializations.hpp Outdated
Comment thread opm/simulators/wells/StandardWell.hpp Outdated
Comment thread opm/simulators/wells/MultisegmentWellEval.hpp Outdated
Comment thread opm/simulators/wells/MultisegmentWellEval.cpp Outdated
Comment thread opm/simulators/wells/BlackoilWellModel.hpp Outdated
Comment thread opm/simulators/wells/BlackoilWellModel_impl.hpp Outdated

@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.

Many (all?) of the new headers use #pragma once instead of traditional include guards. Is there a reason for this? Did we decide that #pragma once is accepted now? If not, I would really prefer that we use traditional include guards instead.

@atgeirr

atgeirr commented Jun 22, 2026

Copy link
Copy Markdown
Member

jenkins build this serial please

2 similar comments
@atgeirr

atgeirr commented Jun 23, 2026

Copy link
Copy Markdown
Member

jenkins build this serial please

@atgeirr

atgeirr commented Jun 23, 2026

Copy link
Copy Markdown
Member

jenkins build this serial please

@atgeirr

atgeirr commented Jun 23, 2026

Copy link
Copy Markdown
Member

All looks good now, I will check out and run some extra tests before merging.

@atgeirr

atgeirr commented Jun 23, 2026

Copy link
Copy Markdown
Member

jenkins build this serial please

2 similar comments
@atgeirr

atgeirr commented Jun 25, 2026

Copy link
Copy Markdown
Member

jenkins build this serial please

@atgeirr

atgeirr commented Jun 25, 2026

Copy link
Copy Markdown
Member

jenkins build this serial 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.

Before we even consider merging this, we need to fix the new warnings introduced here, not to mention the unit test failures. I would also really prefer if we made sure that all files end in a newline character. I believe all code editors have a setting to enforce this.

Other than that, I see a number of minor niggles but those should be addressed at the code base level–e.g., using C++20's s.ends_with(".json") instead of

s.substr(s.size() - 5) == ".json"

and consistently using std::size_t instead of "bare" size_t.

@atgeirr

atgeirr commented Jun 25, 2026

Copy link
Copy Markdown
Member

jenkins build this serial please

Introduce a prototype for solving the reservoir and well degrees of freedom
as a single coupled linear system. This complements the existing approach of
handling wells separately through Schur complement elimination.

Key design choices:
- The linear solve operates on the full coupled system (reservoir + well DOFs)
  to simplify the solver architecture and reduce special-case well handling
- The underlying solver uses standard sparse matrices with no well-aware
  operators, improving modularity and reducing code complexity
- The included preconditioner is configurable to reproduce standard CPR behavior,
  providing a baseline for validation before further performance tuning
- An approximate well-block solve is supported for potential performance gains

Important changes:
- Add linear solver implementation with coupled system support
- Configure preconditioner to match existing CPR behavior for correctness
- Remove need for separate well-block elimination in the linear solve path
- Update solver selection to allow --linear-solver=system_cpr option

This implementation serves as a prototype to validate the coupled system
approach before further optimization and benchmarking.
@atgeirr

atgeirr commented Jun 25, 2026

Copy link
Copy Markdown
Member

jenkins build this serial please

@atgeirr

atgeirr commented Jun 25, 2026

Copy link
Copy Markdown
Member

Great work everyone, good to see this go in!

@atgeirr atgeirr merged commit 13ed7bd into OPM:master Jun 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:new-feature This is a new feature and should be described in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants