From cdff2c8e18323316a284af85056c658fc8c4202c Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Wed, 21 Feb 2024 14:27:19 -0500 Subject: [PATCH] Updated mrhs adef --- Grid/algorithms/iterative/AdefGeneric.h | 93 ++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 10 deletions(-) diff --git a/Grid/algorithms/iterative/AdefGeneric.h b/Grid/algorithms/iterative/AdefGeneric.h index 474a6b1d..cc9d2e10 100644 --- a/Grid/algorithms/iterative/AdefGeneric.h +++ b/Grid/algorithms/iterative/AdefGeneric.h @@ -41,6 +41,7 @@ Author: Peter Boyle */ NAMESPACE_BEGIN(Grid); + template class TwoLevelCG : public LinearFunction { @@ -278,9 +279,9 @@ class TwoLevelCG : public LinearFunction ////////////////////////// // x0 = Vstart -- possibly modify guess ////////////////////////// - for(int rhs=0;rhs virtual void PcgM1(std::vector & in,std::vector & out) { - std::cout << "PcgM1 default (cheat) mrhs versoin"<PcgM1(in[rhs],out[rhs]); } } virtual void PcgM1(Field & in, Field & out) =0; + virtual void Vstart(std::vector & x,std::vector & src) + { + std::cout << "Vstart default (cheat) mrhs version"<Vstart(x[rhs],src[rhs]); + } + } virtual void Vstart(Field & x,const Field & src)=0; virtual void PcgM2(const Field & in, Field & out) { @@ -536,24 +544,67 @@ class TwoLevelADEF2mrhs : public TwoLevelADEF2 public: GridBase *coarsegridmrhs; LinearFunction &_CoarseSolverMrhs; + LinearFunction &_CoarseSolverPreciseMrhs; LinearFunction &_CoarseGuesser; TwoLevelADEF2mrhs(RealD tol, Integer maxit, LinearOperatorBase &FineLinop, LinearFunction &Smoother, - LinearFunction &CoarseSolver, - LinearFunction &CoarseSolverPrecise, + // LinearFunction &CoarseSolver, + // LinearFunction &CoarseSolverPrecise, LinearFunction &CoarseSolverMrhs, + LinearFunction &CoarseSolverPreciseMrhs, LinearFunction &CoarseGuesser, GridBase *rhsgrid, Aggregation &Aggregates) : - TwoLevelADEF2(tol, maxit,FineLinop,Smoother,CoarseSolver,CoarseSolverPrecise,Aggregates), + TwoLevelADEF2(tol, maxit,FineLinop,Smoother,CoarseSolverMrhs,CoarseSolverPreciseMrhs,Aggregates), _CoarseSolverMrhs(CoarseSolverMrhs), + _CoarseSolverPreciseMrhs(CoarseSolverPreciseMrhs), _CoarseGuesser(CoarseGuesser) { coarsegridmrhs = rhsgrid; }; - + + virtual void Vstart(std::vector & x,std::vector & src) + { + int nrhs=x.size(); + std::cout << GridLogMessage<<"HDCG: fPcg Vstart for "<coarsegrid); + CoarseField PleftMss_proj(this->coarsegrid); + + CoarseField PleftProjMrhs(this->coarsegridmrhs); + CoarseField PleftMss_projMrhs(this->coarsegridmrhs); + + std::cout << GridLogMessage<<"HDCG: fPcg Vstart Mrhs projecting "<_Aggregates.ProjectToSubspace(PleftProj,src[rhs]); // can optimise later + InsertSliceFast(PleftProj,PleftProjMrhs,rhs,0); + this->_CoarseGuesser(PleftProj,PleftMss_proj); + InsertSliceFast(PleftMss_proj,PleftMss_projMrhs,rhs,0); + } + + std::cout << GridLogMessage<<"HDCG: fPcg Vstart Mrhs coarse solve "<_CoarseSolverPreciseMrhs(PleftProjMrhs,PleftMss_projMrhs); // Ass^{-1} r_s + + std::cout << GridLogMessage<<"HDCG: fPcg Vstart promote "<_Aggregates.PromoteFromSubspace(PleftMss_proj,x[rhs]); + } + } + virtual void PcgM1(std::vector & in,std::vector & out){ int nrhs=in.size(); @@ -570,13 +621,35 @@ public: CoarseField PleftMss_projMrhs(this->coarsegridmrhs); std::cout << " mrhs Coarse ops "<_Smoother(in[rhs],Min[rhs]); + + std::cout << GridLogMessage<<" HermOp for "<_FineLinop.HermOp(Min[rhs],out[rhs]); + axpy(tmp,-1.0,out[rhs],in[rhs]); // tmp = in - A Min - this->_Aggregates.ProjectToSubspace(PleftProj,tmp); // can optimise later + + // Was + // this->_Aggregates.ProjectToSubspace(PleftProj,tmp); // can optimise later + // Now: + std::cout << GridLogMessage<<" blockProject for "<_Aggregates.subspace); + + std::cout << GridLogMessage<<" InsertSlice for "<_CoarseGuesser(PleftProj,PleftMss_proj); + + std::cout << GridLogMessage<<" InsertSlice for "<_Aggregates.PromoteFromSubspace(PleftMss_proj,tmp);// tmp = Q[in - A Min] // std::cout << " add for "<