opm-simulators
GpuJac.hpp
1 /*
2  Copyright 2022-2023 SINTEF AS
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 #ifndef OPM_GPUJAC_HPP
20 #define OPM_GPUJAC_HPP
21 
22 #include <dune/istl/preconditioner.hh>
23 #include <opm/simulators/linalg/PreconditionerWithUpdate.hpp>
24 #include <opm/simulators/linalg/gpuistl/GpuSparseMatrixWrapper.hpp>
25 #include <opm/simulators/linalg/gpuistl/detail/CuMatrixDescription.hpp>
26 #include <opm/simulators/linalg/gpuistl/detail/CuSparseHandle.hpp>
27 #include <opm/simulators/linalg/gpuistl/detail/CuSparseResource.hpp>
28 
29 
30 
31 namespace Opm::gpuistl
32 {
45 template <class M, class X, class Y, int l = 1>
47 {
48 public:
50  using matrix_type = typename std::remove_const<M>::type;
52  using domain_type = X;
54  using range_type = Y;
56  using field_type = typename X::field_type;
57 
64  GpuJac(const M& A, field_type w);
65 
68  virtual void pre(X& x, Y& b) override;
69 
71  virtual void apply(X& v, const Y& d) override;
72 
75  virtual void post(X& x) override;
76 
78  virtual Dune::SolverCategory::Category category() const override;
79 
81  virtual void update() override;
82 
83 
85  static constexpr bool shouldCallPre()
86  {
87  return false;
88  }
89 
91  static constexpr bool shouldCallPost()
92  {
93  return false;
94  }
95 
96  virtual bool hasPerfectUpdate() const override {
97  return true;
98  }
99 
100 
101 private:
103  const M& m_matrix;
105  const field_type m_relaxationFactor;
107  GpuVector<field_type> m_diagInvFlattened;
108 
109  void invertDiagonalAndFlatten();
110 
111  template<int blocksize>
112  void dispatchInvertDiagonalAndFlatten();
113 };
114 } // end namespace Opm::gpuistl
115 
116 #endif
virtual void post(X &x) override
Post processing.
Definition: GpuJac.cpp:71
virtual Dune::SolverCategory::Category category() const override
Category of the preconditioner (see SolverCategory::Category)
Definition: GpuJac.cpp:77
typename X::field_type field_type
The field type of the preconditioner.
Definition: GpuJac.hpp:56
static constexpr bool shouldCallPost()
Definition: GpuJac.hpp:91
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:33
typename std::remove_const< M >::type matrix_type
The matrix type the preconditioner is for.
Definition: GpuJac.hpp:50
static constexpr bool shouldCallPre()
Definition: GpuJac.hpp:85
virtual void apply(X &v, const Y &d) override
Apply the preconditoner.
Definition: GpuJac.cpp:58
GpuJac(const M &A, field_type w)
Constructor.
Definition: GpuJac.cpp:40
A small, fixed‑dimension MiniVector class backed by std::array that can be used in both host and CUD...
Definition: AmgxInterface.hpp:37
Jacobi preconditioner on the GPU.
Definition: GpuJac.hpp:46
virtual void pre(X &x, Y &b) override
Prepare the preconditioner.
Definition: GpuJac.cpp:52
Y range_type
The range type of the preconditioner.
Definition: GpuJac.hpp:54
virtual void update() override
Updates the matrix data.
Definition: GpuJac.cpp:84
X domain_type
The domain type of the preconditioner.
Definition: GpuJac.hpp:52