CHROMA
t_stout_state.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <cstdio>
4 
5 #include "chroma.h"
6 
10 
11 using namespace Chroma;
12 
13 typedef LatticeFermion T;
14 typedef multi1d<LatticeColorMatrix> P;
15 typedef multi1d<LatticeColorMatrix> Q;
16 
17 int main(int argc, char *argv[])
18 {
19  // Put the machine into a known state
20  Chroma::initialize(&argc, &argv);
21 
22  // Setup the layout
23  const int foo[] = {4,4,4,4};
24  multi1d<int> nrow(Nd);
25  nrow = foo; // Use only Nd elements
26 
27 
28  Real rho=0.22;
29  int n_smear=1;
30  int orthog_dir=15;
31 
32  Layout::setLattSize(nrow);
33  Layout::create();
34 
35  XMLFileWriter xml(Chroma::getXMLOutputFileName());
36  push(xml, "t_stout_state");
37 
38  push(xml,"lattis");
39  write(xml,"Nd", Nd);
40  write(xml,"Nc", Nc);
41  write(xml,"nrow", nrow);
42  pop(xml);
43 
44  //! Example of calling a plaquette routine
45  /*! NOTE: the STL is *not* used to hold gauge fields */
46  multi1d<LatticeColorMatrix> u(Nd);
48 
49  XMLReader file_xml, record_xml;
50  Cfg_t cfg;
52 
53  gaugeStartup(file_xml, record_xml, u, cfg);
54 
55  // Try out the plaquette routine
57  QDPIO::cout << "w_plaq = " << w_plaq << std::endl;
58  QDPIO::cout << "link = " << link << std::endl;
59 
60  // Write out the results
61  push(xml,"Observables");
62  write(xml,"w_plaq", w_plaq);
63  write(xml,"link", link);
64  pop(xml);
65 
66 
67  // ----------------- CHECK SMEARING ----------------------------------------
68  QDPIO::cout << std::endl << "Stout Smearing Checks " << std::endl;
69 
70 
71  push(xml, "SmearingParams");
72  write(xml, "rho", rho);
73  write(xml, "n_smear", n_smear);
74  write(xml, "orthog_dir", orthog_dir);
75  pop(xml);
76 
77  // smeared and unsmeared gauge fields
78  multi1d<LatticeColorMatrix> u_smear(Nd);
79  multi1d<LatticeColorMatrix> u_tmp(Nd);
80 
81  // Setup stout state smearing params.
83  s_p.n_smear = n_smear;
84  s_p.rho.resize(Nd, Nd);
85  s_p.smear_in_this_dirP.resize(Nd);
86 
87  for(int mu=0; mu < Nd; mu++) {
88  for(int nu=0; nu < Nd; nu++) {
89  if( mu != nu) {
90  s_p.rho(mu,nu) = rho;
91  }
92  else {
93  s_p.rho(mu,nu) = 0;
94  }
95  }
96 
97  s_p.smear_in_this_dirP[mu] = ( mu == orthog_dir ) ? false : true;
98  }
99 
100  // Get the unsmeared fields into u_tmp
101  u_tmp = u;
102  for(int i=0; i < n_smear; i++) {
103  for(int mu=0; mu < Nd; mu++){
104  if( mu != orthog_dir) {
105  Stouting::stout_smear(u_smear[mu], u_tmp, mu, s_p.smear_in_this_dirP, s_p.rho);
106  }
107  else {
108  u_smear[mu] = u_tmp[mu];
109  }
110  }
111 
112  u_tmp = u_smear;
113  }
114 
115  MesPlq(u_smear, w_plaq, s_plaq, t_plaq, link);
116  QDPIO::cout << "w_plaq ("<< n_smear << " levels of old stout smearing) = " << w_plaq << std::endl;
117 
118  push(xml, "CheckStoutStateSmear");
119  write(xml, "w_plaq_old_smear", w_plaq);
120  pop(xml);
121 
122  // ------------------ REGRESSION TEST THE STOUT SMEARING IN THE
123  // ------------------ STOUT STATE against the independently cosded routine
124 
125 
126  // Random Gauge Transformed field
127  multi1d<LatticeColorMatrix> u_rg(Nd);
128  LatticeColorMatrix g; // Gauge transformation matrices
129 
130  // Do the gauge transformation
131  u_rg = u;
132  rgauge(u_rg,g);
133 
134 
135  // Create the stout ferm states
136  typedef LatticeFermion T;
137  typedef multi1d<LatticeColorMatrix> P;
138  typedef multi1d<LatticeColorMatrix> Q;
139 
141  // Create Periodic FermBC
142 
143  Handle< StoutFermState<T,P,Q> > s_state( new StoutFermState<T,P,Q>(fbc, s_p, u) );
144  Handle< StoutFermState<T,P,Q> > s_state2( new StoutFermState<T,P,Q>(fbc, s_p, u_rg) );
145 
146 
147 
148  // Get the plaquette
149  MesPlq((*s_state).getLinks(), w_plaq, s_plaq, t_plaq, link);
150  QDPIO::cout << "w_plaq ("<< n_smear << " levels of new stout smearing) = " << w_plaq << std::endl;
151  write(xml, "new_smearing_from_state", w_plaq);
152 
153  // Try out the plaquette routine
154  MesPlq((*s_state2).getLinks(), w_plaq, s_plaq, t_plaq, link);
155  QDPIO::cout << "w_plaq (After gauge transf and " << n_smear << " levels new stout smearing) = " << w_plaq << std::endl << std::endl;
156 
157  write(xml, "new_smearing_from_state_gtrans", w_plaq);
158 
159  for(int mu=0; mu < Nd; mu++) {
160  QDPIO::cout << "mu: " << mu << std::endl;
161  LatticeColorMatrix Q1, Q2;
162  LatticeColorMatrix QQ1,QQ2;
163 
164  LatticeColorMatrix C_tmp;
165  LatticeDouble c0,c1,c0_rg,c1_rg;
166 
167  Stouting::getQsandCs(u_rg, Q2, QQ2, C_tmp, mu, s_p.smear_in_this_dirP, s_p.rho);
168  Stouting::getQsandCs(u,Q1,QQ1, C_tmp, mu, s_p.smear_in_this_dirP, s_p.rho);
169 
170  QDPIO::cout << "Gauge invatiance check for Q: " << norm2( Q2-g*Q1*adj(g) )
171  << std::endl;
172  QDPIO::cout << "Gauge invariance check for Q^2: "
173  << norm2( QQ2 - g*QQ1*adj(g)) << std::endl;
174 
175 
176 
177  multi1d<LatticeComplex> f(3), f_rg(3);
178  multi1d<LatticeComplex> b_1,b_2;
179  Stouting::getFsAndBs(Q2,QQ2,f_rg,b_1,b_2,false);
180  Stouting::getFsAndBs(Q1,QQ1,f,b_1,b_2,false);
181 
182  LatticeColorMatrix expiQ = (f[0]+f[1]*Q1+f[2]*QQ1);
183  LatticeColorMatrix rg_expiQ = (f_rg[0]+f_rg[1]*Q2+f_rg[2]*QQ2);
184  QDPIO::cout << "Gauge invariance check for e(iQ): "
185  << norm2( rg_expiQ - g*expiQ*adj(g)) << std::endl;
186 
187 
188  LatticeColorMatrix stout_link = expiQ*u[mu];
189  LatticeColorMatrix rg_stout_link = rg_expiQ*u_rg[mu];
190  QDPIO::cout << "Gauge invariance check for stout_link: "
191  << norm2( rg_stout_link - g*stout_link*shift(adj(g),FORWARD,mu) )
192  << std::endl;
193 
194  QDPIO::cout << "Diff getLink(): " << norm2(stout_link-s_state->getLinks()[mu])
195  <<std::endl;
196 
197  QDPIO::cout << "Diff getLink() gtrans ["<<mu<<"] = "
198  << norm2(rg_stout_link- s_state2->getLinks()[mu]) << std::endl;
199 
200  LatticeColorMatrix stout_smeared;
201  Stouting::stout_smear(stout_smeared, u, mu, s_p.smear_in_this_dirP, s_p.rho);
202  LatticeColorMatrix rg_stout_smeared;
203  Stouting::stout_smear(rg_stout_smeared, u_rg, mu, s_p.smear_in_this_dirP, s_p.rho);
204 
205  QDPIO::cout << "NonStateStoutSmear - StateStoutSmear: " << norm2(stout_smeared - s_state->getLinks()[mu]) << std::endl;
206  QDPIO::cout << "RG: NOnStateStoutSmeared -StateStoutSmeared: " <<norm2( rg_stout_smeared - s_state2->getLinks()[mu]) << std::endl;
207 
208 
209  }
210 
211  // Test the forces. Assume an action of the form
212  // 2 Re Tr U X where X is a fixed random SU3 matrix
213  // Then the (fat) force is U (or in the case of no smearing
214  // the thin force is U
215  // U Force has to transform as G(x) U adj(G+mu) (G+mu) X adj(G)
216  multi1d<LatticeColorMatrix> X(Nd);
217  for(int mu=0; mu < Nd; mu++) {
218  gaussian(X[mu]);
219  reunit(X[mu]);
220  }
221 
222  // Check that X commutes with U
223  multi1d<LatticeColorMatrix> F1(Nd),F2(Nd);
224  for(int mu=0; mu < Nd; mu++) {
225  F1[mu] = X[mu];
226  F2[mu] = shift(g,FORWARD,mu)*X[mu]*adj(g);
227  }
228 
229  s_state->deriv(F1);
230  s_state2->deriv(F2);
231 
232  for(int mu=0; mu < Nd; mu++) {
233  QDPIO::cout << "tr(RG F - F) = "<< norm2(trace(F2[mu]-F1[mu])) << std::endl;
234  }
235 
236  for(int mu=0; mu < Nd; mu++) {
237  QDPIO::cout << "RG F - gtrans(F) = "<< norm2(F2[mu]-g*F1[mu]*adj(g)) << std::endl;
238  }
239 
240 
241 #if 0
242  // Now get the forces
243  multi1d<LatticeColorMatrix> fat_force1(Nd); // original
244  multi1d<LatticeColorMatrix> fat_force2(Nd); // for the RG transform
245 
246  fat_force1 = zero;
247  fat_force2 = zero;
248 
249  LatticeFermion phi;
250  LatticeFermion X;
251  LatticeFermion Y;
252 
253  // Untransformed
254  gaussian(phi);
255 
256  Real Mass = 0.2;
257  Real RsdCG=Real(1.0e-7);
258  int MaxCG=200;
259 
260  // Get Force for untransformed field
261 
262  X=zero;
263  UnprecWilsonLinOp M1(s_state, Mass);
264  InvCG2<T>(M1, phi, X, RsdCG, MaxCG);
265  M1(Y, X, PLUS);
266  M1.deriv(fat_force, X, Y, MINUS);
267 
268 
269 
270  // Get Force for transformed field
271  LatticeFermion phi2 = g*phi; // Do not transfrom
272  X=zero;
273  UnprecWilsonLinOp M2(s_state2, Mass);
274  InvCG2<T>(M2, phi2, X, RsdCG, MaxCG);
275  M2(Y, X, PLUS);
276  M2.deriv(fat_force2, X,Y, MINUS);
277 
278 
279  for(int mu=0; mu < Nd; mu++) {
280  multi1d<LatticeColorMatrix>& l = fat_force;
281  multi1d<LatticeColorMatrix>& l2 = fat_force2;
282 
283  LatticeColorMatrix tmp_m = s_state2->getLinks()[mu]*l2[mu];
284  LatticeColorMatrix tmp_m2 = s_state->getLinks()[mu]*l[mu];
285 
286  // taproj(tmp_m);
287  //taproj(tmp_m2);
288 
289  LatticeColorMatrix diff_mat = adj(g)*tmp_m2*shift(g,FORWARD, mu) - tmp_m;
290 
291  QDPIO::cout << "Diff ["<<mu<<"] = " << norm2(diff_mat) << std::endl;
292  }
293 
294 #endif
295 
296 #if 0
297  QDPIO::cout << "Force norms before derivative with respect to thin links" << std::endl;
298  QDPIO::cout << "========================================================" << std::endl << std::endl;
299 
300  // Get Force norms
301  Double F_norm;
302 
303  push(xml, "ForcesCheck");
304 
305  F_norm = norm2(fat_force1);
306  QDPIO::cout << "F_norm for fat force is " << F_norm << std::endl;
307  write(xml, "forceNormPreGaugeDeriv", F_norm);
308 
309  F_norm = norm2(fat_force2);
310  QDPIO::cout << "F_norm for RG transformed fat_force is " << F_norm << std::endl;
311  write(xml, "forceNormPreGaugeDerivGt", F_norm);
312 
313 
314  // Now do the recursive derivative wrt thin links.
315  (*s_state).deriv(fat_force);
316  (*s_state2).deriv(fat_force2);
317 
318  QDPIO::cout << std::endl << std::endl;
319  QDPIO::cout << "Force norms after derivative with respect to thin links" << std::endl;
320  QDPIO::cout << "========================================================" << std::endl << std::endl;
321 
322  // Get Force norms
323  F_norm = norm2(fat_force1);
324  QDPIO::cout << "F_norm for fat force is " << F_norm << std::endl;
325  write(xml, "ForceNormPostGaugeDeriv", F_norm);
326 
327  F_norm = norm2(fat_force2);
328  QDPIO::cout << "F_norm for RG transformed fat_force is " << F_norm << std::endl;
329  write(xml, "ForceNormPostGaugeDerivGt", F_norm);
330 
331  multi1d<LatticeColorMatrix> force_diff(Nd);
332 
333  for(int mu=0; mu < Nd; mu++)
334  {
335  force_diff[mu] = fat_force1[mu] - adj(g)*fat_force2[mu]*g;
336  F_norm = sqrt(norm2(force_diff[mu]));
337  QDPIO::cout << "|| force - RG force in dir "<< mu <<" ||= "<< F_norm << std::endl;
338  std::ostringstream tagname;
339  tagname << "force_diff_norm_" << mu;
340  write(xml, tagname.str(), F_norm);
341  }
342  pop(xml);
343 
344  F_norm = sqrt(norm2(force_diff));
345  QDPIO::cout << "Total difference between original and gauge transformed force: " << F_norm << std::endl;
346  push(xml, "ForceDiffNorm");
347  write(xml, "totalForceDiffNorm", F_norm);
348  pop(xml);
349 
350 #endif
351  pop(xml);
352 
353  // Time to bolt
355 
356  exit(0);
357 }
Primary include file for CHROMA in application codes.
Class for counted reference semantics.
Definition: handle.h:33
Concrete class for all fermionic actions with trivial boundary conditions.
Stout field state.
Unpreconditioned Wilson-Dirac operator.
void deriv(multi1d< LatticeColorMatrix > &ds_u, const LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign) const
Derivative of unpreconditioned Wilson dM/dU.
int mu
Definition: cool.cc:24
int nu
Definition: cool.cc:25
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void rgauge(multi1d< LatticeColorMatrix > &u, LatticeColorMatrix &g)
Do a random gauge transformation on the u fields.
Definition: rgauge.cc:24
void getFsAndBs(const LatticeColorMatrix &Q, const LatticeColorMatrix &QQ, multi1d< LatticeComplex > &f, multi1d< LatticeComplex > &b1, multi1d< LatticeComplex > &b2, bool dobs)
Given c0 and c1 compute the f-s and b-s.
Definition: stout_utils.cc:874
void getQsandCs(const multi1d< LatticeColorMatrix > &u, LatticeColorMatrix &Q, LatticeColorMatrix &QQ, LatticeColorMatrix &C, int mu, const multi1d< bool > &smear_in_this_dirP, const multi2d< Real > &rho)
Given field U, construct the staples into C, form Q and Q^2 and compute c0 and c1.
Definition: stout_utils.cc:105
void stout_smear(LatticeColorMatrix &next, const multi1d< LatticeColorMatrix > &current, int mu, const multi1d< bool > &smear_in_this_dirP, const multi2d< Real > &rho)
Stout smear in a specific link direction.
Definition: stout_utils.cc:970
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
@ CFG_TYPE_WEAK_FIELD
Conjugate-Gradient algorithm for a generic Linear Operator.
Nd
Definition: meslate.cc:74
LatticeReal phi
Definition: mesq.cc:27
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
std::string getXMLOutputFileName()
Get output file name.
Definition: chroma_init.cc:91
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > enum InvType invType const multi1d< Real > & RsdCG
Definition: pbg5p_w.cc:30
static multi1d< LatticeColorMatrix > u
LinOpSysSolverMGProtoClover::Q Q
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > & Mass
Definition: pbg5p_w.cc:29
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > enum InvType invType const multi1d< Real > int MaxCG
Definition: pbg5p_w.cc:32
int i
Definition: pbg5p_w.cc:55
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
void reunit(LatticeColorMatrixF3 &xa)
Definition: reunit.cc:467
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
Double zero
Definition: invbicg.cc:106
FloatingPoint< double > Double
Definition: gtest.h:7351
Double link
Definition: pade_trln_w.cc:146
Double t_plaq
Definition: pade_trln_w.cc:145
int l
Definition: pade_trln_w.cc:111
Double w_plaq
Definition: pade_trln_w.cc:143
Double s_plaq
Definition: pade_trln_w.cc:144
#define FORWARD
Definition: primitives.h:82
Stout field state for stout links and a creator.
Gauge configuration structure.
Definition: cfgtype_io.h:16
CfgType cfg_type
Definition: cfgtype_io.h:17
int main(int argc, char *argv[])
multi1d< LatticeColorMatrix > P