CHROMA
inline_glueball_ops.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline measurement of glueball operators
3  */
4 
5 
6 #include "handle.h"
11 #include "meas/smear/displace.h"
12 #include "meas/glue/mesplq.h"
13 #include "meas/glue/mesfield.h"
15 #include "util/ferm/key_val_db.h"
17 #include "util/gauge/taproj.h"
18 #include "util/ft/sftmom.h"
19 #include "util/info/proginfo.h"
21 
23 
24 namespace Chroma
25 {
26  /*!
27  * \ingroup inlineglue
28  *
29  * @{
30  */
31  namespace InlineGlueballOpsEnv
32  {
33  // Reader for input parameters
34  void read(XMLReader& xml, const std::string& path, Params::Param_t& param)
35  {
36  XMLReader paramtop(xml, path);
37 
38  int version;
39  read(paramtop, "version", version);
40 
41  switch (version)
42  {
43  case 1:
44  /**************************************************************************/
45  break;
46 
47  default :
48  /**************************************************************************/
49 
50  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
51  QDP_abort(1);
52  }
53 
54  read(paramtop, "mom2_max", param.mom2_max);
55  read(paramtop, "displacement_length", param.displacement_length);
56  read(paramtop, "displacement_list", param.displacement_list);
57  read(paramtop, "decay_dir", param.decay_dir);
58 
59  param.link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
60  }
61 
62 
63  // Writer for input parameters
64  void write(XMLWriter& xml, const std::string& path, const Params::Param_t& param)
65  {
66  push(xml, path);
67 
68  int version = 1;
69 
70  write(xml, "version", version);
71  write(xml, "mom2_max", param.mom2_max);
72  write(xml, "displacement_length", param.displacement_length);
73  write(xml, "displacement_list", param.displacement_list);
74  write(xml, "decay_dir", param.decay_dir);
75  xml << param.link_smearing.xml;
76 
77  pop(xml);
78  }
79 
80  //! Read named objects
81  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
82  {
83  XMLReader inputtop(xml, path);
84 
85  read(inputtop, "gauge_id", input.gauge_id);
86  read(inputtop, "glue_op_file", input.glue_op_file);
87  }
88 
89  //! Write named objects
90  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
91  {
92  push(xml, path);
93 
94  write(xml, "gauge_id", input.gauge_id);
95  write(xml, "glue_op_file", input.glue_op_file);
96 
97  pop(xml);
98  }
99 
100  // Writer for input parameters
101  void write(XMLWriter& xml, const std::string& path, const Params& param)
102  {
103  param.writeXML(xml, path);
104  }
105  }
106 
107 
108  namespace InlineGlueballOpsEnv
109  {
110  // Anonymous namespace for registration
111  namespace
112  {
113  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
114  const std::string& path)
115  {
116  return new InlineMeas(Params(xml_in, path));
117  }
118 
119  const std::string name = "GLUEBALL_OPS";
120 
121  //! Local registration flag
122  bool registered = false;
123  }
124 
125  //! Register all the factories
126  bool registerAll()
127  {
128  bool success = true;
129  if (! registered)
130  {
131  success &= LinkSmearingEnv::registerAll();
132  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
133  registered = true;
134  }
135  return success;
136  }
137 
138 
139  //! Anonymous namespace
140  /*! Diagnostic stuff */
141  namespace
142  {
143  StandardOutputStream& operator<<(StandardOutputStream& os, const multi1d<int>& d)
144  {
145  if (d.size() > 0)
146  {
147  os << d[0];
148 
149  for(int i=1; i < d.size(); ++i)
150  os << " " << d[i];
151  }
152 
153  return os;
154  }
155  }
156 
157 
158  //----------------------------------------------------------------------------
159  // Param stuff
161  {
162  frequency = 0;
163  param.mom2_max = 0;
164  }
165 
166  Params::Params(XMLReader& xml_in, const std::string& path)
167  {
168  try
169  {
170  XMLReader paramtop(xml_in, path);
171 
172  if (paramtop.count("Frequency") == 1)
173  read(paramtop, "Frequency", frequency);
174  else
175  frequency = 1;
176 
177  // Read program parameters
178  read(paramtop, "Param", param);
179 
180  // Read in the output propagator/source configuration info
181  read(paramtop, "NamedObject", named_obj);
182 
183  // Possible alternate XML file pattern
184  if (paramtop.count("xml_file") != 0)
185  {
186  read(paramtop, "xml_file", xml_file);
187  }
188  }
189  catch(const std::string& e)
190  {
191  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
192  QDP_abort(1);
193  }
194  }
195 
196 
197  void
198  Params::writeXML(XMLWriter& xml_out, const std::string& path) const
199  {
200  push(xml_out, path);
201 
202  // Parameters for source construction
203  write(xml_out, "Param", param);
204 
205  // Write out the output propagator/source configuration info
206  write(xml_out, "NamedObject", named_obj);
207 
208  pop(xml_out);
209  }
210 
211 
212  //----------------------------------------------------------------------------
213  //! Normalize just one displacement array
214  multi1d<int> normDisp(const multi1d<int>& orig)
215  {
216  START_CODE();
217 
218  multi1d<int> disp;
219  multi1d<int> empty;
220  multi1d<int> no_disp(1); no_disp[0] = 0;
221 
222  // NOTE: a no-displacement is recorded as a zero-length array
223  // Convert a length one array with no displacement into a no-displacement array
224  if (orig.size() == 1)
225  {
226  if (orig == no_disp)
227  disp = empty;
228  else
229  disp = orig;
230  }
231  else
232  {
233  disp = orig;
234  }
235 
236  END_CODE();
237 
238  return disp;
239  } // void normDisp
240 
241 
242  //-------------------------------------------------------------------------------
243  // Function call
244  void
245  InlineMeas::operator()(unsigned long update_no,
246  XMLWriter& xml_out)
247  {
248  // If xml file not empty, then use alternate
249  if (params.xml_file != "")
250  {
251  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
252 
253  push(xml_out, "GlueballOps");
254  write(xml_out, "update_no", update_no);
255  write(xml_out, "xml_file", xml_file);
256  pop(xml_out);
257 
258  XMLFileWriter xml(xml_file);
259  func(update_no, xml);
260  }
261  else
262  {
263  func(update_no, xml_out);
264  }
265  }
266 
267 
268  // Function call
269  void
270  InlineMeas::func(unsigned long update_no,
271  XMLWriter& xml_out)
272  {
273  START_CODE();
274 
275  StopWatch snoop;
276  snoop.reset();
277  snoop.start();
278 
279 
280  StopWatch swiss;
281 
282  // Test and grab a reference to the gauge field
283  XMLBufferWriter gauge_xml;
284  try
285  {
286  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
287  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
288  }
289  catch( std::bad_cast )
290  {
291  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
292  QDP_abort(1);
293  }
294  catch (const std::string& e)
295  {
296  QDPIO::cerr << name << ": std::map call failed: " << e << std::endl;
297  QDP_abort(1);
298  }
299 
300  // Cast should be valid now
301  const multi1d<LatticeColorMatrix>& u =
302  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
303 
304  push(xml_out, "GlueballOps");
305  write(xml_out, "update_no", update_no);
306 
307  QDPIO::cout << name << ": Glueball operators" << std::endl;
308 
309  proginfo(xml_out); // Print out basic program info
310 
311  // Write out the input
312  params.writeXML(xml_out, "Input");
313 
314  // Write out the config info
315  write(xml_out, "Config_info", gauge_xml);
316 
317  push(xml_out, "Output_version");
318  write(xml_out, "out_version", 1);
319  pop(xml_out);
320 
321  //First calculate some gauge invariant observables just for info.
322  //This is really cheap.
323  MesPlq(xml_out, "Observables", u);
324 
325  //
326  // Hack for the moment. Can only support 0-momentum. For non-zero momentum,
327  // we need leftNabla-s that have proper momentum.
328  //
329  if (params.param.mom2_max != 0)
330  {
331  QDPIO::cerr << name << ": only support zero momentum at the moment. Need generalizatin for left derivs\n";
332  QDP_abort(1);
333  }
334 
335  //
336  // Initialize the slow Fourier transform phases
337  //
338  SftMom phases(params.param.mom2_max, false, params.param.decay_dir);
339 
340  //
341  // Smear the gauge field if needed
342  //
343  multi1d<LatticeColorMatrix> u_smr = u;
344 
345  try
346  {
347  std::istringstream xml_l(params.param.link_smearing.xml);
348  XMLReader linktop(xml_l);
349  QDPIO::cout << "Link smearing type = " << params.param.link_smearing.id << std::endl;
350 
351 
353  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.param.link_smearing.id,
354  linktop,
356 
357  (*linkSmearing)(u_smr);
358  }
359  catch(const std::string& e)
360  {
361  QDPIO::cerr << name << ": Caught Exception link smearing: " << e << std::endl;
362  QDP_abort(1);
363  }
364 
365  // Record the smeared observables
366  MesPlq(xml_out, "Smeared_Observables", u_smr);
367 
368 
369  //
370  // Construct chroma-mag fields
371  //
372  multi1d<LatticeColorMatrix> B_mag(Nd-1);
373 
374  try
375  {
376  if (Nd != 4)
377  {
378  QDPIO::cerr << name << ": expects a 4d build\n";
379  QDP_abort(1);
380  }
381 
382  // Computes anti-hermitian F fields
383  multi1d<LatticeColorMatrix> f;
384  mesField(f, u_smr);
385 
386  // The B fields
387  multi1d<int> ind(3);
388  ind[0] = 3;
389  ind[1] = 1;
390  ind[2] = 0;
391 
392  multi1d<int> sgnn(3);
393  sgnn[0] = +1;
394  sgnn[1] = -1;
395  sgnn[2] = +1;
396 
397  // Already anti-hermitan. Remove trace and convert to hermitian to keep my sanity.
398  for(int i=0; i < B_mag.size(); ++i)
399  {
400  taproj(f[ind[i]]);
401  B_mag[i] = sgnn[i] * imag(f[ind[i]]);
402  }
403  }
404  catch(const std::string& e)
405  {
406  QDPIO::cerr << name << ": some exception while producing B fields: " << e << std::endl;
407  QDP_abort(1);
408  }
409 
410 
411  //
412  // DB storage
413  //
414  BinaryStoreDB< SerialDBKey<KeyGlueElementalOperator_t>, SerialDBData<ValGlueElementalOperator_t> >
415  qdp_db;
416 
417  // Open the file, and write the meta-data and the binary for this operator
418  if (! qdp_db.fileExists(params.named_obj.glue_op_file))
419  {
420  XMLBufferWriter file_xml;
421 
422  // A hacked version of eigenvalues
423  multi1d<SubsetVectorWeight_t> evals(1);
424  evals[0].weights.resize(QDP::Layout::lattSize()[params.param.decay_dir]);
425  evals[0].weights = Real(1);
426 
427  push(file_xml, "DBMetaData");
428  write(file_xml, "id", std::string("glueElemOp"));
429  write(file_xml, "lattSize", QDP::Layout::lattSize());
430  write(file_xml, "decay_dir", params.param.decay_dir);
431  proginfo(file_xml); // Print out basic program info
432  write(file_xml, "Params", params.param);
433  write(file_xml, "Op_Info", params.param.displacement_list);
434  write(file_xml, "Config_info", gauge_xml);
435  write(file_xml, "Weights", evals);
436  pop(file_xml);
437 
438  std::string file_str(file_xml.str());
439  qdp_db.setMaxUserInfoLen(file_str.size());
440 
441  qdp_db.open(params.named_obj.glue_op_file, O_RDWR | O_CREAT, 0664);
442 
443  qdp_db.insertUserdata(file_str);
444  }
445  else
446  {
447  qdp_db.open(params.named_obj.glue_op_file, O_RDWR, 0664);
448  }
449 
450 
451  //
452  // Glue operators
453  //
454  // The creation and annihilation operators are the same without the
455  // spin matrices.
456  //
457  QDPIO::cout << "Building glue operators" << std::endl;
458 
459  push(xml_out, "ElementalOps");
460 
461 
462  // Loop over all time slices for the source. This is the same
463  // as the subsets for phases
464 
465  // Loop over each operator
466  for(int l=0; l < params.param.displacement_list.size(); ++l)
467  {
468  swiss.reset();
469  swiss.start();
470 
471  // Build the operator
472  QDPIO::cout << "Elemental operator: op = " << l << std::endl;
473 
474  // Make sure displacement is something sensible
475  multi1d<int> disp = normDisp(params.param.displacement_list[l]);
476 
477  QDPIO::cout << "displacement = " << disp << std::endl;
478 
479  // Right mag field
480  for(int j = 0 ; j < B_mag.size(); ++j)
481  {
482  // Displace the right std::vector
483  LatticeColorMatrix shift_vec = rightNabla(u_smr,
484  B_mag[j],
486  disp);
487 
488  // Left mag field
489  for(int i = 0 ; i < B_mag.size(); ++i)
490  {
491  // Contract over color indices.
492  // NOTE: no need for daggers - B fields are hermitian
493  LatticeComplex lop = trace(B_mag[i] * shift_vec);
494 
495 
496  // Big loop over the momentum projection
497  for(int mom_num = 0 ; mom_num < phases.numMom() ; ++mom_num)
498  {
499  // Slow fourier-transform
500  multi1d<ComplexD> op_sum = sumMulti(phases[mom_num] * lop, phases.getSet());
501 
502  // The keys for the spin and displacements for this particular elemental operator
503  // No displacement for left B-field, only displace right B-field
504  // Invert the time - make it an independent key.
506 
507  for(int t=0; t < phases.numSubsets(); ++t)
508  {
509  buf.key.key().t_slice = t;
510  buf.key.key().mom = phases.numToMom(mom_num);
511  buf.key.key().left = i + 1;
512  buf.key.key().right = j + 1;
513  buf.key.key().displacement = disp;
514 
515  // Should not be a phase
516  buf.val.data().op.resize(1);
517  buf.val.data().op(0) = op_sum[t];
518 
519 // QDPIO::cout << "insert: mom= " << phases.numToMom(mom_num) << " displacement= " << disp << std::endl;
520  qdp_db.insert(buf.key, buf.val);
521 
522  } // end for t
523  } // end for i
524  } // end for j
525 
526  } // mom_num
527 
528  swiss.stop();
529 
530  QDPIO::cout << "Glue operator= " << l
531  << " time= "
532  << swiss.getTimeInSeconds()
533  << " secs" << std::endl;
534 
535  } // for l
536 
537  pop(xml_out); // ElementalOps
538 
539  // Close the namelist output file XMLDAT
540  pop(xml_out); // GlueballOpstor
541 
542  snoop.stop();
543  QDPIO::cout << name << ": total time = "
544  << snoop.getTimeInSeconds()
545  << " secs" << std::endl;
546 
547  QDPIO::cout << name << ": ran successfully" << std::endl;
548 
549  END_CODE();
550  } // func
551  } // namespace InlineGlueballOpsEnv
552 
553  /*! @} */ // end of group inlineglue
554 
555 } // namespace Chroma
556 
557 
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
void func(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
Serializable value harness.
Definition: key_val_db.h:69
Fourier transform phase factor support.
Definition: sftmom.h:35
int numSubsets() const
Number of subsets - length in decay direction.
Definition: sftmom.h:63
multi1d< int > numToMom(int mom_num) const
Convert momenta id to actual array of momenta.
Definition: sftmom.h:78
int numMom() const
Number of momenta.
Definition: sftmom.h:60
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
static T & Instance()
Definition: singleton.h:432
Parallel transport a lattice field.
void taproj(LatticeColorMatrix &a)
Take the traceless antihermitian projection of a color matrix.
Definition: taproj.cc:31
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
std::string makeXMLFileName(std::string xml_file, unsigned long update_no)
Return a xml file name for inline measurements.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
LatticeColorVector rightNabla(const multi1d< LatticeColorMatrix > &u, const LatticeColorVector &chi, int length, const multi1d< int > &path)
Apply a right nabla path to a lattice field.
Class for counted reference semantics.
Inline measurement of glueball operators.
Key for glueball colorstd::vector matrix elements.
Key and values for DB.
unsigned j
Definition: ldumul_w.cc:35
Make xml file writer.
Calculates the antihermitian field strength tensor iF(mu,nu)
int t
Definition: meslate.cc:37
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
const std::string name
Name to be used.
void write(XMLWriter &xml, const std::string &path, const Params::Param_t &param)
bool registerAll()
Register all the factories.
void read(XMLReader &xml, const std::string &path, Params::Param_t &param)
multi1d< int > normDisp(const multi1d< int > &orig)
Normalize just one displacement array.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
QDP::StandardOutputStream & operator<<(QDP::StandardOutputStream &s, const multi1d< int > &d)
Definition: npr_vertex_w.cc:12
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
void mesField(multi1d< LatticeColorMatrixF > &f, const multi1d< LatticeColorMatrixF > &u)
Calculates the antihermitian field strength tensor iF(mu,nu)
Definition: mesfield.cc:80
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
DComplex d
Definition: invbicg.cc:99
START_CODE()
::std::string string
Definition: gtest.h:1979
int l
Definition: pade_trln_w.cc:111
Print out basic info about this program.
Fourier transform phase factor support.
void writeXML(XMLWriter &xml_out, const std::string &path) const
Holds key and value as temporaries.
SerialDBKey< KeyGlueElementalOperator_t > key
SerialDBData< ValGlueElementalOperator_t > val
Holds of vectors and weights.
Take the traceless antihermitian projection of a color matrix.