From fcf1ccf669290ecb3236c5b9c4d24ce33554ccee Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 15 Jan 2018 00:17:58 +0000 Subject: [PATCH] Namespace, indent, badly formatted --- .../iterative/BlockConjugateGradient.h | 960 +++++++++--------- 1 file changed, 480 insertions(+), 480 deletions(-) diff --git a/lib/algorithms/iterative/BlockConjugateGradient.h b/lib/algorithms/iterative/BlockConjugateGradient.h index e0eeddcb..686de545 100644 --- a/lib/algorithms/iterative/BlockConjugateGradient.h +++ b/lib/algorithms/iterative/BlockConjugateGradient.h @@ -26,12 +26,12 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ -/* END LEGAL */ + /* END LEGAL */ #ifndef GRID_BLOCK_CONJUGATE_GRADIENT_H #define GRID_BLOCK_CONJUGATE_GRADIENT_H -namespace Grid { +NAMESPACE_BEGIN(Grid); enum BlockCGtype { BlockCG, BlockCGrQ, CGmultiRHS }; @@ -40,7 +40,7 @@ enum BlockCGtype { BlockCG, BlockCGrQ, CGmultiRHS }; ////////////////////////////////////////////////////////////////////////// template class BlockConjugateGradient : public OperatorFunction { - public: +public: typedef typename Field::scalar_type scomplex; @@ -59,548 +59,548 @@ class BlockConjugateGradient : public OperatorFunction { : Tolerance(tol), CGtype(cgtype), blockDim(_Orthog), MaxIterations(maxit), ErrorOnNoConverge(err_on_no_conv) {}; -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Thin QR factorisation (google it) -//////////////////////////////////////////////////////////////////////////////////////////////////// -void ThinQRfact (Eigen::MatrixXcd &m_rr, - Eigen::MatrixXcd &C, - Eigen::MatrixXcd &Cinv, - Field & Q, - const Field & R) -{ - int Orthog = blockDim; // First dimension is block dim; this is an assumption //////////////////////////////////////////////////////////////////////////////////////////////////// - //Dimensions - // R_{ferm x Nblock} = Q_{ferm x Nblock} x C_{Nblock x Nblock} -> ferm x Nblock - // - // Rdag R = m_rr = Herm = L L^dag <-- Cholesky decomposition (LLT routine in Eigen) - // - // Q C = R => Q = R C^{-1} - // - // Want Ident = Q^dag Q = C^{-dag} R^dag R C^{-1} = C^{-dag} L L^dag C^{-1} = 1_{Nblock x Nblock} - // - // Set C = L^{dag}, and then Q^dag Q = ident - // - // Checks: - // Cdag C = Rdag R ; passes. - // QdagQ = 1 ; passes + // Thin QR factorisation (google it) //////////////////////////////////////////////////////////////////////////////////////////////////// - sliceInnerProductMatrix(m_rr,R,R,Orthog); + void ThinQRfact (Eigen::MatrixXcd &m_rr, + Eigen::MatrixXcd &C, + Eigen::MatrixXcd &Cinv, + Field & Q, + const Field & R) + { + int Orthog = blockDim; // First dimension is block dim; this is an assumption + //////////////////////////////////////////////////////////////////////////////////////////////////// + //Dimensions + // R_{ferm x Nblock} = Q_{ferm x Nblock} x C_{Nblock x Nblock} -> ferm x Nblock + // + // Rdag R = m_rr = Herm = L L^dag <-- Cholesky decomposition (LLT routine in Eigen) + // + // Q C = R => Q = R C^{-1} + // + // Want Ident = Q^dag Q = C^{-dag} R^dag R C^{-1} = C^{-dag} L L^dag C^{-1} = 1_{Nblock x Nblock} + // + // Set C = L^{dag}, and then Q^dag Q = ident + // + // Checks: + // Cdag C = Rdag R ; passes. + // QdagQ = 1 ; passes + //////////////////////////////////////////////////////////////////////////////////////////////////// + sliceInnerProductMatrix(m_rr,R,R,Orthog); - // Force manifest hermitian to avoid rounding related - m_rr = 0.5*(m_rr+m_rr.adjoint()); + // Force manifest hermitian to avoid rounding related + m_rr = 0.5*(m_rr+m_rr.adjoint()); #if 0 - std::cout << " Calling Cholesky ldlt on m_rr " << m_rr < &Linop, const Field &Src, Field &Psi) -{ - if ( CGtype == BlockCGrQ ) { - BlockCGrQsolve(Linop,Src,Psi); - } else if (CGtype == BlockCG ) { - BlockCGsolve(Linop,Src,Psi); - } else if (CGtype == CGmultiRHS ) { - CGmultiRHSsolve(Linop,Src,Psi); - } else { - assert(0); + // std::cout << " Calling Cholesky llt on m_rr " < &Linop, const Field &Src, Field &Psi) + { + if ( CGtype == BlockCGrQ ) { + BlockCGrQsolve(Linop,Src,Psi); + } else if (CGtype == BlockCG ) { + BlockCGsolve(Linop,Src,Psi); + } else if (CGtype == CGmultiRHS ) { + CGmultiRHSsolve(Linop,Src,Psi); + } else { + assert(0); + } } -} -//////////////////////////////////////////////////////////////////////////// -// BlockCGrQ implementation: -//-------------------------- -// X is guess/Solution -// B is RHS -// Solve A X_i = B_i ; i refers to Nblock index -//////////////////////////////////////////////////////////////////////////// -void BlockCGrQsolve(LinearOperatorBase &Linop, const Field &B, Field &X) -{ - int Orthog = blockDim; // First dimension is block dim; this is an assumption - Nblock = B._grid->_fdimensions[Orthog]; + //////////////////////////////////////////////////////////////////////////// + // BlockCGrQ implementation: + //-------------------------- + // X is guess/Solution + // B is RHS + // Solve A X_i = B_i ; i refers to Nblock index + //////////////////////////////////////////////////////////////////////////// + void BlockCGrQsolve(LinearOperatorBase &Linop, const Field &B, Field &X) + { + int Orthog = blockDim; // First dimension is block dim; this is an assumption + Nblock = B._grid->_fdimensions[Orthog]; - std::cout< residuals(Nblock); - std::vector ssq(Nblock); + // Initial residual computation & set up + std::vector residuals(Nblock); + std::vector ssq(Nblock); - sliceNorm(ssq,B,Orthog); - RealD sssum=0; - for(int b=0;b Thin QR factorisation (google it) - * for k: - * Z = AD - * M = [D^dag Z]^{-1} - * X = X + D MC - * QS = Q - ZM - * D = Q + D S^dag - * C = S C - */ - /////////////////////////////////////// - // Initial block: initial search dir is guess - /////////////////////////////////////// - std::cout << GridLogMessage<<"BlockCGrQ algorithm initialisation " < Thin QR factorisation (google it) - - Linop.HermOp(X, AD); - tmp = B - AD; - //std::cout << GridLogMessage << " initial tmp " << norm2(tmp)<< std::endl; - ThinQRfact (m_rr, m_C, m_Cinv, Q, tmp); - //std::cout << GridLogMessage << " initial Q " << norm2(Q)<< std::endl; - //std::cout << GridLogMessage << " m_rr " << m_rr< Thin QR factorisation (google it) + * for k: + * Z = AD + * M = [D^dag Z]^{-1} + * X = X + D MC + * QS = Q - ZM + * D = Q + D S^dag + * C = S C */ - m_rr = m_C.adjoint() * m_C; + /////////////////////////////////////// + // Initial block: initial search dir is guess + /////////////////////////////////////// + std::cout << GridLogMessage<<"BlockCGrQ algorithm initialisation " < Thin QR factorisation (google it) - for(int b=0;b max_resid ) max_resid = rr; - } + Linop.HermOp(X, AD); + tmp = B - AD; + //std::cout << GridLogMessage << " initial tmp " << norm2(tmp)<< std::endl; + ThinQRfact (m_rr, m_C, m_Cinv, Q, tmp); + //std::cout << GridLogMessage << " initial Q " << norm2(Q)<< std::endl; + //std::cout << GridLogMessage << " m_rr " << m_rr< max_resid ) max_resid = rr; } - std::cout << GridLogMessage<<"\tMax residual is "< &Linop, const Field &Src, Field &Psi) + { + int Orthog = blockDim; // First dimension is block dim; this is an assumption + Nblock = Src._grid->_fdimensions[Orthog]; - if (ErrorOnNoConverge) assert(0); - IterationsToComplete = k; -} -////////////////////////////////////////////////////////////////////////// -// Block conjugate gradient; Original O'Leary Dimension zero should be the block direction -////////////////////////////////////////////////////////////////////////// -void BlockCGsolve(LinearOperatorBase &Linop, const Field &Src, Field &Psi) -{ - int Orthog = blockDim; // First dimension is block dim; this is an assumption - Nblock = Src._grid->_fdimensions[Orthog]; + std::cout< residuals(Nblock); - std::vector ssq(Nblock); + // Initial residual computation & set up + std::vector residuals(Nblock); + std::vector ssq(Nblock); - sliceNorm(ssq,Src,Orthog); - RealD sssum=0; - for(int b=0;b max_resid ) max_resid = rr; - } - - if ( max_resid < Tolerance*Tolerance ) { + int k; + for (k = 1; k <= MaxIterations; k++) { - SolverTimer.Stop(); + RealD rrsum=0; + for(int b=0;b max_resid ) max_resid = rr; } - std::cout << GridLogMessage<<"\tMax residual is "< &Linop, const Field &Src, Field &Psi) -{ - int Orthog = blockDim; // First dimension is block dim - Nblock = Src._grid->_fdimensions[Orthog]; - - std::cout< v_pAp(Nblock); - std::vector v_rr (Nblock); - std::vector v_rr_inv(Nblock); - std::vector v_alpha(Nblock); - std::vector v_beta(Nblock); - - // Initial residual computation & set up - std::vector residuals(Nblock); - std::vector ssq(Nblock); - - sliceNorm(ssq,Src,Orthog); - RealD sssum=0; - for(int b=0;b max_resid ) max_resid = rr; - } - - if ( max_resid < Tolerance*Tolerance ) { - - SolverTimer.Stop(); - - std::cout << GridLogMessage<<"MultiRHS solver converged in " < &Linop, const Field &Src, Field &Psi) + { + int Orthog = blockDim; // First dimension is block dim + Nblock = Src._grid->_fdimensions[Orthog]; - if (ErrorOnNoConverge) assert(0); - IterationsToComplete = k; -} + std::cout< v_pAp(Nblock); + std::vector v_rr (Nblock); + std::vector v_rr_inv(Nblock); + std::vector v_alpha(Nblock); + std::vector v_beta(Nblock); + + // Initial residual computation & set up + std::vector residuals(Nblock); + std::vector ssq(Nblock); + + sliceNorm(ssq,Src,Orthog); + RealD sssum=0; + for(int b=0;b max_resid ) max_resid = rr; + } + + if ( max_resid < Tolerance*Tolerance ) { + + SolverTimer.Stop(); + + std::cout << GridLogMessage<<"MultiRHS solver converged in " <