CHROMA
inline_glue_diag_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 InlineGlueDiagMatElemColorVecEnv
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 InlineGlueDiagMatElemColorVecEnv
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_DIAG_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, "GlueDiagMatElemColorVec");
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, "GlueDiagMatElemColorVec");
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  // Hack for the moment. Can only support 0-momentum. For non-zero momentum,
335  // we need leftNabla-s that have proper momentum.
336  //
337  if (params.param.mom2_max != 0)
338  {
339  QDPIO::cerr << name << ": only support zero momentum at the moment. Need generalizatin for left derivs\n";
340  QDP_abort(1);
341  }
342 
343  //
344  // Initialize the slow Fourier transform phases
345  //
346  SftMom phases(params.param.mom2_max, false, params.param.decay_dir);
347 
348  //
349  // Smear the gauge field if needed
350  //
351  multi1d<LatticeColorMatrix> u_smr = u;
352 
353  try
354  {
355  std::istringstream xml_l(params.param.link_smearing.xml);
356  XMLReader linktop(xml_l);
357  QDPIO::cout << "Link smearing type = " << params.param.link_smearing.id << std::endl;
358 
359 
361  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.param.link_smearing.id,
362  linktop,
364 
365  (*linkSmearing)(u_smr);
366  }
367  catch(const std::string& e)
368  {
369  QDPIO::cerr << name << ": Caught Exception link smearing: " << e << std::endl;
370  QDP_abort(1);
371  }
372 
373  // Record the smeared observables
374  MesPlq(xml_out, "Smeared_Observables", u_smr);
375 
376  //
377  // DB storage
378  //
379  BinaryStoreDB< SerialDBKey<KeyGlueElementalOperator_t>, SerialDBData<ValGlueElementalOperator_t> >
380  qdp_db;
381 
382  // Open the file, and write the meta-data and the binary for this operator
383  if (! qdp_db.fileExists(params.named_obj.glue_op_file))
384  {
385  XMLBufferWriter file_xml;
386 
387  push(file_xml, "DBMetaData");
388  write(file_xml, "id", std::string("glueElemOp"));
389  write(file_xml, "lattSize", QDP::Layout::lattSize());
390  write(file_xml, "decay_dir", params.param.decay_dir);
391  proginfo(file_xml); // Print out basic program info
392  write(file_xml, "Params", params.param);
393  write(file_xml, "Op_Info", params.param.displacement_list);
394  write(file_xml, "Config_info", gauge_xml);
395  write(file_xml, "Weights", getEigenValues(eigen_source, params.param.num_vecs));
396  pop(file_xml);
397 
398  std::string file_str(file_xml.str());
399  qdp_db.setMaxUserInfoLen(file_str.size());
400 
401  qdp_db.open(params.named_obj.glue_op_file, O_RDWR | O_CREAT, 0664);
402 
403  qdp_db.insertUserdata(file_str);
404  }
405  else
406  {
407  qdp_db.open(params.named_obj.glue_op_file, O_RDWR, 0664);
408  }
409 
410 
411  //
412  // Glue operators
413  //
414  // The creation and annihilation operators are the same without the
415  // spin matrices.
416  //
417  QDPIO::cout << "Building glue operators" << std::endl;
418 
419  push(xml_out, "ElementalOps");
420 
421 
422  // Loop over all time slices for the source. This is the same
423  // as the subsets for phases
424 
425  // Loop over each operator
426  for(int l=0; l < params.param.displacement_list.size(); ++l)
427  {
428  StopWatch watch;
429 
430  QDPIO::cout << "Elemental operator: op = " << l << std::endl;
431 
432  // Make sure displacement is something sensible
433  multi1d<int> disp = normDisp(params.param.displacement_list[l]);
434 
435  QDPIO::cout << "displacement = " << disp << std::endl;
436 
437  // Build the operator
438  swiss.reset();
439  swiss.start();
440 
441  // Big loop over the momentum projection
442  for(int mom_num = 0 ; mom_num < phases.numMom() ; ++mom_num)
443  {
444  // The keys for the spin and displacements for this particular elemental operator
445  // No displacement for left colorstd::vector, only displace right colorstd::vector
446  // Invert the time - make it an independent key
447  multi1d<KeyValGlueElementalOperator_t> buf(phases.numSubsets());
448  for(int t=0; t < phases.numSubsets(); ++t)
449  {
450  buf[t].key.key().t_slice = t;
451  buf[t].key.key().mom = phases.numToMom(mom_num);
452  buf[t].key.key().left = 0; // not used
453  buf[t].key.key().right = 0; // not used
454  buf[t].key.key().displacement = disp; // only right colorstd::vector
455  buf[t].val.data().op.resize(params.param.num_vecs);
456  }
457 
458  for(int j = 0 ; j < params.param.num_vecs; ++j)
459  {
460  watch.reset();
461  watch.start();
462 
463  // Displace the right std::vector and multiply by the momentum phase
464  EVPair<LatticeColorVector> tmpvec; eigen_source.get(j,tmpvec);
465  LatticeColorVector lvec(tmpvec.eigenVector);
466 
467  LatticeColorVector shift_vec = rightNabla(u_smr,
468  lvec,
470  disp);
471 
472  // Contract over color indices
473  // Do the relevant quark contraction
474  LatticeComplex lop = localInnerProduct(lvec, shift_vec);
475 
476  // Slow fourier-transform
477  multi1d<ComplexD> op_sum = sumMulti(phases[mom_num] * lop, phases.getSet());
478 
479  watch.stop();
480 
481  for(int t=0; t < op_sum.size(); ++t)
482  {
483  buf[t].val.data().op(j) = op_sum[t];
484  }
485  } // end for j
486 
487 // QDPIO::cout << "insert: mom= " << phases.numToMom(mom_num) << " displacement= " << disp << std::endl;
488  for(int t=0; t < phases.numSubsets(); ++t)
489  {
490  qdp_db.insert(buf[t].key, buf[t].val);
491  }
492 
493  } // mom_num
494 
495  swiss.stop();
496 
497  QDPIO::cout << "Glue operator= " << l
498  << " time= "
499  << swiss.getTimeInSeconds()
500  << " secs" << std::endl;
501 
502  } // for l
503 
504  pop(xml_out); // ElementalOps
505 
506  // Close the namelist output file XMLDAT
507  pop(xml_out); // GlueDiagMatElemColorVector
508 
509  snoop.stop();
510  QDPIO::cout << name << ": total time = "
511  << snoop.getTimeInSeconds()
512  << " secs" << std::endl;
513 
514  QDPIO::cout << name << ": ran successfully" << std::endl;
515 
516  END_CODE();
517  } // func
518  } // namespace InlineGlueDiagMatElemColorVecEnv
519 
520  /*! @} */ // end of group inlineglue
521 
522 } // namespace Chroma
523 
524 
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 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 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 write(XMLWriter &xml, const std::string &path, const Params::Param_t &param)
void read(XMLReader &xml, const std::string &path, Params::Param_t &param)
multi1d< int > normDisp(const multi1d< int > &orig)
Normalize just one displacement array.
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.