12#ifndef CGTERMINATIONCRITERIA_HH
13#define CGTERMINATIONCRITERIA_HH
20#include <dune/common/fvector.hh>
21#include <dune/common/fmatrix.hh>
95 virtual operator bool() = 0;
111 template <
class R =
double>
155 virtual operator bool()
209 template <
class R =
double>
225 : tol(atol), maxit(maxit), lookah(6)
268 gammas2.push_back(
gamma2);
283 virtual operator bool()
285 return (gammas2.size()>=5 &&
error() <= tol) || gammas2.size()>=maxit;
293 int const n = gammas2.size();
297 return std::numeric_limits<R>::max();
310 int const m = std::min(n,5+lookah);
313 AtA[0][0] = m; AtA[0][1] = (m-1)*m/2;
314 AtA[1][0] = (m-1)*m/2; AtA[1][1] = (m-1)*m*(2*m-1)/6;
315 for (
int i=0; i<m; ++i)
317 f[0] += std::log(gammas2[n-m+i]);
318 f[1] += i*std::log(gammas2[n-m+i]);
322 R q = std::exp(x[1]);
325 R eps2 = std::accumulate(begin(gammas2)+n-lookah,end(gammas2),q*gammas2.back()/(1-q));
326 return std::sqrt(eps2);
337 std::vector<Real>
const&
gamma2()
const {
return gammas2; }
343 std::vector<Real> gammas2;
395 : tol(tol_), maxit(maxit_), eps(eps_)
414 : tol(tol_), maxit(maxit_), eps(eps_), minTol(minTol_)
422 scaledGamma2.clear();
448 scaledGamma2.push_back( gamma );
463 virtual operator bool()
465 return scaledGamma2.size() > d &&
relativeError() < std::max(eps,tol*tol);
473 if( scaledGamma2.size() < d )
return std::numeric_limits<Real>::max();
474 return std::accumulate(scaledGamma2.end() - d, scaledGamma2.end(), 0.) / energyNorm;
483 std::vector<Real> scaledGamma2;
486 double eps = 1e-12, minTol = 1e-2;
538 : tol(tol_), maxit(maxit_), eps(eps_)
556 : tol(tol_), maxit(maxit_), eps(eps_), minTol(minTol_)
564 scaledGamma2.clear();
591 scaledGamma2.push_back( gamma );
604 steps2.push_back(qPq/qAq);
618 virtual operator bool()
620 return scaledGamma2.size() > 2*d &&
relativeError() < std::max(eps,tol*tol);
628 if( scaledGamma2.size() < 2*d )
return std::numeric_limits<Real>::max();
630 size_t j = scaledGamma2.size() - 2*d;
632 for(
size_t i = j; i < j + d; ++i)
633 tau += steps2[i] * ( scaledGamma2[i] +
634 2 * std::accumulate(scaledGamma2.begin()+i+1, scaledGamma2.end(),0) );
644 std::vector<Real> scaledGamma2, steps2;
647 double eps = 1e-12, minTol = 1e-2;
virtual void step(Real)
supplies energy of step to the termination criterion
virtual PCGTerminationCriterion< R > & tolerance(Real)
unused
PCGCountingTerminationCriterion(int n_)
Constructor.
virtual int getMaxIterationSteps()
get the maximum number of allowed iteration steps
virtual void clear()
re-initializes the termination criterion for a new IterateType::CG run
virtual int getMaxIterationSteps()
get the maximum number of allowed iteration steps
virtual void clear()
re-initializes the termination criterion for a new IterateType::CG run
virtual void step(Real gamma2)
supplies energy of step to the termination criterion
PCGEnergyErrorTerminationCriterion(Real atol, int maxit)
constructor
Real error() const
returns the estimated absolute energy error
PCGEnergyErrorTerminationCriterion< Real > & lookahead(int lah)
set requested lookahead value
void setMaxit(int m)
Sets a new value for the maximal number of iterations.
std::vector< Real > const & gamma2() const
virtual PCGEnergyErrorTerminationCriterion< Real > & tolerance(Real atol)
set requested absolute tolerance
Interface for IterateType::PCG termination criterion policy classes.
virtual void step(Real gamma)=0
supplies energy of step to the termination criterion
virtual void clear()=0
re-initializes the termination criterion for a new IterateType::CG run
virtual int getMaxIterationSteps()=0
get the maximum number of allowed iteration steps
virtual void residual(Real sigma)
supplies the preconditioned residual to the termination criterion
virtual bool minimalDecreaseAchieved()
whether a minimal decrease has been achieved (used by hybrid CG)
virtual void stepDetail(Real alpha, Real qAq, Real qPq, Real rPINVr)
supplies additional algorithmic quantities to the termination criterion
virtual PCGTerminationCriterion< Real > & tolerance(Real tol)=0
set requested tolerance
virtual PCGTerminationCriterion< Real > & tolerance(Real tol_)
set requested relative tolerance
StrakosTichyEnergyErrorTerminationCriterion(Real tol_, Real minTol_, int maxit_, double eps_=1e-12)
constructor
StrakosTichyEnergyErrorTerminationCriterion(Real tol_, int maxit_, double eps_=1e-12)
constructor
bool minimalDecreaseAchieved()
whether a minimal decrease has been achieved (used by hybrid CG)
virtual void clear()
re-initializes the termination criterion for a new IterateType::CG run
virtual void step(Real gamma)
supplies energy of step to the termination criterion
virtual int getMaxIterationSteps()
get the maximum number of allowed iteration steps
void setLookAhead(int d_)
set requested lookahead value
Real relativeError()
returns the estimated relative energy error
Real relativeError()
returns the estimated relative error
StrakosTichyPTerminationCriterion(Real tol_, int maxit_, double eps_=1e-12)
constructor
virtual void clear()
re-initializes the termination criterion for a new IterateType::CG run
virtual PCGTerminationCriterion< Real > & tolerance(Real tol_)
set requested relative tolerance
bool minimalDecreaseAchieved()
whether a minimal decrease has been achieved (used by hybrid CG)
StrakosTichyPTerminationCriterion(Real tol_, Real minTol_, int maxit_, double eps_=1e-12)
constructor
virtual void step(Real gamma)
supplies energy of step to the termination criterion
virtual int getMaxIterationSteps()
get the maximum number of allowed iteration steps
virtual void stepDetail(Real alpha, Real qAq, Real qPq, Real rPINVr)
supplies additional quantities for the -criterion
void setLookAhead(int d_)
set requested lookahead value
int count(Cell const &cell, int codim)
Computes the number of subentities of codimension c of a given entity.
double energyNorm(const Dune::BCRSMatrix< Dune::FieldMatrix< double, 1, 1 > > &matrix_, const Dune::BlockVector< Dune::FieldVector< double, 1 > > &vec_)