CHROMA
inline_qqq_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of qqq_w
3  *
4  * QQQ calcs
5  */
6 
10 #include "meas/glue/mesplq.h"
11 #include "util/ft/sftmom.h"
12 #include "util/info/proginfo.h"
13 #include "util/info/unique_id.h"
14 #include "util/ferm/diractodr.h"
16 
17 namespace Chroma
18 {
19  namespace InlineQQQEnv
20  {
21  namespace
22  {
23  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
24  const std::string& path)
25  {
26  return new InlineMeas(Params(xml_in, path));
27  }
28 
29  //! Local registration flag
30  bool registered = false;
31  }
32 
33  const std::string name = "QQQ";
34 
35  //! Register all the factories
36  bool registerAll()
37  {
38  bool success = true;
39  if (! registered)
40  {
41  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
42  registered = true;
43  }
44  return success;
45  }
46 
47 
48  //! Param input
49  void read(XMLReader& xml, const std::string& path, InlineQQQEnv::Params::Param_t& input)
50  {
51  XMLReader paramtop(xml, path);
52 
53  int version;
54  read(paramtop, "version", version);
55 
56  switch (version)
57  {
58  case 4:
59  input.sparseP = false;
60  break;
61 
62  case 5:
63  read(paramtop, "sparseP", input.sparseP);
64  break;
65 
66  default:
67  /**************************************************************************/
68  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
69  QDP_abort(1);
70  }
71 
72  read(paramtop, "Dirac_basis", input.Dirac_basis);
73  if (input.sparseP)
74  {
75  read(paramtop, "SpinIndices", input.spin_indices);
76  }
77  }
78 
79  //! Param output
80  void write(XMLWriter& xml, const std::string& path, const InlineQQQEnv::Params::Param_t& input)
81  {
82  push(xml, path);
83 
84  int version = 5;
85  write(xml, "version", version);
86  write(xml, "sparseP", input.sparseP);
87  write(xml, "Dirac_basis", input.Dirac_basis);
88  if (input.sparseP)
89  {
90  write(xml, "SpinIndices", input.spin_indices);
91  }
92 
93  pop(xml);
94  }
95 
96  //! Propagator input
97  void read(XMLReader& xml, const std::string& path, InlineQQQEnv::Params::NamedObject_t& input)
98  {
99  XMLReader inputtop(xml, path);
100 
101  read(inputtop, "gauge_id", input.gauge_id);
102  read(inputtop, "prop_ids", input.prop_ids);
103  read(inputtop, "qqq_file", input.qqq_file);
104  }
105 
106  //! Propagator output
107  void write(XMLWriter& xml, const std::string& path, const InlineQQQEnv::Params::NamedObject_t& input)
108  {
109  push(xml, path);
110 
111  write(xml, "gauge_id", input.gauge_id);
112  write(xml, "prop_ids", input.prop_ids);
113  write(xml, "qqq_file", input.qqq_file);
114 
115  pop(xml);
116  }
117 
118 
119  // Param stuff
121 
122  Params::Params(XMLReader& xml_in, const std::string& path)
123  {
124  try
125  {
126  XMLReader paramtop(xml_in, path);
127 
128  if (paramtop.count("Frequency") == 1)
129  read(paramtop, "Frequency", frequency);
130  else
131  frequency = 1;
132 
133  // Parameters for source construction
134  read(paramtop, "Param", param);
135 
136  // Read in the output propagator/source configuration info
137  read(paramtop, "NamedObject", named_obj);
138  }
139  catch(const std::string& e)
140  {
141  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
142  QDP_abort(1);
143  }
144  }
145 
146 
147  void
148  Params::writeXML(XMLWriter& xml_out, const std::string& path)
149  {
150  push(xml_out, path);
151 
152  // Parameters for source construction
153  write(xml_out, "Param", param);
154 
155  // Write out the output propagator/source configuration info
156  write(xml_out, "NamedObject", named_obj);
157 
158  pop(xml_out);
159  }
160 
161 
162  // Function call
163  void
164  InlineMeas::operator()(unsigned long update_no,
165  XMLWriter& xml_out)
166  {
167  START_CODE();
168 
169  StopWatch snoop;
170  snoop.reset();
171  snoop.start();
172 
173  // Test and grab a reference to the gauge field
174  XMLBufferWriter gauge_xml;
175  try
176  {
177  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
178  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
179  }
180  catch( std::bad_cast )
181  {
182  QDPIO::cerr << InlineQQQEnv::name << ": caught dynamic cast error"
183  << std::endl;
184  QDP_abort(1);
185  }
186  catch (const std::string& e)
187  {
188  QDPIO::cerr << InlineQQQEnv::name << ": std::map call failed: " << e
189  << std::endl;
190  QDP_abort(1);
191  }
192  const multi1d<LatticeColorMatrix>& u =
193  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
194 
195  push(xml_out,"qqq");
196  write(xml_out, "update_no", update_no);
197 
198  QDPIO::cout << InlineQQQEnv::name << ": Generalized propagator generation" << std::endl;
199  StopWatch swatch;
200 
201  // Write out the input
202  params.writeXML(xml_out, "Input");
203 
204  proginfo(xml_out); // Print out basic program info
205 
206  // Write out the input
207  params.writeXML(xml_out, "Input");
208 
209  // Write out the config info
210  write(xml_out, "Config_info", gauge_xml);
211 
212  push(xml_out, "Output_version");
213  write(xml_out, "out_version", 5);
214  pop(xml_out);
215 
216  // Calculate some gauge invariant observables just for info.
217  MesPlq(xml_out, "Observables", u);
218 
219  // Check to make sure there are 3 ids
220  const int Nprops = 3;
221  if (params.named_obj.prop_ids.size() != Nprops)
222  {
223  QDPIO::cerr << "Error on input params - expecting 3 buffers" << std::endl;
224  QDP_abort(1);
225  }
226 
227  write(xml_out, "propIds", params.named_obj.prop_ids);
228  write(xml_out, "barcompFile", params.named_obj.qqq_file);
229 
230  /*
231  * Read the quark propagators and extract headers
232  */
233  multi1d<LatticePropagator> quark_propagator(Nprops);
234  QQQBarcomp_t qqq;
235  qqq.Dirac_basis = false;
236  qqq.forward_props.resize(Nprops);
237 
238  for(int i=0; i < Nprops; ++i)
239  {
240  QDPIO::cout << InlineQQQEnv::name << ": parse id = " << params.named_obj.prop_ids[i] << std::endl;
241  try
242  {
243  // Snarf the data into a copy
244  quark_propagator[i] =
245  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_ids[i]);
246 
247  // Snarf the prop info. This is will throw if the prop_ids is not there.
248  XMLReader prop_file_xml, prop_record_xml;
249  TheNamedObjMap::Instance().get(params.named_obj.prop_ids[i]).getFileXML(prop_file_xml);
250  TheNamedObjMap::Instance().get(params.named_obj.prop_ids[i]).getRecordXML(prop_record_xml);
251 
252  // Try to invert this record XML into a ChromaProp struct
253  // Also pull out the id of this source
254  {
255  read(prop_record_xml, "/SinkSmear", qqq.forward_props[i]);
256  }
257  }
258  catch( std::bad_cast )
259  {
260  QDPIO::cerr << InlineQQQEnv::name << ": caught dynamic cast error"
261  << std::endl;
262  QDP_abort(1);
263  }
264  catch (const std::string& e)
265  {
266  QDPIO::cerr << InlineQQQEnv::name << ": error message: " << e
267  << std::endl;
268  QDP_abort(1);
269  }
270  QDPIO::cout << InlineQQQEnv::name << ": object successfully parsed" << std::endl;
271  }
272 
273 
274  // Save prop input
275  write(xml_out, "Propagator_input", qqq);
276 
277  // Derived from input prop
278  multi1d<int> boundary = getFermActBoundary(qqq.forward_props[0].prop_header.fermact);
279  int t0 = qqq.forward_props[0].source_header.t_source;
280  int j_decay = qqq.forward_props[0].source_header.j_decay;
281  int bc_spec = boundary[j_decay];
282 
283  // Initialize the slow Fourier transform phases
284  SftMom phases(0, true, j_decay);
285 
286  // Sanity check - write out the propagator (pion) correlator in the j_decay direction
287  push(xml_out, "SinkSmearedProp_correlator");
288  for(int i=0; i < Nprops; ++i)
289  {
290  multi1d<Double> prop_corr = sumMulti(localNorm2(TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_ids[i])),
291  phases.getSet());
292 
293  push(xml_out, "elem");
294  write(xml_out, "correlator_num", i);
295  write(xml_out, "sink_smeared_prop_corr", prop_corr);
296  pop(xml_out);
297  }
298  pop(xml_out);
299 
300  /*
301  * Generalized propagator calculation
302  */
303  multi1d<ComplexF> barprop_1d;
304 
305  // Switch to Dirac-basis if desired.
307  {
308  qqq.Dirac_basis = true;
309 
310  // The spin basis matrix
311  SpinMatrix U = DiracToDRMat();
312 
313  LatticePropagator q_tmp;
314  for(int i=0; i < Nprops; ++i)
315  {
316  q_tmp = adj(U) * quark_propagator[i] * U; // DeGrand-Rossi ---> Dirac
317  quark_propagator[i] = q_tmp;
318  }
319  }
320 
321  // Decide the computational mode depending on whether the data is sparse
322  // or not
323  if (params.param.sparseP)
324  {
325  qqq.sparseP = true;
327  QQQSparse_t barprop;
328 
329  // Compute generation propagator
330  barcompSparse(barprop,
331  quark_propagator[0],
332  quark_propagator[1],
333  quark_propagator[2],
335  phases, t0, bc_spec);
336 
337  // Convert the data into a mult1d
338  barprop_1d = barprop.serialize();
339  }
340  else
341  {
342  qqq.sparseP = false;
343  QQQDense_t barprop;
344 
345  // Compute generation propagator
346  barcomp(barprop,
347  quark_propagator[0],
348  quark_propagator[1],
349  quark_propagator[2],
350  phases, t0, bc_spec);
351 
352  // Convert the data into a mult1d
353  barprop_1d = barprop.serialize();
354  }
355 
356  // Save the qqq output
357  // ONLY SciDAC output format is supported!
358  {
359  XMLBufferWriter file_xml;
360  push(file_xml, "qqq");
361  write(file_xml, "id", uniqueId()); // NOTE: new ID form
362  pop(file_xml);
363 
364  XMLBufferWriter record_xml;
365  push(record_xml, "QQQ");
366  write(record_xml, ".", qqq); // do not write the outer group
367  write(record_xml, "Config_info", gauge_xml);
368  pop(record_xml); // QQQ
369 
370  // Write the scalar data
371  QDPFileWriter to(file_xml, params.named_obj.qqq_file,
372  QDPIO_SINGLEFILE, QDPIO_SERIAL, QDPIO_OPEN);
373  write(to,record_xml,barprop_1d);
374  close(to);
375  }
376 
377  pop(xml_out); // qqq
378 
379 
380  snoop.stop();
381  QDPIO::cout << InlineQQQEnv::name << ": total time = "
382  << snoop.getTimeInSeconds()
383  << " secs" << std::endl;
384 
385  QDPIO::cout << InlineQQQEnv::name << ": ran successfully" << std::endl;
386 
387  END_CODE();
388  }
389 
390  }
391 
392 }
Inline measurement factory.
Construct all components of a baryon propagator.
Inline measurement of QQQ's.
Definition: inline_qqq_w.h:52
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
Fourier transform phase factor support.
Definition: sftmom.h:35
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
static T & Instance()
Definition: singleton.h:432
Basis rotation matrix from Dirac to Degrand-Rossi (and reverse)
SpinMatrixD DiracToDRMat()
The Dirac to Degrand-Rossi spin transformation matrix (and reverse)
Definition: diractodr.cc:22
void barcomp(QQQDense_t &barprop, const LatticePropagator &quark_propagator_1, const LatticePropagator &quark_propagator_2, const LatticePropagator &quark_propagator_3, const SftMom &phases, int t0, int bc_spec)
Construct all components of a baryon propagator.
Definition: barcomp_w.cc:167
void barcompSparse(QQQSparse_t &barprop, const LatticePropagator &quark_propagator_1, const LatticePropagator &quark_propagator_2, const LatticePropagator &quark_propagator_3, const multi1d< QQQSpinIndices_t > spin_indices, const SftMom &phases, int t0, int bc_spec)
Construct all components of a baryon propagator.
Definition: barcomp_w.cc:66
std::string uniqueId()
Return a unique id.
Definition: unique_id.cc:18
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
int bc_spec
Inline construction of qqq_w.
int j_decay
Definition: meslate.cc:22
Named object function std::map.
static bool registered
Local registration flag.
void write(XMLWriter &xml, const std::string &path, const InlineQQQEnv::Params::Param_t &input)
Param output.
Definition: inline_qqq_w.cc:80
const std::string name
Definition: inline_qqq_w.cc:33
void read(XMLReader &xml, const std::string &path, InlineQQQEnv::Params::Param_t &input)
Param input.
Definition: inline_qqq_w.cc:49
bool registerAll()
Register all the factories.
Definition: inline_qqq_w.cc:36
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
multi1d< int > getFermActBoundary(const GroupXML_t &fermact)
Given a fermion action in std::string form, return the boundary.
Definition: qprop_io.cc:61
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
START_CODE()
::std::string string
Definition: gtest.h:1979
Print out basic info about this program.
Fourier transform phase factor support.
multi1d< QQQSpinIndices_t > spin_indices
Definition: inline_qqq_w.h:35
Parameter structure.
Definition: inline_qqq_w.h:26
struct Chroma::InlineQQQEnv::Params::Param_t param
struct Chroma::InlineQQQEnv::Params::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)
Mega structure holding QQQ props.
Definition: qprop_io.h:180
multi1d< ForwardProp_t > forward_props
Definition: qprop_io.h:185
multi1d< QQQSpinIndices_t > spin_indices
Definition: qprop_io.h:182
Dense QQQ object.
Definition: barcomp_w.h:36
multi1d< ComplexF > serialize()
Serialize generalized object.
Definition: barcomp_w.cc:126
Sparse QQQ object.
Definition: barcomp_w.h:18
multi1d< ComplexF > serialize()
Serialize generalized object.
Definition: barcomp_w.cc:13
multi1d< LatticeColorMatrix > U
Generate a unique id.