QUDA  1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
gamma.cuh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <complex_quda.h>
4 
5 namespace quda {
6 
7  //A simple Euclidean gamma matrix class for use with the Wilson projectors.
8  template <typename ValueType, QudaGammaBasis basis, int dir>
9  class Gamma {
10  private:
11  static constexpr int ndim = 4;
12 
13  protected:
14 
15  //Which gamma matrix (dir = 0,4)
16  //dir = 0: gamma^1, dir = 1: gamma^2, dir = 2: gamma^3, dir = 3: gamma^4, dir =4: gamma^5
17  //int dir;
18 
19  //The basis to be used.
20  //QUDA_DEGRAND_ROSSI_GAMMA_BASIS is the chiral basis
21  //QUDA_UKQCD_GAMMA_BASIS is the non-relativistic basis.
22  //QudaGammaBasis basis;
23 
24  public:
25  __device__ __host__ inline Gamma() { }
26  __device__ __host__ inline Gamma(const Gamma &g) { }
27 
28  __device__ __host__ inline int getcol(int row) const {
29  if (basis == QUDA_DEGRAND_ROSSI_GAMMA_BASIS) {
30  switch(dir) {
31  case 0:
32  case 1:
33  switch(row) {
34  case 0: return 3;
35  case 1: return 2;
36  case 2: return 1;
37  case 3: return 0;
38  }
39  break;
40  case 2:
41  case 3:
42  switch(row) {
43  case 0: return 2;
44  case 1: return 3;
45  case 2: return 0;
46  case 3: return 1;
47  }
48  break;
49  case 4:
50  switch(row) {
51  case 0: return 0;
52  case 1: return 1;
53  case 2: return 2;
54  case 3: return 3;
55  }
56  break;
57  }
58  } else {
59  switch(dir) {
60  case 0:
61  case 1:
62  switch(row) {
63  case 0: return 3;
64  case 1: return 2;
65  case 2: return 1;
66  case 3: return 0;
67  }
68  break;
69  case 2:
70  switch(row) {
71  case 0: return 2;
72  case 1: return 3;
73  case 2: return 0;
74  case 3: return 1;
75  }
76  break;
77  case 3:
78  switch(row) {
79  case 0: return 0;
80  case 1: return 1;
81  case 2: return 2;
82  case 3: return 3;
83  }
84  break;
85  case 4:
86  switch(row) {
87  case 0: return 2;
88  case 1: return 3;
89  case 2: return 0;
90  case 3: return 1;
91  }
92  break;
93  }
94  }
95  return 0;
96  }
97 
98  __device__ __host__ inline complex<ValueType> getelem(int row) const {
99  complex<ValueType> I(0,1);
100  if (basis == QUDA_DEGRAND_ROSSI_GAMMA_BASIS) {
101  switch(dir) {
102  case 0:
103  switch(row) {
104  case 0:
105  case 1:
106  return I;
107  case 2:
108  case 3:
109  return -I;
110  }
111  break;
112  case 1:
113  switch(row) {
114  case 0:
115  case 3:
116  return -1;
117  case 1:
118  case 2:
119  return 1;
120  }
121  break;
122  case 2:
123  switch(row) {
124  case 0:
125  case 3:
126  return I;
127  case 1:
128  case 2:
129  return -I;
130  }
131  break;
132  case 3:
133  switch(row) {
134  case 0:
135  case 1:
136  case 2:
137  case 3:
138  return 1;
139  }
140  break;
141  case 4:
142  switch(row) {
143  case 0:
144  case 1:
145  return -1;
146  case 2:
147  case 3:
148  return 1;
149  }
150  break;
151  }
152  } else if (basis == QUDA_UKQCD_GAMMA_BASIS) {
153  switch(dir) {
154  case 0:
155  switch(row) {
156  case 0:
157  case 1:
158  return I;
159  case 2:
160  case 3:
161  return -I;
162  }
163  break;
164  case 1:
165  switch(row) {
166  case 0:
167  case 3:
168  return 1;
169  case 1:
170  case 2:
171  return -1;
172  }
173  break;
174  case 2:
175  switch(row) {
176  case 0:
177  case 3:
178  return I;
179  case 1:
180  case 2:
181  return -I;
182  }
183  break;
184  case 3:
185  switch(row) {
186  case 0:
187  case 1:
188  return 1;
189  case 2:
190  case 3:
191  return -1;
192  }
193  break;
194  case 4:
195  switch(row) {
196  case 0:
197  case 1:
198  case 2:
199  case 3:
200  return 1;
201  }
202  break;
203  }
204  }
205  return 0;
206  }
207 
208  //Returns the matrix element.
209  __device__ __host__ inline complex<ValueType> getelem(int row, int col) const {
210  return getcol(row) == col ? getelem(row) : 0;
211  }
212 
213  //Like getelem, but one only needs to specify the row.
214  //The column of the non-zero component is returned via the "col" reference
215  __device__ __host__ inline complex<ValueType> getrowelem(int row, int &col) const {
216  col = getcol(row);
217  return getelem(row);
218  }
219 
220  // Multiplies a given row of the gamma matrix to a complex number
221  __device__ __host__ inline complex<ValueType> apply(int row, const complex<ValueType> &a) const {
222  complex<ValueType> I(0,1);
223  if (basis == QUDA_DEGRAND_ROSSI_GAMMA_BASIS) {
224  switch(dir) {
225  case 0:
226  switch(row) {
227  case 0: case 1: return complex<ValueType>(-a.imag(), a.real()); // I
228  case 2: case 3: return complex<ValueType>(a.imag(), -a.real()); // -I
229  }
230  break;
231  case 1:
232  switch(row) {
233  case 0: case 3: return -a;
234  case 1: case 2: return a;
235  }
236  break;
237  case 2:
238  switch(row) {
239  case 0: case 3: return complex<ValueType>(-a.imag(), a.real()); // I
240  case 1: case 2: return complex<ValueType>(a.imag(), -a.real()); // -I
241  }
242  break;
243  case 3:
244  switch(row) {
245  case 0: case 1: case 2: case 3: return a;
246  }
247  break;
248  case 4:
249  switch(row) {
250  case 0: case 1: return complex<ValueType>(-a.real(), -a.imag());
251  case 2: case 3: return a;
252  }
253  break;
254  }
255  } else if (basis == QUDA_UKQCD_GAMMA_BASIS) {
256  switch(dir) {
257  case 0:
258  switch(row) {
259  case 0: case 1: return complex<ValueType>(-a.imag(), a.real()); // I
260  case 2: case 3:return complex<ValueType>(a.imag(), -a.real()); // -I
261  }
262  break;
263  case 1:
264  switch(row) {
265  case 0: case 3: return a;
266  case 1: case 2: return -a;
267  }
268  break;
269  case 2:
270  switch(row) {
271  case 0: case 3: return complex<ValueType>(-a.imag(), a.real()); // I
272  case 1: case 2: return complex<ValueType>(a.imag(), -a.real()); // -I
273  }
274  break;
275  case 3:
276  switch(row) {
277  case 0: case 1: return a;
278  case 2: case 3: return -a;
279  }
280  break;
281  case 4:
282  switch(row) {
283  case 0: case 1: case 2: case 3: return a;
284  }
285  break;
286  }
287  }
288  return a;
289  }
290 
291  //Returns the type of Gamma matrix
292  inline constexpr int Dir() const { return dir; }
293  };
294 
295 } // namespace quda
static constexpr int ndim
Definition: gamma.cuh:11
__device__ __host__ Gamma()
Definition: gamma.cuh:25
constexpr int Dir() const
Definition: gamma.cuh:292
__device__ __host__ complex< ValueType > apply(int row, const complex< ValueType > &a) const
Definition: gamma.cuh:221
__device__ __host__ complex< ValueType > getrowelem(int row, int &col) const
Definition: gamma.cuh:215
__device__ __host__ Gamma(const Gamma &g)
Definition: gamma.cuh:26
__device__ __host__ int getcol(int row) const
Definition: gamma.cuh:28
__device__ __host__ complex< ValueType > getelem(int row, int col) const
Definition: gamma.cuh:209
__device__ __host__ complex< ValueType > getelem(int row) const
Definition: gamma.cuh:98