00001 // -*- C++ -*- 00002 // $Id: syssolver_mdagm_eigcg_qdp.h,v 3.2 2009/06/02 15:56:40 bjoo Exp $ 00003 /*! \file 00004 * \brief Solve a M^dag*M*psi=chi linear system by EigCG 00005 */ 00006 00007 #ifndef __syssolver_mdagm_eigcg_qdp_h__ 00008 #define __syssolver_mdagm_eigcg_qdp_h__ 00009 00010 #include "handle.h" 00011 #include "syssolver.h" 00012 #include "linearop.h" 00013 #include "lmdagm.h" 00014 #include "named_obj.h" 00015 #include "meas/inline/io/named_objmap.h" 00016 00017 #include "actions/ferm/invert/syssolver_mdagm.h" 00018 #include "actions/ferm/invert/syssolver_eigcg_params.h" 00019 #include "actions/ferm/invert/containers.h" 00020 00021 namespace Chroma 00022 { 00023 00024 //! Eigenvector accelerated CG system solver namespace 00025 namespace MdagMSysSolverQDPEigCGEnv 00026 { 00027 //! Register the syssolver 00028 bool registerAll(); 00029 } 00030 00031 00032 //! Solve a M*psi=chi linear system by CG2 with eigenvectors 00033 /*! \ingroup invert 00034 */ 00035 template<typename T> 00036 class MdagMSysSolverQDPEigCG : public MdagMSystemSolver<T> 00037 { 00038 public: 00039 //! Constructor 00040 /*! 00041 * \param M_ Linear operator ( Read ) 00042 * \param invParam_ inverter parameters ( Read ) 00043 */ 00044 MdagMSysSolverQDPEigCG(Handle< LinearOperator<T> > A_, 00045 const SysSolverEigCGParams& invParam_) : 00046 MdagM(new MdagMLinOp<T>(A_)), A(A_), invParam(invParam_) 00047 { 00048 // NEED to grab the eignvectors from the named buffer here 00049 if (! TheNamedObjMap::Instance().check(invParam.eigen_id)) 00050 { 00051 TheNamedObjMap::Instance().create< LinAlg::RitzPairs<T> >(invParam.eigen_id); 00052 LinAlg::RitzPairs<T>& GoodEvecs = 00053 TheNamedObjMap::Instance().getData< LinAlg::RitzPairs<T> >(invParam.eigen_id); 00054 00055 if(invParam.Neig_max>0 ){ 00056 GoodEvecs.init(invParam.Neig_max); 00057 } 00058 else{ 00059 GoodEvecs.init(invParam.Neig); 00060 } 00061 } 00062 } 00063 00064 //! Destructor is automatic 00065 ~MdagMSysSolverQDPEigCG() 00066 { 00067 if (invParam.cleanUpEvecs) 00068 { 00069 TheNamedObjMap::Instance().erase(invParam.eigen_id); 00070 } 00071 } 00072 00073 //! Return the subset on which the operator acts 00074 const Subset& subset() const {return A->subset();} 00075 00076 //! Solver the linear system 00077 /*! 00078 * \param psi solution ( Modify ) 00079 * \param chi source ( Read ) 00080 * \return syssolver results 00081 * 00082 * Definitions supplied in the correspond .cc file 00083 */ 00084 SystemSolverResults_t operator() (T& psi, const T& chi) const; 00085 00086 00087 //! Solve the linear system starting with a chrono guess 00088 /*! 00089 * \param psi solution (Write) 00090 * \param chi source (Read) 00091 * \param predictor a chronological predictor (Read) 00092 * \return syssolver results 00093 */ 00094 00095 SystemSolverResults_t operator()(T& psi, const T& chi, 00096 AbsChronologicalPredictor4D<T>& predictor) const 00097 { 00098 00099 START_CODE(); 00100 00101 // This solver uses InvCG2, so A is just the matrix. 00102 // I need to predict with A^\dagger A 00103 { 00104 Handle< LinearOperator<T> > MdagM( new MdagMLinOp<T>(A) ); 00105 predictor(psi, (*MdagM), chi); 00106 } 00107 // Do solve 00108 SystemSolverResults_t res=(*this)(psi,chi); 00109 00110 // Store result 00111 predictor.newVector(psi); 00112 END_CODE(); 00113 return res; 00114 } 00115 00116 private: 00117 // Hide default constructor 00118 MdagMSysSolverQDPEigCG() {} 00119 00120 Handle< LinearOperator<T> > MdagM; 00121 Handle< LinearOperator<T> > A; 00122 SysSolverEigCGParams invParam; 00123 }; 00124 00125 } // End namespace 00126 00127 #endif 00128
1.4.7