CHROMA
inline_bar3ptfn_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline measurement of bar3ptfn
3  *
4  * Form-factor measurements
5  */
6 
9 #include "io/qprop_io.h"
10 #include "meas/glue/mesplq.h"
11 #include "util/ft/sftmom.h"
12 #include "util/info/proginfo.h"
13 #include "meas/hadron/formfac_w.h"
14 
16 
17 namespace Chroma
18 {
19  namespace InlineBar3ptfnEnv
20  {
21  namespace
22  {
23  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
24  const std::string& path)
25  {
26  return new InlineBar3ptfn(InlineBar3ptfnParams(xml_in, path));
27  }
28 
29  //! Local registration flag
30  bool registered = false;
31  }
32 
33  const std::string name = "BAR3PTFN";
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 
49  //! Propagator parameters
50  void read(XMLReader& xml, const std::string& path, InlineBar3ptfnParams::SeqProp_t& input)
51  {
52  XMLReader inputtop(xml, path);
53 
54  read(inputtop, "seqprop_id", input.seqprop_id);
55  read(inputtop, "gamma_insertion", input.gamma_insertion);
56  }
57 
58  //! Propagator parameters
59  void write(XMLWriter& xml, const std::string& path, const InlineBar3ptfnParams::SeqProp_t& input)
60  {
61  push(xml, path);
62 
63  write(xml, "seqprop_id", input.seqprop_id);
64  write(xml, "gamma_insertion", input.gamma_insertion);
65 
66  pop(xml);
67  }
68 
69 
70  //! Propagator parameters
71  void read(XMLReader& xml, const std::string& path, InlineBar3ptfnParams::NamedObject_t& input)
72  {
73  XMLReader inputtop(xml, path);
74 
75  read(inputtop, "gauge_id", input.gauge_id);
76  read(inputtop, "prop_id", input.prop_id);
77  read(inputtop, "seqprops", input.seqprops);
78  read(inputtop, "bar3ptfn_file", input.bar3ptfn_file);
79  }
80 
81  //! Propagator parameters
82  void write(XMLWriter& xml, const std::string& path, const InlineBar3ptfnParams::NamedObject_t& input)
83  {
84  push(xml, path);
85 
86  write(xml, "gauge_id", input.gauge_id);
87  write(xml, "prop_id", input.prop_id);
88  write(xml, "seqprops", input.seqprops);
89  write(xml, "bar3ptfn_file", input.bar3ptfn_file);
90 
91  pop(xml);
92  }
93 
94 
95  // Reader for input parameters
96  void read(XMLReader& xml, const std::string& path, InlineBar3ptfnParams::Param_t& param)
97  {
98  XMLReader paramtop(xml, path);
99 
100  int version;
101  read(paramtop, "version", version);
102 
103  switch (version)
104  {
105  case 6:
106  // Uggh, assume j_decay = Nd-1 here. This could come from source.
107  param.j_decay = Nd-1;
108  break;
109 
110  case 7:
111  read(paramtop, "j_decay", param.j_decay);
112  break;
113 
114  default :
115  /**************************************************************************/
116 
117  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
118  QDP_abort(1);
119  }
120 
121  read(paramtop, "mom2_max", param.mom2_max);
122  }
123 
124 
125  // Reader for input parameters
126  void write(XMLWriter& xml, const std::string& path, const InlineBar3ptfnParams::Param_t& param)
127  {
128  push(xml, path);
129 
130  int version = 6;
131 
132  write(xml, "version", version);
133  write(xml, "mom2_max", param.mom2_max);
134 
135  pop(xml);
136  }
137 
138 
139  // Param stuff
141  {
142  frequency = 0;
143  }
144 
146  {
147  try
148  {
149  XMLReader paramtop(xml_in, path);
150 
151  if (paramtop.count("Frequency") == 1)
152  read(paramtop, "Frequency", frequency);
153  else
154  frequency = 1;
155 
156  // Parameters for source construction
157  read(paramtop, "Param", param);
158 
159  // Read in the output propagator/source configuration info
160  read(paramtop, "NamedObject", named_obj);
161  }
162  catch(const std::string& e)
163  {
164  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
165  QDP_abort(1);
166  }
167  }
168 
169 
170  void
171  InlineBar3ptfnParams::write(XMLWriter& xml_out, const std::string& path)
172  {
173  push(xml_out, path);
174 
175  // Parameters for source construction
176  Chroma::write(xml_out, "Param", param);
177 
178  // Write out the output propagator/source configuration info
179  Chroma::write(xml_out, "NamedObject", named_obj);
180 
181  pop(xml_out);
182  }
183 
184 
185 
186  //--------------------------------------------------------------
188  {
190  };
191 
193  {
195  int t_source;
196  int t_sink;
197  multi1d<int> sink_mom;
200  };
201 
203  {
204  int output_version; // Unique id for each output version of the structures
205  multi1d<FormFac_sequential_source_t> seqsrc;
206  };
207 
208  struct Bar3ptfn_t
209  {
213  };
214 
215 
216  // params
217  void write(BinaryWriter& bin, const Output_version_t& ver)
218  {
219  write(bin, ver.out_version);
220  }
221 
222  // params
223  void write(BinaryWriter& bin, const InlineBar3ptfnParams::Param_t& param)
224  {
225  write(bin, param.mom2_max);
226  write(bin, param.j_decay);
227  write(bin, Layout::lattSize());
228  }
229 
230 
231  //
232  void write(BinaryWriter& bin, const FormFac_sequential_source_t& src)
233  {
234  write(bin, src.seqsrc_type);
235  write(bin, src.t_source);
236  write(bin, src.t_sink);
237  write(bin, src.sink_mom);
238  write(bin, src.gamma_insertion);
239  write(bin, src.formFacs);
240  }
241 
242  // Write a hadron measurements
243  void write(BinaryWriter& bin, const FormFac_Wilson_3Pt_fn_measurements_t& had)
244  {
245  write(bin, had.output_version);
246  write(bin, had.seqsrc);
247  }
248 
249  // Write all formfactor measurements
250  void write(BinaryWriter& bin, const Bar3ptfn_t& bar)
251  {
252  write(bin, bar.output_version);
253  write(bin, bar.param);
254  write(bin, bar.bar);
255  }
256 
257  //--------------------------------------------------------------
258 
259 
260  // Function call
261  void
262  InlineBar3ptfn::operator()(unsigned long update_no,
263  XMLWriter& xml_out)
264  {
265  START_CODE();
266 
267  StopWatch snoop;
268  snoop.reset();
269  snoop.start();
270 
271  // Test and grab a reference to the gauge field
272  XMLBufferWriter gauge_xml;
273  try
274  {
275  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
276  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
277  }
278  catch( std::bad_cast )
279  {
280  QDPIO::cerr << InlineBar3ptfnEnv::name << ": caught dynamic cast error"
281  << std::endl;
282  QDP_abort(1);
283  }
284  catch (const std::string& e)
285  {
286  QDPIO::cerr << InlineBar3ptfnEnv::name << ": std::map call failed: " << e
287  << std::endl;
288  QDP_abort(1);
289  }
290  const multi1d<LatticeColorMatrix>& u =
291  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
292 
293  push(xml_out, "bar3ptfn");
294  write(xml_out, "update_no", update_no);
295 
296  QDPIO::cout << InlineBar3ptfnEnv::name << ": Baryon form factors for Wilson fermions" << std::endl;
297 
298  proginfo(xml_out); // Print out basic program info
299 
300  // Write out the input
301  params.write(xml_out, "Input");
302 
303  // Write out the config info
304  write(xml_out, "Config_info", gauge_xml);
305 
306  push(xml_out, "Output_version");
307  write(xml_out, "out_version", 11);
308  pop(xml_out);
309 
310  // First calculate some gauge invariant observables just for info.
311  // This is really cheap.
312  MesPlq(xml_out, "Observables", u);
313 
314  //
315  // Read the quark propagator and extract headers
316  //
317  XMLReader prop_file_xml, prop_record_xml;
318  LatticePropagator quark_propagator;
320  PropSourceConst_t source_header;
321  QDPIO::cout << "Attempt to parse forward propagator" << std::endl;
322  try
323  {
324  // Snarf the forward prop
325  quark_propagator =
326  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_id);
327 
328  // Snarf the source info. This is will throw if the source_id is not there
329  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getFileXML(prop_file_xml);
330  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getRecordXML(prop_record_xml);
331 
332  // Try to invert this record XML into a ChromaProp struct
333  // Also pull out the id of this source
334  {
335  read(prop_record_xml, "/Propagator/ForwardProp", prop_header);
336  read(prop_record_xml, "/Propagator/PropSource", source_header);
337  }
338 
339  // Save propagator input
340  write(xml_out, "Propagator_file_info", prop_file_xml);
341  write(xml_out, "Propagator_record_info", prop_record_xml);
342  }
343  catch( std::bad_cast )
344  {
345  QDPIO::cerr << InlineBar3ptfnEnv::name << ": caught dynamic cast error"
346  << std::endl;
347  QDP_abort(1);
348  }
349  catch (const std::string& e)
350  {
351  QDPIO::cerr << InlineBar3ptfnEnv::name << ": error message: " << e
352  << std::endl;
353  QDP_abort(1);
354  }
355  QDPIO::cout << "Forward propagator successfully parsed" << std::endl;
356 
357  // Derived from input prop
358  multi1d<int> t_srce = source_header.getTSrce() ;
359  int j_decay = params.param.j_decay;
360  int t_source = source_header.t_source;
361 
362  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
363  // Use this for any possible verification
364  {
365  // Initialize the slow Fourier transform phases
366  SftMom phases(0, true, j_decay);
367 
368  multi1d<Double> forward_prop_corr = sumMulti(localNorm2(quark_propagator),
369  phases.getSet());
370 
371  push(xml_out, "Forward_prop_correlator");
372  write(xml_out, "forward_prop_corr", forward_prop_corr);
373  pop(xml_out);
374  }
375 
376 
377  //
378  // Big nested structure that is image of entire file
379  //
380  Bar3ptfn_t bar3pt;
381  bar3pt.output_version.out_version = 11; // bump this up everytime something changes
382  bar3pt.param = params.param; // copy entire structure
383 
384  push(xml_out, "Wilson_3Pt_fn_measurements");
385 
386  // Big nested structure that is image of all form-factors
387 // FormFac_Wilson_3Pt_fn_measurements_t formfacs;
388  bar3pt.bar.output_version = 4; // bump this up everytime something changes
389  bar3pt.bar.seqsrc.resize(params.named_obj.seqprops.size());
390 
391  XMLArrayWriter xml_seq_src(xml_out, params.named_obj.seqprops.size());
392  push(xml_seq_src, "Sequential_source");
393 
394  for (int seq_src_ctr = 0; seq_src_ctr < params.named_obj.seqprops.size(); ++seq_src_ctr)
395  {
396  push(xml_seq_src);
397  write(xml_seq_src, "seq_src_ctr", seq_src_ctr);
398 
399  // Read the sequential propagator
400  // Read the quark propagator and extract headers
401  LatticePropagator seq_quark_prop;
402  SeqSource_t seqsource_header;
403  QDPIO::cout << "Attempt to parse sequential propagator" << std::endl;
404  try
405  {
406  std::string seqprop_id = params.named_obj.seqprops[seq_src_ctr].seqprop_id;
407 
408  // Snarf the backward prop
409  seq_quark_prop =
410  TheNamedObjMap::Instance().getData<LatticePropagator>(seqprop_id);
411 
412  // Snarf the source info. This is will throw if the source_id is not there
413  XMLReader seqprop_file_xml, seqprop_record_xml;
414  TheNamedObjMap::Instance().get(seqprop_id).getFileXML(seqprop_file_xml);
415  TheNamedObjMap::Instance().get(seqprop_id).getRecordXML(seqprop_record_xml);
416 
417  // Try to invert this record XML into a ChromaProp struct
418  // Also pull out the id of this source
419  // NEED SECURITY HERE - need a way to cross check props. Use the ID.
420  {
421  read(seqprop_record_xml, "/SequentialProp/SeqSource", seqsource_header);
422  }
423 
424  // Save seqprop input
425  write(xml_seq_src, "SequentialProp_file_info", seqprop_file_xml);
426  write(xml_seq_src, "SequentialProp_record_info", seqprop_record_xml);
427  }
428  catch( std::bad_cast )
429  {
430  QDPIO::cerr << InlineBar3ptfnEnv::name << ": caught dynamic cast error"
431  << std::endl;
432  QDP_abort(1);
433  }
434  catch (const std::string& e)
435  {
436  QDPIO::cerr << InlineBar3ptfnEnv::name << ": std::map call failed: " << e
437  << std::endl;
438  QDP_abort(1);
439  }
440  QDPIO::cout << "Sequential propagator successfully parsed" << std::endl;
441 
442  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
443  // Use this for any possible verification
444  {
445  // Initialize the slow Fourier transform phases
446  SftMom phases(0, true, Nd-1);
447 
448  multi1d<Double> backward_prop_corr = sumMulti(localNorm2(seq_quark_prop),
449  phases.getSet());
450 
451  push(xml_seq_src, "Backward_prop_correlator");
452  write(xml_seq_src, "backward_prop_corr", backward_prop_corr);
453  pop(xml_seq_src);
454  }
455 
456  // Use extra gamma insertion
457  int gamma_insertion = params.named_obj.seqprops[seq_src_ctr].gamma_insertion;
458 
459  // Derived from input seqprop
460  std::string seqsrc_type = seqsource_header.seqsrc.id;
461  QDPIO::cout << "Seqsource name = " << seqsrc_type << std::endl;
462  int t_sink = seqsource_header.t_sink;
463  multi1d<int> sink_mom = seqsource_header.sink_mom;
464 
465  write(xml_seq_src, "hadron_type", "HADRON");
466  write(xml_seq_src, "seqsrc_type", seqsrc_type);
467  write(xml_seq_src, "t_source", t_source);
468  write(xml_seq_src, "t_sink", t_sink);
469  write(xml_seq_src, "sink_mom", sink_mom);
470  write(xml_seq_src, "gamma_insertion", gamma_insertion);
471 
472  bar3pt.bar.seqsrc[seq_src_ctr].seqsrc_type = seqsrc_type;
473  bar3pt.bar.seqsrc[seq_src_ctr].t_source = t_source;
474  bar3pt.bar.seqsrc[seq_src_ctr].t_sink = t_sink;
475  bar3pt.bar.seqsrc[seq_src_ctr].sink_mom = sink_mom;
476  bar3pt.bar.seqsrc[seq_src_ctr].gamma_insertion = gamma_insertion;
477 
478 
479  // Now the 3pt contractions
480  SftMom phases(params.param.mom2_max, t_srce, sink_mom, false, j_decay);
481  FormFac(bar3pt.bar.seqsrc[seq_src_ctr].formFacs,
482  u, quark_propagator, seq_quark_prop, gamma_insertion,
483  phases, t_source);
484 
485  pop(xml_seq_src); // elem
486  } // end loop over sequential sources
487 
488  pop(xml_seq_src); // Sequential_source
489 
490 // BinaryWFileriter bin_out(params.named_obj.bar3ptfn_file);
491 // write(bin_out, bar3ptfn);
492 // bin_out.close();
493 
494  pop(xml_out); // Wilson_3Pt_fn_measurements
495 
496  // Close the namelist output file XMLDAT
497  pop(xml_out); // bar3ptfn
498 
499  BinaryFileWriter bin_out(params.named_obj.bar3ptfn_file);
500  write(bin_out, bar3pt);
501  bin_out.close();
502 
503  snoop.stop();
504  QDPIO::cout << InlineBar3ptfnEnv::name << ": total time = "
505  << snoop.getTimeInSeconds()
506  << " secs" << std::endl;
507 
508  QDPIO::cout << InlineBar3ptfnEnv::name << ": ran successfully" << std::endl;
509 
510  END_CODE();
511  }
512 
513 }
Inline measurement factory.
Inline measurement of 3pt functions.
InlineBar3ptfnParams params
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
Form-factors.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void FormFac(FormFac_insertions_t &form, const multi1d< LatticeColorMatrix > &u, const LatticePropagator &quark_propagator, const LatticePropagator &seq_quark_prop, int gamma_insertion, const SftMom &phases, int t0)
Compute contractions for current insertion 3-point functions.
Definition: formfac_w.cc:92
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
Inline measurement of bar3ptfn.
multi1d< int > t_srce
ForwardProp_t prop_header
int j_decay
Definition: meslate.cc:22
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
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.
Routines associated with Chroma propagator IO.
Fourier transform phase factor support.
FormFac_Wilson_3Pt_fn_measurements_t bar
InlineBar3ptfnParams::Param_t param
Output_version_t output_version
Propagator parameters.
Definition: qprop_io.h:75
multi1d< FormFac_sequential_source_t > seqsrc
void write(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineBar3ptfnParams::NamedObject_t named_obj
struct Chroma::InlineBar3ptfnParams::Param_t param
Propagator source construction parameters.
Definition: qprop_io.h:27
multi1d< int > getTSrce() const
Definition: qprop_io.cc:120
Sequential source parameters.
Definition: qprop_io.h:90
multi1d< int > sink_mom
Definition: qprop_io.h:95
GroupXML_t seqsrc
Definition: qprop_io.h:93