Skip to content

TPSA restructure (2/3): New preconditioner structure - #7358

Open
svenn-t wants to merge 1 commit into
OPM:masterfrom
svenn-t:tpsa_lin_system_restructure
Open

TPSA restructure (2/3): New preconditioner structure#7358
svenn-t wants to merge 1 commit into
OPM:masterfrom
svenn-t:tpsa_lin_system_restructure

Conversation

@svenn-t

@svenn-t svenn-t commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Use the new matrix and vector framework for TPSA to make a new preconditioner structure, following the same principles as the SystemPreconditioner for flow. This enable the use of separate preconditioners on the diagonal blocks of the TPSA system matrix. New default solver is Hypre, with fallback to ILU0 if not installed.

Includes PR #7357, which should be merged first. Draft mode until then.

@svenn-t svenn-t added the manual:enhancement This is an enhancement/improvent that needs to be documented in the manual label Aug 25, 2026
@svenn-t

svenn-t commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

jenkins build this please

@svenn-t
svenn-t force-pushed the tpsa_lin_system_restructure branch 2 times, most recently from a4e6659 to e87ba0f Compare August 27, 2026 10:57
@svenn-t
svenn-t marked this pull request as ready for review August 27, 2026 10:58
@akva2
akva2 requested a balanced review from Copilot August 27, 2026 10:58
@svenn-t

svenn-t commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Making this ready-to-review since #7357 was merged

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

Introduces a field-split TPSA preconditioner and integrates it with the new TPSA matrix/vector framework.

Changes:

  • Adds sequential and parallel five-field TPSA preconditioners.
  • Adds per-block Hypre/ILU/AMG solver configuration.
  • Migrates TPSA solver and linearizer integration to the new types.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
CMakeLists_files.cmake Registers new preconditioner files.
TPSALinearSolverParameters.hpp Changes the default to Hypre.
TPSALinearSolverParameters.cpp Updates TPSA solver parameters and help.
setupPropertyTree.hpp Declares TPSA configuration setup.
setupPropertyTree.cpp Builds block-solver configuration and fallback.
tpsa/TpsaPreconditioner.hpp Implements the field-split preconditioner.
tpsa/TpsaPreconditioner.cpp Adds explicit template instantiations.
tpsa/TpsaPreconditionerFactory.hpp Registers sequential and MPI factories.
ISTLSolverTPSA.hpp Integrates the new matrix and preconditioner.
TTagFlowProblemTPSA.hpp Selects new TPSA matrix/vector types.
tpsalinearizer.hpp Uses stable TPSA block handles.
Suppressed comments (1)

opm/simulators/linalg/tpsa/TpsaPreconditioner.hpp:236

  • The sweep is described as block lower-triangular, but the solid-pressure defect omits the stored lower-triangular rotation coupling S[_4][_3]. For a nonzero solid-pressure/rotation block, the final solve therefore applies a different (block-diagonal in rotation/pressure) preconditioner than documented.
        S_[_4][_0].mmv(v[_0], d4);
        S_[_4][_1].mmv(v[_1], d4);
        S_[_4][_2].mmv(v[_2], d4);
        sPresSolver_->apply(v[_4], d4, result);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +483 to +487
if (conf == "hypre") {
OpmLog::warning(
"--tpsa-linear-solver=hypre requires a build with Hypre support (USE_HYPRE=ON). "
"Switching to ilu0!");
conf = "ilu0"s;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed const from conf input

newton_use_gmres_ = false;
ignoreConvergenceFailure_ = false;
linsolver_ = "ilu0";
linsolver_ = "default";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thought I'd purged this... Changed to hypre

Comment on lines +224 to +226
dispSolver0_->apply(v[_0], d0, result);
dispSolver1_->apply(v[_1], d1, result);
dispSolver2_->apply(v[_2], d2, result);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All istl solvers set v = 0.0 before apply(), but added a v = 0.0 inside apply() just in case...

* \param v Update, overwritten by the result
* \param d Defect to precondition
*/
void apply(MultiVector& v, const MultiVector& d) override

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added a new unit test for TpsaPreconditioner. Just apply() tests for now. The block S[_4][_3] is not used in preconditioner. It might be zero anyways (needs further investigation...)

Comment on lines +80 to +82
("Configuration for linear solver. Valid preset options are: hypre, ilu0, dilu, "
"or amg. Alternatively, you can request a configuration to be read from a JSON file by "
"giving the filename here, ending with '.json.'");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@svenn-t
svenn-t force-pushed the tpsa_lin_system_restructure branch from e87ba0f to 1b09f7a Compare August 27, 2026 12:37
module for the precise wording of the license and the list of
copyright holders.
*/
#include <config.h>

@akva2 akva2 Aug 28, 2026

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 know this is inherited faulty structure, but unless the .hpp only contains the template definitions, and the implementations are in a _impl.hpp file (which is only included in this file), this .cpp file is basically just additional work for no gain. it will still instantiate and compile the implementation in all TUs using it, with the linker deduplicating it in the end. have a look at e.g. Transmissibility(_impl).[hc]pp if it's unclear what I mean.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I see what you mean, but before I do some changes I want to confirm: If I split the implementation out to an _impl.hpp file and use that one in the cpp file, then it will only be compiled once?

@akva2 akva2 Aug 28, 2026

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.

yes. this serves two goals;

the .cpp file contains the explicit instantiations for the chosen combinations, and downstream code relying on those instantiations can just include the .hpp file and they will share instantiations (ie they do not see the implementations of the templates at all, only the declaration).

however, should a downstream code need some other instantiation, they can explicitly include the _impl.hpp file, the whole template definition is then available to them and they can instantiate for other types.

you can see this pattern being used in e.g. flow_blackoil_alugrid.cpp. Transmissibility.cpp only contains instantiations for CpGrid. Instead of using Transmissibility.hpp we include the Transmissibility_impl.hpp so we can instantiate for Alugrid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the explanation! It has not been clear to me the reason for _impl files, just thought it was purely a code style thing, but now I see the point! I will update the PR with an _impl file for TpsaPreconditioner.

- One preconditioner for whole TPSA system; three sub-block preconditioner can be set by user
- Allows for Hypre, which is default if linked; else ilu0
@svenn-t
svenn-t force-pushed the tpsa_lin_system_restructure branch from 1b09f7a to 1aaed7e Compare August 28, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:enhancement This is an enhancement/improvent that needs to be documented in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants