CHROMA
inline_static_prop_colorvec_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Compute a static prop (1/2)*(1+gamma_4)U*U*...U * multi1d<LatticeColorVector>
3  *
4  * Propagator calculation on a colorstd::vector
5  */
6 
7 #include "fermact.h"
10 #include "meas/glue/mesplq.h"
12 #include "meas/smear/displace.h"
14 
16 #include "util/ferm/transf.h"
17 #include "util/ft/sftmom.h"
18 #include "util/info/proginfo.h"
20 
22 
25 
26 namespace Chroma
27 {
28  namespace InlineStaticPropColorVecEnv
29  {
30  //! Propagator input
31  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
32  {
33  XMLReader inputtop(xml, path);
34 
35  read(inputtop, "gauge_id", input.gauge_id);
36  read(inputtop, "colorvec_id", input.colorvec_id);
37  read(inputtop, "prop_id", input.prop_id);
38 
39  // User Specified MapObject tags
40  input.prop_obj = readXMLGroup(inputtop, "PropMapObject", "MapObjType");
41  }
42 
43  //! Propagator output
44  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
45  {
46  push(xml, path);
47 
48  write(xml, "gauge_id", input.gauge_id);
49  write(xml, "colorvec_id", input.colorvec_id);
50  write(xml, "prop_id", input.prop_id);
51  xml << input.prop_obj.xml;
52 
53  pop(xml);
54  }
55 
56 
57  //! Propagator input
58  void read(XMLReader& xml, const std::string& path, Params::Param_t::Contract_t& input)
59  {
60  XMLReader inputtop(xml, path);
61 
62  read(inputtop, "num_vecs", input.num_vecs);
63  read(inputtop, "t_sources", input.t_sources);
64  read(inputtop, "decay_dir", input.decay_dir);
65  }
66 
67  //! Propagator output
68  void write(XMLWriter& xml, const std::string& path, const Params::Param_t::Contract_t& input)
69  {
70  push(xml, path);
71 
72  write(xml, "num_vecs", input.num_vecs);
73  write(xml, "t_sources", input.t_sources);
74  write(xml, "decay_dir", input.decay_dir);
75 
76  pop(xml);
77  }
78 
79 
80  //! Propagator input
81  void read(XMLReader& xml, const std::string& path, Params::Param_t& input)
82  {
83  XMLReader inputtop(xml, path);
84 
85  read(inputtop, "Contractions", input.contract);
86  }
87 
88  //! Propagator output
89  void write(XMLWriter& xml, const std::string& path, const Params::Param_t& input)
90  {
91  push(xml, path);
92 
93  write(xml, "Contractions", input.contract);
94 
95  pop(xml);
96  }
97 
98 
99  //! Propagator input
100  void read(XMLReader& xml, const std::string& path, Params& input)
101  {
103  input = tmp;
104  }
105 
106  //! Propagator output
107  void write(XMLWriter& xml, const std::string& path, const Params& input)
108  {
109  push(xml, path);
110 
111  write(xml, "Param", input.param);
112  write(xml, "NamedObject", input.named_obj);
113 
114  pop(xml);
115  }
116  } // namespace InlineStaticPropColorVecEnv
117 
118 
119  namespace InlineStaticPropColorVecEnv
120  {
121  namespace
122  {
123  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
124  const std::string& path)
125  {
126  return new InlineMeas(Params(xml_in, path));
127  }
128 
129  //! Local registration flag
130  bool registered = false;
131 
132  const std::string name = "STATIC_PROP_COLORVEC";
133  }
134 
135  //! Register all the factories
136  bool registerAll()
137  {
138  bool success = true;
139  if (! registered)
140  {
141  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
143  registered = true;
144  }
145  return success;
146  }
147 
148 
149  //----------------------------------------------------------------------------
150  // Param stuff
152 
153  Params::Params(XMLReader& xml_in, const std::string& path)
154  {
155  try
156  {
157  XMLReader paramtop(xml_in, path);
158 
159  if (paramtop.count("Frequency") == 1)
160  read(paramtop, "Frequency", frequency);
161  else
162  frequency = 1;
163 
164  // Parameters for source construction
165  read(paramtop, "Param", param);
166 
167  // Read in the output propagator/source configuration info
168  read(paramtop, "NamedObject", named_obj);
169 
170  // Possible alternate XML file pattern
171  if (paramtop.count("xml_file") != 0)
172  {
173  read(paramtop, "xml_file", xml_file);
174  }
175  }
176  catch(const std::string& e)
177  {
178  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
179  QDP_abort(1);
180  }
181  }
182 
183 
184 
185  // Function call
186  void
187  InlineMeas::operator()(unsigned long update_no,
188  XMLWriter& xml_out)
189  {
190  // If xml file not empty, then use alternate
191  if (params.xml_file != "")
192  {
193  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
194 
195  push(xml_out, "StaticPropColorVec");
196  write(xml_out, "update_no", update_no);
197  write(xml_out, "xml_file", xml_file);
198  pop(xml_out);
199 
200  XMLFileWriter xml(xml_file);
201  func(update_no, xml);
202  }
203  else
204  {
205  func(update_no, xml_out);
206  }
207  }
208 
209 
210  // Real work done here
211  void
212  InlineMeas::func(unsigned long update_no,
213  XMLWriter& xml_out)
214  {
215  START_CODE();
216 
217  StopWatch snoop;
218  snoop.reset();
219  snoop.start();
220 
221  // Test and grab a reference to the gauge field
222  multi1d<LatticeColorMatrix> u;
223  XMLBufferWriter gauge_xml;
224  try
225  {
226  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
227  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
228  }
229  catch( std::bad_cast )
230  {
231  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
232  QDP_abort(1);
233  }
234  catch (const std::string& e)
235  {
236  QDPIO::cerr << name << ": std::map call failed: " << e << std::endl;
237  QDP_abort(1);
238  }
239 
240  push(xml_out, "PropColorVec");
241  write(xml_out, "update_no", update_no);
242 
243  QDPIO::cout << name << ": propagator calculation" << std::endl;
244 
245  proginfo(xml_out); // Print out basic program info
246 
247  // Write out the input
248  write(xml_out, "Input", params);
249 
250  // Write out the config header
251  write(xml_out, "Config_info", gauge_xml);
252 
253  push(xml_out, "Output_version");
254  write(xml_out, "out_version", 1);
255  pop(xml_out);
256 
257  // Calculate some gauge invariant observables just for info.
258  MesPlq(xml_out, "Observables", u);
259 
260  //
261  // Read in the source along with relevant information.
262  //
263  XMLReader source_file_xml, source_record_xml;
264 
265  QDPIO::cout << "Snarf the source from a named buffer" << std::endl;
266  try
267  {
269 
270  // Snarf the source info. This is will throw if the colorvec_id is not there
271  TheNamedObjMap::Instance().get(params.named_obj.colorvec_id).getFileXML(source_file_xml);
272  TheNamedObjMap::Instance().get(params.named_obj.colorvec_id).getRecordXML(source_record_xml);
273 
274  // Write out the source header
275  write(xml_out, "Source_file_info", source_file_xml);
276  write(xml_out, "Source_record_info", source_record_xml);
277  }
278  catch (std::bad_cast)
279  {
280  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
281  QDP_abort(1);
282  }
283  catch (const std::string& e)
284  {
285  QDPIO::cerr << name << ": error extracting source_header: " << e << std::endl;
286  QDP_abort(1);
287  }
288 
289  // Cast should be valid now
290  const QDP::MapObject<int,EVPair<LatticeColorVector> >& eigen_source =
292 
293  QDPIO::cout << "Source successfully read and parsed" << std::endl;
294 
295  //
296  // Create the output files
297  //
298  try
299  {
300  // Generate a metadata
301  std::string file_str;
302  if (1)
303  {
304  XMLBufferWriter file_xml;
305 
306  push(file_xml, "MODMetaData");
307  write(file_xml, "id", std::string("propColorVec"));
308  write(file_xml, "lattSize", QDP::Layout::lattSize());
309  write(file_xml, "decay_dir", params.param.contract.decay_dir);
310  write(file_xml, "num_vecs", params.param.contract.num_vecs);
311  write(file_xml, "Contractions", params.param.contract);
312  write(file_xml, "Config_info", gauge_xml);
313  pop(file_xml);
314 
315  file_str = file_xml.str();
316  }
317 
318  // Create the entry
319  std::istringstream xml_s(params.named_obj.prop_obj.xml);
320  XMLReader MapObjReader(xml_s);
321 
325  MapObjReader,
327  file_str);
328  }
329  catch (std::bad_cast)
330  {
331  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
332  QDP_abort(1);
333  }
334  catch (const std::string& e)
335  {
336  QDPIO::cerr << name << ": error creating prop: " << e << std::endl;
337  QDP_abort(1);
338  }
339 
340  // Cast should be valid now
341  QDP::MapObject<KeyPropColorVec_t,LatticeFermion>& prop_obj =
343 
344  // Sanity check - write out the norm2 of the source in the Nd-1 direction
345  // Use this for any possible verification
346  {
347  // Initialize the slow Fourier transform phases
348  SftMom phases(0, true, Nd-1);
349 
350  EVPair<LatticeColorVector> tmpvec; eigen_source.get(0, tmpvec);
351  multi1d<Double> source_corrs = sumMulti(localNorm2(tmpvec.eigenVector), phases.getSet());
352 
353  push(xml_out, "Source_correlators");
354  write(xml_out, "source_corrs", source_corrs);
355  pop(xml_out);
356  }
357 
358  // Another sanity check
360  {
361  QDPIO::cerr << __func__ << ": num_vecs= " << params.param.contract.num_vecs
362  << " is greater than the number of available colorvectors= "
363  << eigen_source.size() << std::endl;
364  QDP_abort(1);
365  }
366 
367 
368  // Total number of iterations
369  int ncg_had = 0;
370 
371  //
372  // Try the factories
373  //
374  try
375  {
376  //
377  // Loop over the source color and spin, creating the source
378  // and calling the relevant propagator routines.
379  //
380  const int num_vecs = params.param.contract.num_vecs;
381  const int decay_dir = params.param.contract.decay_dir;
382  const multi1d<int>& t_sources = params.param.contract.t_sources;
383 
384  // Initialize the slow Fourier transform phases
385  SftMom phases(0, true, decay_dir);
386 
387  // This is the spin matrix part part of the static prop = (1/2)*(1 + gamma_4)
388  SpinMatrix spin_mat = BaryonSpinMats::NR();
389 
390  // Lattice extent
391  const int Nt = phases.numSubsets();
392 
393  // Loop over each operator
394  for(int tt=0; tt < t_sources.size(); ++tt)
395  {
396  int t_source = t_sources[tt];
397  QDPIO::cout << "t_source = " << t_source << std::endl;
398 
399  //
400  // We now want the static prop, which is the product of each source and U
401  // fields around the lattice. We do this by the inefficient (but simple) method
402  // of Nt number of mults and shifts of the gauge field. We can then hold this
403  // gauge field and use to multiply each colorstd::vector source in succession
404  //
405  LatticeColorMatrix u_shift = zero;
406  u_shift[phases.getSet()[t_source]] = 1.0; // unit matrix only on t_source
407 
408  for(int t=1; t < Nt; ++t)
409  {
410  int ti = (t + t_source + Nt) % Nt;
411  LatticeColorMatrix tmp = shift(adj(u[decay_dir]) * u_shift, BACKWARD, decay_dir);
412  u_shift[phases.getSet()[ti]] = tmp;
413  }
414 
415 
416  // All the loops
417  for(int colorvec_source=0; colorvec_source < num_vecs; ++colorvec_source)
418  {
419  QDPIO::cout << "colorvec_source = " << colorvec_source << std::endl;
420 
421  // Pull out a time-slice of the color std::vector source
422  LatticeColorVector vec_srce = zero;
423  EVPair<LatticeColorVector> tmpvec ; eigen_source.get(colorvec_source, tmpvec);
424  vec_srce[phases.getSet()[t_source]] = tmpvec.eigenVector;
425 
426  for(int t=1; t < Nt; ++t)
427  {
428  int ti = (t + t_source + Nt) % Nt;
429  LatticeColorVector tmp = shift(vec_srce, BACKWARD, decay_dir);
430  vec_srce[phases.getSet()[ti]] = tmp;
431  }
432 
433  // The color part of the static prop is just the shifted source
434  LatticeColorVector vec_shift = u_shift * vec_srce;
435 
436  // Drop these vectors into a fermion
437  for(int spin_source=0; spin_source < Ns; ++spin_source)
438  {
439  // Insert a ColorVector into spin index spin_source
440  // This only overwrites sections, so need to initialize first
441  LatticeFermion chi = zero;
442  CvToFerm(vec_shift, chi, spin_source);
443 
444  // The final prop
445  LatticeFermion quark_soln = spin_mat * chi;
446 
447  // Insert it
448  KeyPropColorVec_t key;
449  key.t_source = t_source;
450  key.colorvec_src = colorvec_source;
451  key.spin_src = spin_source;
452 
453  prop_obj.insert(key, quark_soln);
454  } // for spin_source
455  } // for colorvec_source
456  } // for t_source
457 
458  prop_obj.flush();
459  }
460  catch (const std::string& e)
461  {
462  QDPIO::cout << name << ": caught exception around static prop: " << e << std::endl;
463  QDP_abort(1);
464  }
465 
466  pop(xml_out); // static_prop_colorvec
467 
468  // Write the meta-data for this operator
469  {
470  XMLBufferWriter file_xml;
471 
472  push(file_xml, "PropColorVectors");
473  write(file_xml, "num_records", prop_obj.size());
474  write(file_xml, "Params", params.param);
475  write(file_xml, "Config_info", gauge_xml);
476  pop(file_xml);
477 
478  XMLBufferWriter record_xml;
479  push(record_xml, "PropColorVector");
480  write(record_xml, "num_records", prop_obj.size());
481  pop(record_xml);
482 
483  // Write the propagator xml info
484  TheNamedObjMap::Instance().get(params.named_obj.prop_id).setFileXML(file_xml);
485  TheNamedObjMap::Instance().get(params.named_obj.prop_id).setRecordXML(record_xml);
486  }
487 
488  snoop.stop();
489  QDPIO::cout << name << ": total time = "
490  << snoop.getTimeInSeconds()
491  << " secs" << std::endl;
492 
493  QDPIO::cout << name << ": ran successfully" << std::endl;
494 
495  END_CODE();
496  }
497 
498  }
499 
500 } // namespace Chroma
Inline measurement factory.
Baryon spin and projector matrices.
Class for counted reference semantics.
Definition: handle.h:33
void func(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
Fourier transform phase factor support.
Definition: sftmom.h:35
int numSubsets() const
Number of subsets - length in decay direction.
Definition: sftmom.h:63
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.
Class structure for fermion actions.
void CvToFerm(const LatticeColorVectorF &a, LatticeFermionF &b, int spin_index)
Convert (insert) a LatticeColorVector into a LatticeFermion.
Definition: transf.cc:18
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.
MODS_t & eigen_source
Eigenvectors.
Compute a static prop (1/2)*(1+gamma_4)U*U*...U * multi1d<LatticeColorVector>
Key for propagator colorstd::vector sources.
Make xml file writer.
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.
SpinMatrix NR()
NR = (1/2)* ( 1 + g_4 )
Definition: barspinmat_w.cc:15
bool registerAll()
Register all the factories.
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Propagator output.
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Propagator input.
bool registerAll()
aggregate everything
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
multi1d< LatticeFermion > chi(Ncb)
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
START_CODE()
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
#define BACKWARD
Definition: primitives.h:83
Print out basic info about this program.
Fourier transform phase factor support.
A Pair type.
struct Chroma::InlineStaticPropColorVecEnv::Params::NamedObject_t named_obj
struct Chroma::InlineStaticPropColorVecEnv::Params::Param_t param
Holds of vectors and weights.