CHROMA
inline_glue_matelem_colorvec.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline measurement of glueball operators via colorstd::vector matrix elements
3  */
4 
5 
6 #include "handle.h"
11 #include "meas/smear/displace.h"
12 #include "meas/glue/mesplq.h"
14 #include "util/ferm/key_val_db.h"
16 #include "util/ft/sftmom.h"
17 #include "util/info/proginfo.h"
19 
21 
22 namespace Chroma
23 {
24  /*!
25  * \ingroup inlineglue
26  *
27  * @{
28  */
29  namespace InlineGlueMatElemColorVecEnv
30  {
31  // Reader for input parameters
32  void read(XMLReader& xml, const std::string& path, Params::Param_t& param)
33  {
34  XMLReader paramtop(xml, path);
35 
36  int version;
37  read(paramtop, "version", version);
38 
39  switch (version)
40  {
41  case 1:
42  /**************************************************************************/
43  break;
44 
45  default :
46  /**************************************************************************/
47 
48  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
49  QDP_abort(1);
50  }
51 
52  read(paramtop, "mom2_max", param.mom2_max);
53  read(paramtop, "displacement_length", param.displacement_length);
54  read(paramtop, "displacement_list", param.displacement_list);
55  read(paramtop, "num_vecs", param.num_vecs);
56  read(paramtop, "decay_dir", param.decay_dir);
57 
58  param.link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
59  }
60 
61 
62  // Writer for input parameters
63  void write(XMLWriter& xml, const std::string& path, const Params::Param_t& param)
64  {
65  push(xml, path);
66 
67  int version = 1;
68 
69  write(xml, "version", version);
70  write(xml, "mom2_max", param.mom2_max);
71  write(xml, "displacement_length", param.displacement_length);
72  write(xml, "displacement_list", param.displacement_list);
73  write(xml, "num_vecs", param.num_vecs);
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, "colorvec_id", input.colorvec_id);
87  read(inputtop, "glue_op_file", input.glue_op_file);
88  }
89 
90  //! Write named objects
91  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
92  {
93  push(xml, path);
94 
95  write(xml, "gauge_id", input.gauge_id);
96  write(xml, "colorvec_id", input.colorvec_id);
97  write(xml, "glue_op_file", input.glue_op_file);
98 
99  pop(xml);
100  }
101 
102  // Writer for input parameters
103  void write(XMLWriter& xml, const std::string& path, const Params& param)
104  {
105  param.writeXML(xml, path);
106  }
107  }
108 
109 
110  namespace InlineGlueMatElemColorVecEnv
111  {
112  // Anonymous namespace for registration
113  namespace
114  {
115  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
116  const std::string& path)
117  {
118  return new InlineMeas(Params(xml_in, path));
119  }
120 
121  const std::string name = "GLUEBALL_MATELEM_COLORVEC";
122 
123  //! Local registration flag
124  bool registered = false;
125  }
126 
127  //! Register all the factories
128  bool registerAll()
129  {
130  bool success = true;
131  if (! registered)
132  {
133  success &= LinkSmearingEnv::registerAll();
134  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
135  registered = true;
136  }
137  return success;
138  }
139 
140 
141  //! Anonymous namespace
142  /*! Diagnostic stuff */
143  namespace
144  {
145  StandardOutputStream& operator<<(StandardOutputStream& os, const multi1d<int>& d)
146  {
147  if (d.size() > 0)
148  {
149  os << d[0];
150 
151  for(int i=1; i < d.size(); ++i)
152  os << " " << d[i];
153  }
154 
155  return os;
156  }
157  }
158 
159 
160  //----------------------------------------------------------------------------
161  // Param stuff
163  {
164  frequency = 0;
165  param.mom2_max = 0;
166  }
167 
168  Params::Params(XMLReader& xml_in, const std::string& path)
169  {
170  try
171  {
172  XMLReader paramtop(xml_in, path);
173 
174  if (paramtop.count("Frequency") == 1)
175  read(paramtop, "Frequency", frequency);
176  else
177  frequency = 1;
178 
179  // Read program parameters
180  read(paramtop, "Param", param);
181 
182  // Read in the output propagator/source configuration info
183  read(paramtop, "NamedObject", named_obj);
184 
185  // Possible alternate XML file pattern
186  if (paramtop.count("xml_file") != 0)
187  {
188  read(paramtop, "xml_file", xml_file);
189  }
190  }
191  catch(const std::string& e)
192  {
193  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
194  QDP_abort(1);
195  }
196  }
197 
198 
199  void
200  Params::writeXML(XMLWriter& xml_out, const std::string& path) const
201  {
202  push(xml_out, path);
203 
204  // Parameters for source construction
205  write(xml_out, "Param", param);
206 
207  // Write out the output propagator/source configuration info
208  write(xml_out, "NamedObject", named_obj);
209 
210  pop(xml_out);
211  }
212 
213 
214  //----------------------------------------------------------------------------
215  //! Normalize just one displacement array
216  multi1d<int> normDisp(const multi1d<int>& orig)
217  {
218  START_CODE();
219 
220  multi1d<int> disp;
221  multi1d<int> empty;
222  multi1d<int> no_disp(1); no_disp[0] = 0;
223 
224  // NOTE: a no-displacement is recorded as a zero-length array
225  // Convert a length one array with no displacement into a no-displacement array
226  if (orig.size() == 1)
227  {
228  if (orig == no_disp)
229  disp = empty;
230  else
231  disp = orig;
232  }
233  else
234  {
235  disp = orig;
236  }
237 
238  END_CODE();
239 
240  return disp;
241  } // void normDisp
242 
243 
244  //-------------------------------------------------------------------------------
245  // Function call
246  void
247  InlineMeas::operator()(unsigned long update_no,
248  XMLWriter& xml_out)
249  {
250  // If xml file not empty, then use alternate
251  if (params.xml_file != "")
252  {
253  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
254 
255  push(xml_out, "GlueMatElemColorVec");
256  write(xml_out, "update_no", update_no);
257  write(xml_out, "xml_file", xml_file);
258  pop(xml_out);
259 
260  XMLFileWriter xml(xml_file);
261  func(update_no, xml);
262  }
263  else
264  {
265  func(update_no, xml_out);
266  }
267  }
268 
269 
270  // Function call
271  void
272  InlineMeas::func(unsigned long update_no,
273  XMLWriter& xml_out)
274  {
275  START_CODE();
276 
277  StopWatch snoop;
278  snoop.reset();
279  snoop.start();
280 
281 
282  StopWatch swiss;
283 
284  // Test and grab a reference to the gauge field
285  XMLBufferWriter gauge_xml;
286  try
287  {
288  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
289  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
290 
291  // NB We are just checking this is here.
293  }
294  catch( std::bad_cast )
295  {
296  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
297  QDP_abort(1);
298  }
299  catch (const std::string& e)
300  {
301  QDPIO::cerr << name << ": std::map call failed: " << e << std::endl;
302  QDP_abort(1);
303  }
304 
305  // Cast should be valid now
306  const multi1d<LatticeColorMatrix>& u =
307  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
308 
309  const MapObject<int,EVPair<LatticeColorVector> >& eigen_source =
311 
312  push(xml_out, "GlueMatElemColorVec");
313  write(xml_out, "update_no", update_no);
314 
315  QDPIO::cout << name << ": Glue color-std::vector matrix element" << std::endl;
316 
317  proginfo(xml_out); // Print out basic program info
318 
319  // Write out the input
320  params.writeXML(xml_out, "Input");
321 
322  // Write out the config info
323  write(xml_out, "Config_info", gauge_xml);
324 
325  push(xml_out, "Output_version");
326  write(xml_out, "out_version", 1);
327  pop(xml_out);
328 
329  //First calculate some gauge invariant observables just for info.
330  //This is really cheap.
331  MesPlq(xml_out, "Observables", u);
332 
333  //
334  // Initialize the slow Fourier transform phases
335  //
336  SftMom phases(params.param.mom2_max, false, params.param.decay_dir);
337 
338  //
339  // Smear the gauge field if needed
340  //
341  multi1d<LatticeColorMatrix> u_smr = u;
342 
343  try
344  {
345  std::istringstream xml_l(params.param.link_smearing.xml);
346  XMLReader linktop(xml_l);
347  QDPIO::cout << "Link smearing type = " << params.param.link_smearing.id << std::endl;
348 
349 
351  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.param.link_smearing.id,
352  linktop,
354 
355  (*linkSmearing)(u_smr);
356  }
357  catch(const std::string& e)
358  {
359  QDPIO::cerr << name << ": Caught Exception link smearing: " << e << std::endl;
360  QDP_abort(1);
361  }
362 
363  // Record the smeared observables
364  MesPlq(xml_out, "Smeared_Observables", u_smr);
365 
366  //
367  // DB storage
368  //
369  BinaryStoreDB< SerialDBKey<KeyGlueElementalOperator_t>, SerialDBData<ValGlueElementalOperator_t> >
370  qdp_db;
371 
372  // Open the file, and write the meta-data and the binary for this operator
373  if (! qdp_db.fileExists(params.named_obj.glue_op_file))
374  {
375  XMLBufferWriter file_xml;
376 
377  push(file_xml, "DBMetaData");
378  write(file_xml, "id", std::string("glueElemOp"));
379  write(file_xml, "lattSize", QDP::Layout::lattSize());
380  write(file_xml, "decay_dir", params.param.decay_dir);
381  proginfo(file_xml); // Print out basic program info
382  write(file_xml, "Params", params.param);
383  write(file_xml, "Op_Info", params.param.displacement_list);
384  write(file_xml, "Config_info", gauge_xml);
385  write(file_xml, "Weights", getEigenValues(eigen_source, params.param.num_vecs));
386  pop(file_xml);
387 
388  std::string file_str(file_xml.str());
389  qdp_db.setMaxUserInfoLen(file_str.size());
390 
391  qdp_db.open(params.named_obj.glue_op_file, O_RDWR | O_CREAT, 0664);
392 
393  qdp_db.insertUserdata(file_str);
394  }
395  else
396  {
397  qdp_db.open(params.named_obj.glue_op_file, O_RDWR, 0664);
398  }
399 
400 
401  //
402  // Glue operators
403  //
404  // The creation and annihilation operators are the same without the
405  // spin matrices.
406  //
407  QDPIO::cout << "Building glue operators" << std::endl;
408 
409  push(xml_out, "ElementalOps");
410 
411 
412  // Loop over all time slices for the source. This is the same
413  // as the subsets for phases
414 
415  // Loop over each operator
416  for(int l=0; l < params.param.displacement_list.size(); ++l)
417  {
418  StopWatch watch;
419 
420  QDPIO::cout << "Elemental operator: op = " << l << std::endl;
421 
422  // Make sure displacement is something sensible
423  multi1d<int> disp = normDisp(params.param.displacement_list[l]);
424 
425  QDPIO::cout << "displacement = " << disp << std::endl;
426 
427  // The first version of this code used just rightNabla instead of leftRightNabla.
428  // Account for the change in normalization. Namely, for each derivative, multiply by -1/2.
429  Real fnorm = 1.0;
430  for(int mu=0; mu < disp.size(); ++mu)
431  fnorm *= -Real(0.5);
432 
433  // Build the operator
434  swiss.reset();
435  swiss.start();
436 
437  // Big loop over the momentum projection
438  for(int mom_num = 0 ; mom_num < phases.numMom() ; ++mom_num)
439  {
440  // The keys for the spin and displacements for this particular elemental operator
441  // Note: the "disp" is actually left-right derivatives. Apply them to the right std::vector.
442  // Invert the time - make it an independent key
443  multi1d<KeyValGlueElementalOperator_t> buf(phases.numSubsets());
444  for(int t=0; t < phases.numSubsets(); ++t)
445  {
446  buf[t].key.key().t_slice = t;
447  buf[t].key.key().mom = phases.numToMom(mom_num);
448  buf[t].key.key().left = 0; // not used
449  buf[t].key.key().right = 0; // not used
450  buf[t].key.key().displacement = disp; // only right colorstd::vector
451  buf[t].val.data().op.resize(params.param.num_vecs);
452  }
453 
454  for(int j = 0 ; j < params.param.num_vecs; ++j)
455  {
456  watch.reset();
457  watch.start();
458 
459  // Apply a left-right derivative onto the right std::vector. The momentum is required.
460  // Multiply by the momentum phase to project onto a definite momentum.
461  EVPair<LatticeColorVector> tmpvec; eigen_source.get(j,tmpvec);
462  LatticeColorVector lvec(tmpvec.eigenVector);
463 
464  LatticeColorVector shift_vec = leftRightNabla(u_smr,
465  lvec,
467  disp,
468  phases.numToMom(mom_num));
469 
470  // Contract over color indices
471  // Do the relevant quark contraction
472  LatticeComplex lop = localInnerProduct(lvec, shift_vec);
473 
474  // Slow fourier-transform
475  multi1d<ComplexD> op_sum = sumMulti(phases[mom_num] * lop, phases.getSet());
476 
477  watch.stop();
478 
479  for(int t=0; t < op_sum.size(); ++t)
480  {
481  buf[t].val.data().op(j) = fnorm * op_sum[t];
482  }
483  } // end for j
484 
485 // QDPIO::cout << "insert: mom= " << phases.numToMom(mom_num) << " displacement= " << disp << std::endl;
486  for(int t=0; t < phases.numSubsets(); ++t)
487  {
488  qdp_db.insert(buf[t].key, buf[t].val);
489  }
490 
491  } // mom_num
492 
493  swiss.stop();
494 
495  QDPIO::cout << "Glue operator= " << l
496  << " time= "
497  << swiss.getTimeInSeconds()
498  << " secs" << std::endl;
499 
500  } // for l
501 
502  pop(xml_out); // ElementalOps
503 
504  // Close the namelist output file XMLDAT
505  pop(xml_out); // GlueMatElemColorVector
506 
507  snoop.stop();
508  QDPIO::cout << name << ": total time = "
509  << snoop.getTimeInSeconds()
510  << " secs" << std::endl;
511 
512  QDPIO::cout << name << ": ran successfully" << std::endl;
513 
514  END_CODE();
515  } // func
516  } // namespace InlineGlueMatElemColorVecEnv
517 
518  /*! @} */ // end of group inlineglue
519 
520 } // namespace Chroma
521 
522 
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
int mu
Definition: cool.cc:24
Parallel transport a lattice field.
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 leftRightNabla(const LatticeColorVector &F, const multi1d< LatticeColorMatrix > &u, int mu, int length, int mom)
Apply first deriv to the right onto source.
Definition: displace.cc:415
Class for counted reference semantics.
Inline measurement of glueball operators via colorstd::vector matrix elements.
MODS_t & eigen_source
Eigenvectors.
Key for glueball colorstd::vector matrix elements.
Key and values for DB.
unsigned j
Definition: ldumul_w.cc:35
Make xml file writer.
int t
Definition: meslate.cc:37
Named object function std::map.
static bool registered
Local registration flag.
const std::string name
Name to be used.
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.
void write(XMLWriter &xml, const std::string &path, const Params::Param_t &param)
QDPSubTypeTrait< typename BinaryReturn< C1, C2, FnLocalInnerProduct >::Type_t >::Type_t localInnerProduct(const QDPSubType< T1, C1 > &l, const QDPType< T2, C2 > &r)
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
multi1d< SubsetVectorWeight_t > getEigenValues(const MapObject< int, EVPair< LatticeColorVector > > &eigen_source, int num_vecs)
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.
A Pair type.
void writeXML(XMLWriter &xml_out, const std::string &path) const
Holds of vectors and weights.