17#ifndef OPM_ISTLSOLVERRUNTIMEOPTIONPROXY_HEADER_INCLUDED
18#define OPM_ISTLSOLVERRUNTIMEOPTIONPROXY_HEADER_INCLUDED
20#include "opm/simulators/linalg/FlowLinearSolverParameters.hpp"
21#include <opm/simulators/linalg/setupPropertyTree.hpp>
22#include <opm/simulators/linalg/AbstractISTLSolver.hpp>
23#include <opm/simulators/linalg/ISTLSolver.hpp>
25#include <opm/simulators/linalg/ISTLSolverGpuBridge.hpp>
29#include <opm/simulators/linalg/gpuistl_hip/ISTLSolverGPUISTL.hpp>
31#include <opm/simulators/linalg/gpuistl/ISTLSolverGPUISTL.hpp>
34#include <fmt/format.h>
42template <
class TypeTag>
49 using Matrix =
typename SparseMatrixAdapter::IstlMatrix;
52 using CommunicationType = Dune::OwnerOverlapCopyCommunication<int, int>;
54 using CommunicationType = Dune::Communication<int>;
58 static void registerParameters()
60 FlowLinearSolverParameters::registerParameters();
72 bool forceSerial =
false)
74 createSolver(simulator, parameters, forceSerial);
81 createSolver(simulator);
87 istlSolver_->eraseMatrix();
92 istlSolver_->setActiveSolver(num);
97 return istlSolver_->numAvailableSolvers();
100 void prepare(
const SparseMatrixAdapter& M, Vector& b)
override
102 istlSolver_->prepare(M, b);
105 void prepare(
const Matrix& M, Vector& b)
override
107 istlSolver_->prepare(M, b);
112 istlSolver_->setResidual(b);
117 istlSolver_->getResidual(b);
122 istlSolver_->setMatrix(M);
127 return istlSolver_->solve(x);
132 return istlSolver_->iterations();
135 const CommunicationType*
comm()
const override
137 return istlSolver_->comm();
142 return istlSolver_->getSolveCount();
146 std::unique_ptr<AbstractISTLSolver<TypeTag>> istlSolver_;
149 template <
class... Args>
150 void createSolver(
const Simulator& simulator, Args&&... args)
152 const auto backend = Parameters::linearSolverAcceleratorTypeFromCLI();
153 if (backend == Parameters::LinearSolverAcceleratorType::CPU) {
155#if COMPILE_GPU_BRIDGE
156 istlSolver_ = std::make_unique<ISTLSolverGpuBridge<TypeTag>>(simulator, std::forward<Args>(args)...);
158 istlSolver_ = std::make_unique<ISTLSolver<TypeTag>>(simulator, std::forward<Args>(args)...);
162 else if (backend == Parameters::LinearSolverAcceleratorType::GPU) {
163 istlSolver_ = std::make_unique<gpuistl::ISTLSolverGPUISTL<TypeTag>>(simulator, std::forward<Args>(args)...);
169 OPM_THROW(std::invalid_argument, fmt::format(fmt::runtime(
"Unknown backend: {}"), Parameters::toString(backend)));
Abstract interface for ISTL solvers.
Definition AbstractISTLSolver.hpp:45
ISTLSolverRuntimeOptionProxy(const Simulator &simulator, const FlowLinearSolverParameters ¶meters, bool forceSerial=false)
Construct a system solver.
Definition ISTLSolverRuntimeOptionProxy.hpp:70
int numAvailableSolvers() const override
Get the number of available solvers.
Definition ISTLSolverRuntimeOptionProxy.hpp:95
void setResidual(Vector &b) override
Set the residual vector.
Definition ISTLSolverRuntimeOptionProxy.hpp:110
void getResidual(Vector &b) const override
Get the residual vector.
Definition ISTLSolverRuntimeOptionProxy.hpp:115
ISTLSolverRuntimeOptionProxy(const Simulator &simulator)
Construct a system solver.
Definition ISTLSolverRuntimeOptionProxy.hpp:79
void setActiveSolver(int num) override
Set the active solver by its index.
Definition ISTLSolverRuntimeOptionProxy.hpp:90
int getSolveCount() const override
Get the count of how many times the solver has been called.
Definition ISTLSolverRuntimeOptionProxy.hpp:140
const CommunicationType * comm() const override
Get the communication object used by the solver.
Definition ISTLSolverRuntimeOptionProxy.hpp:135
bool solve(Vector &x) override
Solve the system of equations Ax = b.
Definition ISTLSolverRuntimeOptionProxy.hpp:125
void setMatrix(const SparseMatrixAdapter &M) override
Set the matrix for the solver.
Definition ISTLSolverRuntimeOptionProxy.hpp:120
void prepare(const SparseMatrixAdapter &M, Vector &b) override
Prepare the solver with the given sparse matrix and right-hand side vector.
Definition ISTLSolverRuntimeOptionProxy.hpp:100
int iterations() const override
Get the number of iterations used in the last solve.
Definition ISTLSolverRuntimeOptionProxy.hpp:130
void eraseMatrix() override
Signals that the memory for the matrix internally in the solver could be erased.
Definition ISTLSolverRuntimeOptionProxy.hpp:85
void prepare(const Matrix &M, Vector &b) override
Prepare the solver with the given matrix and right-hand side vector.
Definition ISTLSolverRuntimeOptionProxy.hpp:105
Manages the initializing and running of time dependent problems.
Definition simulator.hh:84
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:45
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