16#include "dune/istl/solvers.hh"
17#include "dune/istl/istlexception.hh"
18#include "dune/istl/operators.hh"
19#include "dune/istl/preconditioners.hh"
20#include "dune/istl/scalarproducts.hh"
40 template<
class L,
class P>
42 ssp(), _op(op), _prec(prec), _sp(ssp), _reduction(reduction), _maxit(maxit), _verbose(verbose)
44 static_assert(
static_cast<int>(L::category) ==
static_cast<int>(P::category),
45 "L and P must have the same category!");
46 static_assert(
static_cast<int>(L::category) ==
static_cast<int>(Dune::SolverCategory::sequential),
47 "L must be sequential!");
55 virtual void apply (
X& u,
X& b, Dune::InverseOperatorResult& res)
66 _op.applyscaleadd(-1,u,r);
71 double def0 = _sp.norm(rq);
80 std::cout <<
"=== rate=" << res.conv_rate
81 <<
", T=" << res.elapsed <<
", TIT=" << res.elapsed
82 <<
", IT=0" << std::endl;
88 std::cout <<
"=== NMIIIPCGSolver" << std::endl;
90 this->printHeader(std::cout);
91 this->printOutput(std::cout,(
double) 0,def0);
96 double def=def0, defnew=def0;
98 sigma = _sp.dot(r,rq);
102 for ( ; i<=_maxit; i++ )
106 alpha = sigma/_sp.dot(q,h);
112 this->printOutput(std::cout,(
double) i,defnew,def);
114 if (defnew<sqrt(_reduction) || def<1E-30)
116 res.converged =
true;
127 double sigmaNew = _sp.dot(r,rq);
128 beta = sigmaNew/sigma;
136 this->printOutput(std::cout,(
double) i,def);
139 res.reduction = def/def0;
140 res.conv_rate = pow(res.reduction,1.0/i);
141 res.elapsed = watch.elapsed();
145 std::cout <<
"=== rate=" << res.conv_rate
146 <<
", T=" << res.elapsed
147 <<
", TIT=" << res.elapsed/i
148 <<
", IT=" << i << std::endl;
157 virtual void apply (
X& x,
X& b,
double reduction, Dune::InverseOperatorResult& res)
159 _reduction = reduction;
160 (*this).apply(x,b,res);
164 Dune::SeqScalarProduct<X> ssp;
165 Dune::LinearOperator<X,X>& _op;
166 Dune::Preconditioner<X,X>& _prec;
167 Dune::ScalarProduct<X>& _sp;
conjugate gradient method
virtual void apply(X &u, X &b, Dune::InverseOperatorResult &res)
Apply inverse operator.
X domain_type
The domain type of the operator to be inverted.
X::field_type field_type
The field type of the operator to be inverted.
NMIIIPCGSolver(L &op, P &prec, double reduction, int maxit, int verbose)
Set up conjugate gradient solver.
X range_type
The range type of the operator to be inverted.
virtual void apply(X &x, X &b, double reduction, Dune::InverseOperatorResult &res)
Apply inverse operator with given reduction factor.