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#include <opm/simulators/linalg/bda/ILUReorder.hpp>
25
26namespace Opm
27{
28namespace Accelerator
29{
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 PreconditionerType {
56 BILU0,
57 CPR,
58 BISAI
59 };
60
61 static std::unique_ptr<Preconditioner> create(PreconditionerType type, int verbosity, ILUReorder opencl_ilu_reorder);
62
63 virtual ~Preconditioner() = default;
64
65 // nested Preconditioners might need to override this
66 virtual void setOpencl(std::shared_ptr<cl::Context>& context, std::shared_ptr<cl::CommandQueue>& queue);
67
68 // apply preconditioner, x = prec(y)
69 virtual void apply(const cl::Buffer& y, cl::Buffer& x) = 0;
70
71 // analyze matrix, e.g. the sparsity pattern
72 // probably only called once
73 // the version with two params can be overloaded, if not, it will default to using the one param version
74 virtual bool analyze_matrix(BlockedMatrix *mat) = 0;
75 virtual bool analyze_matrix(BlockedMatrix *mat, BlockedMatrix *jacMat);
76
77 // create/update preconditioner, probably used every linear solve
78 // the version with two params can be overloaded, if not, it will default to using the one param version
79 virtual bool create_preconditioner(BlockedMatrix *mat) = 0;
80 virtual bool create_preconditioner(BlockedMatrix *mat, BlockedMatrix *jacMat);
81
82 // get reordering mappings
83 virtual int* getToOrder() = 0;
84 virtual int* getFromOrder() = 0;
85
86 // get reordered matrix
87 virtual BlockedMatrix* getRMat() = 0;
88};
89
90} //namespace Accelerator
91} //namespace Opm
92
93#endif
This class implements a Blocked ILU0 preconditioner The decomposition is done on CPU,...
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:37
This class implements a Constrained Pressure Residual (CPR) preconditioner.
Definition: CPR.hpp:52
Definition: Preconditioner.hpp:36
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27