22#ifndef OPM_ISTLSOLVER_WITH_GPUBRIDGE_HEADER_INCLUDED
23#define OPM_ISTLSOLVER_WITH_GPUBRIDGE_HEADER_INCLUDED
25#include <opm/simulators/linalg/ISTLSolver.hpp>
37template<
class Matrix,
class Vector,
int block_size>
class GpuBridge;
38template<
class Scalar>
class WellContributions;
41template<
class Matrix,
class Vector>
44 using Scalar =
typename Vector::field_type;
51 const Scalar tolerance,
54 const bool opencl_ilu_parallel,
60 void prepare(
const Grid& grid,
64 const std::vector<int>& cellPartition,
65 const std::size_t nonzeroes,
68 bool apply(Vector& rhs,
74 Dune::InverseOperatorResult&
result);
78 int numJacobiBlocks_ = 0;
84 void blockJacobiAdjacency(
const Grid& grid,
86 std::size_t nonzeroes);
88 void copyMatToBlockJac(
const Matrix& mat, Matrix&
blockJac);
90 std::unique_ptr<Bridge> bridge_;
91 std::string accelerator_mode_;
92 std::unique_ptr<Matrix> blockJacobiForGPUILU0_;
93 std::vector<std::set<int>> wellConnectionsGraph_;
102template <
class TypeTag>
114 using Matrix =
typename SparseMatrixAdapter::IstlMatrix;
117 using AbstractSolverType = Dune::InverseOperator<Vector, Vector>;
118 using AbstractOperatorType = Dune::AssembledLinearOperator<Matrix, Vector, Vector>;
125 using CommunicationType = Dune::OwnerOverlapCopyCommunication<int,int>;
127 using CommunicationType = Dune::Communication<int>;
131 using AssembledLinearOperatorType = Dune::AssembledLinearOperator< Matrix, Vector, Vector >;
155 std::string accelerator_mode = Parameters::Get<Parameters::AcceleratorMode>();
157 if ((this->simulator_.vanguard().grid().comm().size() > 1) && (accelerator_mode !=
"none")) {
158 const bool on_io_rank = (this->simulator_.gridView().comm().rank() == 0);
160 OpmLog::warning(
"Cannot use AcceleratorMode feature with MPI, setting AcceleratorMode to 'none'.");
162 accelerator_mode =
"none";
165 if (accelerator_mode ==
"none") {
170 const int platformID = Parameters::Get<Parameters::OpenclPlatformId>();
171 const int deviceID = Parameters::Get<Parameters::GpuDeviceId>();
172 const int maxit = Parameters::Get<Parameters::LinearSolverMaxIter>();
173 const double tolerance = Parameters::Get<Parameters::LinearSolverReduction>();
174 const bool opencl_ilu_parallel = Parameters::Get<Parameters::OpenclIluParallel>();
176 std::string
linsolver = Parameters::Get<Parameters::LinearSolver>();
177 gpuBridge_ = std::make_unique<detail::GpuSolverInfo<Matrix,Vector>>(accelerator_mode,
195 ParentType::initPrepare(M,
b);
200#if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
207 gpuBridge_->numJacobiBlocks_ = Parameters::Get<Parameters::NumJacobiBlocks>();
208 gpuBridge_->prepare(this->simulator_.vanguard().grid(),
209 this->simulator_.vanguard().cartesianIndexMapper(),
210 this->simulator_.vanguard().schedule().getWellsatEnd(),
211 this->simulator_.vanguard().schedule().getPossibleFutureConnections(),
212 this->simulator_.vanguard().cellPartition(),
213 this->getMatrix().nonzeroes(),
this->useWellConn_);
241 this->solveCount_ += 1;
243 const int verbosity = this->prm_[this->activeSolverNum_].template
get<int>(
"verbosity", 0);
246 Helper::writeSystem(this->simulator_,
253 Dune::InverseOperatorResult
result;
258 this->simulator_.problem().wellModel().getWellContributions(
w);
261 this->simulator_.gridView().comm().rank(),
262 const_cast<Matrix&
>(
this->getMatrix()),
265 if(gpuBridge_->gpuActive()){
267 ParentType::prepareFlexibleSolver();
269 assert(this->flexibleSolver_[this->activeSolverNum_].solver_);
270 this->flexibleSolver_[this->activeSolverNum_].solver_->apply(x, *(this->rhs_),
result);
274 return this->checkConvergence(
result);
278 std::unique_ptr<detail::GpuSolverInfo<Matrix, Vector>> gpuBridge_;
Definition CollectDataOnIORank.hpp:49
Interface class adding the update() method to the preconditioner interface.
Definition PreconditionerWithUpdate.hpp:32
GpuBridge acts as interface between opm-simulators with the GpuSolvers.
Definition GpuBridge.hpp:37
This class solves the fully implicit black-oil system by solving the reduced system (after eliminatin...
Definition ISTLSolverGpuBridge.hpp:104
void setMatrix(const SparseMatrixAdapter &)
Set the matrix for the solver.
Definition ISTLSolverGpuBridge.hpp:229
ISTLSolverGpuBridge(const Simulator &simulator, const FlowLinearSolverParameters ¶meters)
Construct a system solver.
Definition ISTLSolverGpuBridge.hpp:137
ISTLSolverGpuBridge(const Simulator &simulator)
Construct a system solver.
Definition ISTLSolverGpuBridge.hpp:145
bool solve(Vector &x)
Solve the system of equations Ax = b.
Definition ISTLSolverGpuBridge.hpp:234
void prepare(const Matrix &M, Vector &b)
Prepare the solver with the given matrix and right-hand side vector.
Definition ISTLSolverGpuBridge.hpp:187
void setResidual(Vector &)
Set the residual vector.
Definition ISTLSolverGpuBridge.hpp:219
void getResidual(Vector &b) const
Get the residual vector.
Definition ISTLSolverGpuBridge.hpp:224
This class solves the fully implicit black-oil system by solving the reduced system (after eliminatin...
Definition ISTLSolver.hpp:149
void prepare(const SparseMatrixAdapter &M, Vector &b) override
Prepare the solver with the given sparse matrix and right-hand side vector.
Definition ISTLSolver.hpp:368
bool solve(Vector &x) override
Solve the system of equations Ax = b.
Definition ISTLSolver.hpp:407
This class serves to eliminate the need to include the WellContributions into the matrix (with –matri...
Definition WellContributions.hpp:51
Definition WellOperators.hpp:70
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:240
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition propertysystem.hh:233
This class carries all parameters for the NewtonIterationBlackoilInterleaved class.
Definition FlowLinearSolverParameters.hpp:98
Definition ISTLSolverGpuBridge.hpp:43