My Project
Loading...
Searching...
No Matches
Preconditioner.hpp
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
24#include <opm/simulators/linalg/gpubridge/opencl/opencl.hpp>
25#endif
26
27#include <memory>
28
29namespace Opm::Accelerator {
30
31enum PreconditionerType {
32 BILU0,
33 CPR,
34 BISAI
35};
36
37template<class Scalar> class BlockedMatrix;
38
39template<class Scalar, unsigned int block_size, class ApplyScalar = Scalar>
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 virtual ~Preconditioner() = default;
55
56 static std::unique_ptr<Preconditioner> create(PreconditionerType type,
57 bool opencl_ilu_parallel,
58 int verbosity);
59
60 // apply preconditioner, x = prec(y)
61 virtual void apply(const ApplyScalar& y, ApplyScalar& x) = 0;
62
63 // analyze matrix, e.g. the sparsity pattern
64 // probably only called once
65 // the version with two params can be overloaded, if not, it will default to using the one param version
66 virtual bool analyze_matrix(BlockedMatrix<Scalar>* mat) = 0;
67 virtual bool analyze_matrix(BlockedMatrix<Scalar>* mat,
68 BlockedMatrix<Scalar>* jacMat) = 0;
69
70 // create/update preconditioner, probably used every linear solve
71 // the version with two params can be overloaded, if not, it will default to using the one param version
72 virtual bool create_preconditioner(BlockedMatrix<Scalar>* mat) = 0;
73 virtual bool create_preconditioner(BlockedMatrix<Scalar>* mat,
74 BlockedMatrix<Scalar>* jacMat) = 0;
75};
76
77} // namespace Opm::Accelerator
78
79#endif
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition BlockedMatrix.hpp:29
Definition Preconditioner.hpp:41
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242