My Project
Loading...
Searching...
No Matches
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/bda/BdaResult.hpp>
24#include <opm/simulators/linalg/bda/BdaSolver.hpp>
25#include <opm/simulators/linalg/bda/WellContributions.hpp>
26
27namespace rocalution {
28template<class Matrix, class Vector, class Scalar> class BiCGStab;
29template<class Matrix, class Vector, class Scalar> class ILU;
30template<class Scalar> class LocalMatrix;
31template<class Scalar> class LocalVector;
32}
33
34namespace Opm::Accelerator {
35
38template<class Scalar, unsigned int block_size>
39class rocalutionSolverBackend : public BdaSolver<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
54private:
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
75public:
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,
98 BdaResult& res) override;
99
102 void get_result(Scalar* x) override;
103
104}; // end class rocalutionSolverBackend
105
106} // namespace Opm::Accelerator
107
108#endif
109
110
This class is based on InverseOperatorResult struct from dune/istl/solver.hh It is needed to prevent ...
Definition BdaResult.hpp:31
This class serves to simplify choosing between different backend solvers, such as cusparseSolver and ...
Definition BdaSolver.hpp:46
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition BlockedMatrix.hpp:29
This class implements a rocalution based linear solver solver on GPU It uses ilu0-bicgstab.
Definition rocalutionSolverBackend.hpp:40
SolverStatus solve_system(std::shared_ptr< BlockedMatrix< Scalar > > matrix, Scalar *b, std::shared_ptr< BlockedMatrix< Scalar > > jacMatrix, WellContributions< Scalar > &wellContribs, BdaResult &res) override
Solve linear system, A*x = b, matrix A must be in blocked-CSR format.
Definition rocalutionSolverBackend.cpp:156
~rocalutionSolverBackend()
Destroy a rocalutionSolver, and free memory.
Definition rocalutionSolverBackend.cpp:70
void get_result(Scalar *x) override
Get result after linear solve, and peform postprocessing if necessary.
Definition rocalutionSolverBackend.cpp:141
This class serves to eliminate the need to include the WellContributions into the matrix (with –matri...
Definition WellContributions.hpp:53
Definition rocalutionSolverBackend.hpp:28
Definition rocalutionSolverBackend.hpp:29
Definition rocalutionSolverBackend.hpp:30
Definition rocalutionSolverBackend.hpp:31
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242