TpsaPreconditioner.hpp
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 Copyright 2025 NORCE AS
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21#ifndef OPM_TPSA_PRECONDITIONER_HPP
22#define OPM_TPSA_PRECONDITIONER_HPP
23
24#include <dune/istl/operators.hh>
25#include <dune/istl/owneroverlapcopy.hh>
26#include <dune/istl/schwarz.hh>
27#include <dune/istl/paamg/pinfo.hh>
28
33
34#include <functional>
35#include <memory>
36#include <type_traits>
37
38namespace Opm
39{
40
42template <typename Scalar>
43using SeqDispDispOperatorT = Dune::MatrixAdapter<Linear::DispDispMatrix00T<Scalar>,
47template <typename Scalar>
48using SeqRotRotOperatorT = Dune::MatrixAdapter<Linear::RotRotMatrixT<Scalar>,
52template <typename Scalar>
53using SeqSPresSPresOperatorT = Dune::MatrixAdapter<Linear::SPresSPresMatrixT<Scalar>,
56
57#if HAVE_MPI
59using TpsaParComm = Dune::OwnerOverlapCopyCommunication<int, int>;
60
62template <typename Scalar>
63using ParDispDispOperatorT = Dune::OverlappingSchwarzOperator<Linear::DispDispMatrix00T<Scalar>,
68template <typename Scalar>
69using ParRotRotOperatorT = Dune::OverlappingSchwarzOperator<Linear::RotRotMatrixT<Scalar>,
74template <typename Scalar>
75using ParSPresSPresOperatorT = Dune::OverlappingSchwarzOperator<Linear::SPresSPresMatrixT<Scalar>,
79#endif
80
101template <class Scalar, class DispOp, class RotOp, class SPresOp,
102 class Comm = Dune::Amg::SequentialInformation>
104 : public Dune::PreconditionerWithUpdate<Linear::TpsaMultiVector<Scalar>,
105 Linear::TpsaMultiVector<Scalar> >
106{
107 using MultiVector = Linear::TpsaMultiVector<Scalar>;
111
112public:
114 static constexpr bool isParallel = !std::is_same_v<Comm, Dune::Amg::SequentialInformation>;
115
117 static constexpr auto _0 = Dune::Indices::_0;
118 static constexpr auto _1 = Dune::Indices::_1;
119 static constexpr auto _2 = Dune::Indices::_2;
120 static constexpr auto _3 = Dune::Indices::_3;
121 static constexpr auto _4 = Dune::Indices::_4;
122
124 static constexpr std::size_t pressureIdx = 0;
125
135 requires (!isParallel);
136
149 const PropertyTree& prm,
150 const Comm& comm)
151 requires (isParallel);
152
154 void pre(MultiVector&, MultiVector&) override;
155
157 void post(MultiVector&) override;
158
160 Dune::SolverCategory::Category category() const override;
161
163 void update() override;
164
166 bool hasPerfectUpdate() const override;
167
178 void apply(MultiVector& v, const MultiVector& d) override;
179
180private:
186 void initSubSolvers_(const PropertyTree& prm);
187
191 const Comm* comm_{nullptr};
192
193 // Operators of the diagonal blocks, referenced by the solvers below.
194 std::unique_ptr<DispOp> dispOp0_;
195 std::unique_ptr<DispOp> dispOp1_;
196 std::unique_ptr<DispOp> dispOp2_;
197 std::unique_ptr<RotOp> rotOp_;
198 std::unique_ptr<SPresOp> sPresOp_;
199
200 // Solvers of the diagonal blocks.
201 std::unique_ptr<DispSolver> dispSolver0_;
202 std::unique_ptr<DispSolver> dispSolver1_;
203 std::unique_ptr<DispSolver> dispSolver2_;
204 std::unique_ptr<RotSolver> rotSolver_;
205 std::unique_ptr<SPresSolver> sPresSolver_;
206};
207
208} // namespace Opm
209
210#endif // OPM_TPSA_PRECONDITIONER_HPP
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:394
Definition: FlexibleSolver.hpp:45
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:34
Lightweight, non-owning 5x5 view over the sub-matrices owned by TpsaMatrix. Provides the operator int...
Definition: TpsaTypes.hpp:132
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:39
Block lower-triangular preconditioner for the field-split TPSA system.
Definition: TpsaPreconditioner.hpp:106
void pre(MultiVector &, MultiVector &) override
Nothing to prepare, the sub-solvers set themselves up.
Definition: TpsaPreconditioner_impl.hpp:56
static constexpr auto _4
Definition: TpsaPreconditioner.hpp:121
static constexpr auto _0
Field indices into the multi-vector: u_x, u_y, u_z, rotation, solid pressure.
Definition: TpsaPreconditioner.hpp:117
static constexpr std::size_t pressureIdx
The sub-solvers have no pressure equation to single out.
Definition: TpsaPreconditioner.hpp:124
void apply(MultiVector &v, const MultiVector &d) override
Apply the preconditioner, i.e. approximately solve S v = d.
Definition: TpsaPreconditioner_impl.hpp:102
static constexpr auto _1
Definition: TpsaPreconditioner.hpp:118
Dune::SolverCategory::Category category() const override
Solver category, overlapping in parallel and sequential otherwise.
Definition: TpsaPreconditioner_impl.hpp:70
bool hasPerfectUpdate() const override
The block solvers are rebuilt from the current matrix on update().
Definition: TpsaPreconditioner_impl.hpp:94
void post(MultiVector &) override
Nothing to clean up after the last apply().
Definition: TpsaPreconditioner_impl.hpp:63
static constexpr auto _2
Definition: TpsaPreconditioner.hpp:119
TpsaPreconditioner(const Linear::TpsaMatrixView< Scalar > &S, const PropertyTree &prm)
Sequential constructor.
Definition: TpsaPreconditioner_impl.hpp:34
static constexpr bool isParallel
Whether this instance runs the parallel code path.
Definition: TpsaPreconditioner.hpp:114
static constexpr auto _3
Definition: TpsaPreconditioner.hpp:120
void update() override
Recompute the preconditioners of all five diagonal block solvers.
Definition: TpsaPreconditioner_impl.hpp:82
Dune::BlockVector< Dune::FieldVector< Scalar, numDispDofs > > DispVector0T
Definition: TpsaTypes.hpp:100
Dune::MultiTypeBlockVector< DispVector0T< Scalar >, DispVector1T< Scalar >, DispVector2T< Scalar >, RotVectorT< Scalar >, SPresVectorT< Scalar > > TpsaMultiVector
The vector the Krylov solver and the preconditioner operate on.
Definition: TpsaTypes.hpp:116
Dune::BlockVector< Dune::FieldVector< Scalar, numSolidPresDofs > > SPresVectorT
Definition: TpsaTypes.hpp:108
Dune::BlockVector< Dune::FieldVector< Scalar, numRotDofs > > RotVectorT
Definition: TpsaTypes.hpp:106
Definition: blackoilbioeffectsmodules.hh:45
Dune::OverlappingSchwarzOperator< Linear::SPresSPresMatrixT< Scalar >, Linear::SPresVectorT< Scalar >, Linear::SPresVectorT< Scalar >, TpsaParComm > ParSPresSPresOperatorT
Parallel operator for the solid pressure block.
Definition: TpsaPreconditioner.hpp:78
Dune::MatrixAdapter< Linear::RotRotMatrixT< Scalar >, Linear::RotVectorT< Scalar >, Linear::RotVectorT< Scalar > > SeqRotRotOperatorT
Sequential operator for the rotation block.
Definition: TpsaPreconditioner.hpp:50
Dune::MatrixAdapter< Linear::DispDispMatrix00T< Scalar >, Linear::DispVector0T< Scalar >, Linear::DispVector0T< Scalar > > SeqDispDispOperatorT
Sequential operator for one of the three scalar displacement blocks.
Definition: TpsaPreconditioner.hpp:45
Dune::OverlappingSchwarzOperator< Linear::DispDispMatrix00T< Scalar >, Linear::DispVector0T< Scalar >, Linear::DispVector0T< Scalar >, TpsaParComm > ParDispDispOperatorT
Parallel operator for one of the three scalar displacement blocks.
Definition: TpsaPreconditioner.hpp:66
Dune::OverlappingSchwarzOperator< Linear::RotRotMatrixT< Scalar >, Linear::RotVectorT< Scalar >, Linear::RotVectorT< Scalar >, TpsaParComm > ParRotRotOperatorT
Parallel operator for the rotation block.
Definition: TpsaPreconditioner.hpp:72
Dune::MatrixAdapter< Linear::SPresSPresMatrixT< Scalar >, Linear::SPresVectorT< Scalar >, Linear::SPresVectorT< Scalar > > SeqSPresSPresOperatorT
Sequential operator for the solid pressure block.
Definition: TpsaPreconditioner.hpp:55
Dune::OwnerOverlapCopyCommunication< int, int > TpsaParComm
Communication type of a single TPSA field.
Definition: TpsaPreconditioner.hpp:59