CHROMA
stag_propShift_s.cc
Go to the documentation of this file.
1 /*! This function, converts a set of shifts stored in delta, into
2  * an index for the array of propagators.
3  */
4 
5 #include "chromabase.h"
8 
9 namespace Chroma {
10 
11 int deltaToPropIndex(multi1d<int>& delta)
12 {
13 
14  if( Nd != 4 ) {
15  QDPIO::cerr << "This routine only works for Nd=4, not Nd="<<Nd << std::endl;
16  QDP_abort(1);
17  }
18 
19  /* Paranoia -- Delta has to have Nd elements */
20  if( delta.size() != Nd ) {
21  QDPIO::cerr << "Delta has to have Nd elements as opposed to " << delta.size();
22  QDP_abort(1);
23  }
24 
25  /* Paranoia2 -- Delta can contain only 0 (no shift) and 1s (shift) */
26  for( int mu = 0; mu < Nd; mu++) {
27  if( delta[mu] != 0 && delta[mu] != 1 ) {
28  QDPIO::cerr << "Delta must be made up of either zeros or ones. Element " << mu << " has value " << delta[mu] << std::endl;
29  QDP_abort(1);
30  }
31  }
32 
33  /* The delta array is turned into a lexicographic index within
34  the 4d hypercube */
35  return(delta[0] + 2*( delta[1] + 2*(delta[2] + 2*delta[3])));
36 }
37 
38 
39 
40 
41 void PropIndexTodelta(int src_index, multi1d<int>& delta)
42 {
43 
44  if( Nd != 4 ) {
45  QDPIO::cerr << "This routine only works for Nd=4, not Nd="<<Nd << std::endl;
46  QDP_abort(1);
47  }
48 
49  /* Paranoia -- Delta has to have Nd elements */
50  if( delta.size() != Nd ) {
51  QDPIO::cerr << "Delta has to have Nd elements as opposed to " << delta.size();
52  QDP_abort(1);
53  }
54 
55  /* Paranoia1 -- src_index must lie in range */
56  if( src_index < 0 || src_index > 15 ) {
57  QDPIO::cerr << "src_index out of range " << src_index << "\n" ;
58  QDP_abort(1);
59  }
60 
61  //
62  delta[0] = src_index % 2 ;
63 
64  int tmp = ( src_index - delta[0] ) / 2 ;
65  delta[1] = tmp % 2 ;
66 
67  int tmpA = ( tmp - delta[1] ) / 2 ;
68  delta[2] = tmpA % 2 ;
69 
70  tmp = ( tmpA - delta[2] ) / 2 ;
71  delta[3] = tmp % 2 ;
72 
73 
74  /* Paranoia3 -- Delta can contain only 0 (no shift) and 1s (shift) */
75  for( int mu = 0; mu < Nd; mu++) {
76  if( delta[mu] != 0 && delta[mu] != 1 ) {
77  QDPIO::cerr << "Delta must be made up of either zeros or ones. Element " << mu << " has value " << delta[mu] << std::endl;
78  QDP_abort(1);
79  }
80  }
81 
82  return ;
83 }
84 
85 
86 /*! Given an array of forward shifts (up to 1 in each dimension) and a
87  * propagator. This routine will carry out up to 4 shifts on the input,
88  * possibly 1 in each dimension
89  */
90 
91 LatticeStaggeredPropagator shiftDeltaProp(multi1d<int>& delta,
92  const LatticeStaggeredPropagator& src)
93 {
94 
95  int mu;
96 
97  if( delta.size() != Nd ) {
98  QDPIO::cerr << "Delta has to have Nd elements as opposed to " << delta.size();
99  QDP_abort(1);
100  }
101 
102  for( mu = 0; mu < Nd; mu++) {
103  if( delta[mu] != 0 && delta[mu] != 1 ) {
104  QDPIO::cerr << "Delta must be made up of either zeros or ones. Element " << mu << " has value " << delta[mu] << std::endl;
105  QDP_abort(1);
106  }
107  }
108 
109  LatticeStaggeredPropagator ret_val = src;
110  LatticeStaggeredPropagator tmp;
111 
112  for( mu = 0; mu < Nd; mu++) {
113  if( delta[mu] == 1 ) {
114  // This at the moment cannot occur without a temporary
115  tmp = shift(ret_val, FORWARD, mu);
116  ret_val = tmp;
117  }
118  }
119 
120  return ret_val;
121 }
122 
123 
124 
125 
126 /**********************************************************************/
127 
128 template<typename T>
129 T shiftDeltaPropCov_t(multi1d<int>& delta,
130  const T & src,
131  multi1d<LatticeColorMatrix> u, bool sym_flag){
132 
133  /* This variant of shiftDeltaProp takes as an argument:
134  sym_flag=true for symmetric shifting;
135  sym_flag=false for no symmetric shifting;
136 
137  This is the gauge covariant shiftDeltaProp for gauge fixed configs.
138 
139  Shift averages over all paths between start and end locations.
140  */
141 
142 
143  int mu; /* shift direction */
144  int num_perms; /* number of permutations of shifts */
145  int i; /* loop index */
146  int j; /* loop index */
147  int fac; /* index for computing factorial */
148  const int length = 1 ; /* shift only one lat unit */
149  double inv_num_perms; /* = 1/num_perms */
150 
151  T ret_val=zero; /* returned value */
152  T tmp1; /* temp for holding shifted prop */
153  T tmp2; /* temp for holding shifted prop */
154 
155  const int shift_index[24][4]=
156  {{0,1,2,3},{1,0,2,3},{0,2,1,3},{2,0,1,3},{1,2,0,3},{2,1,0,3},
157  {0,1,3,2},{1,0,3,2},{0,3,1,2},{3,0,1,2},{1,3,0,2},{3,1,0,2},
158  {0,2,3,1},{0,3,2,1},{2,0,3,1},{2,3,0,1},{3,2,0,1},{3,0,2,1},
159  {1,2,3,0},{1,3,2,0},{2,1,3,0},{2,3,1,0},{3,1,2,0},{3,2,1,0}};
160 
161  /*
162  Some notes about the shift_index. This 24x4 matrix is all of the
163  24 permutations of 4 different links, that is, they make up
164  the 24 different paths connecting opposite corners of a 4-d
165  hypercube.
166 
167  The ordering is significant!
168  The "upper-left" 6x3 matrix contained within it is the collection
169  of all 6 permutations of 3 paths:
170  {{0,1,2},{1,0,2},{0,2,1},{2,0,1},{1,2,0},{2,1,0}}
171 
172  Likewise the "upper-left" 2x2 matrix contained within is
173  the collection of both 2-link paths connecting opposite corners of
174  a square:
175  {{0,1},{1,0}}
176 
177  Of course the first element (a 1x1) is the one 1-link path between
178  two adjacent vertices:
179  {{0}}
180 
181  Of course this little hack crashes and burns when Nd>4
182 
183  */
184 
185  /*debug*/
186  /*
187  if(sym_flag){
188  printf("SYM SHIFT!\n");
189  }else{
190  printf("NOT SYM SHIFT!\n");
191  }
192  */
193  if( Nd != 4 ) {
194  QDPIO::cerr << "This only works for Nd=4 , not Nd=" << Nd;
195  QDP_abort(1);
196  }
197 
198  if( delta.size() != Nd ) {
199  QDPIO::cerr << "Delta has to have Nd elements as opposed to " << delta.size();
200  QDP_abort(1);
201  }
202 
203  for( mu = 0; mu < Nd; mu++) {
204  if( delta[mu] != 0 && delta[mu] != 1 ) {
205  QDPIO::cerr << "Delta must be made up of either zeros or ones. Element " << mu << " has value " << delta[mu] << std::endl;
206  QDP_abort(1);
207  }
208  }
209 
210  int num_shifts = 0 ;
211  multi1d<int> delta_order(4);
212  delta_order = 0 ;
213 
214  for( mu = 0; mu < Nd; mu++) {
215  if(delta[mu] ==1 ){
216  delta_order[num_shifts] = mu ;
217  ++num_shifts ;
218  }
219  }
220 
221 
222  /* find the number of permutations = factorial(num_shifts) */
223  num_perms=1;
224  fac=num_shifts;
225 
226  while(fac>1){
227  num_perms*=fac;
228  fac--;
229  }
230  inv_num_perms= 1.0/((double)num_perms);
231 
232  ret_val=zero; /* initialize returned value */
233 
234  for(i=0; i<num_perms; i++){
235  tmp1=src;
236  tmp2=src;
237  for(j=0; j<num_shifts; j++){
238 
239  displacement(u,tmp1,length, delta_order[shift_index[i][j]]);
240 
241  if(sym_flag){
242 
243  displacement(u,tmp2,-length, delta_order[shift_index[i][j]]);
244 
245  tmp1+=tmp2;
246  tmp1*=0.5;
247  tmp2=tmp1;
248  }
249  }
250 
251  ret_val+=tmp1;
252 
253  }
254  /* normalize by the number of permutations */
255  ret_val*=inv_num_perms;
256 
257  return ret_val;
258 }
259 
260 LatticeStaggeredPropagator shiftDeltaPropCov(multi1d<int>& delta,
261  const LatticeStaggeredPropagator& src,
262  multi1d<LatticeColorMatrix> u, bool sym_flag)
263 {
264 
265  return shiftDeltaPropCov_t<LatticeStaggeredPropagator>(delta,src,u,
266  sym_flag);
267 }
268 
269 
270 
271 LatticeStaggeredFermion shiftDeltaPropCov(multi1d<int>& delta,
272  const LatticeStaggeredFermion& src,
273  multi1d<LatticeColorMatrix> u, bool sym_flag)
274 {
275 
276  LatticeStaggeredFermion tmp =
277  shiftDeltaPropCov_t<LatticeStaggeredFermion>(delta,src,u,
278  sym_flag);
279 
280  // LatticeStaggeredFermion tmp = zero ; // DEBUG
281 
282  return tmp ;
283 }
284 
285 
286 
287 
288 
289 /*************************************************************************/
290 LatticeStaggeredPropagator shiftDeltaProp(multi1d<int>& delta,
291  const LatticeStaggeredPropagator& src,
292  bool sym_flag){
293 
294  /* This variant of shiftDeltaProp takes as an argument:
295  sym_flag=true for symmetric shifting;
296  sym_flag=false for no symmetric shifting;
297 
298  This is the non-covariant shiftDeltaProp for gauge fixed configs.
299 
300  Maybe should have a test to make sure gauge is fixed???
301 
302  */
303 
304  int mu;
305 
306  if( delta.size() != Nd ) {
307  QDPIO::cerr << "Delta has to have Nd elements as opposed to " << delta.size();
308  QDP_abort(1);
309  }
310 
311  for( mu = 0; mu < Nd; mu++) {
312  if( delta[mu] != 0 && delta[mu] != 1 ) {
313  QDPIO::cerr << "Delta must be made up of either zeros or ones. Element " << mu << " has value " << delta[mu] << std::endl;
314  QDP_abort(1);
315  }
316  }
317 
318  LatticeStaggeredPropagator ret_val = src;
319  LatticeStaggeredPropagator tmp1;
320  LatticeStaggeredPropagator tmp2;
321 
322  for( mu = 0; mu < Nd; mu++) {
323  if( delta[mu] == 1 ) {
324  // This at the moment cannot occur without a temporary
325  tmp1 = shift(ret_val, FORWARD, mu);
326  if(sym_flag){
327  tmp2 = shift(ret_val, BACKWARD, mu);
328  }
329  if(sym_flag){
330  ret_val = 0.5*(tmp1+tmp2);
331  }else{
332  ret_val = tmp1;
333  }
334  }
335  }
336 
337  return ret_val;
338 }
339 
340 } // end namespace Chroma
Primary include file for CHROMA library code.
int mu
Definition: cool.cc:24
Parallel transport a lattice field.
LatticePropagator displacement(const multi1d< LatticeColorMatrix > &u, const LatticePropagator &chi, int length, int dir)
Apply a displacement operator to a lattice field.
unsigned j
Definition: ldumul_w.cc:35
Nd
Definition: meslate.cc:74
Double tmp2
Definition: mesq.cc:30
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
int deltaToPropIndex(multi1d< int > &delta)
LinOpSysSolverMGProtoClover::T T
int i
Definition: pbg5p_w.cc:55
LatticeStaggeredPropagator shiftDeltaPropCov(multi1d< int > &delta, const LatticeStaggeredPropagator &src, multi1d< LatticeColorMatrix > u, bool sym_flag)
T shiftDeltaPropCov_t(multi1d< int > &delta, const T &src, multi1d< LatticeColorMatrix > u, bool sym_flag)
void PropIndexTodelta(int src_index, multi1d< int > &delta)
LatticeStaggeredPropagator shiftDeltaProp(multi1d< int > &delta, const LatticeStaggeredPropagator &src)
Double zero
Definition: invbicg.cc:106
#define FORWARD
Definition: primitives.h:82
#define BACKWARD
Definition: primitives.h:83