#ifndef GRID_POLYNOMIAL_APPROX_H #define GRID_POLYNOMIAL_APPROX_H #include #include namespace Grid { //////////////////////////////////////////////////////////////////////////////////////////// // Simple general polynomial with user supplied coefficients //////////////////////////////////////////////////////////////////////////////////////////// template class Polynomial : public OperatorFunction { private: std::vector _oeffs; public: Polynomial(std::vector &_Coeffs) : Coeffs(_Coeffs) {}; // Implement the required interface void operator() (LinearOperatorBase &Linop, const Field &in, Field &out) { Field AtoN = in; out = AtoN*Coeffs[0]; for(int n=1;n class Chebyshev : public OperatorFunction { private: std::vector Coeffs; int order; double hi; double lo; public: Chebyshev(double _lo,double _hi,int _order, double (* func)(double) ){ lo=_lo; hi=_hi; order=_order; if(order < 2) exit(-1); Coeffs.resize(order); for(int j=0;j &Linop, const Field &in, Field &out) { Field T0 = in; Field T1 = T0; // Field T1(T0._grid); more efficient but hardwires Lattice class Field T2 = T1; // use a pointer trick to eliminate copies Field *Tnm = &T0; Field *Tn = &T1; Field *Tnp = &T2; Field y = in; double xscale = 2.0/(hi-lo); double mscale = -(hi+lo)/(hi-lo); Field *T0=Tnm; Field *T1=Tn; // Tn=T1 = (xscale M + mscale)in Linop.Op(T0,y); T1=y*xscale+in*mscale; // sum = .5 c[0] T0 + c[1] T1 out = (0.5*coeffs[0])*T0 + coeffs[1]*T1; for(int n=2;n