CHROMA
spin_rep.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Sparse matrix representation of spin matrices
3  */
4 
5 #include "util/ferm/spin_rep.h"
6 
7 namespace Chroma
8 {
9  //----------------------------------------------------------------------------------
10  // Construct a spin matrix in the DR rep
11  SpinMatrix constructSpinDR(int gamma)
12  {
13  return Gamma(gamma) * SpinMatrix(Real(1));
14  }
15 
16  //----------------------------------------------------------------------------------
17  // Construct a spin matrix in the DP rep
18  SpinMatrix constructSpinDP(int gamma)
19  {
20  return GammaDP(gamma) * SpinMatrix(Real(1));
21  }
22 
23 
24  //----------------------------------------------------------------------------
25  //! MatrixSpinRep reader
26  void read(XMLReader& xml, const std::string& path, MatrixSpinRep_t& param)
27  {
28  XMLReader paramtop(xml, path);
29 
30  read(paramtop, "left", param.left);
31  read(paramtop, "right", param.right);
32  read(paramtop, "Op", param.op);
33  }
34 
35  //! MatrixSpinRep writer
36  void write(XMLWriter& xml, const std::string& path, const MatrixSpinRep_t& param)
37  {
38  push(xml, path);
39 
40  write(xml, "left", param.left);
41  write(xml, "right", param.right);
42  write(xml, "Op", param.op);
43 
44  pop(xml);
45  }
46 
47  //----------------------------------------------------------------------------
48  //! MatrixSpinRep reader
49  void read(BinaryReader& bin, MatrixSpinRep_t& param)
50  {
51  read(bin, param.left);
52  read(bin, param.right);
53  read(bin, param.op);
54  }
55 
56  //! MatrixSpinRep writer
57  void write(BinaryWriter& bin, const MatrixSpinRep_t& param)
58  {
59  write(bin, param.left);
60  write(bin, param.right);
61  write(bin, param.op);
62  }
63 
64 
65  //----------------------------------------------------------------------------------
66  // Convert a generic spin matrix into a sparse spin representation
67  std::vector<MatrixSpinRep_t> convertTwoQuarkSpin(const SpinMatrix& in)
68  {
69  std::vector<MatrixSpinRep_t> out;
70 
71  for(int sl = 0; sl < Ns; ++sl)
72  {
73  for(int sr = 0; sr < Ns; ++sr)
74  {
75  Complex ss = peekSpin(in, sl, sr);
76  Real dd = localNorm2(ss);
77 
78  if (toBool(dd > Real(0.0)))
79  {
80  MatrixSpinRep_t rep;
81  rep.left = sl;
82  rep.right = sr;
83  rep.op = ss;
84 
85  out.push_back(rep);
86  }
87  }
88  }
89 
90  return out;
91  }
92 
93  //----------------------------------------------------------------------------------
94  // Convert a DR gamma matrix indexed by gamma into a sparse spin representation
95  std::vector<MatrixSpinRep_t> convertTwoQuarkSpinDR(int gamma)
96  {
97  return convertTwoQuarkSpin(constructSpinDR(gamma));
98  }
99 
100  //----------------------------------------------------------------------------------
101  // Convert a DP gamma matrix indexed by gamma into a sparse spin representation
102  std::vector<MatrixSpinRep_t> convertTwoQuarkSpinDP(int gamma)
103  {
104  return convertTwoQuarkSpin(constructSpinDP(gamma));
105  }
106 
107 
108  //----------------------------------------------------------------------------------
109  //! Fold in gamma_4 for source ops
111  {
112  MatrixSpinRep_t obj(spin);
113 
114  int lfac = 1;
115  int rfac = 1;
116 
117  if (src)
118  {
119  if (obj.left > 1)
120  lfac = -1;
121 
122  if (obj.right > 1)
123  rfac = -1;
124  }
125 
126  obj.op *= Real(lfac * rfac);
127 
128  return obj;
129  }
130 
131  //! Fold in gamma_4 for source ops
132  std::vector<MatrixSpinRep_t> foldSourceDP(const std::vector<MatrixSpinRep_t>& spin, bool src)
133  {
134  std::vector<MatrixSpinRep_t> obj;
135 
136  for(int aks = 0; aks < spin.size(); ++aks)
137  {
138  obj.push_back(foldSourceDP(spin[aks], src));
139  }
140 
141  return obj;
142  }
143 
144 
145  //----------------------------------------------------------------------------
146  //! Rank3SpinRep reader
147  void read(XMLReader& xml, const std::string& path, Rank3SpinRep_t& param)
148  {
149  XMLReader paramtop(xml, path);
150 
151  read(paramtop, "left", param.left);
152  read(paramtop, "middle", param.middle);
153  read(paramtop, "right", param.right);
154  read(paramtop, "Op", param.op);
155  }
156 
157  //! Rank3SpinRep writer
158  void write(XMLWriter& xml, const std::string& path, const Rank3SpinRep_t& param)
159  {
160  push(xml, path);
161 
162  write(xml, "left", param.left);
163  write(xml, "middle", param.middle);
164  write(xml, "right", param.right);
165  write(xml, "Op", param.op);
166 
167  pop(xml);
168  }
169 
170  //----------------------------------------------------------------------------
171  //! Rank3SpinRep reader
172  void read(BinaryReader& bin, Rank3SpinRep_t& param)
173  {
174  read(bin, param.left);
175  read(bin, param.middle);
176  read(bin, param.right);
177  read(bin, param.op);
178  }
179 
180  //! Rank3SpinRep writer
181  void write(BinaryWriter& bin, const Rank3SpinRep_t& param)
182  {
183  write(bin, param.left);
184  write(bin, param.middle);
185  write(bin, param.right);
186  write(bin, param.op);
187  }
188 
189 
190  //----------------------------------------------------------------------------
191  //! Convert a generic spin tensor into a sparse spin representation
192  std::vector<Rank3SpinRep_t> convertThreeQuarkSpin(const Array3dO<Complex>& in)
193  {
194  std::vector<Rank3SpinRep_t> out;
195 
196  if ((in.size1() != Ns) || (in.size2() != Ns) || (in.size3() != Ns))
197  {
198  std::cerr << __func__ << ": input has unexpected size\n";
199  exit(1);
200  }
201 
202  for(int sl = 0; sl < Ns; ++sl)
203  {
204  for(int sm = 0; sm < Ns; ++sm)
205  {
206  for(int sr = 0; sr < Ns; ++sr)
207  {
208  Complex ss = in(sl+1,sm+1,sr+1);
209  Real dd = localNorm2(ss);
210 
211  // Avoid round-off funnies. Numbers should not be really small. Consider that zero.
212  if (toBool(dd > Real(1.0e-15)))
213  {
214  Rank3SpinRep_t rep;
215  rep.left = sl;
216  rep.middle = sm;
217  rep.right = sr;
218  rep.op = ss;
219 
220  out.push_back(rep);
221  }
222  }
223  }
224  }
225 
226  return out;
227  }
228 
229 
230  //----------------------------------------------------------------------------------
231  //! Fold in gamma_4 for source ops
233  {
234  Rank3SpinRep_t obj(spin);
235 
236  int lfac = 1;
237  int mfac = 1;
238  int rfac = 1;
239 
240  if (src)
241  {
242  if (obj.left > 1)
243  lfac = -1;
244 
245  if (obj.middle > 1)
246  mfac = -1;
247 
248  if (obj.right > 1)
249  rfac = -1;
250  }
251 
252  obj.op *= Real(lfac * mfac * rfac);
253 
254  return obj;
255  }
256 
257  //! Fold in gamma_4 for source ops
258  std::vector<Rank3SpinRep_t> foldSourceDP(const std::vector<Rank3SpinRep_t>& spin, bool src)
259  {
260  std::vector<Rank3SpinRep_t> obj;
261 
262  for(int aks = 0; aks < spin.size(); ++aks)
263  {
264  obj.push_back(foldSourceDP(spin[aks], src));
265  }
266 
267  return obj;
268  }
269 
270 
271 } // end namespace Chroma
272 
273 
274 
275 
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
Handle< MapObject< int, EVPair< LatticeColorVector > > > obj
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
SpinMatrix constructSpinDR(int gamma)
Construct a spin matrix in the DR rep.
Definition: spin_rep.cc:11
SpinMatrix constructSpinDP(int gamma)
Construct a spin matrix in the DP rep.
Definition: spin_rep.cc:18
std::vector< MatrixSpinRep_t > convertTwoQuarkSpinDP(int gamma)
Convert a DP gamma matrix indexed by gamma into a sparse spin representation.
Definition: spin_rep.cc:102
std::vector< MatrixSpinRep_t > convertTwoQuarkSpin(const SpinMatrix &in)
Convert a generic spin matrix into a sparse spin representation.
Definition: spin_rep.cc:67
MatrixSpinRep_t foldSourceDP(const MatrixSpinRep_t &spin, bool src)
Fold in gamma_4 for source ops.
Definition: spin_rep.cc:110
pop(xml_out)
std::vector< Rank3SpinRep_t > convertThreeQuarkSpin(const Array3dO< Complex > &in)
Convert a generic spin tensor into a sparse spin representation.
Definition: spin_rep.cc:192
std::vector< MatrixSpinRep_t > convertTwoQuarkSpinDR(int gamma)
Convert a DR gamma matrix indexed by gamma into a sparse spin representation.
Definition: spin_rep.cc:95
static QDP_ColorVector * out
Constructor.
static QDP_ColorVector * in
::std::string string
Definition: gtest.h:1979
Sparse matrix representation of spin matrices.
The sparse representation of a spin matrix.
Definition: spin_rep.h:16
The sparse representation of a spin rank-3 tensor.
Definition: spin_rep.h:68