CHROMA
eoprec_twm_linop_array_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Even-odd preconditioned Twisted-mass linop where each flavor is one of two array elements
3  */
4 
6 
7 namespace Chroma
8 {
9  //! Creation routine
10  /*!
11  * \param fs gauge field (Read)
12  * \param Mass_ fermion mass (Read)
13  * \param mu_sigma_ first parity mass term (Read)
14  */
15  void EvenOddPrecParWilsonLinOp::create(Handle< FermState<T,P,Q> > fs,
16  const Real& Mass_,
17  const Real& mu_sigma_, const Real& mu_delta_)
18  {
19  // This needs work
20  Mass = Mass_;
21  H = H_;
22 // u = u_;
23  D.create(fs);
24 
25  // This needs work
26  fact = Nd + Mass;
27  Real tmp = 1.0 / (fact*fact + mu_sigma_);
28  invfact1 = fact * tmp;
29  invfact2 = H * tmp;
30  }
31 
32 
33  //! Apply the the even-even block onto a source std::vector
34  void
35  EvenOddPrecParWilsonLinOp::evenEvenLinOp(LatticeFermion& chi, const LatticeFermion& psi,
36  enum PlusMinus isign) const
37  {
38  switch (isign)
39  {
40  case PLUS:
41  chi[rb[0]] = fact*psi + GammaConst<Ns,Ns*Ns-1>()*(H*timesI(psi));
42  break;
43 
44  case MINUS:
45  chi[rb[0]] = fact*psi - GammaConst<Ns,Ns*Ns-1>()*(H*timesI(psi));
46  break;
47  }
48  }
49 
50 
51  //! Return flops performed by the operator()
52  unsigned long EvenOddPrecParWilsonLinOp::nFlops() const
53  {
54  unsigned long cbsite_flops = 2*D.nFlops()+16*Nc*Ns;
55  return cbsite_flops*(Layout::sitesOnNode()/2);
56  }
57 
58 
59  //! Apply the inverse of the even-even block onto a source std::vector
60  void
61  EvenOddPrecParWilsonLinOp::evenEvenInvLinOp(LatticeFermion& chi, const LatticeFermion& psi,
62  enum PlusMinus isign) const
63  {
64  // tmp = D' (1-i isign H gamma_5) D' Psi
65  // O O,E E,O O
66  switch (isign)
67  {
68  case PLUS:
69  chi[rb[0]] = invfact1*psi - GammaConst<Ns,Ns*Ns-1>()*(invfact2*timesI(psi));
70  break;
71 
72  case MINUS:
73  chi[rb[0]] = invfact1*psi + GammaConst<Ns,Ns*Ns-1>()*(invfact2*timesI(psi));
74  break;
75  }
76  }
77 
78 
79  //! Apply the the odd-odd block onto a source std::vector
80  void
81  EvenOddPrecParWilsonLinOp::oddOddLinOp(LatticeFermion& chi, const LatticeFermion& psi,
82  enum PlusMinus isign) const
83  {
84  switch (isign)
85  {
86  case PLUS:
87  chi[rb[1]] = fact*psi + GammaConst<Ns,Ns*Ns-1>()*(H*timesI(psi));
88  break;
89 
90  case MINUS:
91  chi[rb[1]] = fact*psi - GammaConst<Ns,Ns*Ns-1>()*(H*timesI(psi));
92  break;
93  }
94  }
95 
96  //! Apply even-odd linop component
97  /*!
98  * The operator acts on the entire even sublattice
99  *
100  * \param chi Pseudofermion field (Write)
101  * \param psi Pseudofermion field (Read)
102  * \param isign Flag ( PLUS | MINUS ) (Read)
103  */
104  void
106  const LatticeFermion& psi,
107  enum PlusMinus isign) const
108  {
109  START_CODE();
110 
111  Real mhalf = -0.5;
112 
113  D.apply(chi, psi, isign, 0);
114  chi[rb[0]] *= mhalf;
115 
116  END_CODE();
117  }
118 
119 
120  //! Apply odd-even linop component
121  /*!
122  * The operator acts on the entire odd sublattice
123  *
124  * \param chi Pseudofermion field (Write)
125  * \param psi Pseudofermion field (Read)
126  * \param isign Flag ( PLUS | MINUS ) (Read)
127  */
128  void
130  const LatticeFermion& psi,
131  enum PlusMinus isign) const
132  {
133  START_CODE();
134 
135  Real mhalf = -0.5;
136 
137  D.apply(chi, psi, isign, 1);
138  chi[rb[1]] *= mhalf;
139 
140  END_CODE();
141  }
142 
143 
144  //! Override inherited one with a few more funkies
145  void
146  EvenOddPrecParWilsonLinOp::operator()(LatticeFermion & chi,
147  const LatticeFermion& psi,
148  enum PlusMinus isign) const
149  {
150  LatticeFermion tmp1, tmp2, tmp3; // if an array is used here,
151 
152  moveToFastMemoryHint(tmp1);
153  moveToFastMemoryHint(tmp2);
154  moveToFastMemoryHint(tmp3);
155 
156  Real mquarter = -0.25;
157 
158  // tmp = D' (1-i isign H gamma_5) D' Psi
159  // O O,E E,O O
160  switch (isign)
161  {
162  case PLUS:
163  // tmp1[0] = D_eo psi[1]
164  D.apply(tmp1, psi, isign, 0);
165 
166  tmp2[rb[0]] = invfact1*tmp1 - invfact2*(GammaConst<Ns,Ns*Ns-1>()*timesI(tmp1));
167 
168  // tmp2[1] = D_oe tmp2[0]
169  D.apply(tmp3, tmp2, isign, 1);
170 
171  chi[rb[1]] = fact*psi + mquarter*tmp3;
172  chi[rb[1]] += H*(GammaConst<Ns,Ns*Ns-1>()*timesI(psi));
173  break;
174 
175  case MINUS:
176  // tmp1[0] = D_eo psi[1]
177  D.apply(tmp1, psi, isign, 0);
178 
179  tmp2[rb[0]] = invfact1*tmp1 + invfact2*(GammaConst<Ns,Ns*Ns-1>()*timesI(tmp1));
180 
181  // tmp2[1] = D_oe tmp2[0]
182  D.apply(tmp3, tmp2, isign, 1);
183 
184  chi[rb[1]] = fact*psi + mquarter*tmp3;
185  chi[rb[1]] -= H*(GammaConst<Ns,Ns*Ns-1>()*timesI(psi));
186  break;
187  }
188 
189  getFermBC().modifyF(chi, rb[1]);
190  }
191 
192 
193  //! Derivative of even-odd linop component
194  void
195  EvenOddPrecParWilsonLinOp::derivEvenOddLinOp(multi1d<LatticeColorMatrix>& ds_u,
196  const LatticeFermion& chi,
197  const LatticeFermion& psi,
198  enum PlusMinus isign) const
199  {
200  START_CODE();
201 
202  ds_u.resize(Nd);
203 
204  D.deriv(ds_u, chi, psi, isign, 0);
205  for(int mu=0; mu < Nd; mu++) {
206  ds_u[mu] *= Real(-0.5);
207  }
208 
209  END_CODE();
210  }
211 
212 
213  //! Derivative of odd-even linop component
214  void
215  EvenOddPrecParWilsonLinOp::derivOddEvenLinOp(multi1d<LatticeColorMatrix>& ds_u,
216  const LatticeFermion& chi,
217  const LatticeFermion& psi,
218  enum PlusMinus isign) const
219  {
220  START_CODE();
221 
222  ds_u.resize(Nd);
223 
224  D.deriv(ds_u, chi, psi, isign, 1);
225  for(int mu=0; mu < Nd; mu++) {
226  ds_u[mu] *= Real(-0.5);
227  }
228  END_CODE();
229  }
230 
231 
232 
233 #if 0
234 // Code is here only as a reference. It should be deleted at some point.
235 // This is converted szin code.
236 // The above derivs will work, calling evenEvenInvLinOp to get that
237 // contribution.
238 // However, for more performance, one should copy the regular Wilson
239 // deriv() routine and modify it.
240 
241 #error "ANCIENT SZIN CODE"
242 #error "Not quite correct implementation"
243 
244 
245  //! Computes the derivative of the fermionic action respect to the link field
246  /*!
247  * | dS dS_f
248  * ds_u -- | ---- + ----- ( Write )
249  * | dU dU
250  *
251  * psi -- [1./(M_dag*M)]*chi_ ( read )
252  *
253  * \param ds_u result ( Write )
254  * \param state gauge field ( Read )
255  * \param psi solution to linear system ( Read )
256  */
257 
258  void
259  EvenOddPrecParWilsonFermAct::deriv(multi1d<LatticeColorMatrix>& ds_u,
260  const LatticeFermion& chi,
261  const LatticeFermion& psi,
262  enum PlusMinus isign) const
263  {
264  START_CODE();
265 
266  QDPIO::cerr << "EvenOddPrecParWilsonFermAct::dsdu not implemented" << std::endl;
267  QDP_abort(1);
268 
269  const multi1d<LatticeColorMatrix>& u = state->getLinks();
270 
271  LatticeColorMatrix utmp_1; moveToFastMemoryHint(utmp_1);
272  LatticeFermion phi; moveToFastMemoryHint(phi);
273  LatticeFermion rho; moveToFastMemoryHint(rho);
274  LatticeFermion sigma; moveToFastMemoryHint(sigma);
275  LatticeFermion ftmp_1; moveToFastMemoryHint(ftmp_1);
276  LatticeFermion ftmp_2; moveToFastMemoryHint(ftmp_2);
277  Double ddummy;
278  Real dummy;
279  int nu;
280  int cb;
281 
282  /* Do the Wilson fermion dS_f/dU with parity breaking term */
283 
284 // CONSTRUCT_LINEAR_OPERATOR(A, lwlhmpsi, u, KappaMD);
285 
286  /* phi = M(u)*psi */
287  A (A, psi, phi, 1, PLUS);
288 
289  /* rho = (1-i H gamma_5) * Dslash(0<-1) * psi */
290  dslash (u, psi, ftmp_1, PLUS, 1);
291  PARBREAK(ftmp_1, H_parity, rho, MINUS);
292 
293  /* phi = (KappaMD^2)*phi/(1+h^2) = -(KappaMD^2)*M*psi/(1+h^2) */
294  dummy = -(KappaMD*KappaMD) / (WORD_VALUE(WORD_H_parity, ONE) + H_parity*H_parity);
295  phi = phi * dummy;
296 
297  /* sigma = (1+i H gamma_5) * Dslash_dag(0<-1) * phi */
298  dslash (u, phi, ftmp_1, MINUS, 1);
299  PARBREAK(ftmp_1, H_parity, sigma, PLUS);
300 
301 
302  for(int mu = 0; mu < Nd; ++mu)
303  {
304  cb = 0;
305 
306  /* ftmp_2 = (gamma(mu))*psi */
307  SPIN_PRODUCT(psi,(INTEGER_LSHIFT_FUNCTION(1,mu)),ftmp_2);
308  /* ftmp_2(x) = -(psi(x) - ftmp_2(x)) = -(1 - gamma(mu))*psi( x ) */
309  ftmp_2 -= psi;
310  utmp_1 = -(shift(ftmp_2, cb, FORWARD, mu) * adj(sigma));
311 
312  /* ftmp_2 = (gamma(mu))*phi */
313  SPIN_PRODUCT(phi,(INTEGER_LSHIFT_FUNCTION(1,mu)),ftmp_2);
314  /* ftmp_2 = phi + ftmp_2 = (1 + gamma(mu))*phi( x) */
315  ftmp_2 += phi;
316  utmp_1 += shift(ftmp_2, cb, FORWARD, mu) * adj(rho);
317 
318  /* THIS NEEDS TO BE CHANGED (removed) */
319  ds_u[mu][cb] += u[mu][cb] * utmp_1;
320 
321  cb = 1;
322 
323  /* ftmp_2 = (gamma(mu))*ftmp_1 */
324  SPIN_PRODUCT(rho,(INTEGER_LSHIFT_FUNCTION(1,mu)),ftmp_2);
325  /* ftmp_2 = -(rho - ftmp_2) = -(1 - gamma(mu))*rho( x ) */
326  ftmp_2 -= rho;
327  utmp_1 = -(shift(ftmp_2, cb, FORWARD, mu) * adj(phi));
328 
329  /* ftmp_2 = (gamma(mu))*sigma */
330  SPIN_PRODUCT(sigma,(INTEGER_LSHIFT_FUNCTION(1,mu)),ftmp_2);
331  /* ftmp_1 = ftmp_1 + ftmp_2 = (1 + gamma(mu))*sigma( x + mu) */
332  ftmp_2 += sigma;
333  utmp_1 += shift(ftmp_2, cb, FORWARD, mu) * adj(psi);
334 
335  /* THIS NEEDS TO BE CHANGED (removed) */
336  ds_u[mu][cb] += u[mu][cb] * utmp_1;
337 
338  }
339 
340  getFermBC().zero(ds_u);
341 
342  END_CODE();
343  }
344 #endif
345 
346 } // End Namespace Chroma
347 
void evenEvenInvLinOp(LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign) const
Apply the inverse of the even-even block onto a source std::vector.
void oddEvenLinOp(LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign) const
Apply the the odd-even block onto a source std::vector.
void evenOddLinOp(LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign) const
Apply the the even-odd block onto a source std::vector.
void create(Handle< FermState< T, P, Q > > fs, const Real &Mass_, const Real &H_)
Creation routine.
unsigned long nFlops() const
Return flops performed by the operator()
void derivEvenOddLinOp(multi1d< LatticeColorMatrix > &ds_u, const LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign) const
Apply the the even-odd block onto a source std::vector.
void operator()(LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign) const
Override inherited one with a few more funkies.
void evenEvenLinOp(LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign) const
Apply the the even-even block onto a source std::vector.
const FermBC< T, P, Q > & getFermBC() const
Return the fermion BC object for this linear operator.
void derivOddEvenLinOp(multi1d< LatticeColorMatrix > &ds_u, const LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign) const
Apply the the odd-even block onto a source std::vector.
void oddOddLinOp(LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign) const
Apply the the odd-odd block onto a source std::vector.
virtual const FermBC< T, P, Q > & getFermBC() const
Return the fermion BC object for this action.
Definition: fermact.h:79
void create(Handle< FermState< T, P, Q > > state)
Creation routine.
Definition: lwldslash_w.h:161
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign) const
Take deriv of D.
unsigned long nFlops() const
Return flops performed by the operator()
Real H_parity
EXTERN Real KappaMD
int mu
Definition: cool.cc:24
int nu
Definition: cool.cc:25
Even-odd preconditioned Wilson fermion linear operator with parity breaking term.
void apply(T &chi, const T &psi, enum PlusMinus isign, int cb) const
General Wilson-Dirac dslash.
Definition: lwldslash_w.h:228
Nd
Definition: meslate.cc:74
Double tmp2
Definition: mesq.cc:30
Double tmp3
Definition: mesq.cc:31
LatticeReal phi
Definition: mesq.cc:27
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
dslash(u, eta, tmp, MINUS, 1)
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
START_CODE()
A(A, psi, r, Ncb, PLUS)
int cb
Definition: invbicg.cc:120
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
FloatingPoint< double > Double
Definition: gtest.h:7351
#define FORWARD
Definition: primitives.h:82
Real dummy
Definition: qtopcor.cc:36
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.
#define ONE