FlexibleSolverWrapper.hpp
Go to the documentation of this file.
1/*
2 Copyright 2025 Equinor ASA
3
4 This file is part of the Open Porous Media project (OPM).
5 OPM is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 OPM is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with OPM. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17#ifndef OPM_FLEXIBLESOLVERWRAPPER_HEADER_INCLUDED
18#define OPM_FLEXIBLESOLVERWRAPPER_HEADER_INCLUDED
19
20#include <functional>
21#include <memory>
22#include <type_traits>
23
24#include <dune/common/parallel/communication.hh>
25#include <dune/istl/operators.hh>
26#include <dune/istl/solver.hh>
30
32{
33
43template <class Matrix, class Vector, class Comm>
45{
46public:
47 using AbstractSolverType = Dune::InverseOperator<Vector, Vector>;
49 using AbstractOperatorType = Dune::AssembledLinearOperator<Matrix, Vector, Vector>;
50
51 using AbstractOperatorPtrType = std::unique_ptr<AbstractOperatorType>;
52 using AbstractSolverPtrType = std::unique_ptr<AbstractSolverType>;
53 using GpuCommunicationType = std::conditional_t<
54 std::is_same_v<Comm, Dune::Communication<int>>,
55 int, // Dummy type for serial case
57
58 FlexibleSolverWrapper(const Matrix& matrix,
59 bool parallel,
60 const PropertyTree& prm,
61 std::size_t pressureIndex,
62 const std::function<Vector()>& weightCalculator,
63 bool forceSerial,
64 const Comm* comm);
65
66 void update();
67
68 void apply(Vector& x, Vector& y, Dune::InverseOperatorResult& result);
69
70private:
71 AbstractOperatorPtrType m_operator;
72 AbstractSolverPtrType m_solver;
73
74 AbstractPreconditionerType& m_preconditioner;
75 std::shared_ptr<GpuCommunicationType> m_gpuCommunication;
76
78 std::tuple<AbstractOperatorPtrType, AbstractSolverPtrType, std::reference_wrapper<AbstractPreconditionerType>, std::shared_ptr<GpuCommunicationType>>&&
79 solverTuple);
80};
81} // namespace Opm::gpuistl::detail
82
83#endif // OPM_FLEXIBLESOLVERWRAPPER_HEADER_INCLUDED
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:304
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:32
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:39
CUDA compatiable variant of Dune::OwnerOverlapCopyCommunication.
Definition: GpuOwnerOverlapCopy.hpp:55
FlexibleSolverWrapper is compilational trick to reduce compile time overhead.
Definition: FlexibleSolverWrapper.hpp:45
Dune::InverseOperator< Vector, Vector > AbstractSolverType
Definition: FlexibleSolverWrapper.hpp:47
std::unique_ptr< AbstractOperatorType > AbstractOperatorPtrType
Definition: FlexibleSolverWrapper.hpp:51
std::conditional_t< std::is_same_v< Comm, Dune::Communication< int > >, int, GpuOwnerOverlapCopy< typename Matrix::field_type, Comm > > GpuCommunicationType
Definition: FlexibleSolverWrapper.hpp:56
std::unique_ptr< AbstractSolverType > AbstractSolverPtrType
Definition: FlexibleSolverWrapper.hpp:52
Dune::AssembledLinearOperator< Matrix, Vector, Vector > AbstractOperatorType
Definition: FlexibleSolverWrapper.hpp:49
FlexibleSolverWrapper(const Matrix &matrix, bool parallel, const PropertyTree &prm, std::size_t pressureIndex, const std::function< Vector()> &weightCalculator, bool forceSerial, const Comm *comm)
void apply(Vector &x, Vector &y, Dune::InverseOperatorResult &result)
Definition: autotuner.hpp:30
Dune::InverseOperatorResult InverseOperatorResult
Definition: GpuBridge.hpp:32