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;
61 Dune::ScalarProduct<Vector>& scalarProduct)
62 : preconditioner_(preconditioner)
63 , convergenceCriterion_(convergenceCriterion)
64 , scalarProduct_(scalarProduct)
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(1e10);
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!");
165 if (verbosity_ > 0) {
166 std::cout <<
"-------- BiCGStabSolver --------" << std::endl;
174 const Vector& r0hat = *b_;
193 unsigned n = x.size();
197 Scalar rho_i = scalarProduct_.dot(r0hat, r);
200 if (std::abs(rho) <= breakdownEps || std::abs(omega) <= breakdownEps)
201 throw NumericalProblem(
"Breakdown of the BiCGStab solver (division by zero)");
202 Scalar beta = (rho_i/rho)*(alpha/omega);
211 for (
unsigned i = 0; i < n; ++i) {
225 preconditioner_.apply(y, p);
231 Scalar denom = scalarProduct_.dot(r0hat, v);
232 if (std::abs(denom) <= breakdownEps)
233 throw NumericalProblem(
"Breakdown of the BiCGStab solver (division by zero)");
235 if (std::abs(alpha) <= breakdownEps)
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) {
257 std::cout <<
"-------- /BiCGStabSolver --------" << std::endl;
261 preconditioner_.post(x);
265 else if (convergenceCriterion_.
failed()) {
266 if (verbosity_ > 0) {
268 std::cout <<
"-------- /BiCGStabSolver --------" << std::endl;
280 preconditioner_.apply(z, s);
287 denom = scalarProduct_.dot(t, t);
288 if (std::abs(denom) <= breakdownEps)
289 throw NumericalProblem(
"Breakdown of the BiCGStab solver (division by zero)");
290 omega = scalarProduct_.dot(t, s)/denom;
291 if (std::abs(omega) <= breakdownEps)
292 throw NumericalProblem(
"Breakdown of the BiCGStab solver (stagnation detected)");
299 convergenceCriterion_.
update(x, z, r);
301 if (verbosity_ > 0) {
303 std::cout <<
"-------- /BiCGStabSolver --------" << std::endl;
306 preconditioner_.post(x);
310 else if (convergenceCriterion_.
failed()) {
311 if (verbosity_ > 0) {
313 std::cout <<
"-------- /BiCGStabSolver --------" << std::endl;
334 convergenceCriterion_ = &crit;
341 const LinearOperator* A_;
344 Preconditioner& preconditioner_;
346 Dune::ScalarProduct<Vector>& scalarProduct_;
349 unsigned maxIterations_;
Implements a preconditioned stabilized BiCG linear solver.
Definition: bicgstabsolver.hh:54
void setConvergenceCriterion(ConvergenceCriterion &crit)
Definition: bicgstabsolver.hh:332
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
const SolverReport & report() const
Definition: bicgstabsolver.hh:337
void setRhs(const Vector *b)
Set the right hand side "b" of the linear system.
Definition: bicgstabsolver.hh:114
BiCGStabSolver(Preconditioner &preconditioner, ConvergenceCriterion &convergenceCriterion, Dune::ScalarProduct< Vector > &scalarProduct)
Definition: bicgstabsolver.hh:59
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
Collects summary information about the execution of the linear solver.
Definition: linearsolverreport.hh:40
bool converged() const
Definition: linearsolverreport.hh:67
unsigned iterations() const
Definition: linearsolverreport.hh:58
const Timer & timer() const
Definition: linearsolverreport.hh:52
void reset()
Definition: linearsolverreport.hh:45
void setConverged(bool value)
Definition: linearsolverreport.hh:70
void increment()
Definition: linearsolverreport.hh:61
A simple class which makes sure that a timer gets stopped if an exception is thrown.
Definition: timerguard.hh:42
void start()
Start counting the time resources used by the simulation.
Define some base class for the convergence criteria of the linear solvers of DUNE-ISTL.
Definition: blackoilboundaryratevector.hh:39