From 9246e653cd4610dfa4f6a0f73e60fa4755895d05 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Mon, 25 Sep 2023 17:20:58 -0400 Subject: [PATCH] Basic non-local coarsening of operator test --- tests/debug/Test_general_coarse.cc | 192 ++++++++--------------------- 1 file changed, 52 insertions(+), 140 deletions(-) diff --git a/tests/debug/Test_general_coarse.cc b/tests/debug/Test_general_coarse.cc index 1430ed1d..61248d6d 100644 --- a/tests/debug/Test_general_coarse.cc +++ b/tests/debug/Test_general_coarse.cc @@ -37,6 +37,9 @@ Author: Peter Boyle using namespace std; using namespace Grid; +/////////////////////// +// Tells little dirac op to use MdagM as the .Op() +/////////////////////// template class HermOpAdaptor : public LinearOperatorBase { @@ -56,81 +59,6 @@ public: void HermOp(const Field &in, Field &out){ wrapped.HermOp(in,out); } - -}; - -template -class PVdagMLinearOperator : public LinearOperatorBase { - Matrix &_Mat; - Matrix &_PV; -public: - PVdagMLinearOperator(Matrix &Mat,Matrix &PV): _Mat(Mat),_PV(PV){}; - - void OpDiag (const Field &in, Field &out) { assert(0); } - void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); } - void OpDirAll (const Field &in, std::vector &out){ assert(0); }; - void Op (const Field &in, Field &out){ - Field tmp(in.Grid()); - _Mat.M(in,tmp); - _PV.Mdag(tmp,out); - } - void AdjOp (const Field &in, Field &out){ - Field tmp(in.Grid()); - _PV.M(tmp,out); - _Mat.Mdag(in,tmp); - } - void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ assert(0); } - void HermOp(const Field &in, Field &out){ - Field tmp(in.Grid()); - _Mat.M(in,tmp); - _PV.Mdag(tmp,out); - _PV.M(out,tmp); - _Mat.Mdag(tmp,out); - } -}; - -template class DumbOperator : public LinearOperatorBase { -public: - LatticeComplex scale; - DumbOperator(GridBase *grid) : scale(grid) - { - scale = 0.0; - LatticeComplex scalesft(grid); - LatticeComplex scaletmp(grid); - for(int d=0;d<4;d++){ - Lattice > x(grid); LatticeCoordinate(x,d+1); - LatticeCoordinate(scaletmp,d+1); - scalesft = Cshift(scaletmp,d+1,1); - scale = 100.0*scale + where( mod(x ,2)==(Integer)0, scalesft,scaletmp); - } - // std::cout << " scale\n" << scale << std::endl; - } - // Support for coarsening to a multigrid - void OpDiag (const Field &in, Field &out) {}; - void OpDir (const Field &in, Field &out,int dir,int disp){}; - void OpDirAll (const Field &in, std::vector &out) {}; - - void Op (const Field &in, Field &out){ - out = scale * in; - } - void AdjOp (const Field &in, Field &out){ - out = scale * in; - } - void HermOp(const Field &in, Field &out){ - double n1, n2; - HermOpAndNorm(in,out,n1,n2); - } - void HermOpAndNorm(const Field &in, Field &out,double &n1,double &n2){ - ComplexD dot; - - out = scale * in; - - dot= innerProduct(in,out); - n1=real(dot); - - dot = innerProduct(out,out); - n2=real(dot); - } }; @@ -140,7 +68,9 @@ int main (int argc, char ** argv) const int Ls=4; - GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi()); + GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), + GridDefaultSimd(Nd,vComplex::Nsimd()), + GridDefaultMpi()); GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); @@ -151,7 +81,10 @@ int main (int argc, char ** argv) for(int d=0;d seeds4({1,2,3,4}); @@ -167,19 +100,15 @@ int main (int argc, char ** argv) LatticeFermion tmp(FGrid); LatticeFermion err(FGrid); LatticeGaugeField Umu(UGrid); - //SU::HotConfiguration(RNG4,Umu); - SU::ColdConfiguration(Umu); - // auto U = peekLorentz(Umu,0); - // Umu=Zero(); // Make operator local for now - // pokeLorentz(Umu,U,0); + SU::HotConfiguration(RNG4,Umu); + // Umu=Zero(); - RealD mass=0.5; + RealD mass=0.1; RealD M5=1.8; DomainWallFermionD Ddwf(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5); - DomainWallFermionD Dpv(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,1.0,M5); - const int nbasis = 20; + const int nbasis = 4; const int cb = 0 ; LatticeFermion prom(FGrid); @@ -187,40 +116,52 @@ int main (int argc, char ** argv) std::cout< HermDefOp(Ddwf); - DumbOperator Diagonal(FGrid); - typedef Aggregation Subspace; + /////////////////////////////////////////////////// + // Random aggregation space + /////////////////////////////////////////////////// + std::cout< Subspace; Subspace Aggregates(Coarse5d,FGrid,cb); Aggregates.CreateSubspaceRandom(RNG5); - std::cout< LittleDiracOperator; typedef LittleDiracOperator::CoarseVector CoarseVector; - NextToNearestStencilGeometry5D geom; + NextToNearestStencilGeometry5D geom(Coarse5d); LittleDiracOperator LittleDiracOp(geom,FGrid,Coarse5d); - LittleDiracOp.CoarsenOperator(HermDefOp,Aggregates); - // LittleDiracOp.CoarsenOperator(Diagonal,Aggregates); + LittleDiracOperator LittleDiracOpCol(geom,FGrid,Coarse5d); - std::cout< HOA(HermDefOp); + + int pp=16; + // LittleDiracOpCol.CoarsenOperator(HOA,Aggregates); + // std::cout << "LittleDiracOp old " << LittleDiracOpCol._A[pp]< PVdagM(Ddwf,Dpv); - HermOpAdaptor HOA(PVdagM); - - // Run power method on HOA?? - PowerMethod PM; PM(HOA,src); - - // Warning: This routine calls PVdagM.Op, not PVdagM.HermOp - Subspace AggregatesPD(Coarse5d,FGrid,cb); - AggregatesPD.CreateSubspaceChebyshev(RNG5, - HOA, - nbasis, - 5000.0, - 0.02, - 100, - 50, - 50, - 0.0); - - LittleDiracOperator LittleDiracOpPV(geom,FGrid,Coarse5d); - LittleDiracOpPV.CoarsenOperator(PVdagM,AggregatesPD); - - std::cout<