CHROMA
syssolver_linop_richardson_multiprec_clover.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Solve a MdagM*psi=chi linear system by BiCGStab
4  */
5 
6 #ifndef __syssolver_linop_richardson_multiprec_h__
7 #define __syssolver_linop_richardson_multiprec_h__
8 #include "chroma_config.h"
9 
10 #include "handle.h"
11 #include "state.h"
12 #include "syssolver.h"
13 #include "linearop.h"
14 #include "lmdagm.h"
22 
23 #include <string>
24 
25 namespace Chroma
26 {
27 
28  //! Richardson system solver namespace
29  namespace LinOpSysSolverRichardsonCloverEnv
30  {
31  //! Register the syssolver
32  bool registerAll();
33  }
34 
35 
36 
37  //! Solve a system using Richardson iteration.
38  /*! \ingroup invert
39  *** WARNING THIS SOLVER WORKS FOR CLOVER FERMIONS ONLY ***
40  */
41 
42  class LinOpSysSolverRichardsonClover : public LinOpSystemSolver<LatticeFermion>
43  {
44  public:
45  typedef LatticeFermion T;
46  typedef LatticeColorMatrix U;
47  typedef multi1d<LatticeColorMatrix> Q;
48 
49  typedef LatticeFermionF TF;
50  typedef LatticeColorMatrixF UF;
51  typedef multi1d<LatticeColorMatrixF> QF;
52 
53  typedef LatticeFermionD TD;
54  typedef LatticeColorMatrixD UD;
55  typedef multi1d<LatticeColorMatrixD> QD;
56 
57  //! Constructor
58  /*!
59  * \param M_ Linear operator ( Read )
60  * \param invParam inverter parameters ( Read )
61  */
63  Handle< FermState<T,Q,Q> > state_,
64  const SysSolverRichardsonCloverParams& invParam_) :
65  A(A_), invParam(invParam_)
66  {
67 
68  // Get the Links out of the state and convertto single.
69  QF links_single; links_single.resize(Nd);
70  QD links_double; links_double.resize(Nd);
71 
72  const Q& links = state_->getLinks();
73  for(int mu=0; mu < Nd; mu++) {
74  links_single[mu] = links[mu];
75  links_double[mu] = links[mu];
76  }
77 
78 
79  // Links single hold the possibly stouted links
80  // with gaugeBCs applied...
81  // Now I need to create a single prec state...
82  fstate_single = new PeriodicFermState<TF,QF,QF>(links_single);
83  fstate_double = new PeriodicFermState<TD,QD,QD>(links_double);
84 
85  // Make single precision M
88 
89  std::istringstream is( invParam_.innerSolverParams.xml );
90  XMLReader paramtop(is);
91 
92  DInv = TheLinOpFFermSystemSolverFactory::Instance().createObject( invParam_.innerSolverParams.id, paramtop,
93  invParam_.innerSolverParams.path,
95  M_single);
96 
97 
98  }
99 
100  //! Destructor is automatic
102 
103  //! Return the subset on which the operator acts
104  const Subset& subset() const {return A->subset();}
105 
106  //! Solver the linear system
107  /*!
108  * \param psi solution ( Modify )
109  * \param chi source ( Read )
110  * \return syssolver results
111  */
113  {
115 
116  START_CODE();
117  StopWatch swatch;
118  swatch.start();
119 
120  // T MdagChi;
121 
122  // This is a CGNE. So create new RHS
123  // (*A)(MdagChi, chi, MINUS);
124  // Handle< LinearOperator<T> > MM(new MdagMLinOp<T>(A));
125 
126  TD psi_d = psi;
127  TD chi_d = chi;
128 
130  *M_double,
131  chi_d,
132  psi_d,
135  res);
136 
137  psi = psi_d;
138 
139  swatch.stop();
140  double time = swatch.getTimeInSeconds();
141 
142  {
143  T r;
144  r[A->subset()]=chi;
145  T tmp;
146  (*A)(tmp, psi, PLUS);
147  r[A->subset()] -= tmp;
148  res.resid = sqrt(norm2(r, A->subset())/norm2(chi, A->subset()));
149  }
150  QDPIO::cout << "MULTIPREC_RICHARDSON_SOLVER: " << res.n_count << " iterations. Rsd = " << res.resid << " Relative Rsd = " << res.resid/sqrt(norm2(chi,A->subset())) << std::endl;
151  QDPIO::cout << "MULTIPREC_RICHARDSON_SOLVER_TIME: "<<time<< " sec" << std::endl;
152 
153 
154  END_CODE();
155  return res;
156  }
157 
158 
159  private:
160  // Hide default constructor
164 
165  // Created and initialized here.
171 
172 
173  };
174 
175 
176 } // End namespace
177 
178 #endif
179 
Even-odd preconditioned Clover-Dirac operator.
Even-odd preconditioned Clover-Dirac operator.
Support class for fermion actions and linear operators.
Definition: state.h:94
Class for counted reference semantics.
Definition: handle.h:33
LinOpSysSolverRichardsonClover(Handle< LinearOperator< T > > A_, Handle< FermState< T, Q, Q > > state_, const SysSolverRichardsonCloverParams &invParam_)
Constructor.
const Subset & subset() const
Return the subset on which the operator acts.
SystemSolverResults_t operator()(T &psi, const T &chi) const
Solver the linear system.
SystemSolver disambiguator.
Linear Operator.
Definition: linearop.h:27
Periodic version of FermState.
static T & Instance()
Definition: singleton.h:432
Parameters for Clover fermion action.
int mu
Definition: cool.cc:24
Even-odd preconditioned Clover fermion linear operator.
Class for counted reference semantics.
Linear Operators.
M^dag*M composition of a linear operator.
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
void InvMultiPrecRichardson(const SystemSolver< LatticeFermionF > &Dinv, const LinearOperator< LatticeFermionD > &D, const LatticeFermionD &b, LatticeFermionD &x, int MaxIter, Real RsdTarget, SystemSolverResults_t &res)
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
START_CODE()
Periodic ferm state and a creator.
Support class for fermion actions and linear operators.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Linear system solvers.
Factory for solving M*psi=chi where M is not hermitian or pos. def.
Disambiguator for MdagM system solvers.