/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./tests/Test_dwf_hdcr.cc Copyright (C) 2015 Author: Daniel Richtmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ #include // #include //#include using namespace std; using namespace Grid; using namespace Grid::QCD; template class TestVectorAnalyzer { public: void operator()(LinearOperatorBase &Linop, std::vector const & vectors) { // this function corresponds to testvector_analysis_PRECISION from the // DD-αAMG codebase std::vector tmp(4, vectors[0]._grid); // bit hacky? Gamma g5(Gamma::Algebra::Gamma5); std::cout << GridLogMessage << "Test vector analysis:" << std::endl; for (auto i = 0; i < vectors.size(); ++i) { Linop.Op(vectors[i], tmp[3]); tmp[0] = g5 * tmp[3]; // is this the same as coarse_gamma5_PRECISION? auto lambda = innerProduct(vectors[i], tmp[0]) / innerProduct(vectors[i], vectors[i]); tmp[1] = tmp[0] - lambda * vectors[i]; auto mu = ::sqrt(norm2(tmp[1]) / norm2(vectors[i])); std::cout << GridLogMessage << std::setprecision(2) << "vector " << i << ": " << "singular value: " << lambda << " singular vector precision: " << mu << std::endl; } } }; class myclass: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(myclass, int, domaindecompose, int, domainsize, int, order, int, Ls, double, mq, double, lo, double, hi, int, steps); myclass(){}; }; myclass params; 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 & _FineMatrix; FineOperator & _FineOperator; Matrix & _SmootherMatrix; FineOperator & _SmootherOperator; // Constructor MultiGridPreconditioner(Aggregates &Agg, CoarseOperator &Coarse, FineOperator &Fine,Matrix &FineMatrix, FineOperator &Smooth,Matrix &SmootherMatrix) : _Aggregates(Agg), _CoarseOperator(Coarse), _FineOperator(Fine), _FineMatrix(FineMatrix), _SmootherOperator(Smooth), _SmootherMatrix(SmootherMatrix) { } void PowerMethod(const FineField &in) { FineField p1(in._grid); FineField p2(in._grid); MdagMLinearOperator fMdagMOp(_FineMatrix); 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< CG(1.0e-10,100000); ConjugateGradient fCG(3.0e-2,1000); HermitianLinearOperator HermOp(_CoarseOperator); MdagMLinearOperator MdagMOp(_CoarseOperator); MdagMLinearOperator fMdagMOp(_FineMatrix); 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< CG(1.0e-10,100000); ConjugateGradient fCG(3.0e-2,1000); HermitianLinearOperator HermOp(_CoarseOperator); MdagMLinearOperator MdagMOp(_CoarseOperator); ShiftedMdagMLinearOperator fMdagMOp(_FineMatrix,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< > coor(src._grid); Lattice > subset(src._grid); FineField r(src._grid); FineField zz(src._grid); zz=zero; FineField vec1(src._grid); FineField vec2(src._grid); const Integer block=params.domainsize; subset=zero; for(int mu=0;mu fMdagMOp(_SmootherMatrix,0.0); Chebyshev Cheby (params.lo,params.hi,params.order,InverseApproximation); RealD resid; for(int i=0;i fMdagMOp(_FineMatrix); ShiftedMdagMLinearOperator fMdagMOp(_SmootherMatrix,0.0); RealD Ni,r; Ni = norm2(in); for(int ilo=0;ilo<3;ilo++){ for(int ord=5;ord<50;ord*=2){ _SmootherOperator.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< CG(3.0e-3,100000); // ConjugateGradient fCG(3.0e-2,1000); HermitianLinearOperator HermOp(_CoarseOperator); MdagMLinearOperator MdagMOp(_CoarseOperator); // MdagMLinearOperator fMdagMOp(_FineMatrix); ShiftedMdagMLinearOperator fMdagMOp(_SmootherMatrix,0.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 (params.lo,params.hi,params.order,InverseApproximation); Chebyshev ChebyAccu(params.lo,params.hi,params.order,InverseApproximation); // Cheby.JacksonSmooth(); // ChebyAccu.JacksonSmooth(); // _Aggregates.ProjectToSubspace (Csrc,in); // _Aggregates.PromoteFromSubspace(Csrc,out); // std::cout< CG(1.0e-3,100000); HermitianLinearOperator HermOp(_CoarseOperator); MdagMLinearOperator MdagMOp(_CoarseOperator); FineField vec1(in._grid); FineField vec2(in._grid); _Aggregates.ProjectToSubspace (Csrc,in); _Aggregates.PromoteFromSubspace(Csrc,out); std::cout< blockSize({2,2,2,2}); const int nbasis= 16; std::vector cLattSize = GridDefaultLatt(); for(int d=0;d seedsFine({1,2,3,4}); std::vector seedsCoarse({5,6,7,8}); GridParallelRNG pRNGFine(FGrid); pRNGFine.SeedFixedIntegers(seedsFine); GridParallelRNG pRNGCoarse(CGrid); pRNGCoarse.SeedFixedIntegers(seedsCoarse); Gamma g5(Gamma::Algebra::Gamma5); LatticeFermion src(FGrid); gaussian(pRNGFine,src);// src=src+g5*src; LatticeFermion result(FGrid); result=zero; LatticeFermion ref(FGrid); ref=zero; LatticeFermion tmp(FGrid); LatticeFermion err(FGrid); LatticeGaugeField Umu(FGrid); SU3::HotConfiguration(pRNGFine,Umu); LatticeGaugeField UmuDD(FGrid); LatticeColourMatrix U(FGrid); LatticeColourMatrix zz(FGrid); if ( params.domaindecompose ) { Lattice > coor(FGrid); zz=zero; for(int mu=0;mu(Umu,mu); U = where(mod(coor,params.domainsize)==(Integer)0,zz,U); PokeIndex(UmuDD,U,mu); } } else { UmuDD = Umu; } RealD mass=params.mq; std::cout< Subspace; typedef CoarsenedMatrix CoarseOperator; typedef CoarseOperator::CoarseVector CoarseVector; std::cout< HermOp(Dw); Subspace Aggregates(CGrid,FGrid,0); assert ((nbasis & 0x1)==0); int nb=nbasis/2; std::cout< Blah(Dw); Gamma5HermitianLinearOperator BlahDD(DwDD); CoarsenedMatrix LDOp(*CGrid); LDOp.CoarsenOperator(FGrid,Blah,Aggregates); // problem with this line since it enforces hermiticity std::cout< PosdefLdop(LDOp); // ConjugateGradient CG(1.0e-6,100000); // // CG(PosdefLdop,c_src,c_res); // // std::cout< HermIndefLdop(LDOp); // // ConjugateResidual MCR(1.0e-6,100000); // //MCR(HermIndefLdop,c_src,c_res); std::cout< Precon (Aggregates, LDOp, Blah,Dw, BlahDD,DwDD); MultiGridPreconditioner PreconDD(Aggregates, LDOp, Blah,Dw, BlahDD,DwDD); // MultiGridPreconditioner(Aggregates &Agg, CoarseOperator &Coarse, // FineOperator &Fine,Matrix &FineMatrix, // FineOperator &Smooth,Matrix &SmootherMatrix) TrivialPrecon simple; Grid_finalize(); }