/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./tests/Test_dwf_compressed_lanczos_reorg.cc Copyright (C) 2017 Author: Leans heavily on Christoph Lehner's code 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 */ /* * Reimplement the badly named "multigrid" lanczos as compressed Lanczos using the features * in Grid that were intended to be used to support blocked Aggregates, from */ #include #include using namespace std; using namespace Grid; ; template class ProjectedHermOp : public LinearFunction > > { public: using LinearFunction > >::operator(); typedef iVector CoarseSiteVector; typedef Lattice CoarseField; typedef Lattice CoarseScalar; // used for inner products on fine field typedef Lattice FineField; LinearOperatorBase &_Linop; Aggregation &_Aggregate; ProjectedHermOp(LinearOperatorBase& linop, Aggregation &aggregate) : _Linop(linop), _Aggregate(aggregate) { }; void operator()(const CoarseField& in, CoarseField& out) { GridBase *FineGrid = _Aggregate.FineGrid; FineField fin(FineGrid); FineField fout(FineGrid); _Aggregate.PromoteFromSubspace(in,fin); _Linop.HermOp(fin,fout); _Aggregate.ProjectToSubspace(out,fout); } }; template class ProjectedFunctionHermOp : public LinearFunction > > { public: using LinearFunction > >::operator (); typedef iVector CoarseSiteVector; typedef Lattice CoarseField; typedef Lattice CoarseScalar; // used for inner products on fine field typedef Lattice FineField; OperatorFunction & _poly; LinearOperatorBase &_Linop; Aggregation &_Aggregate; ProjectedFunctionHermOp(OperatorFunction & poly,LinearOperatorBase& linop, Aggregation &aggregate) : _poly(poly), _Linop(linop), _Aggregate(aggregate) { }; void operator()(const CoarseField& in, CoarseField& out) { GridBase *FineGrid = _Aggregate.FineGrid; FineField fin(FineGrid) ;fin.Checkerboard() =_Aggregate.Checkerboard(); FineField fout(FineGrid);fout.Checkerboard() =_Aggregate.Checkerboard(); _Aggregate.PromoteFromSubspace(in,fin); _poly(_Linop,fin,fout); _Aggregate.ProjectToSubspace(out,fout); } }; // Make serializable Lanczos params template class CoarseFineIRL { public: typedef iVector CoarseSiteVector; typedef Lattice CoarseScalar; // used for inner products on fine field typedef Lattice CoarseField; typedef Lattice FineField; private: GridBase *_CoarseGrid; GridBase *_FineGrid; int _checkerboard; LinearOperatorBase & _FineOp; Aggregation _Aggregate; public: CoarseFineIRL(GridBase *FineGrid, GridBase *CoarseGrid, LinearOperatorBase &FineOp, int checkerboard) : _CoarseGrid(CoarseGrid), _FineGrid(FineGrid), _Aggregate(CoarseGrid,FineGrid,checkerboard), _FineOp(FineOp), _checkerboard(checkerboard) {}; template static RealD normalise(T& v) { RealD nn = norm2(v); nn = ::sqrt(nn); v = v * (1.0/nn); return nn; } void testFine(void) { int Nk = nbasis; _Aggregate.subspace.resize(Nk,_FineGrid); _Aggregate.subspace[0]=1.0; _Aggregate.subspace[0].Checkerboard()=_checkerboard; normalise(_Aggregate.subspace[0]); PlainHermOp Op(_FineOp); for(int k=1;k Cheby(alpha,beta,Npoly); FunctionHermOp ChebyOp(Cheby,_FineOp); PlainHermOp Op(_FineOp); int Nk = nbasis; std::vector eval(Nm); FineField src(_FineGrid); src=1.0; src.Checkerboard() = _checkerboard; ImplicitlyRestartedLanczos IRL(ChebyOp,Op,Nk,Nk,Nm,resid,MaxIt,betastp,MinRes); _Aggregate.subspace.resize(Nm,_FineGrid); IRL.calc(eval,_Aggregate.subspace,src,Nk,false); _Aggregate.subspace.resize(Nk,_FineGrid); for(int k=0;k Cheby(alpha,beta,Npoly); ProjectedHermOp Op(_FineOp,_Aggregate); ProjectedFunctionHermOp ChebyOp(Cheby,_FineOp,_Aggregate); std::vector eval(Nm); std::vector evec(Nm,_CoarseGrid); CoarseField src(_CoarseGrid); src=1.0; ImplicitlyRestartedLanczos IRL(ChebyOp,ChebyOp,Nk,Nk,Nm,resid,MaxIt,betastp,MinRes); IRL.calc(eval,evec,src,Nk,false); // We got the evalues of the Cheby operator; // Reconstruct eigenvalues of original operator via Chebyshev inverse for (int i=0;i, blockSize, std::string, config, std::vector < ComplexD >, omega, RealD, mass, RealD, M5 ); }; int main (int argc, char ** argv) { Grid_init(&argc,&argv); CompressedLanczosParams Params; { Params.omega.resize(10); Params.blockSize.resize(5); XmlWriter writer("Params_template.xml"); write(writer,"Params",Params); std::cout << GridLogMessage << " Written Params_template.xml" < blockSize = Params.blockSize; // Grids GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi()); GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid); Coordinate fineLatt = GridDefaultLatt(); int dims=fineLatt.size(); assert(blockSize.size()==dims+1); Coordinate coarseLatt(dims); Coordinate coarseLatt5d ; for (int d=0;d seeds4({1,2,3,4}); GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4); SU::HotConfiguration(RNG4, Umu); } std::cout << GridLogMessage << "Lattice dimensions: " << GridDefaultLatt() << " Ls: " << Ls << std::endl; // ZMobius EO Operator ZMobiusFermionD Ddwf(Umu, *FGrid, *FrbGrid, *UGrid, *UrbGrid, mass, M5, Params.omega,1.,0.); SchurDiagTwoOperator HermOp(Ddwf); // Eigenvector storage LanczosParams fine =Params.FineParams; LanczosParams coarse=Params.CoarseParams; const int Nm1 = fine.Nm; const int Nm2 = coarse.Nm; std::cout << GridLogMessage << "Keep " << fine.Nk << " full vectors" << std::endl; std::cout << GridLogMessage << "Keep " << coarse.Nk << " total vectors" << std::endl; assert(Nm2 >= Nm1); const int nbasis= 32; CoarseFineIRL IRL(FrbGrid,CoarseGrid5rb,HermOp,Odd); std::cout << GridLogMessage << "Constructed CoarseFine IRL" << std::endl; std::cout << GridLogMessage << "Performing fine grid IRL Nk "<< nbasis<<" Nm "<