#ifndef GRID_PREC_CONJUGATE_RESIDUAL_H #define GRID_PREC_CONJUGATE_RESIDUAL_H namespace Grid { ///////////////////////////////////////////////////////////// // Base classes for iterative processes based on operators // single input vec, single output vec. ///////////////////////////////////////////////////////////// template class PrecConjugateResidual : public OperatorFunction { public: RealD Tolerance; Integer MaxIterations; int verbose; LinearFunction &Preconditioner; PrecConjugateResidual(RealD tol,Integer maxit,LinearFunction &Prec) : Tolerance(tol), MaxIterations(maxit), Preconditioner(Prec) { verbose=1; }; void operator() (LinearOperatorBase &Linop,const Field &src, Field &psi){ RealD a, b, c, d; RealD cp, ssq,rsq; RealD rAr, rAAr, rArp; RealD pAp, pAAp; GridBase *grid = src._grid; Field r(grid), p(grid), Ap(grid), Ar(grid), z(grid); psi=zero; r = src; Preconditioner(r,p); Linop.HermOpAndNorm(p,Ap,pAp,pAAp); Ar=Ap; rAr=pAp; rAAr=pAAp; cp =norm2(r); ssq=norm2(src); rsq=Tolerance*Tolerance*ssq; if (verbose) std::cout<