Bridge++  Ver. 2.0.2
field_F_imp.cpp
Go to the documentation of this file.
1 
14 #include "Field/field_F.h"
15 #include "Field/field_thread-inc.h"
16 
17 #if defined USE_GROUP_SU3
18 #include "field_F_imp_SU3-inc.h"
19 #elif defined USE_GROUP_SU2
20 #include "field_F_imp_SU2-inc.h"
21 #elif defined USE_GROUP_SU_N
22 #include "field_F_imp_SU_N-inc.h"
23 #endif
24 
25 //====================================================================
27 {
28  // assert(NC == CommonParameters::Nc());
29  // assert(ND == CommonParameters::Nd());
30 
31  check_Nc();
32 }
33 
34 
35 //====================================================================
36 void mult_Field_Gn(Field_F& y, const int ex,
37  const Field_G& U, const int ex1,
38  const Field_F& x, const int ex2)
39 {
40  assert(ex < y.nex());
41  assert(ex1 < U.nex());
42  assert(ex2 < x.nex());
43  int Nvol = y.nvol();
44  assert(U.nvol() == Nvol);
45  assert(x.nvol() == Nvol);
46 
47  const int Nd = x.nd();
48  const int Nc = x.nc();
49  const int Nc2 = x.nc2();
50  const int Ncd2 = Nc2 * Nd;
51  const int Ndf = Nc2 * Nc;
52 
53  int ith, nth, is, ns;
54  set_threadtask(ith, nth, is, ns, Nvol);
55 
56  double *v = y.ptr(0, is, ex);
57  const double *g = U.ptr(0, is, ex1);
58  const double *w = x.ptr(0, is, ex2);
59 
60  for (int site = 0; site < ns; ++site) {
61  int ig = Ndf * site;
62  int iv = Ncd2 * site;
63  for (int s = 0; s < Nd; ++s) {
64  for (int ic = 0; ic < Nc; ++ic) {
65  int ig2 = ic * Nc2 + ig;
66  int iv2 = s * Nc2 + iv;
67  v[2 * ic + iv2] = mult_Gn_r(&g[ig2], &w[iv2], Nc);
68  v[2 * ic + 1 + iv2] = mult_Gn_i(&g[ig2], &w[iv2], Nc);
69  }
70  }
71  }
72 }
73 
74 
75 //====================================================================
76 void mult_Field_Gd(Field_F& y, const int ex,
77  const Field_G& U, const int ex1,
78  const Field_F& x, const int ex2)
79 {
80  assert(ex < y.nex());
81  assert(ex1 < U.nex());
82  assert(ex2 < x.nex());
83  int Nvol = y.nvol();
84  assert(U.nvol() == Nvol);
85  assert(x.nvol() == Nvol);
86 
87  const int Nd = x.nd();
88  const int Nc = x.nc();
89  const int Nc2 = x.nc2();
90  const int Ncd2 = Nc2 * Nd;
91  const int Ndf = Nc2 * Nc;
92 
93  int ith, nth, is, ns;
94  set_threadtask(ith, nth, is, ns, Nvol);
95 
96  double *v = y.ptr(0, is, ex);
97  const double *g = U.ptr(0, is, ex1);
98  const double *w = x.ptr(0, is, ex2);
99 
100  for (int site = 0; site < ns; ++site) {
101  int ig = Ndf * site;
102  int iv = Ncd2 * site;
103  for (int s = 0; s < Nd; ++s) {
104  for (int ic = 0; ic < Nc; ++ic) {
105  int ig2 = ic * 2 + ig;
106  int iv2 = s * Nc2 + iv;
107  v[2 * ic + iv2] = mult_Gd_r(&g[ig2], &w[iv2], Nc);
108  v[2 * ic + 1 + iv2] = mult_Gd_i(&g[ig2], &w[iv2], Nc);
109  }
110  }
111  }
112 }
113 
114 
115 //====================================================================
116 void multadd_Field_Gn(Field_F& y, const int ex,
117  const Field_G& U, const int ex1,
118  const Field_F& x, const int ex2,
119  const double a)
120 {
121  assert(ex < y.nex());
122  assert(ex1 < U.nex());
123  assert(ex2 < x.nex());
124  int Nvol = y.nvol();
125  assert(U.nvol() == Nvol);
126  assert(x.nvol() == Nvol);
127 
128  const int Nd = x.nd();
129  const int Nc = x.nc();
130  const int Nc2 = x.nc2();
131  const int Ncd2 = Nc2 * Nd;
132  const int Ndf = Nc2 * Nc;
133 
134  int ith, nth, is, ns;
135  set_threadtask(ith, nth, is, ns, Nvol);
136 
137  double *v = y.ptr(0, is, ex);
138  const double *g = U.ptr(0, is, ex1);
139  const double *w = x.ptr(0, is, ex2);
140 
141  for (int site = 0; site < ns; ++site) {
142  int ig = Ndf * site;
143  int iv = Ncd2 * site;
144  for (int s = 0; s < Nd; ++s) {
145  for (int ic = 0; ic < Nc; ++ic) {
146  int ig2 = ic * Nc2 + ig;
147  int iv2 = s * Nc2 + iv;
148  v[2 * ic + iv2] += a * mult_Gn_r(&g[ig2], &w[iv2], Nc);
149  v[2 * ic + 1 + iv2] += a * mult_Gn_i(&g[ig2], &w[iv2], Nc);
150  }
151  }
152  }
153 }
154 
155 
156 //====================================================================
157 void multadd_Field_Gd(Field_F& y, const int ex,
158  const Field_G& U, const int ex1,
159  const Field_F& x, const int ex2,
160  const double a)
161 {
162  assert(ex < y.nex());
163  assert(ex1 < U.nex());
164  assert(ex2 < x.nex());
165  int Nvol = y.nvol();
166  assert(U.nvol() == Nvol);
167  assert(x.nvol() == Nvol);
168 
169  const int Nd = x.nd();
170  const int Nc = x.nc();
171  const int Nc2 = x.nc2();
172  const int Ncd2 = Nc2 * Nd;
173  const int Ndf = Nc2 * Nc;
174 
175  int ith, nth, is, ns;
176  set_threadtask(ith, nth, is, ns, Nvol);
177 
178  double *v = y.ptr(0, is, ex);
179  const double *g = U.ptr(0, is, ex1);
180  const double *w = x.ptr(0, is, ex2);
181 
182  for (int site = 0; site < ns; ++site) {
183  int ig = Ndf * site;
184  int iv = Ncd2 * site;
185  for (int s = 0; s < Nd; ++s) {
186  for (int ic = 0; ic < Nc; ++ic) {
187  int ig2 = ic * 2 + ig;
188  int iv2 = s * Nc2 + iv;
189  v[2 * ic + iv2] += a * mult_Gd_r(&g[ig2], &w[iv2], Nc);
190  v[2 * ic + 1 + iv2] += a * mult_Gd_i(&g[ig2], &w[iv2], Nc);
191  }
192  }
193  }
194 }
195 
196 
197 //====================================================================
198 void mult_GM(Field_F& y, const GammaMatrix& gm, const Field_F& x)
199 {
200  assert(x.nex() == y.nex());
201  int Nvol = y.nvol();
202  assert(x.nvol() == Nvol);
203 
204  const int Nd = x.nd();
205  const int Nc = x.nc();
206  const int Nc2 = x.nc2();
207  const int Ncd2 = Nc2 * Nd;
208 
209  int id[Nd];
210  int idc_r[Nd];
211  int idc_i[Nd];
212  double gv_r[Nd];
213  double gv_i[Nd];
214 
215  for (int s = 0; s < Nd; ++s) {
216  id[s] = gm.index(s);
217  gv_r[s] = gm.value_r(s);
218  gv_i[s] = gm.value_i(s);
219  idc_r[s] = gm.index_c(s);
220  idc_i[s] = 1 - idc_r[s];
221  }
222 
223  int ith, nth, is, ns;
224  set_threadtask(ith, nth, is, ns, Nvol);
225 
226  const int Nex = y.nex();
227 
228  for (int ex = 0; ex < Nex; ++ex) {
229  double *v = y.ptr(0, is, ex);
230  const double *w = x.ptr(0, is, ex);
231 
232  for (int site = 0; site < ns; ++site) {
233  int iv = Ncd2 * site;
234 
235  for (int s = 0; s < Nd; ++s) {
236  int iv2 = s * Nc2 + iv;
237  int iw2 = id[s] * Nc2 + iv;
238 
239  for (int ic = 0; ic < Nc; ++ic) {
240  v[2 * ic + iv2] = gv_r[s] * w[2 * ic + idc_r[s] + iw2];
241  v[2 * ic + 1 + iv2] = gv_i[s] * w[2 * ic + idc_i[s] + iw2];
242  }
243  }
244  }
245  }
246 }
247 
248 
249 //====================================================================
250 void mult_iGM(Field_F& y, const GammaMatrix& gm, const Field_F& x)
251 {
252  assert(x.nex() == y.nex());
253  int Nvol = y.nvol();
254  assert(x.nvol() == Nvol);
255 
256  assert(x.nd() == ND);
257  const int Nc = x.nc();
258  const int Nc2 = x.nc2();
259  const int Ncd2 = Nc2 * ND;
260 
261  int id[ND];
262  int idc_r[ND];
263  int idc_i[ND];
264  double gv_r[ND];
265  double gv_i[ND];
266 
267  for (int s = 0; s < ND; ++s) {
268  id[s] = gm.index(s);
269  gv_r[s] = -gm.value_i(s);
270  gv_i[s] = gm.value_r(s);
271  idc_r[s] = 1 - gm.index_c(s);
272  idc_i[s] = 1 - idc_r[s];
273  }
274 
275  int ith, nth, is, ns;
276  set_threadtask(ith, nth, is, ns, Nvol);
277 
278  const int Nex = y.nex();
279 
280  for (int ex = 0; ex < Nex; ++ex) {
281  double *v = y.ptr(0, is, ex);
282  const double *w = x.ptr(0, is, ex);
283 
284  for (int site = 0; site < ns; ++site) {
285  int iv = Ncd2 * site;
286 
287  for (int s = 0; s < ND; ++s) {
288  int iv2 = s * Nc2 + iv;
289  int iw2 = id[s] * Nc2 + iv;
290  for (int ic = 0; ic < Nc; ++ic) {
291  v[2 * ic + iv2] = gv_r[s] * w[2 * ic + idc_r[s] + iw2];
292  v[2 * ic + 1 + iv2] = gv_i[s] * w[2 * ic + idc_i[s] + iw2];
293  }
294  }
295  }
296  }
297 }
298 
299 
300 //====================================================================
302  const int pm, const GammaMatrix& gm,
303  const Field_F& w)
304 {
305  assert(w.nvol() == y.nvol());
306  assert(w.nex() == y.nex());
307 
308  mult_GM(y, gm, w);
309 
310  if (pm == 1) {
311  axpy(y, 1.0, w); // y += w;
312  scal(y, 0.5); // y *= 0.5;
313  } else if (pm == -1) {
314  axpy(y, -1.0, w); // y -= w i.e. y = (gamma - 1) * w
315  scal(y, -0.5); // y *= -0.5 i.e. y = (1 - gamma)/2 * w
316  } else {
317  vout.crucial("Error at %s: wrong pm.\n", __func__);
318  exit(EXIT_FAILURE);
319  }
320 }
321 
322 
323 //====================================================================
325  const int pm, const GammaMatrix& gm,
326  const Field_F& w)
327 {
328  assert(w.nvol() == y.nvol());
329  assert(w.nex() == y.nex());
330 
331  mult_GM(y, gm, w);
332 
333  if (pm == 1) {
334  axpy(y, 1.0, w); // y += w;
335  } else if (pm == -1) {
336  axpy(y, -1.0, w); // y -= w;
337  scal(y, -1.0); // y *= -1.0;
338  } else {
339  vout.crucial("Error at %s: wrong pm.\n", __func__);
340  exit(EXIT_FAILURE);
341  }
342 }
343 
344 
345 //====================================================================
347  const double nu_s,
348  const int pm,
349  const double r_s,
350  const GammaMatrix& gm,
351  const Field_F& w)
352 {
353  assert(w.nvol() == y.nvol());
354  assert(w.nex() == y.nex());
355 
356  mult_GM(y, gm, w);
357  scal(y, nu_s); // y *= nu_s;
358 
359  if (pm == 1) {
360  axpy(y, r_s, w); // y += r_s * w;
361  } else if (pm == -1) {
362  axpy(y, -r_s, w); // y -= r_s * w i.e. y = (nu_s * gamma - r_s) * w
363  scal(y, -1.0); // y *= -1.0 i.e. y = (r_s - nu_s * gamma) * w
364  } else {
365  vout.crucial("Error at %s: wrong pm = %d\n", __func__, pm);
366  exit(EXIT_FAILURE);
367  }
368 }
369 
370 
371 //============================================================END=====
mult_GMproj
void mult_GMproj(Field_F &y, const int pm, const GammaMatrix &gm, const Field_F &w)
projection with gamma matrix: (1 \pm gamma)/2
Definition: field_F_imp.cpp:301
mult_GMproj2
void mult_GMproj2(Field_F &y, const int pm, const GammaMatrix &gm, const Field_F &w)
projection with gamma matrix: (1 \pm gamma)
Definition: field_F_imp.cpp:324
field_F.h
GammaMatrix::index_c
int index_c(int row) const
Definition: gammaMatrix.h:93
GammaMatrix::index
int index(int row) const
Definition: gammaMatrix.h:83
GammaMatrix
Gamma Matrix class.
Definition: gammaMatrix.h:44
GammaMatrix::value_i
double value_i(int row) const
Definition: gammaMatrix.h:103
Field::nex
int nex() const
Definition: field.h:128
GammaMatrix::value_r
double value_r(int row) const
Definition: gammaMatrix.h:98
Field_F::nc
int nc() const
Definition: field_F.h:89
Field_F::nc2
int nc2() const
Definition: field_F.h:90
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
mult_GM
void mult_GM(Field_F &y, const GammaMatrix &gm, const Field_F &x)
gamma matrix multiplication
Definition: field_F_imp.cpp:198
Field_F::check
void check()
check several assumptions for performance implementation.
Definition: field_F_imp.cpp:26
field_F_imp_SU2-inc.h
multadd_Field_Gn
void multadd_Field_Gn(Field_F &y, const int ex, const Field_G &U, const int ex1, const Field_F &x, const int ex2, const double a)
Definition: field_F_imp.cpp:116
field_F_imp_SU_N-inc.h
ND
#define ND
Definition: field_F_imp_SU2-inc.h:5
Field::nvol
int nvol() const
Definition: field.h:127
field_F_imp_SU3-inc.h
Field::ptr
const double * ptr(const int jin, const int site, const int jex) const
Definition: field.h:153
mult_iGM
void mult_iGM(Field_F &y, const GammaMatrix &gm, const Field_F &x)
gamma matrix multiplication (i is multiplied)
Definition: field_F_imp.cpp:250
mult_Field_Gd
void mult_Field_Gd(Field_F &y, const int ex, const Field_G &U, const int ex1, const Field_F &x, const int ex2)
Definition: field_F_imp.cpp:76
multadd_Field_Gd
void multadd_Field_Gd(Field_F &y, const int ex, const Field_G &U, const int ex1, const Field_F &x, const int ex2, const double a)
Definition: field_F_imp.cpp:157
scal
void scal(Field &x, const double a)
scal(x, a): x = a * x
Definition: field.cpp:261
Field_F
Wilson-type fermion field.
Definition: field_F.h:37
field_thread-inc.h
mult_Field_Gn
void mult_Field_Gn(Field_F &y, const int ex, const Field_G &U, const int ex1, const Field_F &x, const int ex2)
Definition: field_F_imp.cpp:36
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Field_G
SU(N) gauge field.
Definition: field_G.h:38
Field_F::nd
int nd() const
Definition: field_F.h:91
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512