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