Bridge++  Version 1.4.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
contract_4spinor.cpp
Go to the documentation of this file.
1 
15 
16 #include <cassert>
17 
18 #if defined USE_GROUP_SU3
19 #define NC 3
20 #define NC2 6
21 #define ND 4
22 #define NCD2 24
23 #define C1 0
24 #define C2 2
25 #define C3 4
26 #elif defined USE_GROUP_SU2
27 #define NC 2
28 #define NC2 4
29 #define ND 4
30 #define NCD2 16
31 #endif
32 
33 //====================================================================
34 void contract_at_t(dcomplex& corr,
35  const GammaMatrix& gm_sink,
36  const Field_F& v1, const Field_F& v2,
37  const int time)
38 {
39 #if defined USE_GROUP_SU_N
40  int NC = CommonParameters::Nc();
41  int ND = CommonParameters::Nd();
42  int NC2 = 2 * NC;
43  int NCD2 = NC2 * ND;
44 #endif
45 
46  const int Nvol = v1.nvol();
47  const int Nvol_s = Nvol / CommonParameters::Nt();
48 
49  assert(Nvol == v2.nvol());
50  assert(v1.nex() == 1);
51  assert(v2.nex() == 1);
52 
53  const double *w1 = v1.ptr(0);
54  const double *w2 = v2.ptr(0);
55 
56  int id1[ND];
57  int id2[ND];
58  for (int id = 0; id < ND; ++id) {
59  id1[id] = id * NC2;
60  id2[id] = gm_sink.index(id) * NC2;
61  }
62 
63  double c_r[ND];
64  double c_i[ND];
65  for (int id = 0; id < ND; ++id) {
66  c_r[id] = 0.0;
67  c_i[id] = 0.0;
68  }
69 
70 
71  for (int ss = 0; ss < Nvol_s; ++ss) {
72  int site = NCD2 * (ss + time * Nvol_s);
73 
74  for (int cc = 0; cc < NC; ++cc) {
75  for (int id = 0; id < ND; ++id) {
76  int ic1_r = 2 * cc + id1[id] + site;
77  int ic2_r = 2 * cc + id2[id] + site;
78 
79  int ic1_i = 2 * cc + 1 + id1[id] + site;
80  int ic2_i = 2 * cc + 1 + id2[id] + site;
81 
82  c_r[id] += w1[ic2_r] * w2[ic1_r]
83  + w1[ic2_i] * w2[ic1_i];
84 
85  c_i[id] += -w1[ic2_r] * w2[ic1_i]
86  + w1[ic2_i] * w2[ic1_r];
87  }
88  }
89  }
90 
91  corr = cmplx(0.0, 0.0);
92  for (int id = 0; id < ND; ++id) {
93  corr += gm_sink.value(id) * cmplx(c_r[id], c_i[id]);
94  }
95 }
96 
97 
98 //====================================================================
99 void contract_at_t(dcomplex& corr,
100  const std::vector<int>& momentum_sink,
101  const GammaMatrix& gm_sink,
102  const std::vector<int>& source_position,
103  const Field_F& v1, const Field_F& v2,
104  const int time)
105 {
106 #if defined USE_GROUP_SU_N
107  int NC = CommonParameters::Nc();
108  int ND = CommonParameters::Nd();
109  int NC2 = 2 * NC;
110  int NCD2 = NC2 * ND;
111 #endif
112 
113  const int Nvol = v1.nvol();
114  const int Nvol_s = Nvol / CommonParameters::Nt();
115  const int Nx = CommonParameters::Nx();
116  const int Ny = CommonParameters::Ny();
117  const int Nz = CommonParameters::Nz();
118  const int Lx = CommonParameters::Lx();
119  const int Ly = CommonParameters::Ly();
120  const int Lz = CommonParameters::Lz();
121 
122  assert(Nvol == v2.nvol());
123  assert(v1.nex() == 1);
124  assert(v2.nex() == 1);
125  assert(momentum_sink.size() == ND - 1);
126 
127  const double *w1 = v1.ptr(0);
128  const double *w2 = v2.ptr(0);
129 
130  int id1[ND];
131  int id2[ND];
132  for (int id = 0; id < ND; ++id) {
133  id1[id] = id * NC2;
134  id2[id] = gm_sink.index(id) * NC2;
135  }
136 
137  double c_r[ND];
138  double c_i[ND];
139  for (int id = 0; id < ND; ++id) {
140  c_r[id] = 0.0;
141  c_i[id] = 0.0;
142  }
143 
144  static const double PI = 4.0 * atan(1.0);
145  std::vector<double> p_unit(ND - 1);
146  p_unit[0] = (2.0 * PI / Lx) * momentum_sink[0];
147  p_unit[1] = (2.0 * PI / Ly) * momentum_sink[1];
148  p_unit[2] = (2.0 * PI / Lz) * momentum_sink[2];
149 
150  std::vector<int> ipe(ND - 1);
151  ipe[0] = Communicator::ipe(0);
152  ipe[1] = Communicator::ipe(1);
153  ipe[2] = Communicator::ipe(2);
154 
155 
156  for (int ss = 0; ss < Nvol_s; ++ss) {
157  int site = NCD2 * (ss + time * Nvol_s);
158 
159  int x = ss % Nx;
160  int y = ss % (Nx * Ny) / Nx;
161  int z = ss % (Nx * Ny * Nz) / (Nx * Ny);
162 
163  int x_global = x + ipe[0] * Nx;
164  int y_global = y + ipe[1] * Ny;
165  int z_global = z + ipe[2] * Nz;
166 
167  double p_x = p_unit[0] * (x_global - source_position[0]);
168  double p_y = p_unit[1] * (y_global - source_position[1]);
169  double p_z = p_unit[2] * (z_global - source_position[2]);
170 
171  double cos_p_xyz = cos(p_x + p_y + p_z);
172  double sin_p_xyz = sin(p_x + p_y + p_z);
173 
174  for (int cc = 0; cc < NC; ++cc) {
175  for (int id = 0; id < ND; ++id) {
176  int ic1_r = 2 * cc + id1[id] + site;
177  int ic2_r = 2 * cc + id2[id] + site;
178 
179  int ic1_i = 2 * cc + 1 + id1[id] + site;
180  int ic2_i = 2 * cc + 1 + id2[id] + site;
181 
182  double w1_w2_r = w1[ic2_r] * w2[ic1_r] + w1[ic2_i] * w2[ic1_i];
183  double w1_w2_i = -w1[ic2_r] * w2[ic1_i] + w1[ic2_i] * w2[ic1_r];
184 
185  //- corr[s0] += v2^dagger * v1 * exp(i * p_i * x_i)
186  c_r[id] += w1_w2_r * cos_p_xyz - w1_w2_i * sin_p_xyz;
187  c_i[id] += w1_w2_r * sin_p_xyz + w1_w2_i * cos_p_xyz;
188  }
189  }
190  }
191 
192  corr = cmplx(0.0, 0.0);
193  for (int id = 0; id < ND; ++id) {
194  corr += gm_sink.value(id) * cmplx(c_r[id], c_i[id]);
195  }
196 }
197 
198 
199 //====================================================================
200 void contract_at_t(dcomplex& corr,
201  const GammaMatrix& gm_sink,
202  const int i_alpha,
203  const Field_F& v1, const Field_F& v2, const Field_F& v3,
204  const int time)
205 {
206 #if defined USE_GROUP_SU3
207  const int Nvol = v1.nvol();
208  const int Nvol_s = Nvol / CommonParameters::Nt();
209 
210  assert(Nvol == v2.nvol());
211  assert(Nvol == v3.nvol());
212  assert(v1.nex() == 1);
213  assert(v2.nex() == 1);
214  assert(v3.nex() == 1);
215 
216  const double *w1 = v1.ptr(0);
217  const double *w2 = v2.ptr(0);
218  const double *w3 = v3.ptr(0);
219 
220  int id1[ND];
221  int id2[ND];
222  for (int id = 0; id < ND; ++id) {
223  id1[id] = id * NC2;
224  id2[id] = gm_sink.index(id) * NC2;
225  }
226  int id3 = i_alpha * NC2;
227 
228  double c_r[ND];
229  double c_i[ND];
230  for (int id = 0; id < ND; ++id) {
231  c_r[id] = 0.0;
232  c_i[id] = 0.0;
233  }
234 
235 
236  for (int ss = 0; ss < Nvol_s; ++ss) {
237  int site = NCD2 * (ss + time * Nvol_s);
238 
239  for (int id = 0; id < ND; ++id) {
240  int ic11_r = C1 + id1[id] + site;
241  int ic22_r = C2 + id2[id] + site;
242  int ic33_r = C3 + id3 + site;
243 
244  int ic11_i = C1 + 1 + id1[id] + site;
245  int ic22_i = C2 + 1 + id2[id] + site;
246  int ic33_i = C3 + 1 + id3 + site;
247 
248  int ic21_r = C2 + id1[id] + site;
249  int ic32_r = C3 + id2[id] + site;
250  int ic13_r = C1 + id3 + site;
251 
252  int ic21_i = C2 + 1 + id1[id] + site;
253  int ic32_i = C3 + 1 + id2[id] + site;
254  int ic13_i = C1 + 1 + id3 + site;
255 
256  int ic31_r = C3 + id1[id] + site;
257  int ic12_r = C1 + id2[id] + site;
258  int ic23_r = C2 + id3 + site;
259 
260  int ic31_i = C3 + 1 + id1[id] + site;
261  int ic12_i = C1 + 1 + id2[id] + site;
262  int ic23_i = C2 + 1 + id3 + site;
263 
264 
265  c_r[id] += (w1[ic11_r] * w2[ic22_r] - w1[ic11_i] * w2[ic22_i]) * w3[ic33_r]
266  - (w1[ic11_r] * w2[ic22_i] + w1[ic11_i] * w2[ic22_r]) * w3[ic33_i];
267  c_i[id] += (w1[ic11_r] * w2[ic22_r] - w1[ic11_i] * w2[ic22_i]) * w3[ic33_i]
268  + (w1[ic11_r] * w2[ic22_i] + w1[ic11_i] * w2[ic22_r]) * w3[ic33_r];
269 
270  c_r[id] += (w1[ic21_r] * w2[ic32_r] - w1[ic21_i] * w2[ic32_i]) * w3[ic13_r]
271  - (w1[ic21_r] * w2[ic32_i] + w1[ic21_i] * w2[ic32_r]) * w3[ic13_i];
272  c_i[id] += (w1[ic21_r] * w2[ic32_r] - w1[ic21_i] * w2[ic32_i]) * w3[ic13_i]
273  + (w1[ic21_r] * w2[ic32_i] + w1[ic21_i] * w2[ic32_r]) * w3[ic13_r];
274 
275  c_r[id] += (w1[ic31_r] * w2[ic12_r] - w1[ic31_i] * w2[ic12_i]) * w3[ic23_r]
276  - (w1[ic31_r] * w2[ic12_i] + w1[ic31_i] * w2[ic12_r]) * w3[ic23_i];
277  c_i[id] += (w1[ic31_r] * w2[ic12_r] - w1[ic31_i] * w2[ic12_i]) * w3[ic23_i]
278  + (w1[ic31_r] * w2[ic12_i] + w1[ic31_i] * w2[ic12_r]) * w3[ic23_r];
279 
280  c_r[id] -= (w1[ic31_r] * w2[ic22_r] - w1[ic31_i] * w2[ic22_i]) * w3[ic13_r]
281  - (w1[ic31_r] * w2[ic22_i] + w1[ic31_i] * w2[ic22_r]) * w3[ic13_i];
282  c_i[id] -= (w1[ic31_r] * w2[ic22_r] - w1[ic31_i] * w2[ic22_i]) * w3[ic13_i]
283  + (w1[ic31_r] * w2[ic22_i] + w1[ic31_i] * w2[ic22_r]) * w3[ic13_r];
284 
285  c_r[id] -= (w1[ic21_r] * w2[ic12_r] - w1[ic21_i] * w2[ic12_i]) * w3[ic33_r]
286  - (w1[ic21_r] * w2[ic12_i] + w1[ic21_i] * w2[ic12_r]) * w3[ic33_i];
287  c_i[id] -= (w1[ic21_r] * w2[ic12_r] - w1[ic21_i] * w2[ic12_i]) * w3[ic33_i]
288  + (w1[ic21_r] * w2[ic12_i] + w1[ic21_i] * w2[ic12_r]) * w3[ic33_r];
289 
290  c_r[id] -= (w1[ic11_r] * w2[ic32_r] - w1[ic11_i] * w2[ic32_i]) * w3[ic23_r]
291  - (w1[ic11_r] * w2[ic32_i] + w1[ic11_i] * w2[ic32_r]) * w3[ic23_i];
292  c_i[id] -= (w1[ic11_r] * w2[ic32_r] - w1[ic11_i] * w2[ic32_i]) * w3[ic23_i]
293  + (w1[ic11_r] * w2[ic32_i] + w1[ic11_i] * w2[ic32_r]) * w3[ic23_r];
294  }
295  }
296 
297  corr = cmplx(0.0, 0.0);
298  for (int id = 0; id < ND; ++id) {
299  corr += gm_sink.value(id) * cmplx(c_r[id], c_i[id]);
300  }
301 #endif // (USE_GROUP_SU3)
302 }
303 
304 
305 //====================================================================
306 //============================================================END=====
const double * ptr(const int jin, const int site, const int jex) const
Definition: field.h:142
void contract_at_t(dcomplex &corr, const GammaMatrix &gm_sink, const Field_F &v1, const Field_F &v2, const int time)
Contraction of hadron for 4-spinor fermion.
int nvol() const
Definition: field.h:116
static int ipe(const int dir)
logical coordinate of current proc.
#define NC
Wilson-type fermion field.
Definition: field_F.h:37
Gamma Matrix class.
Definition: gammaMatrix.h:44
int nex() const
Definition: field.h:117
dcomplex value(int row) const
Definition: gammaMatrix.h:88
int index(int row) const
Definition: gammaMatrix.h:83