From e0543e8af5bfd07fa9b02824baa3c15366b73961 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Wed, 15 Nov 2023 17:57:39 -0500 Subject: [PATCH] Implement flexible preconditioned CG --- Grid/algorithms/iterative/AdefGeneric.h | 160 ++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/Grid/algorithms/iterative/AdefGeneric.h b/Grid/algorithms/iterative/AdefGeneric.h index 2157dd5e..4344dfa7 100644 --- a/Grid/algorithms/iterative/AdefGeneric.h +++ b/Grid/algorithms/iterative/AdefGeneric.h @@ -69,6 +69,7 @@ class TwoLevelCG : public LinearFunction virtual void operator() (const Field &src, Field &x) { +#if 0 Field resid(grid); RealD f; RealD rtzp,rtz,a,d,b; @@ -113,6 +114,7 @@ class TwoLevelCG : public LinearFunction RealD ssq = norm2(src); RealD rsq = ssq*Tolerance*Tolerance; + GRID_TRACE("MultiGrid TwoLevel "); std::cout< std::cout< p(mmax,grid); + std::vector mmp(mmax,grid); + std::vector pAp(mmax); + Field z(grid); + Field tmp(grid); + Field mp (grid); + Field r (grid); + Field mu (grid); + + //Initial residual computation & set up + RealD guess = norm2(x); + RealD src_nrm = norm2(src); + + if ( src_nrm == 0.0 ) { + std::cout << GridLogMessage<<"HDCG: fPcg given trivial source norm "< z + b p ; b = + b = (rtzp)/rtz; + + int northog; + // k=zero <=> peri_kp=1; northog = 1 + // k=1 <=> peri_kp=2; northog = 2 + // ... ... ... + // k=mmax-2<=> peri_kp=mmax-1; northog = mmax-1 + // k=mmax-1<=> peri_kp=0; northog = 1 + + // northog = (peri_kp==0)?1:peri_kp; // This is the fCG(mmax) algorithm + northog = (k>mmax-1)?(mmax-1):k; // This is the fCG-Tr(mmax-1) algorithm + + std::cout< virtual void PcgM1(Field & in, Field & out) { + GRID_TRACE("MultiGridPreconditioner "); // [PTM+Q] in = [1 - Q A] M in + Q in = Min + Q [ in -A Min] Field tmp(this->grid); @@ -334,6 +493,7 @@ public: // Override PcgM1 virtual void PcgM1(Field & in, Field & out) { + GRID_TRACE("EvecPreconditioner "); int N=evec.size(); Field Pin(this->grid); Field Qin(this->grid);