27#ifndef EWOMS_BICG_STAB_SOLVER_HH
28#define EWOMS_BICG_STAB_SOLVER_HH
37#include <opm/common/Exceptions.hpp>
52template <
class LinearOperator,
class Vector,
class Preconditioner>
56 using Scalar =
typename LinearOperator::field_type;
62 : preconditioner_(preconditioner)
69 maxIterations_ = 1000;
77 { maxIterations_ = value; }
84 {
return maxIterations_; }
97 { verbosity_ = value; }
103 {
return verbosity_; }
123 const Scalar
breakdownEps = std::numeric_limits<Scalar>::min() * Scalar(1
e10);
131 report_.timer().
start();
145 preconditioner_.pre(x,
r);
152 for (
unsigned i = 0; i < x.size(); ++i) {
153 const auto&
u = x[i];
155 throw std::logic_error(
"The preconditioner is assumed not to modify the initial solution!");
161 report_.setConverged(
true);
162 return report_.converged();
165 if (verbosity_ > 0) {
166 std::cout <<
"-------- BiCGStabSolver --------" << std::endl;
174 const Vector&
r0hat = *b_;
193 unsigned n = x.size();
195 for (; report_.iterations() < maxIterations_; report_.increment()) {
201 throw NumericalProblem(
"Breakdown of the BiCGStab solver (division by zero)");
211 for (
unsigned i = 0; i <
n; ++i) {
225 preconditioner_.apply(
y,
p);
233 throw NumericalProblem(
"Breakdown of the BiCGStab solver (division by zero)");
236 throw NumericalProblem(
"Breakdown of the BiCGStab solver (stagnation detected)");
240 for (
unsigned i = 0; i <
n; ++i) {
253 convergenceCriterion_.
update(
h,
y, s);
255 if (verbosity_ > 0) {
256 convergenceCriterion_.
print(report_.iterations() + 0.5);
257 std::cout <<
"-------- /BiCGStabSolver --------" << std::endl;
261 preconditioner_.post(x);
262 report_.setConverged(
true);
263 return report_.converged();
265 else if (convergenceCriterion_.
failed()) {
266 if (verbosity_ > 0) {
267 convergenceCriterion_.
print(report_.iterations() + 0.5);
268 std::cout <<
"-------- /BiCGStabSolver --------" << std::endl;
271 report_.setConverged(
false);
272 return report_.converged();
276 convergenceCriterion_.
print(report_.iterations() + 0.5);
280 preconditioner_.apply(
z, s);
287 denom = scalarProduct_.dot(
t,
t);
289 throw NumericalProblem(
"Breakdown of the BiCGStab solver (division by zero)");
292 throw NumericalProblem(
"Breakdown of the BiCGStab solver (stagnation detected)");
299 convergenceCriterion_.
update(x,
z,
r);
301 if (verbosity_ > 0) {
302 convergenceCriterion_.
print(1.0 + report_.iterations());
303 std::cout <<
"-------- /BiCGStabSolver --------" << std::endl;
306 preconditioner_.post(x);
307 report_.setConverged(
true);
308 return report_.converged();
310 else if (convergenceCriterion_.
failed()) {
311 if (verbosity_ > 0) {
312 convergenceCriterion_.
print(1.0 + report_.iterations());
313 std::cout <<
"-------- /BiCGStabSolver --------" << std::endl;
316 report_.setConverged(
false);
317 return report_.converged();
321 convergenceCriterion_.
print(1.0 + report_.iterations());
328 report_.setConverged(
false);
329 return report_.converged();
334 convergenceCriterion_ = &
crit;
337 const SolverReport& report()
const
341 const LinearOperator* A_;
344 Preconditioner& preconditioner_;
345 ConvergenceCriterion& convergenceCriterion_;
346 Dune::ScalarProduct<Vector>& scalarProduct_;
347 SolverReport report_;
349 unsigned maxIterations_;
Implements a preconditioned stabilized BiCG linear solver.
Definition bicgstabsolver.hh:54
void setVerbosity(unsigned value)
Set the verbosity level of the linear solver.
Definition bicgstabsolver.hh:96
void setLinearOperator(const LinearOperator *A)
Set the matrix "A" of the linear system.
Definition bicgstabsolver.hh:108
bool apply(Vector &x)
Run the stabilized BiCG solver and store the result into the "x" vector.
Definition bicgstabsolver.hh:120
unsigned verbosity() const
Return the verbosity level of the linear solver.
Definition bicgstabsolver.hh:102
void setMaxIterations(unsigned value)
Set the maximum number of iterations before we give up without achieving convergence.
Definition bicgstabsolver.hh:76
unsigned maxIterations() const
Return the maximum number of iterations before we give up without achieving convergence.
Definition bicgstabsolver.hh:83
void setRhs(const Vector *b)
Set the right hand side "b" of the linear system.
Definition bicgstabsolver.hh:114
Base class for all convergence criteria which only defines an virtual API.
Definition convergencecriterion.hh:56
virtual void setInitial(const Vector &curSol, const Vector &curResid)=0
Set the initial solution of the linear system of equations.
virtual void update(const Vector &curSol, const Vector &changeIndicator, const Vector &curResid)=0
Update the internal members of the convergence criterion with the current solution.
virtual bool failed() const
Returns true if the convergence criterion cannot be met anymore because the solver has broken down.
Definition convergencecriterion.hh:115
virtual bool converged() const =0
Returns true if and only if the convergence criterion is met.
virtual void printInitial(std::ostream &=std::cout) const
Prints the initial information about the convergence behaviour.
Definition convergencecriterion.hh:135
virtual void print(Scalar, std::ostream &=std::cout) const
Prints the information about the convergence behaviour for the current iteration.
Definition convergencecriterion.hh:146
A simple class which makes sure that a timer gets stopped if an exception is thrown.
Definition timerguard.hh:41
void start()
Start counting the time resources used by the simulation.
Definition timer.cpp:46
Collects summary information about the execution of the linear solver.
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
Provides a convergence criterion which looks at the reduction of the two-norm of the residual for the...
Provides an encapsulation to measure the system time.
A simple class which makes sure that a timer gets stopped if an exception is thrown.