opm-simulators
rocalutionSolverBackend.hpp
1 /*
2  Copyright 2022 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_ROCALUTIONSOLVER_BACKEND_HEADER_INCLUDED
21 #define OPM_ROCALUTIONSOLVER_BACKEND_HEADER_INCLUDED
22 
23 #include <opm/simulators/linalg/gpubridge/GpuResult.hpp>
24 #include <opm/simulators/linalg/gpubridge/GpuSolver.hpp>
25 #include <opm/simulators/linalg/gpubridge/WellContributions.hpp>
26 
27 namespace rocalution {
28 template<class Matrix, class Vector, class Scalar> class BiCGStab;
29 template<class Matrix, class Vector, class Scalar> class ILU;
30 template<class Scalar> class LocalMatrix;
31 template<class Scalar> class LocalVector;
32 }
33 
34 namespace Opm::Accelerator {
35 
38 template<class Scalar, unsigned int block_size>
39 class rocalutionSolverBackend : public GpuSolver<Scalar,block_size>
40 {
42 
43  using Base::N;
44  using Base::Nb;
45  using Base::nnz;
46  using Base::nnzb;
47  using Base::verbosity;
48  using Base::platformID;
49  using Base::deviceID;
50  using Base::maxit;
51  using Base::tolerance;
52  using Base::initialized;
53 
54 private:
55  std::vector<Scalar> h_x; // store solution vector on host
56  int *tmp_rowpointers; // store matrix on host, this pointer is given to and freed by rocalution
57  int *tmp_colindices; // store matrix on host, this pointer is given to and freed by rocalution
58  Scalar* tmp_nnzvalues; // store matrix on host, this pointer is given to and freed by rocalution
59 
62 
63  std::unique_ptr<rocalution::ILU<Mat,Vec,Scalar>> roc_prec;
64  std::unique_ptr<rocalution::BiCGStab<Mat,Vec,Scalar>> roc_solver;
65 
68  void initialize(BlockedMatrix<Scalar>* matrix);
69 
73  void convert_matrix(BlockedMatrix<Scalar>* matrix);
74 
75 public:
81  rocalutionSolverBackend(int linear_solver_verbosity,
82  int maxit, Scalar tolerance);
83 
86 
94  SolverStatus solve_system(std::shared_ptr<BlockedMatrix<Scalar>> matrix,
95  Scalar* b,
96  std::shared_ptr<BlockedMatrix<Scalar>> jacMatrix,
97  WellContributions<Scalar>& wellContribs,
98  GpuResult& res) override;
99 
102  void get_result(Scalar* x) override;
103 
104 }; // end class rocalutionSolverBackend
105 
106 } // namespace Opm::Accelerator
107 
108 #endif
Definition: rocalutionSolverBackend.hpp:27
Definition: rocalutionSolverBackend.hpp:31
Definition: rocalutionSolverBackend.hpp:29
Definition: amgclSolverBackend.cpp:49
~rocalutionSolverBackend()
Destroy a rocalutionSolver, and free memory.
Definition: rocalutionSolverBackend.cpp:70
This class implements a rocalution based linear solver solver on GPU It uses ilu0-bicgstab.
Definition: rocalutionSolverBackend.hpp:39
void get_result(Scalar *x) override
Get result after linear solve, and peform postprocessing if necessary.
Definition: rocalutionSolverBackend.cpp:141
This class is based on InverseOperatorResult struct from dune/istl/solver.hh It is needed to prevent ...
Definition: GpuResult.hpp:30
Definition: rocalutionSolverBackend.hpp:28
rocalutionSolverBackend(int linear_solver_verbosity, int maxit, Scalar tolerance)
Construct a rocalutionSolver also initialize rocalution library and rocalution variables.
Definition: rocalutionSolverBackend.cpp:56
This class serves to eliminate the need to include the WellContributions into the matrix (with –matr...
Definition: GpuBridge.hpp:30
SolverStatus solve_system(std::shared_ptr< BlockedMatrix< Scalar >> matrix, Scalar *b, std::shared_ptr< BlockedMatrix< Scalar >> jacMatrix, WellContributions< Scalar > &wellContribs, GpuResult &res) override
Solve linear system, A*x = b, matrix A must be in blocked-CSR format.
Definition: rocalutionSolverBackend.cpp:156
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition: BlockedMatrix.hpp:28
Definition: rocalutionSolverBackend.hpp:30
This class serves to simplify choosing between different backend solvers, such as cusparseSolver and ...
Definition: GpuSolver.hpp:45