My Project
Preconditioner.hpp
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
23#include <opm/simulators/linalg/bda/opencl/opencl.hpp>
24
25namespace Opm
26{
27namespace Accelerator
28{
29
30
31class BlockedMatrix;
32
33template <unsigned int block_size>
35{
36
37protected:
38 int N = 0; // number of rows of the matrix
39 int Nb = 0; // number of blockrows of the matrix
40 int nnz = 0; // number of nonzeroes of the matrix (scalar)
41 int nnzb = 0; // number of blocks of the matrix
42 int verbosity = 0;
43
44 std::shared_ptr<cl::Context> context;
45 std::shared_ptr<cl::CommandQueue> queue;
46 std::vector<cl::Event> events;
47 cl_int err;
48
49 Preconditioner(int verbosity_) :
50 verbosity(verbosity_)
51 {};
52
53public:
54 enum PreconditionerType {
55 BILU0,
56 CPR,
57 BISAI
58 };
59
60 static std::unique_ptr<Preconditioner> create(PreconditionerType type, int verbosity, bool opencl_ilu_parallel);
61
62 virtual ~Preconditioner() = default;
63
64 // nested Preconditioners might need to override this
65 virtual void setOpencl(std::shared_ptr<cl::Context>& context, std::shared_ptr<cl::CommandQueue>& queue);
66
67 // apply preconditioner, x = prec(y)
68 virtual void apply(const cl::Buffer& y, cl::Buffer& x) = 0;
69
70 // analyze matrix, e.g. the sparsity pattern
71 // probably only called once
72 // the version with two params can be overloaded, if not, it will default to using the one param version
73 virtual bool analyze_matrix(BlockedMatrix *mat) = 0;
74 virtual bool analyze_matrix(BlockedMatrix *mat, BlockedMatrix *jacMat);
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
78 virtual bool create_preconditioner(BlockedMatrix *mat) = 0;
79 virtual bool create_preconditioner(BlockedMatrix *mat, BlockedMatrix *jacMat);
80};
81
82} //namespace Accelerator
83} //namespace Opm
84
85#endif
This class implements a Blocked ILU0 preconditioner The decomposition is done on GPU,...
Definition: BILU0.hpp:42
This class implements a Blocked version of the Incomplete Sparse Approximate Inverse (ISAI) precondit...
Definition: BISAI.hpp:40
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition: BlockedMatrix.hpp:31
This class implements a Constrained Pressure Residual (CPR) preconditioner.
Definition: CPR.hpp:46
Definition: Preconditioner.hpp:35
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27