Preconditioner.hpp
Go to the documentation of this file.
1/*
2 Copyright 2021 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
24
25#include <memory>
26
27namespace Opm
28{
29namespace Accelerator
30{
31
32class BlockedMatrix;
33
34template <unsigned int block_size>
36{
37
38protected:
39 int N = 0; // number of rows of the matrix
40 int Nb = 0; // number of blockrows of the matrix
41 int nnz = 0; // number of nonzeroes of the matrix (scalar)
42 int nnzb = 0; // number of blocks of the matrix
43 int verbosity = 0;
44
45 std::shared_ptr<cl::Context> context;
46 std::shared_ptr<cl::CommandQueue> queue;
47 std::vector<cl::Event> events;
48 cl_int err;
49
50 Preconditioner(int verbosity_) :
51 verbosity(verbosity_)
52 {};
53
54public:
55 enum class Type {
56 BILU0,
57 CPR,
58 BISAI
59 };
60
61 static std::unique_ptr<Preconditioner> create(Type type,
62 bool opencl_ilu_parallel,
63 int verbosity);
64
65 virtual ~Preconditioner() = default;
66
67 // nested Preconditioners might need to override this
68 virtual void setOpencl(std::shared_ptr<cl::Context>& context, std::shared_ptr<cl::CommandQueue>& queue);
69
70 // apply preconditioner, x = prec(y)
71 virtual void apply(const cl::Buffer& y, cl::Buffer& x) = 0;
72
73 // analyze matrix, e.g. the sparsity pattern
74 // probably only called once
75 // the version with two params can be overloaded, if not, it will default to using the one param version
76 virtual bool analyze_matrix(BlockedMatrix *mat) = 0;
77 virtual bool analyze_matrix(BlockedMatrix *mat, BlockedMatrix *jacMat);
78
79 // create/update preconditioner, probably used every linear solve
80 // the version with two params can be overloaded, if not, it will default to using the one param version
81 virtual bool create_preconditioner(BlockedMatrix *mat) = 0;
83};
84
85} //namespace Accelerator
86} //namespace Opm
87
88#endif
Definition: BILU0.hpp:42
Definition: BISAI.hpp:40
Definition: BlockedMatrix.hpp:31
This class implements a Constrained Pressure Residual (CPR) preconditioner.
Definition: CPR.hpp:46
Definition: Preconditioner.hpp:36
virtual bool analyze_matrix(BlockedMatrix *mat, BlockedMatrix *jacMat)
virtual void setOpencl(std::shared_ptr< cl::Context > &context, std::shared_ptr< cl::CommandQueue > &queue)
int nnz
Definition: Preconditioner.hpp:41
std::vector< cl::Event > events
Definition: Preconditioner.hpp:47
std::shared_ptr< cl::CommandQueue > queue
Definition: Preconditioner.hpp:46
Preconditioner(int verbosity_)
Definition: Preconditioner.hpp:50
int N
Definition: Preconditioner.hpp:39
int verbosity
Definition: Preconditioner.hpp:43
virtual bool create_preconditioner(BlockedMatrix *mat)=0
static std::unique_ptr< Preconditioner > create(Type type, bool opencl_ilu_parallel, int verbosity)
cl_int err
Definition: Preconditioner.hpp:48
int Nb
Definition: Preconditioner.hpp:40
std::shared_ptr< cl::Context > context
Definition: Preconditioner.hpp:45
virtual bool analyze_matrix(BlockedMatrix *mat)=0
int nnzb
Definition: Preconditioner.hpp:42
virtual ~Preconditioner()=default
Type
Definition: Preconditioner.hpp:55
virtual void apply(const cl::Buffer &y, cl::Buffer &x)=0
virtual bool create_preconditioner(BlockedMatrix *mat, BlockedMatrix *jacMat)
Definition: BlackoilPhases.hpp:27