GpuJac.hpp
Go to the documentation of this file.
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>
28
29
30
31namespace Opm::gpuistl
32{
45template <class M, class X, class Y, int l = 1>
47{
48public:
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
101private:
103 const M& m_cpuMatrix;
105 const field_type m_relaxationFactor;
107 GpuSparseMatrix<field_type> m_gpuMatrix;
109 GpuVector<field_type> m_diagInvFlattened;
110
111 void invertDiagonalAndFlatten();
112};
113} // end namespace Opm::gpuistl
114
115#endif
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:32
Jacobi preconditioner on the GPU.
Definition: GpuJac.hpp:47
typename X::field_type field_type
The field type of the preconditioner.
Definition: GpuJac.hpp:56
Y range_type
The range type of the preconditioner.
Definition: GpuJac.hpp:54
virtual Dune::SolverCategory::Category category() const override
Category of the preconditioner (see SolverCategory::Category)
static constexpr bool shouldCallPre()
Definition: GpuJac.hpp:85
virtual void update() override
Updates the matrix data.
GpuJac(const M &A, field_type w)
Constructor.
virtual void apply(X &v, const Y &d) override
Apply the preconditoner.
virtual void post(X &x) override
Post processing.
static constexpr bool shouldCallPost()
Definition: GpuJac.hpp:91
X domain_type
The domain type of the preconditioner.
Definition: GpuJac.hpp:52
virtual void pre(X &x, Y &b) override
Prepare the preconditioner.
virtual bool hasPerfectUpdate() const override
Definition: GpuJac.hpp:96
typename std::remove_const< M >::type matrix_type
The matrix type the preconditioner is for.
Definition: GpuJac.hpp:50
Definition: autotuner.hpp:29