AbstractISTLSolver.hpp
Go to the documentation of this file.
1/*
2 Copyright 2025 Equinor ASA
3
4 This file is part of the Open Porous Media project (OPM).
5 OPM is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 OPM is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with OPM. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17#ifndef OPM_ABSTRACTISTLSOLVER_HEADER_INCLUDED
18#define OPM_ABSTRACTISTLSOLVER_HEADER_INCLUDED
19
20#include <opm/common/Exceptions.hpp>
23
24namespace Opm
25{
26
43template <class TypeTag>
45{
46public:
47#if HAVE_MPI
48 using CommunicationType = Dune::OwnerOverlapCopyCommunication<int, int>;
49#else
50 using CommunicationType = Dune::Communication<int>;
51#endif
52
55 using Matrix = typename SparseMatrixAdapter::IstlMatrix;
56
57 virtual ~AbstractISTLSolver() = default;
58
65 virtual void eraseMatrix() = 0;
66
74 virtual void setActiveSolver(int num) = 0;
75
81 virtual int numAvailableSolvers() const = 0;
82
92 virtual void prepare(const Matrix& M, Vector& b) = 0;
93
105 virtual void prepare(const SparseMatrixAdapter& M, Vector& b) = 0;
106
116 virtual void setResidual(Vector& b) = 0;
117
125 virtual void getResidual(Vector& b) const = 0;
126
136 virtual void setMatrix(const SparseMatrixAdapter& M) = 0;
137
152 virtual bool solve(Vector& x) = 0;
153
163 virtual int iterations() const = 0;
164
172 virtual const CommunicationType* comm() const = 0;
173
181 virtual int getSolveCount() const = 0;
182
183protected:
184
195 const FlowLinearSolverParameters& parameters)
196 {
197 if (!result.converged) {
198 if (result.reduction < parameters.relaxed_linear_solver_reduction_) {
199 std::stringstream ss;
200 ss << "Full linear solver tolerance not achieved. The reduction is:" << result.reduction << " after "
201 << result.iterations << " iterations ";
202 OpmLog::warning(ss.str());
203 return true;
204 }
205 }
206 // Check for failure of linear solver.
207 if (!parameters.ignoreConvergenceFailure_ && !result.converged) {
208 const std::string msg("Convergence failure for linear solver.");
209 OPM_THROW_NOLOG(NumericalProblem, msg);
210 }
211
212 return result.converged;
213 }
214};
215} // namespace Opm
216
217#endif
Abstract interface for ISTL solvers.
Definition: AbstractISTLSolver.hpp:45
virtual ~AbstractISTLSolver()=default
virtual void setActiveSolver(int num)=0
Set the active solver by its index.
virtual int iterations() const =0
Get the number of iterations used in the last solve.
Dune::OwnerOverlapCopyCommunication< int, int > CommunicationType
Definition: AbstractISTLSolver.hpp:48
virtual void getResidual(Vector &b) const =0
Get the residual vector.
typename SparseMatrixAdapter::IstlMatrix Matrix
Definition: AbstractISTLSolver.hpp:55
virtual const CommunicationType * comm() const =0
Get the communication object used by the solver.
virtual void setMatrix(const SparseMatrixAdapter &M)=0
Set the matrix for the solver.
virtual int getSolveCount() const =0
Get the count of how many times the solver has been called.
virtual int numAvailableSolvers() const =0
Get the number of available solvers.
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: AbstractISTLSolver.hpp:53
virtual void eraseMatrix()=0
Signals that the memory for the matrix internally in the solver could be erased.
virtual void prepare(const Matrix &M, Vector &b)=0
Prepare the solver with the given matrix and right-hand side vector.
virtual void prepare(const SparseMatrixAdapter &M, Vector &b)=0
Prepare the solver with the given sparse matrix and right-hand side vector.
virtual bool solve(Vector &x)=0
Solve the system of equations Ax = b.
virtual void setResidual(Vector &b)=0
Set the residual vector.
GetPropType< TypeTag, Properties::GlobalEqVector > Vector
Definition: AbstractISTLSolver.hpp:54
static bool checkConvergence(const Dune::InverseOperatorResult &result, const FlowLinearSolverParameters &parameters)
Check the convergence of the linear solver.
Definition: AbstractISTLSolver.hpp:194
Definition: blackoilboundaryratevector.hh:39
Dune::InverseOperatorResult InverseOperatorResult
Definition: GpuBridge.hpp:32
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:95
bool ignoreConvergenceFailure_
Definition: FlowLinearSolverParameters.hpp:107
double relaxed_linear_solver_reduction_
Definition: FlowLinearSolverParameters.hpp:97