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 
26 namespace Opm
27 {
28 namespace Accelerator
29 {
30 
31 
32 class BlockedMatrix;
33 
34 template <unsigned int block_size>
36 {
37 
38 protected:
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 
54 public:
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  // nested Preconditioners might need to override this
64  virtual void setOpencl(std::shared_ptr<cl::Context>& context, std::shared_ptr<cl::CommandQueue>& queue);
65 
66  // apply preconditioner, x = prec(y)
67  virtual void apply(const cl::Buffer& y, cl::Buffer& x) = 0;
68 
69  // analyze matrix, e.g. the sparsity pattern
70  // probably only called once
71  virtual bool analyze_matrix(BlockedMatrix *mat) = 0;
72 
73  // create/update preconditioner, probably used every linear solve
74  virtual bool create_preconditioner(BlockedMatrix *mat) = 0;
75 
76  // get reordering mappings
77  virtual int* getToOrder() = 0;
78  virtual int* getFromOrder() = 0;
79 
80  // get reordered matrix
81  virtual BlockedMatrix* getRMat() = 0;
82 };
83 
84 } //namespace Accelerator
85 } //namespace Opm
86 
87 #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