Preconditioner.hpp
Go to the documentation of this file.
1/*
2 Copyright 2024 Equinor ASA
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_PRECONDITIONER_HEADER_INCLUDED
21#define OPM_PRECONDITIONER_HEADER_INCLUDED
22
23#if HAVE_OPENCL
25#endif
26
27#include <memory>
28
29namespace Opm::Accelerator {
30
34 BISAI
35};
36
37template<class Scalar> class BlockedMatrix;
38
39template<class Scalar, unsigned int block_size>
41{
42protected:
43 int N = 0; // number of rows of the matrix
44 int Nb = 0; // number of blockrows of the matrix
45 int nnz = 0; // number of nonzeroes of the matrix (scalar)
46 int nnzb = 0; // number of blocks of the matrix
47 int verbosity = 0;
48
49 Preconditioner(int verbosity_) :
50 verbosity(verbosity_)
51 {};
52
53public:
54
55 virtual ~Preconditioner() = default;
56
57 static std::unique_ptr<Preconditioner> create(PreconditionerType type,
58 bool opencl_ilu_parallel,
59 int verbosity);
60
61#if HAVE_OPENCL
62 // apply preconditioner, x = prec(y)
63 virtual void apply(const cl::Buffer& y, cl::Buffer& x) = 0;
64#endif
65
66 // apply preconditioner, x = prec(y)
67 virtual void apply(Scalar& y, Scalar& x) = 0;
68
69 // analyze matrix, e.g. the sparsity pattern
70 // probably only called once
71 // the version with two params can be overloaded, if not, it will default to using the one param version
72 virtual bool analyze_matrix(BlockedMatrix<Scalar>* mat) = 0;
74 BlockedMatrix<Scalar>* jacMat) = 0;
75
76 // create/update preconditioner, probably used every linear solve
77 // the version with two params can be overloaded, if not, it will default to using the one param version
80 BlockedMatrix<Scalar>* jacMat) = 0;
81};
82
83} // namespace Opm::Accelerator
84
85#endif
Definition: BlockedMatrix.hpp:29
Definition: Preconditioner.hpp:41
static std::unique_ptr< Preconditioner > create(PreconditionerType type, bool opencl_ilu_parallel, int verbosity)
virtual bool create_preconditioner(BlockedMatrix< Scalar > *mat)=0
int nnz
Definition: Preconditioner.hpp:45
virtual bool analyze_matrix(BlockedMatrix< Scalar > *mat, BlockedMatrix< Scalar > *jacMat)=0
int Nb
Definition: Preconditioner.hpp:44
virtual bool analyze_matrix(BlockedMatrix< Scalar > *mat)=0
virtual void apply(Scalar &y, Scalar &x)=0
Preconditioner(int verbosity_)
Definition: Preconditioner.hpp:49
virtual bool create_preconditioner(BlockedMatrix< Scalar > *mat, BlockedMatrix< Scalar > *jacMat)=0
int verbosity
Definition: Preconditioner.hpp:47
int nnzb
Definition: Preconditioner.hpp:46
virtual ~Preconditioner()=default
int N
Definition: Preconditioner.hpp:43
Definition: amgclSolverBackend.hpp:44
PreconditionerType
Definition: Preconditioner.hpp:31
@ BISAI
Definition: Preconditioner.hpp:34
@ BILU0
Definition: Preconditioner.hpp:32
@ CPR
Definition: Preconditioner.hpp:33