#include #include //#include using namespace std; using namespace Grid; using namespace Grid::QCD; RealD InverseApproximation(RealD x){ return 1.0/x; } template class MultiGridPreconditioner : public LinearFunction< Lattice > { public: typedef Aggregation Aggregates; typedef CoarsenedMatrix CoarseOperator; typedef typename Aggregation::siteVector siteVector; typedef typename Aggregation::CoarseScalar CoarseScalar; typedef typename Aggregation::CoarseVector CoarseVector; typedef typename Aggregation::CoarseMatrix CoarseMatrix; typedef typename Aggregation::FineField FineField; typedef LinearOperatorBase FineOperator; Aggregates & _Aggregates; CoarseOperator & _CoarseOperator; Matrix & _Matrix; FineOperator & _FineOperator; // Constructor MultiGridPreconditioner(Aggregates &Agg, CoarseOperator &Coarse, FineOperator &Fine,Matrix &FineMatrix) : _Aggregates(Agg), _CoarseOperator(Coarse), _FineOperator(Fine), _Matrix(FineMatrix) { } void PowerMethod(const FineField &in) { FineField p1(in._grid); FineField p2(in._grid); MdagMLinearOperator fMdagMOp(_Matrix); p1=in; RealD absp2; for(int i=0;i<20;i++){ RealD absp1=std::sqrt(norm2(p1)); fMdagMOp.HermOp(p1,p2);// this is the G5 herm bit // _FineOperator.Op(p1,p2);// this is the G5 herm bit RealD absp2=std::sqrt(norm2(p2)); if(i%10==9) std::cout << "Power method on mdagm "< fCG(1.0e-3,1000); ConjugateGradient CG(1.0e-8,100000); //////////////////////////////////////////////////////////////////////// // ADEF2: [PTM+Q] in = [1 - Q A] M in + Q in = Min + Q [ in -A Min] //////////////////////////////////////////////////////////////////////// // Smoothing step, followed by coarse grid correction MdagMLinearOperator MdagMOp(_Matrix); Min=in; std::cout<< " Preconditioner in " << norm2(in)< MdagMOp(_CoarseOperator); HermitianLinearOperator HermOp(_CoarseOperator); Csol=zero; _Aggregates.ProjectToSubspace (Csrc,out); HermOp.AdjOp(Csrc,Ctmp);// Normal equations CG(MdagMOp ,Ctmp,Csol); _Aggregates.PromoteFromSubspace(Csol,out); out = Min + out;; */ } #endif //////////////////////////////////////////////////////////////////////// // ADEF2: [PTM+Q] in = [1 - Q A] M in + Q in = Min + Q [ in -A Min] // ADEF1: [MP+Q ] in =M [1 - A Q] in + Q in //////////////////////////////////////////////////////////////////////// #if 0 void operator()(const FineField &in, FineField & out) { CoarseVector Csrc(_CoarseOperator.Grid()); CoarseVector Ctmp(_CoarseOperator.Grid()); CoarseVector Csol(_CoarseOperator.Grid()); ConjugateGradient CG(1.0e-10,100000); ConjugateGradient fCG(3.0e-2,1000); HermitianLinearOperator HermOp(_CoarseOperator); MdagMLinearOperator MdagMOp(_CoarseOperator); MdagMLinearOperator fMdagMOp(_Matrix); FineField tmp(in._grid); FineField res(in._grid); FineField Min(in._grid); // Monitor completeness of low mode space _Aggregates.ProjectToSubspace (Csrc,in); _Aggregates.PromoteFromSubspace(Csrc,out); std::cout<<"Coarse Grid Preconditioner\nCompleteness in: "< CG(1.0e-10,100000); ConjugateGradient fCG(3.0e-2,1000); HermitianLinearOperator HermOp(_CoarseOperator); MdagMLinearOperator MdagMOp(_CoarseOperator); ShiftedMdagMLinearOperator fMdagMOp(_Matrix,0.1); FineField tmp(in._grid); FineField res(in._grid); FineField Qin(in._grid); // Monitor completeness of low mode space // _Aggregates.ProjectToSubspace (Csrc,in); // _Aggregates.PromoteFromSubspace(Csrc,out); // std::cout<<"Coarse Grid Preconditioner\nCompleteness in: "< fMdagMOp(_Matrix); ShiftedMdagMLinearOperator fMdagMOp(_Matrix,0.5); RealD Ni,r; Ni = norm2(in); for(int ilo=0;ilo<4;ilo++){ for(int ord=10;ord<60;ord+=10){ _FineOperator.AdjOp(in,vec1); Chebyshev Cheby (lo[ilo],70.0,ord,InverseApproximation); Cheby(fMdagMOp,vec1,vec2); // solves MdagM = g5 M g5M _FineOperator.Op(vec2,vec1);// this is the G5 herm bit vec1 = in - vec1; // tmp = in - A Min r=norm2(vec1); std::cout << "Smoother resid "< CG(1.0e-5,100000); ConjugateGradient fCG(3.0e-2,1000); HermitianLinearOperator HermOp(_CoarseOperator); MdagMLinearOperator MdagMOp(_CoarseOperator); // MdagMLinearOperator fMdagMOp(_Matrix); ShiftedMdagMLinearOperator fMdagMOp(_Matrix,1.0); FineField vec1(in._grid); FineField vec2(in._grid); // Chebyshev Cheby (0.5,70.0,30,InverseApproximation); // Chebyshev ChebyAccu(0.5,70.0,30,InverseApproximation); Chebyshev Cheby (2.0,70.0,10,InverseApproximation); Chebyshev ChebyAccu(2.0,70.0,10,InverseApproximation); _Aggregates.ProjectToSubspace (Csrc,in); _Aggregates.PromoteFromSubspace(Csrc,out); std::cout<<"Completeness: "< clatt = GridDefaultLatt(); for(int d=0;d seeds4({1,2,3,4}); std::vector seeds5({5,6,7,8}); std::vector cseeds({5,6,7,8}); GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds5); GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4); GridParallelRNG CRNG(Coarse5d);CRNG.SeedFixedIntegers(cseeds); Gamma g5(Gamma::Gamma5); LatticeFermion src(FGrid); gaussian(RNG5,src);// src=src+g5*src; LatticeFermion result(FGrid); result=zero; LatticeFermion ref(FGrid); ref=zero; LatticeFermion tmp(FGrid); LatticeFermion err(FGrid); LatticeGaugeField Umu(UGrid); NerscField header; std::string file("./ckpoint_lat.4000"); readNerscConfiguration(Umu,header,file); // SU3::ColdConfiguration(RNG4,Umu); // SU3::TepidConfiguration(RNG4,Umu); // SU3::HotConfiguration(RNG4,Umu); // Umu=zero; RealD mass=0.01; RealD M5=1.8; std::cout << "**************************************************"<< std::endl; std::cout << "Building g5R5 hermitian DWF operator" < Subspace; typedef CoarsenedMatrix CoarseOperator; typedef CoarseOperator::CoarseVector CoarseVector; std::cout << "**************************************************"<< std::endl; std::cout << "Calling Aggregation class to build subspace" < HermDefOp(Ddwf); Subspace Aggregates(Coarse5d,FGrid); // Aggregates.CreateSubspace(RNG5,HermDefOp,nbasis); assert ( (nbasis & 0x1)==0); int nb=nbasis/2; std::cout << " nbasis/2 = "< HermIndefOp(Ddwf); CoarsenedMatrix LDOp(*Coarse5d); LDOp.CoarsenOperator(FGrid,HermIndefOp,Aggregates); std::cout << "**************************************************"<< std::endl; std::cout << "Testing some coarse space solvers " < PosdefLdop(LDOp); ConjugateGradient CG(1.0e-6,100000); CG(PosdefLdop,c_src,c_res); // std::cout << "**************************************************"<< std::endl; // std::cout << "Solving indef-MCR on coarse space "<< std::endl; // std::cout << "**************************************************"<< std::endl; // HermitianLinearOperator HermIndefLdop(LDOp); // ConjugateResidual MCR(1.0e-6,100000); //MCR(HermIndefLdop,c_src,c_res); std::cout << "**************************************************"<< std::endl; std::cout << "Building deflation preconditioner "<< std::endl; std::cout << "**************************************************"<< std::endl; MultiGridPreconditioner Precon(Aggregates, LDOp,HermIndefOp,Ddwf); TrivialPrecon simple; std::cout << "**************************************************"<< std::endl; std::cout << "Testing smoother efficacy"<< std::endl; std::cout << "**************************************************"<< std::endl; Precon.SmootherTest(src); std::cout << "**************************************************"<< std::endl; std::cout << "Unprec CG "<< std::endl; std::cout << "**************************************************"<< std::endl; // TrivialPrecon simple; // ConjugateGradient fCG(1.0e-8,100000); // fCG(HermDefOp,src,result); // exit(0); std::cout << "**************************************************"<< std::endl; std::cout << "Testing GCR on indef matrix "<< std::endl; std::cout << "**************************************************"<< std::endl; // PrecGeneralisedConjugateResidual UPGCR(1.0e-8,100000,simple,8,128); // UPGCR(HermIndefOp,src,result); /// Get themax eval std::cout << "**************************************************"<< std::endl; std::cout <<" Applying power method to find spectral range "< PGCR(1.0e-8,100000,Precon,8,128); std::cout<<"checking norm src "<