/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./tests/Test_padded_cell.cc Copyright (C) 2023 Author: Peter Boyle 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 #include #include #include using namespace std; using namespace Grid; template class MGPreconditioner : public LinearFunction< Lattice > { public: using LinearFunction >::operator(); typedef Aggregation Aggregates; typedef typename Aggregation::FineField FineField; typedef typename Aggregation::CoarseVector CoarseVector; typedef typename Aggregation::CoarseMatrix CoarseMatrix; typedef LinearOperatorBase FineOperator; typedef LinearFunction FineSmoother; typedef LinearOperatorBase CoarseOperator; typedef LinearFunction CoarseSolver; Aggregates & _Aggregates; FineOperator & _FineOperator; FineSmoother & _PreSmoother; FineSmoother & _PostSmoother; CoarseOperator & _CoarseOperator; CoarseSolver & _CoarseSolve; int level; void Level(int lv) {level = lv; }; MGPreconditioner(Aggregates &Agg, FineOperator &Fine, FineSmoother &PreSmoother, FineSmoother &PostSmoother, CoarseOperator &CoarseOperator_, CoarseSolver &CoarseSolve_) : _Aggregates(Agg), _FineOperator(Fine), _PreSmoother(PreSmoother), _PostSmoother(PostSmoother), _CoarseOperator(CoarseOperator_), _CoarseSolve(CoarseSolve_), level(1) { } virtual void operator()(const FineField &in, FineField & out) { GridBase *CoarseGrid = _Aggregates.CoarseGrid; // auto CoarseGrid = _CoarseOperator.Grid(); CoarseVector Csrc(CoarseGrid); CoarseVector Csol(CoarseGrid); FineField vec1(in.Grid()); FineField vec2(in.Grid()); std::cout< seeds4({1,2,3,4}); std::vector cseeds({5,6,7,8}); GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4); GridParallelRNG CRNG(Coarse4d);CRNG.SeedFixedIntegers(cseeds); Complex one(1.0); LatticeFermion src(FGrid); src=one; LatticeFermion result(FGrid); result=Zero(); LatticeFermion ref(FGrid); ref=Zero(); LatticeFermion tmp(FGrid); LatticeFermion err(FGrid); LatticeFermion precsrc(FGrid); LatticeGaugeField Umu(UGrid); FieldMetaData header; std::string file("ckpoint_lat"); NerscIO::readConfiguration(Umu,header,file); RealD csw =0.0; RealD mass=-0.92; WilsonCloverFermionD Dw(Umu,*UGrid,*UrbGrid,mass,csw,csw); const int nbasis = 20; const int cb = 0 ; LatticeFermion prom(FGrid); typedef GeneralCoarsenedMatrix LittleDiracOperator; typedef LittleDiracOperator::CoarseVector CoarseVector; NearestStencilGeometry4D geom(Coarse4d); std::cout< Subspace; Subspace Aggregates(Coarse4d,FGrid,cb); NonHermitianLinearOperator LinOpDw(Dw); ShiftedNonHermitianLinearOperator ShiftedLinOpDw(Dw,0.01); Aggregates.CreateSubspaceGCR(RNG4, LinOpDw, nbasis); typedef Aggregation CombinedSubspace; CombinedSubspace CombinedUV(Coarse4d,UGrid,cb); for(int b=0;b subspace(2*nbasis,FGrid); subspace=CombinedUV.subspace; c_src = one; // 1 in every element for vector 1. blockPromote(c_src,err,subspace); prom=Zero(); for(int b=0;b<2*nbasis;b++){ prom=prom+subspace[b]; } err=err-prom; std::cout< HermOp(Dw); ConjugateGradient CG(1.0e-8,10000); Dw.Mdag(src,precsrc); CG(HermOp,precsrc,result); result=Zero(); } /////////////////////////////////////// // Coarse grid solver test /////////////////////////////////////// std::cout< simple; NonHermitianLinearOperator LinOpCoarse(LittleDiracOp); ShiftedNonHermitianLinearOperator ShiftedLinOpCoarse(LittleDiracOp,0.001); // ShiftedNonHermitianLinearOperator ShiftedLinOpCoarse(LittleDiracOp,0.01); // ShiftedNonHermitianLinearOperator ShiftedLinOpCoarse(LinOpCoarse,0.001); // PrecGeneralisedConjugateResidualNonHermitian L2PGCR(1.0e-4, 100, LinOpCoarse,simple,10,10); // PrecGeneralisedConjugateResidualNonHermitian L2PGCR(1.0e-1, 100, LinOpCoarse,simple,30,30); PrecGeneralisedConjugateResidualNonHermitian L2PGCR(2.0e-1, 50, ShiftedLinOpCoarse,simple,50,50); L2PGCR.Level(3); c_res=Zero(); L2PGCR(c_src,c_res); //////////////////////////////////////// // Fine grid smoother //////////////////////////////////////// std::cout< simple_fine; PrecGeneralisedConjugateResidualNonHermitian SmootherGCR(0.1,1,ShiftedLinOpDw,simple_fine,4,4); SmootherGCR.Level(2); LatticeFermionD f_src(FGrid); LatticeFermionD f_res(FGrid); f_src = one; // 1 in every element for vector 1. f_res=Zero(); SmootherGCR(f_src,f_res); typedef MGPreconditioner TwoLevelMG; TwoLevelMG TwoLevelPrecon(CombinedUV, LinOpDw, simple_fine, SmootherGCR, LinOpCoarse, L2PGCR); PrecGeneralisedConjugateResidualNonHermitian L1PGCR(1.0e-8,1000,LinOpDw,TwoLevelPrecon,16,16); L1PGCR.Level(1); f_res=Zero(); L1PGCR(f_src,f_res); std::cout<