CHROMA
lwldslash_base_w.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Wilson Dslash linear operator
4  */
5 
6 #ifndef __lwldslash_base_h__
7 #define __lwldslash_base_h__
8 
9 #include "linearop.h"
10 
11 namespace Chroma
12 {
13  //! General Wilson-Dirac dslash
14  /*!
15  * \ingroup linop
16  *
17  * DSLASH
18  *
19  * This routine is specific to Wilson fermions!
20  *
21  * Description:
22  *
23  * This routine applies the operator D' to Psi, putting the result in Chi.
24  *
25  * Nd-1
26  * ---
27  * \
28  * chi(x) := > U (x) (1 - isign gamma ) psi(x+mu)
29  * / mu mu
30  * ---
31  * mu=0
32  *
33  * Nd-1
34  * ---
35  * \ +
36  * + > U (x-mu) (1 + isign gamma ) psi(x-mu)
37  * / mu mu
38  * ---
39  * mu=0
40  *
41  */
42  template <typename T, typename P, typename Q>
44  public DslashLinearOperator<T,P,Q>
45  {
46  public:
47 
48  //! No real need for cleanup here
49  virtual ~WilsonDslashBase() {}
50 
51  //! Subset is all here
52  const Subset& subset() const {return all;}
53 
54  //! Take deriv of D
55  /*!
56  * \param chi left std::vector (Read)
57  * \param psi right std::vector (Read)
58  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
59  *
60  * \return Computes \f$\chi^\dag * \dot(D} * \psi\f$
61  */
62  virtual void deriv(P& ds_u,
63  const T& chi, const T& psi,
64  enum PlusMinus isign) const;
65 
66  //! Take deriv of D
67  /*!
68  * \param chi left std::vector on cb (Read)
69  * \param psi right std::vector on 1-cb (Read)
70  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
71  * \param cb Checkerboard of chi std::vector (Read)
72  *
73  * \return Computes \f$\chi^\dag * \dot(D} * \psi\f$
74  */
75  virtual void deriv(P& ds_u,
76  const T& chi, const T& psi,
77  enum PlusMinus isign, int cb) const ;
78 
79  //! Return flops performed by the operator()
80  unsigned long nFlops() const;
81 
82  protected:
83  //! Get the anisotropy parameters
84  virtual const multi1d<Real>& getCoeffs() const = 0;
85  };
86 
87  template<typename T>
88  class HalfFermionType{};
89 
90  template<>
91  class HalfFermionType<LatticeFermionF> {
92  public:
93  typedef LatticeHalfFermionF Type_t;
94  };
95 
96  template<>
97  class HalfFermionType<LatticeFermionD> {
98  public:
99  typedef LatticeHalfFermionD Type_t;
100  };
101 
102 
103  //! Take deriv of D
104  /*!
105  * \param chi left std::vector (Read)
106  * \param psi right std::vector (Read)
107  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
108  *
109  * \return Computes \f$\chi^\dag * \dot(D} * \psi\f$
110  */
111  template<typename T, typename P, typename Q>
112  void
114  const T& chi, const T& psi,
115  enum PlusMinus isign) const
116  {
117  START_CODE();
118 
119  ds_u.resize(Nd);
120 
121  P ds_tmp;
122  deriv(ds_u, chi, psi, isign, 0);
123  deriv(ds_tmp, chi, psi, isign, 1);
124  ds_u += ds_tmp;
125 
126  END_CODE();
127  }
128 
129 
130  //! Take deriv of D
131  /*! \return Computes \f$\chi^\dag * \dot(D} * \psi\f$ */
132  template<typename T, typename P, typename Q>
133  void
135  const T& chi, const T& psi,
136  enum PlusMinus isign, int cb) const
137  {
138  START_CODE();
139 
140  ds_u.resize(Nd);
141 
142  const multi1d<Real>& anisoWeights = getCoeffs();
143 
144  for(int mu = 0; mu < Nd; ++mu)
145  {
146  // Break this up to use fewer expressions:
147  T temp_ferm1;
148  typename HalfFermionType<T>::Type_t tmp_h;
149 
150  switch (isign)
151  {
152  case PLUS:
153  {
154  // Undaggered: Minus Projectors
155  switch(mu)
156  {
157  case 0:
158  tmp_h[rb[1-cb]] = spinProjectDir0Minus(psi);
159  temp_ferm1[rb[1-cb]] = spinReconstructDir0Minus(tmp_h);
160  break;
161  case 1:
162  tmp_h[rb[1-cb]] = spinProjectDir1Minus(psi);
163  temp_ferm1[rb[1-cb]] = spinReconstructDir1Minus(tmp_h);
164  break;
165  case 2:
166  tmp_h[rb[1-cb]] = spinProjectDir2Minus(psi);
167  temp_ferm1[rb[1-cb]] = spinReconstructDir2Minus(tmp_h);
168  break;
169  case 3:
170  tmp_h[rb[1-cb]] = spinProjectDir3Minus(psi);
171  temp_ferm1[rb[1-cb]] = spinReconstructDir3Minus(tmp_h);
172  break;
173  default:
174  break;
175  };
176 
177  }
178  break;
179 
180  case MINUS:
181  {
182  // Daggered: Plus Projectors
183  typename HalfFermionType<T>::Type_t tmp_h;
184  switch(mu)
185  {
186  case 0:
187  tmp_h[rb[1-cb]] = spinProjectDir0Plus(psi);
188  temp_ferm1[rb[1-cb]] = spinReconstructDir0Plus(tmp_h);
189  break;
190  case 1:
191  tmp_h[rb[1-cb]] = spinProjectDir1Plus(psi);
192  temp_ferm1[rb[1-cb]] = spinReconstructDir1Plus(tmp_h);
193  break;
194  case 2:
195  tmp_h[rb[1-cb]] = spinProjectDir2Plus(psi);
196  temp_ferm1[rb[1-cb]] = spinReconstructDir2Plus(tmp_h);
197  break;
198  case 3:
199  tmp_h[rb[1-cb]] = spinProjectDir3Plus(psi);
200  temp_ferm1[rb[1-cb]] = spinReconstructDir3Plus(tmp_h);
201  break;
202  default:
203  break;
204  };
205  }
206  break;
207 
208  default:
209  QDP_error_exit("unknown case");
210  }
211 
212  // QDP Shifts the whole darn thing anyhow
213  T temp_ferm2 = shift(temp_ferm1, FORWARD, mu);
214  P temp_mat;
215  temp_mat.resize(1);
216 
217  // This step supposedly optimised in QDP++
218  (temp_mat[0])[rb[cb]] = traceSpin(outerProduct(temp_ferm2,chi));
219 
220  // Just do the bit we need.
221  ds_u[mu][rb[cb]] = anisoWeights[mu] * temp_mat[0];
222  ds_u[mu][rb[1-cb]] = zero;
223  }
224  (*this).getFermBC().zero(ds_u);
225 
226  END_CODE();
227  }
228 
229 
230  //! Return flops performed by the operator()
231  template<typename T, typename P, typename Q>
232  unsigned long
233  WilsonDslashBase<T,P,Q>::nFlops() const {return 1320;}
234 
235 #if 0
236 
237  class WilsonDslashBaseF :
238  public DslashLinearOperator<LatticeFermionF,
239  multi1d<LatticeColorMatrixF>,
240  multi1d<LatticeColorMatrixF> >
241  {
242  public:
243  typedef LatticeFermionF T;
244  typedef multi1d<LatticeColorMatrixF> P;
245  typedef multi1d<LatticeColorMatrixF> Q;
246 
247  //! No real need for cleanup here
248  virtual ~WilsonDslashBaseF() {}
249 
250  //! Subset is all here
251  const Subset& subset() const {return all;}
252 
253  //! Take deriv of D
254  /*!
255  * \param chi left std::vector (Read)
256  * \param psi right std::vector (Read)
257  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
258  *
259  * \return Computes \f$\chi^\dag * \dot(D} * \psi\f$
260  */
261  virtual void deriv(P& ds_u,
262  const T& chi, const T& psi,
263  enum PlusMinus isign) const {
264  QDPIO::cout << "Not implemented" << std::endl;
265  QDP_abort(1);
266  }
267 
268  //! Take deriv of D
269  /*!
270  * \param chi left std::vector on cb (Read)
271  * \param psi right std::vector on 1-cb (Read)
272  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
273  * \param cb Checkerboard of chi std::vector (Read)
274  *
275  * \return Computes \f$\chi^\dag * \dot(D} * \psi\f$
276  */
277  virtual void deriv(P& ds_u,
278  const T& chi, const T& psi,
279  enum PlusMinus isign, int cb) const {
280  QDPIO::cout << "Not Implemented" << std::endl;
281  }
282 
283  //! Return flops performed by the operator()
284  unsigned long nFlops() const;
285 
286  protected:
287  //! Get the anisotropy parameters
288  virtual const multi1d<Real>& getCoeffs() const = 0;
289  };
290 
291 #endif
292 
293 } // End Namespace Chroma
294 
295 
296 #endif
Dslash-like Linear Operator.
Definition: linearop.h:221
General Wilson-Dirac dslash.
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign, int cb) const
Take deriv of D.
virtual ~WilsonDslashBase()
No real need for cleanup here.
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign) const
Take deriv of D.
virtual const multi1d< Real > & getCoeffs() const =0
Get the anisotropy parameters.
unsigned long nFlops() const
Return flops performed by the operator()
const Subset & subset() const
Subset is all here.
int mu
Definition: cool.cc:24
Linear Operators.
Nd
Definition: meslate.cc:74
multi1d< LatticeColorMatrix > P
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
QDP_error_exit("too many BiCG iterations", n_count, rsd_sq, cp, c, re_rvr, im_rvr, re_a, im_a, re_b, im_b)
LinOpSysSolverMGProtoClover::Q Q
LinOpSysSolverMGProtoClover::T T
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
START_CODE()
int cb
Definition: invbicg.cc:120
Double zero
Definition: invbicg.cc:106
#define FORWARD
Definition: primitives.h:82
LatticeFermion T
Definition: t_clover.cc:11
multi1d< LatticeColorMatrix > P
Definition: t_clover.cc:13
multi1d< LatticeColorMatrix > deriv(const EvenOddPrecLinearOperator< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > &AP, const LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign)
Apply the operator onto a source std::vector.