Loading...
Searching...
No Matches
rocalutionSolverBackend.hpp
/*
Copyright 2022 Equinor ASA
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_ROCALUTIONSOLVER_BACKEND_HEADER_INCLUDED
#define OPM_ROCALUTIONSOLVER_BACKEND_HEADER_INCLUDED
#include <opm/simulators/linalg/gpubridge/GpuResult.hpp>
#include <opm/simulators/linalg/gpubridge/GpuSolver.hpp>
#include <opm/simulators/linalg/gpubridge/WellContributions.hpp>
namespace rocalution {
template<class Matrix, class Vector, class Scalar> class BiCGStab;
template<class Matrix, class Vector, class Scalar> class ILU;
template<class Scalar> class LocalMatrix;
template<class Scalar> class LocalVector;
}
namespace Opm::Accelerator {
template<class Scalar, unsigned int block_size>
class rocalutionSolverBackend : public GpuSolver<Scalar,block_size>
{
using Base = GpuSolver<Scalar,block_size>;
using Base::N;
using Base::Nb;
using Base::nnz;
using Base::nnzb;
using Base::verbosity;
using Base::platformID;
using Base::deviceID;
using Base::maxit;
using Base::tolerance;
using Base::initialized;
private:
std::vector<Scalar> h_x; // store solution vector on host
int *tmp_rowpointers; // store matrix on host, this pointer is given to and freed by rocalution
int *tmp_colindices; // store matrix on host, this pointer is given to and freed by rocalution
Scalar* tmp_nnzvalues; // store matrix on host, this pointer is given to and freed by rocalution
using Mat = rocalution::LocalMatrix<Scalar>;
using Vec = rocalution::LocalVector<Scalar>;
std::unique_ptr<rocalution::ILU<Mat,Vec,Scalar>> roc_prec;
std::unique_ptr<rocalution::BiCGStab<Mat,Vec,Scalar>> roc_solver;
void initialize(BlockedMatrix<Scalar>* matrix);
void convert_matrix(BlockedMatrix<Scalar>* matrix);
public:
rocalutionSolverBackend(int linear_solver_verbosity,
int maxit, Scalar tolerance);
~rocalutionSolverBackend();
SolverStatus solve_system(std::shared_ptr<BlockedMatrix<Scalar>> matrix,
Scalar* b,
std::shared_ptr<BlockedMatrix<Scalar>> jacMatrix,
WellContributions<Scalar>& wellContribs,
GpuResult& res) override;
void get_result(Scalar* x) override;
}; // end class rocalutionSolverBackend
} // namespace Opm::Accelerator
#endif
Opm::Accelerator::BlockedMatrix
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition BlockedMatrix.hpp:29
Opm::Accelerator::GpuResult
This class is based on InverseOperatorResult struct from dune/istl/solver.hh It is needed to prevent ...
Definition GpuResult.hpp:31
Opm::Accelerator::GpuSolver::GpuSolver
GpuSolver(int linear_solver_verbosity, int max_it, Scalar tolerance_)
Construct a GpuSolver.
Definition GpuSolver.hpp:73
Opm::Accelerator::rocalutionSolverBackend::rocalutionSolverBackend
rocalutionSolverBackend(int linear_solver_verbosity, int maxit, Scalar tolerance)
Construct a rocalutionSolver also initialize rocalution library and rocalution variables.
Definition rocalutionSolverBackend.cpp:56
Opm::Accelerator::rocalutionSolverBackend::~rocalutionSolverBackend
~rocalutionSolverBackend()
Destroy a rocalutionSolver, and free memory.
Definition rocalutionSolverBackend.cpp:70
Opm::Accelerator::rocalutionSolverBackend::get_result
void get_result(Scalar *x) override
Get result after linear solve, and peform postprocessing if necessary.
Definition rocalutionSolverBackend.cpp:141
Opm::Accelerator::rocalutionSolverBackend::solve_system
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
Opm::WellContributions
This class serves to eliminate the need to include the WellContributions into the matrix (with –matri...
Definition WellContributions.hpp:51
rocalution::BiCGStab
Definition rocalutionSolverBackend.hpp:28
rocalution::ILU
Definition rocalutionSolverBackend.hpp:29
rocalution::LocalMatrix
Definition rocalutionSolverBackend.hpp:30
rocalution::LocalVector
Definition rocalutionSolverBackend.hpp:31