/************************************************************************************* 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 */ // copied here from Test_general_coarse_pvdagm.cc #include #include #include #include #include #include #include using namespace std; using namespace Grid; // Hermitize a DWF operator by squaring it template class SquaredLinearOperator : public LinearOperatorBase { public: Matrix &_Mat; public: SquaredLinearOperator(Matrix &Mat): _Mat(Mat) {}; 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){ // std::cout << "Op is overloaded as HermOp" << std::endl; HermOp(in, out); } void AdjOp (const Field &in, Field &out){ HermOp(in, out); } void _Op (const Field &in, Field &out){ // std::cout << "Op: M "< 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){ std::cout << "Op: PVdag M "< class ShiftedPVdagMLinearOperator : public LinearOperatorBase { Matrix &_Mat; Matrix &_PV; RealD shift; public: ShiftedPVdagMLinearOperator(RealD _shift,Matrix &Mat,Matrix &PV): shift(_shift),_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){ std::cout << "Op: PVdag M "< class ShiftedComplexPVdagMLinearOperator : public LinearOperatorBase { Matrix &_Mat; Matrix &_PV; ComplexD shift; public: ShiftedComplexPVdagMLinearOperator(ComplexD _shift,Matrix &Mat,Matrix &PV): shift(_shift),_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){ std::cout << "Op: PVdag M "< 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< lat_size {16, 16, 16, 32}; std::cout << "Lattice size: " << lat_size << std::endl; GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(lat_size, GridDefaultSimd(Nd,vComplex::Nsimd()), GridDefaultMpi()); GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid); // Construct a coarsened grid // poare TODO: replace this with the following line? Coordinate clatt = lat_size; // Coordinate clatt = GridDefaultLatt(); // [PO] initial line before I edited it 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); LatticeFermion src(FGrid); random(RNG5,src); LatticeFermion result(FGrid); result=Zero(); LatticeFermion ref(FGrid); ref=Zero(); LatticeFermion tmp(FGrid); LatticeFermion err(FGrid); LatticeGaugeField Umu(UGrid); FieldMetaData header; // std::string file("ckpoint_lat.4000"); std::string file("/Users/patrickoare/libraries/PETSc-Grid/ckpoint_lat.4000"); NerscIO::readConfiguration(Umu,header,file); RealD mass=0.01; 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; // size of approximate basis for low-mode space const int nbasis = 3; // size of approximate basis for low-mode space const int cb = 0 ; LatticeFermion prom(FGrid); typedef GeneralCoarsenedMatrix LittleDiracOperator; typedef LittleDiracOperator::CoarseVector CoarseVector; NextToNearestStencilGeometry5D geom(Coarse5d); std::cout< PVdagM_t; typedef ShiftedPVdagMLinearOperator ShiftedPVdagM_t; typedef ShiftedComplexPVdagMLinearOperator ShiftedComplexPVdagM_t; PVdagM_t PVdagM(Ddwf, Dpv); ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); SquaredLinearOperator Dsq (Ddwf); NonHermitianLinearOperator DLinOp (Ddwf); // PowerMethod PM; PM(PVdagM, src); int Nm = 10; int Nk = 6; // int Nm = 6; // Nm = 6 case is acting really strangely... with Nm = 6 and Nm = 3 it zeros out the Hessenberg and also makes it imaginary? // int Nk = 2; // int Nk = Nm+1; // if just running once // int maxIter = 5; // int maxIter = 1; int maxIter = 3; // int maxIter = 100; int Nstop = 6; Coordinate origin ({0,0,0,0}); auto tmpSrc = peekSite(src, origin); std::cout << "[DEBUG] Source at origin = " << tmpSrc << std::endl; LatticeFermion src2 = src; // Run Lanczos and Arnoldi on a Hermitian matrix // Arnoldi Arn (Dsq, FGrid, 1e-8, false); // Arn(src, 1, Nm, -1); Arnoldi Arn (Dsq, FGrid, 1e-8, EvalNormLarge); // for comparison to Lanczos // Arn(src, maxIter, Nm, Nk, Nstop); // auto tmpSrcDup = peekSite(src, origin); // std::cout << "[DEBUG] Source at origin = " << tmpSrcDup << std::endl; // auto tmpSrc2Dup = peekSite(src2, origin); // std::cout << "[DEBUG] Source2 at origin = " << tmpSrc2Dup << std::endl; Arn(src, maxIter, Nm, Nk, Nstop); std::cout << "Hessenberg mat for symmetric N = " << Nm << std::endl; std::cout << Arn.getHessenbergMat() << std::endl; // ImplicitlyRestartedLanczosHermOpTester SimpleTester (Dsq); // ImplicitlyRestartedLanczos Lanc (Dsq, Dsq, SimpleTester, Nm, Nm, Nm, 1e-8, Nm); int Nconv; PlainHermOp DsqHermOp (Dsq); // std::vector levals (Nm+1); std::vector levecs (Nm+1, src); // ImplicitlyRestartedLanczos Lanc (DsqHermOp, DsqHermOp, Nm, Nm, Nm + 1, 1e-8, Nm); std::vector levals (Nm+1); std::vector levecs (Nm, src); ImplicitlyRestartedLanczos Lanc (DsqHermOp, DsqHermOp, Nstop, Nk, Nm, 1e-8, maxIter); std::cout << GridLogMessage << "Calculating with Lanczos" << std::endl; // auto tmpSrc1 = peekSite(src, origin); // std::cout << "[DEBUG] Source at origin = " << tmpSrc1 << std::endl; // auto tmpSrc2 = peekSite(src2, origin); // std::cout << "[DEBUG] Source2 at origin = " << tmpSrc2 << std::endl; // std::cout << "[DEBUG] Source norm2: " << norm2(src) << std::endl; std::cout << "running Lanczos now" << std::endl; Lanc.calc(levals, levecs, src2, Nconv); std::cout<