CHROMA
su3hb.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Do one SU(2) subgroup heatbath update of SU(Nc) matrix U with action
3  */
4 
5 #include "chromabase.h"
8 #include "util/gauge/sunfill.h"
9 
10 namespace Chroma
11 {
12 
13  //! Do one SU(2) subgroup heatbath update of SU(Nc) matrix U with action
14  /*!
15  * \ingroup heatbath
16  *
17  * BetaMC * [tr(U*W) + hc] / (2Nc).
18  * Do at most nheat update trials of the Kennedy-Pstd::endleton or Creutz SU(2)
19  * heatbath algorithm.
20  *
21  * \param u field to be updated ( Modify )
22  * \param w "staple" field in the action ( Read )
23  * \param su2_index SU(2) subgroup index ( Read )
24  * \param nheat maximal number of update trials ( Read )
25  * \param ntrials total number of link trials ( Write )
26  * \param nfails total number of failed trials ( Write )
27  * \param sub Subset for updating ( Read )
28  */
29  void su3hb(LatticeColorMatrix& u,
30  const LatticeColorMatrix& w,
31  int su2_index,
32  int nheat,
33  int& ntrials,
34  int& nfails,
35  HeatbathType algorithm,
36  const Subset& sub)
37  {
38  START_CODE();
39 
40  /* V = U*W */
41  LatticeColorMatrix v;
42  v[sub] = u * w;
43 
44  /* Extract components r_k proportional to SU(2) submatrix su2_index */
45  /* from the "SU(Nc)" matrix V. The SU(2) matrix is parametrized in the */
46  /* sigma matrix basis. */
47  multi1d<LatticeReal> r(4);
48  su2Extract(r, v, su2_index, sub);
49 
50  /*
51  * Now project onto SU(2)
52  */
53  LatticeReal r_l;
54  r_l[sub] = sqrt(r[0]*r[0] + r[1]*r[1] + r[2]*r[2] + r[3]*r[3]);
55 
56  // Normalize
57  LatticeBoolean lbtmp;
58  lbtmp[sub] = r_l > fuzz;
59  LatticeReal lftmp;
60  lftmp[sub] = 1.0 / where(lbtmp, r_l, LatticeReal(1));
61 
62  // Fill (r[0]/r_l, -r[1]/r_l, -r[2]/r_l, -r[3]/r_l) for r_l > fuzz
63  // and (1,0,0,0) for sites with r_l < fuzz
64  multi1d<LatticeReal> a(4);
65  a[0][sub] = where(lbtmp, r[0] * lftmp, LatticeReal(1));
66  a[1][sub] = where(lbtmp, -(r[1] * lftmp), LatticeReal(0));
67  a[2][sub] = where(lbtmp, -(r[2] * lftmp), LatticeReal(0));
68  a[3][sub] = where(lbtmp, -(r[3] * lftmp), LatticeReal(0));
69 
70  /* Do up to nheat heatbath trials to create new r_0 */
71  /* This is the only place BetaMC is used, so on AnisoP: */
72 #if 0
73  Real dummy = TO_REAL(BetaMC) / TO_REAL(Nc);
74  if( AnisoP == YES ) dummy /= TO_REAL(xi_0);
75 #else
76  QDPIO::cerr << "FIX Beta" << std::endl;
77  Real dummy = 1; // **WARNING** FIX THIS
78 #endif
79  r_l[sub] *= dummy;
80 
81  int num_sites = sub.numSiteTable();
82  int itrials = num_sites;
83  ntrials = 0;
84  nfails = 0;
85 
86  LatticeBoolean lupdate;
87  LatticeReal lftmp1;
88  LatticeReal lftmp2;
89  LatticeBoolean lbtmp2;
90 
91  switch (algorithm)
92  {
93  case HEATBATH_TYPE_KPHB:
94  {
95  /*
96  * Kennedy-Pstd::endleton heatbath
97  */
98  int n_done = 0;
99  int nhb = 0;
100 
101  r[0][sub] = a[0];
102  lupdate[sub] = true;
103 
104  while ( nhb < nheat && n_done < num_sites )
105  {
106  ntrials += itrials;
107 
108  random(r[1], sub);
109  r[1][sub] = log(r[1]);
110 
111  random(r[2], sub);
112  r[2][sub] = log(r[2]);
113 
114  random(lftmp, sub);
115  r[3][sub] = pow(cos(Real(twopi)*lftmp),2);
116 
117  r[1][sub] += r[2] * r[3];
118  r[2][sub] = r[1] / r_l;
119 
120  /* r[2] is now a trial for 1+r[0] */
121  /* see if this is accepted */
122  random(lftmp, sub);
123  r[1][sub] = lftmp*lftmp;
124 
125  lbtmp[sub] = r[1] <= (1 + 0.5*r[2]);
126  lbtmp2[sub] = lbtmp & lupdate;
127  r[0][sub] = where(lbtmp2, 1+r[2], r[0]);
128 
129  int itmp = toInt(sum(where(lbtmp2, LatticeInteger(1), LatticeInteger(0)),sub));
130  n_done += itmp;
131  itrials -= itmp;
132  nfails += itrials;
133 
134  lupdate &= ! lbtmp;
135 
136  ++nhb;
137  }
138  }
139  break;
140 
141  case HEATBATH_TYPE_CrHB:
142  {
143  /*+ */
144  /* Creutz heatbath */
145  /*- */
146  int n_done = 0;
147  int nhb = 0;
148 
149  lftmp2 = exp(2 * r_l) - 1;
150 
151  r[0] = a[0];
152  lupdate = true;
153 
154  while ( nhb < nheat && n_done < num_sites )
155  {
156  ntrials += itrials;
157 
158  random(r[1], sub);
159  r[2][sub] = log(1 + r[1] * lftmp2) / r_l - 1;
160 
161  /* r[2] is now a trial for r[0] */
162  /* see if this is accepted */
163  random(lftmp1, sub);
164  r[1][sub] = lftmp1 * lftmp1;
165 
166  lbtmp = r[1] <= (1 - r[2] * r[2]);
167  lbtmp2 = lbtmp & lupdate;
168 
169  r[0][sub] = where(lbtmp2, r[2], r[0]);
170 
171  int itmp = toInt(sum(where(lbtmp2, LatticeInteger(1), LatticeInteger(0)),sub));
172  n_done += itmp;
173  itrials -= itmp;
174  nfails += itrials;
175 
176  lupdate &= ! lbtmp;
177 
178  ++nhb;
179  }
180  }
181  break;
182 
183  default:
184  QDPIO::cerr << __func__ << ": unknown algorithm type" << std::endl;
185  QDP_abort(1);
186  }
187 
188 
189  /* Now create r[1], r[2] and r[3] according to the spherical measure */
190  /* Take absolute value to guard against round-off */
191  random(lftmp1, sub);
192  r[2][sub] = 1 - 2*lftmp1;
193 
194  lftmp1[sub] = fabs(1 - r[0]*r[0]);
195  r[3][sub] = -(sqrt(lftmp1) * r[2]);
196 
197  /* Take absolute value to guard against round-off */
198  r_l[sub] = sqrt(fabs(lftmp1 - r[3]*r[3]));
199 
200  random(lftmp1, sub);
201  lftmp1[sub] *= twopi;
202  r[1][sub] = r_l * cos(lftmp1);
203  r[2][sub] = r_l * sin(lftmp1);
204 
205 
206  /* Update matrix is B = R * A, with B, R and A given by b_i, r_i and a_i */
207  multi1d<LatticeReal> b(4);
208  b[0][sub] = r[0]*a[0] - r[1]*a[1] - r[2]*a[2] - r[3]*a[3];
209  b[1][sub] = r[0]*a[1] + r[1]*a[0] - r[2]*a[3] + r[3]*a[2];
210  b[2][sub] = r[0]*a[2] + r[2]*a[0] - r[3]*a[1] + r[1]*a[3];
211  b[3][sub] = r[0]*a[3] + r[3]*a[0] - r[1]*a[2] + r[2]*a[1];
212 
213  /*
214  * Now fill an SU(3) matrix V with the SU(2) submatrix su2_index
215  * paramtrized by a_k in the sigma matrix basis.
216  */
217  sunFill(v, b, su2_index, sub);
218 
219  // U = V*U
220  LatticeColorMatrix tmp;
221  tmp[sub] = v * u;
222  u[sub] = tmp;
223 
224  END_CODE();
225  }
226 
227 } // end namespace Chroma
Primary include file for CHROMA library code.
EXTERN Real BetaMC
int su2_index
Definition: cool.cc:27
void sunFill(LatticeColorMatrix &dest, const multi1d< LatticeReal > &r, int su2_index, const Subset &s)
Fill a dest(su2_index) <- r_0,r_1,r_2,r_3 under a subset.
Definition: sunfill.cc:33
void su2Extract(multi1d< LatticeReal > &r, const LatticeColorMatrix &source, int su2_index, const Subset &s)
Su2_extract: r_0,r_1,r_2,r_3 <- source(su2_index) [SU(N) field] under a subset.
Definition: su2extract.cc:86
void su3hb(LatticeColorMatrix &u, const LatticeColorMatrix &w, int su2_index, int nheat, int &ntrials, int &nfails, HeatbathType algorithm, const Subset &sub)
Do one SU(2) subgroup heatbath update of SU(Nc) matrix U with action.
Definition: su3hb.cc:29
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
static Real xi_0()
Definition: coulgauge.cc:15
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
HeatbathType
Algorithm type.
Definition: su3hb.h:13
@ HEATBATH_TYPE_CrHB
Definition: su3hb.h:15
@ HEATBATH_TYPE_KPHB
Definition: su3hb.h:14
const Real twopi
Definition: chromabase.h:55
Complex a
Definition: invbicg.cc:95
START_CODE()
Complex b
Definition: invbicg.cc:96
#define YES
Definition: primitives.h:84
Double sum
Definition: qtopcor.cc:37
Real dummy
Definition: qtopcor.cc:36
int itmp
Definition: qtopcor.cc:34
Extract an unnormalized SU(2) matrix from a GL(3,C) matrix.
Do one SU(2) subgroup heatbath update of SU(Nc) matrix U with action.
Fill an SU(Nc) matrix with an SU(2) submatrix.