CHROMA
inline_multipole_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline multipole measurement
3  */
4 
7 #include "meas/glue/mesplq.h"
8 #include "util/ft/sftmom.h"
9 #include "util/info/proginfo.h"
11 #include "io/qprop_io.h"
14 
15 namespace Chroma
16 {
17  namespace InlineMultipoleEnv
18  {
19  namespace
20  {
21  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
22  const std::string& path)
23  {
24  return new InlineMultipole(InlineMultipoleParams(xml_in, path));
25  }
26 
27  //! Local registration flag
28  bool registered = false;
29  }
30 
31  const std::string name = "MULTIPOLE";
32 
33  //! Register all the factories
34  bool registerAll()
35  {
36  bool success = true;
37  if (! registered)
38  {
39  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
40  registered = true;
41  }
42  return success;
43  }
44  }
45 
46 
47  // Reader for input parameters
48  void read(XMLReader& xml, const std::string& path, InlineMultipoleParams::Param_t& param)
49  {
50  XMLReader inputtop(xml, path);
51 
52  int version;
53  read(inputtop, "version", version);
54 
55  switch (version)
56  {
57  case 1:
58  /**************************************************************************/
59  break;
60 
61  default :
62  /**************************************************************************/
63 
64  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
65  QDP_abort(1);
66  }
67 
68  read(inputtop, "max_L", param.max_L);
69  }
70 
71 
72  // Writer for input parameters
73  void write(XMLWriter& xml, const std::string& path, const InlineMultipoleParams::Param_t& param)
74  {
75  push(xml, path);
76 
77  int version = 1;
78  write(xml, "version", version);
79  write(xml, "max_L", param.max_L);
80 
81  pop(xml);
82  }
83 
84 
85  //! Propagator input
86  void read(XMLReader& xml, const std::string& path, InlineMultipoleParams::NamedObject_t& input)
87  {
88  XMLReader inputtop(xml, path);
89 
90  read(inputtop, "gauge_id", input.gauge_id);
91  read(inputtop, "seqprop_id", input.seqprop_id);
92  read(inputtop, "GammaInsertion", input.GammaInsertion);
93  }
94 
95  //! Propagator output
96  void write(XMLWriter& xml, const std::string& path, const InlineMultipoleParams::NamedObject_t& input)
97  {
98  push(xml, path);
99 
100  write(xml, "gauge_id", input.gauge_id);
101  write(xml, "seqprop_id", input.seqprop_id);
102  write(xml, "GammaInsertion", input.GammaInsertion);
103 
104  pop(xml);
105  }
106 
107  //! Multipole parameters
108  void read(XMLReader& xml, const std::string& path, InlineMultipoleParams::Multipole_out_t& input)
109  {
110  XMLReader inputtop(xml, path);
111 
112  read(inputtop, "prop_id", input.prop_id);
113  read(inputtop, "seqprops", input.seqprops);
114  }
115 
116  //! Multipole parameters
117  void write(XMLWriter& xml, const std::string& path, const InlineMultipoleParams::Multipole_out_t& input)
118  {
119  push(xml, path);
120 
121  write(xml, "prop_id", input.prop_id);
122  write(xml, "seqprops", input.seqprops);
123 
124  pop(xml);
125  }
126 
127 
128 
129  // Param stuff
131 
133  {
134  try
135  {
136  XMLReader inputtop(xml_in, path);
137 
138  read(inputtop, "Frequency", frequency);
139 
140  // Read program parameters
141  read(inputtop, "Param", param);
142 
143  // Read in the multipole setup
144  read(inputtop, "Multipole", pole);
145 
146  // Possible alternate XML file pattern
147  if (inputtop.count("xml_file") != 0)
148  {
149  read(inputtop, "xml_file", xml_file);
150  }
151  }
152  catch(const std::string& e)
153  {
154  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
155  QDP_abort(1);
156  }
157  }
158 
159  //! Write params
160  void
161  InlineMultipoleParams::write(XMLWriter& xml, const std::string& path)
162  {
163  push(xml, path);
164 
165  Chroma::write(xml, "Param", param);
166  Chroma::write(xml, "Multipole", pole);
167  QDP::write(xml, "xml_file", xml_file);
168 
169  pop(xml);
170  }
171 
172 
173  // Function call
174  void
175  InlineMultipole::operator()(unsigned long update_no,
176  XMLWriter& xml_out)
177  {
178  // If xml file not empty, then use alternate
179  if (params.xml_file != "")
180  {
181  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
182 
183  push(xml_out, "multipole");
184  write(xml_out, "update_no", update_no);
185  write(xml_out, "xml_file", xml_file);
186  pop(xml_out);
187 
188  XMLFileWriter xml(xml_file);
189  func(update_no, xml);
190  }
191  else
192  {
193  func(update_no, xml_out);
194  }
195  }
196 
197 
198  // Real work done here
199  void
200  InlineMultipole::func(unsigned long update_no,
201  XMLWriter& xml_out)
202  {
203  START_CODE();
204 
205  StopWatch snoop;
206  snoop.reset();
207  snoop.start();
208 
209  // Test and grab a reference to the gauge field
210  XMLBufferWriter gauge_xml;
211  try
212  {
213  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
214  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
215  }
216  catch( std::bad_cast )
217  {
218  QDPIO::cerr << InlineMultipoleEnv::name << ": caught dynamic cast error"
219  << std::endl;
220  QDP_abort(1);
221  }
222  catch (const std::string& e)
223  {
224  QDPIO::cerr << InlineMultipoleEnv::name << ": std::map call failed: " << e
225  << std::endl;
226  QDP_abort(1);
227  }
228  const multi1d<LatticeColorMatrix>& u =
229  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
230 
231  push(xml_out, "multipole");
232  write(xml_out, "update_no", update_no);
233 
234  QDPIO::cout << InlineMultipoleEnv::name << ": multipole measurements for Wilson-like fermions" << std::endl;
235 
236  proginfo(xml_out); // Print out basic program info
237 
238  // Write out the input
239  params.write(xml_out, "Input");
240 
241  // Write out the config info
242  write(xml_out, "Config_info", gauge_xml);
243 
244  push(xml_out, "Output_version");
245  write(xml_out, "out_version", 1);
246  pop(xml_out);
247 
248  // First calculate some gauge invariant observables just for info.
249  // This is really cheap.
250  MesPlq(xml_out, "Observables", u);
251 
252  //
253  // Read the quark propagator and extract headers
254  //
255  LatticePropagator quark_propagator;
257  PropSourceConst_t source_header;
258  try
259  {
260  // Snarf the data into a copy
261  quark_propagator =
262  TheNamedObjMap::Instance().getData<LatticePropagator>(params.pole.prop_id);
263 
264  // Snarf the source info. This is will throw if the source_id is not there
265  XMLReader prop_file_xml, prop_record_xml;
266  TheNamedObjMap::Instance().get(params.pole.prop_id).getFileXML(prop_file_xml);
267  TheNamedObjMap::Instance().get(params.pole.prop_id).getRecordXML(prop_record_xml);
268 
269 
270  // Try to invert this record XML into a ChromaProp struct
271  // Also pull out the id of this source
272  try
273  {
274  read(prop_record_xml, "/Propagator/ForwardProp", prop_header);
275  read(prop_record_xml, "/Propagator/PropSource", source_header);
276  }
277  catch (const std::string& e)
278  {
279  QDPIO::cerr << "Error extracting forward_prop header: " << e << std::endl;
280  QDP_abort(1);
281  }
282 
283  // Save propagator input
284  write(xml_out, "Propagator_file_info", prop_file_xml);
285  write(xml_out, "Propagator_record_info", prop_record_xml);
286  }
287  catch( std::bad_cast )
288  {
289  QDPIO::cerr << InlineMultipoleEnv::name << ": caught dynamic cast error"
290  << std::endl;
291  QDP_abort(1);
292  }
293  catch (const std::string& e)
294  {
295  QDPIO::cerr << InlineMultipoleEnv::name << ": std::map call failed: " << e
296  << std::endl;
297  QDP_abort(1);
298  }
299 
300 
301  // Derived from input prop
302  int j_decay = source_header.j_decay;
303  int t_source = source_header.t_source;
304 
305  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
306  // Use this for any possible verification
307  {
308  // Initialize the slow Fourier transform phases
309  SftMom phases(0, true, j_decay);
310 
311  multi1d<Double> forward_prop_corr = sumMulti(localNorm2(quark_propagator),
312  phases.getSet());
313 
314  push(xml_out, "Forward_prop_correlator");
315  write(xml_out, "forward_prop_corr", forward_prop_corr);
316  pop(xml_out);
317  }
318 
319 
320  //
321  // Big nested loop over seqprops
322  //
323  push(xml_out, "Multipole_measurements");
324 
325  XMLArrayWriter xml_seq_src(xml_out, params.pole.seqprops.size());
326  push(xml_seq_src, "Sequential_source");
327 
328  for (int seq_src_ctr = 0; seq_src_ctr < params.pole.seqprops.size(); ++seq_src_ctr)
329  {
330  push(xml_seq_src);
331  write(xml_seq_src, "seq_src_ctr", seq_src_ctr);
332 
333  // Read the sequential propagator
334  // Read the quark propagator and extract headers
335  LatticePropagator seq_quark_prop;
336  SeqSource_t seqsource_header;
337  try
338  {
339  // Snarf the backward prop
340  seq_quark_prop =
341  TheNamedObjMap::Instance().getData<LatticePropagator>(params.pole.seqprops[seq_src_ctr].seqprop_id);
342 
343  // Snarf the source info. This is will throw if the source_id is not there
344  XMLReader seqprop_file_xml, seqprop_record_xml;
345  TheNamedObjMap::Instance().get(params.pole.seqprops[seq_src_ctr].seqprop_id).getFileXML(seqprop_file_xml);
346  TheNamedObjMap::Instance().get(params.pole.seqprops[seq_src_ctr].seqprop_id).getRecordXML(seqprop_record_xml);
347 
348  // Try to invert this record XML into a ChromaProp struct
349  // Also pull out the id of this source
350  // NEED SECURITY HERE - need a way to cross check props. Use the ID.
351  {
352  read(seqprop_record_xml, "/SequentialProp/SeqSource", seqsource_header);
353  }
354 
355  // Save seqprop input
356  write(xml_seq_src, "SequentialProp_file_info", seqprop_file_xml);
357  write(xml_seq_src, "SequentialProp_record_info", seqprop_record_xml);
358  }
359  catch( std::bad_cast )
360  {
361  QDPIO::cerr << InlineMultipoleEnv::name << ": caught dynamic cast error"
362  << std::endl;
363  QDP_abort(1);
364  }
365  catch (const std::string& e)
366  {
367  QDPIO::cerr << InlineMultipoleEnv::name << ": error message: " << e
368  << std::endl;
369  QDP_abort(1);
370  }
371  QDPIO::cout << "Sequential propagator successfully parsed" << std::endl;
372 
373 
374  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
375  // Use this for any possible verification
376  {
377  // Initialize the slow Fourier transform phases
378  SftMom phases(0, true, Nd-1);
379 
380  multi1d<Double> backward_prop_corr = sumMulti(localNorm2(seq_quark_prop),
381  phases.getSet());
382 
383  push(xml_seq_src, "Backward_prop_correlator");
384  write(xml_seq_src, "backward_prop_corr", backward_prop_corr);
385  pop(xml_seq_src);
386  }
387 
388  // Derived from input seqprop
389  std::string seq_src = seqsource_header.seq_src;
390  QDPIO::cout << "Seqsource name = " << seqsource_header.seq_src << std::endl;
391  int t_sink = seqsource_header.t_sink;
392  multi1d<int> sink_mom = seqsource_header.sink_mom;
393 
394  write(xml_seq_src, "hadron_type", "HADRON");
395  write(xml_seq_src, "seq_src", seq_src);
396  write(xml_seq_src, "t_source", t_source);
397  write(xml_seq_src, "t_sink", t_sink);
398  write(xml_seq_src, "sink_mom", sink_mom);
399  write(xml_seq_src, "max_L", params.param.max_L);
400  write(xml_seq_src, "GammaInsertion", params.pole.seqprops[seq_src_ctr].GammaInsertion);
401 
402  // Now the 3pt contractions
403  multipole(quark_propagator, seq_quark_prop, params.pole.seqprops[seq_src_ctr].GammaInsertion,
404  params.param.max_L, j_decay, t_source, xml_seq_src, "Multipole");
405 
406  pop(xml_seq_src); // elem
407  } // end loop over sequential sources
408 
409  pop(xml_seq_src); // Sequential_source
410 
411  pop(xml_out); // Multipole_measurements
412 
413  // Close the namelist output file XMLDAT
414  pop(xml_out); // multipole
415 
416 
417  snoop.stop();
418  QDPIO::cout << InlineMultipoleEnv::name << ": total time = "
419  << snoop.getTimeInSeconds()
420  << " secs" << std::endl;
421 
422  QDPIO::cout << InlineMultipoleEnv::name << ": ran successfully" << std::endl;
423 
424  END_CODE();
425  }
426 
427 };
Inline measurement factory.
Inline measurement of multipole expansion.
void func(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
InlineMultipoleParams 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
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 multipole(const LatticePropagator &quark_propagator, const LatticePropagator &seq_quark_prop, int GammaInsertion, int max_power, int j_decay, int t0, XMLWriter &xml, const std::string &xml_group)
Compute contractions for multipole moments.
Definition: multipole_w.cc:325
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.
ForwardProp_t prop_header
Inline multipole measurements.
Make xml file writer.
int j_decay
Definition: meslate.cc:22
Nd
Definition: meslate.cc:74
Multipole moments.
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()
void write(XMLWriter &xml, const std::string &path, const InlineMultipoleParams::Multipole_out_t &input)
Multipole parameters.
::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.
Propagator parameters.
Definition: qprop_io.h:75
void write(XMLWriter &xml, const std::string &path)
Write params.
struct Chroma::InlineMultipoleParams::Multipole_out_t pole
struct Chroma::InlineMultipoleParams::Param_t param
Propagator source construction parameters.
Definition: qprop_io.h:27
Sequential source parameters.
Definition: qprop_io.h:90
multi1d< int > sink_mom
Definition: qprop_io.h:95