CHROMA
inline_npr_vertex_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of NPR vertices
3  *
4  * NPR vertices on props
5  */
6 
9 #include "meas/glue/mesplq.h"
10 #include "util/ft/sftmom.h"
11 // #include "meas/hadron/BuildingBlocks_w.h"
12 #include "util/info/proginfo.h"
14 
16 
18 
21 
22 namespace Chroma
23 {
24  namespace InlineNprVertexEnv
25  {
26  namespace
27  {
28  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
29  const std::string& path)
30  {
31  return new InlineNprVertex(InlineNprVertexParams(xml_in, path));
32  }
33 
34  //! Local registration flag
35  bool registered = false;
36  }
37 
38  const std::string name = "NPR_VERTEX";
39 
40  //! Register all the factories
41  bool registerAll()
42  {
43  bool success = true;
44  if (! registered)
45  {
47  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
48  registered = true;
49  }
50  return success;
51  }
52  }
53 
54  DPropagator FTpropagator(const LatticePropagator& prop,
55  const multi1d<int> mom,
56  const multi1d<int> t_src){
57  // Initialize the slow Fourier transform phases
58  // Makes no sence to do momemtum average here...
59  SftMom phases(0, t_src, mom);
60  multi1d<int> mm = phases.numToMom(0);
61  QDPIO::cout<<"Sink momentum: " ;
62  QDPIO::cout<<mm[0]<<mm[1]<<mm[2]<<mm[3]<<std::endl;
63  return sum(prop*phases[0])/Double(Layout::vol());
64  }
65 
66  //! Param input
67  void read(XMLReader& xml, const std::string& path, InlineNprVertexParams::Param_t& input)
68  {
69  XMLReader paramtop(xml, path);
70 
71  int version;
72  read(paramtop, "version", version);
73 
74  if (paramtop.count("FermState") != 0)
75  input.cfs = readXMLGroup(paramtop, "FermState", "Name");
76  else
78 
79  switch (version)
80  {
81  case 1:
82  break;
83 
84  default :
85  QDPIO::cerr << InlineNprVertexEnv::name << ": input parameter version "
86  << version << " unsupported." << std::endl;
87  QDP_abort(1);
88  }
89 
90  read(paramtop, "links_max", input.links_max);
91  read(paramtop, "file_name", input.file_name);
92  }
93 
94 
95  //! Param write
96  void write(XMLWriter& xml, const std::string& path, const InlineNprVertexParams::Param_t& input)
97  {
98  push(xml, path);
99 
100  int version = 1;
101  write(xml, "version", version);
102  write(xml, "links_max", input.links_max);
103  write(xml, "file_name", input.file_name);
104  xml << input.cfs.xml;
105 
106  pop(xml);
107  }
108 
109  //! Propagator input
110  void read(XMLReader& xml, const std::string& path, InlineNprVertexParams::NamedObject_t& input)
111  {
112  XMLReader inputtop(xml, path);
113 
114  read(inputtop, "gauge_id", input.gauge_id);
115  read(inputtop, "prop_id", input.prop_id);
116  }
117 
118  //! Propagator output
119  void write(XMLWriter& xml, const std::string& path, const InlineNprVertexParams::NamedObject_t& input)
120  {
121  push(xml, path);
122 
123  write(xml, "gauge_id", input.gauge_id);
124  write(xml, "prop_id", input.prop_id);
125 
126  pop(xml);
127  }
128 
129 
130  // Param stuff
132 
134  {
135  try
136  {
137  XMLReader paramtop(xml_in, path);
138 
139  if (paramtop.count("Frequency") == 1)
140  read(paramtop, "Frequency", frequency);
141  else
142  frequency = 1;
143 
144  // Read program parameters
145  read(paramtop, "Param", param);
146 
147  // Read in the output propagator/source configuration info
148  read(paramtop, "NamedObject", named_obj);
149 
150  // Possible alternate XML file pattern
151  if (paramtop.count("xml_file") != 0)
152  {
153  read(paramtop, "xml_file", xml_file);
154  }
155  }
156  catch(const std::string& e)
157  {
158  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
159  QDP_abort(1);
160  }
161  }
162 
163 
164  void
165  InlineNprVertexParams::write(XMLWriter& xml_out, const std::string& path)
166  {
167  push(xml_out, path);
168 
169  Chroma::write(xml_out, "Param", param);
170  Chroma::write(xml_out, "NamedObject", named_obj);
171  QDP::write(xml_out, "xml_file", xml_file);
172 
173  pop(xml_out);
174  }
175 
176 
177  //###################################################################################//
178  // Accept All Link Patterns //
179  //###################################################################################//
180 
181  void AllLinkPatterns( bool & DoThisPattern,
182  bool & DoFurtherPatterns,
183  multi1d< int > & LinkPattern )
184  {
185  DoThisPattern = true;
186  DoFurtherPatterns = true;
187 
188  return;
189  }
190 
191 
192  // Function call
193  void
194  InlineNprVertex::operator()(unsigned long update_no,
195  XMLWriter& xml_out)
196  {
197  // If xml file not empty, then use alternate
198  if (params.xml_file != "")
199  {
200  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
201 
202  push(xml_out, "NprVertex");
203  write(xml_out, "update_no", update_no);
204  write(xml_out, "xml_file", xml_file);
205  pop(xml_out);
206 
207  XMLFileWriter xml(xml_file);
208  func(update_no, xml);
209  }
210  else
211  {
212  func(update_no, xml_out);
213  }
214  }
215 
216 
217  // Function call
218  void
219  InlineNprVertex::func(unsigned long update_no,
220  XMLWriter& XmlOut)
221  {
222  START_CODE();
223 
224  StopWatch snoop;
225  snoop.reset();
226  snoop.start();
227 
228  push(XmlOut, "NprVertex");
229  write(XmlOut, "update_no", update_no);
230 
231  QDPIO::cout << " ExampleNprVertex" << std::endl;
232  QDPIO::cout << " volume: " << QDP::Layout::lattSize()[0];
233  for (int i=1; i<Nd; ++i) {
234  QDPIO::cout << " x " << QDP::Layout::lattSize()[i];
235  }
236  QDPIO::cout << std::endl;
237 
238  //#################################################################################//
239  // XML output
240  //#################################################################################//
241 
242  proginfo(XmlOut); // Print out basic program info
243 
244  push(XmlOut, "Output_version");
245  write(XmlOut, "out_version", 2);
246  pop(XmlOut);
247 
248  //###############################################################################//
249  // Read Gauge Field //
250  //###############################################################################//
251 
252  QDPIO::cout << "Attempt to initialize the gauge field" << std::endl << std::flush ;
253 
254  // Grab the gauge field
255  multi1d<LatticeColorMatrix> U;
256  XMLBufferWriter gauge_xml;
257 
258  try
259  {
260  U = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
261  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
262 
263  // Set the construct state and modify the fields
264  {
265  QDPIO::cout << "cfs=XX" << params.param.cfs.xml << "XX" << std::endl;
266  std::istringstream xml_s(params.param.cfs.xml);
267  XMLReader fermtop(xml_s);
268 
271  fermtop,
272  params.param.cfs.path));
273 
274  Handle<FermState< LatticeFermion, multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> > >
275  state((*cfs)(U));
276 
277  // Pull the u fields back out from the state since they might have been
278  // munged with fermBC's
279  U = state->getLinks();
280  }
281 
282  }
283  catch( std::bad_cast )
284  {
285  QDPIO::cerr << InlineNprVertexEnv::name << ": caught dynamic cast error"
286  << std::endl;
287  QDP_abort(1);
288  }
289  catch (const std::string& e)
290  {
291  QDPIO::cerr << InlineNprVertexEnv::name << ": std::map call failed: " << e
292  << std::endl;
293  QDP_abort(1);
294  }
295  catch( ... )
296  {
297  QDPIO::cerr << InlineNprVertexEnv::name << ": caught generic exception "
298  << std::endl;
299  QDP_abort(1);
300  }
301 
302  // Write out the input
303  params.write(XmlOut, "Input");
304 
305  // Write out the config info
306  write(XmlOut, "Config_info", gauge_xml);
307 
308  // Calculate some gauge invariant observables just for info.
309  MesPlq(XmlOut, "Observables", U);
310 
311  //#################################################################################//
312  // Read Forward Propagator //
313  //#################################################################################//
314 
315  SftMom phases_nomom( 0, true, Nd-1 ); // used to check props. Fix to Nd-1 direction.
316 
317  LatticePropagator F;
319  PropSourceConst_t source_header;
320  QDPIO::cout << "Attempt to parse forward propagator" << std::endl;
321  QDPIO::cout << "parsing forward propagator " << params.named_obj.prop_id << " ... " << std::endl << std::flush;
322 
323  try
324  {
325  // Snarf a copy
326  F = TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_id);
327 
328  // Snarf the frwd prop info. This is will throw if the frwd prop id is not there
329  XMLReader PropXML, PropRecordXML;
330  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getFileXML(PropXML);
331  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getRecordXML(PropRecordXML);
332 
333  // Try to invert this record XML into a ChromaProp struct
334  {
335  read(PropRecordXML, "/Propagator/ForwardProp", prop_header);
336  read(PropRecordXML, "/Propagator/PropSource", source_header);
337  }
338 
339  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
340  // Use this for any possible verification
341  {
342  multi1d<Double> PropCheck =
343  sumMulti( localNorm2( F ), phases_nomom.getSet() );
344 
345  QDPIO::cout << "forward propagator check = " << PropCheck[0] << std::endl;
346 
347  // Write out the forward propagator header
348  push(XmlOut, "ForwardProp");
349  write(XmlOut, "PropXML", PropXML);
350  write(XmlOut, "PropRecordXML", PropRecordXML);
351  write(XmlOut, "PropCheck", PropCheck);
352  pop(XmlOut);
353  }
354  }
355  catch( std::bad_cast )
356  {
357  QDPIO::cerr << InlineNprVertexEnv::name << ": caught dynamic cast error"
358  << std::endl;
359  QDP_abort(1);
360  }
361  catch (const std::string& e)
362  {
363  QDPIO::cerr << InlineNprVertexEnv::name << ": forward prop: error message: " << e
364  << std::endl;
365  QDP_abort(1);
366  }
367 
368  QDPIO::cout << "Forward propagator successfully parsed" << std::endl;
369 
370 
371  // Get the momentum from the header
372 
373  multi1d<int> mom ;
374  multi1d<int> t_src ;
375  int t_dir = source_header.j_decay ;
376 
377  try{
378  mom = source_header.getMom() ;
379  t_src = source_header.getTSrce() ;
380  }
381  catch (const std::string& e){
382  QDPIO::cerr << InlineNprVertexEnv::name << ": propagator does not have a momentum source or t_src not present: error message: " << e << std::endl;
383  QDP_abort(1);
384  }
385 
386 
387  //#################################################################################//
388  // Construct Building Blocks //
389  //#################################################################################//
390  QDP::StopWatch swatch;
391  swatch.reset();
392 
393  XMLBufferWriter file_xml;
394  push(file_xml, "NprVertex");
395  write(file_xml, "Param", params.param);
396  write(file_xml, "ForwardProp", prop_header);
397  write(file_xml, "PropSource", source_header);
398  write(file_xml, "Config", gauge_xml);
399  pop(file_xml);
400 
401  QDPFileWriter qio_file(file_xml, params.param.file_name,QDPIO_SINGLEFILE,
402  QDPIO_SERIAL, QDPIO_OPEN);
403 
404 
405  //Fourier transform the propagator
406  QDPIO::cout << "Fourier Transforming propagator" << std::endl;
407  swatch.start();
408  multi1d<int> neg_mom(mom.size());
409  //need the oposit momentum on the sink
410  for(int i(0);i<mom.size();i++)
411  neg_mom[i] = -mom[i] ;
412  DPropagator FTprop(FTpropagator(F,neg_mom,t_src));
413  swatch.stop();
414  XMLBufferWriter prop_xml;
415  push(prop_xml,"QuarkPropagator");
416  write(prop_xml,"mom",mom);
417  write(prop_xml,"origin",t_src);
418  write(prop_xml,"t_dir",t_dir);
419  pop(prop_xml) ;
420  write(qio_file, prop_xml, FTprop);
421 
422  QDPIO::cout << "finished Fourier Transforming propagator"
423  << " time= "
424  << swatch.getTimeInSeconds()
425  << " secs" << std::endl;
426 
427  QDPIO::cout << "Calculating building blocks" << std::endl;
428  swatch.reset();
429  swatch.start();
431  swatch.stop();
432 
433  close(qio_file);
434 
435  QDPIO::cout << "finished calculating NprVertex"
436  << " time= "
437  << swatch.getTimeInSeconds()
438  << " secs" << std::endl;
439 
440  pop(XmlOut); // NprVertex
441 
442  snoop.stop();
443  QDPIO::cout << InlineNprVertexEnv::name << ": total time = "
444  << snoop.getTimeInSeconds()
445  << " secs" << std::endl;
446 
447  QDPIO::cout << InlineNprVertexEnv::name << ": ran successfully" << std::endl;
448 
449  END_CODE();
450  }
451 
452 }
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
Inline measurement of NPR vertices.
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.
InlineNprVertexParams params
Fourier transform phase factor support.
Definition: sftmom.h:35
multi1d< int > numToMom(int mom_num) const
Convert momenta id to actual array of momenta.
Definition: sftmom.h:78
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
static T & Instance()
Definition: singleton.h:432
All ferm create-state method.
Fermion create state factory.
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 NprVertex(const LatticePropagator &F, const multi1d< LatticeColorMatrix > &U, const unsigned short int MaxNLinks, const BBLinkPattern LinkPattern, QDPFileWriter &qio_file)
NPR vertices.
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.
std::map< std::string, SinkPropContainer_t > prop
ForwardProp_t prop_header
Inline construction of NPR vertices.
Make xml file writer.
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
GroupXML_t nullXMLGroup()
Returns a periodic createstate group.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
void AllLinkPatterns(bool &DoThisPattern, bool &DoFurtherPatterns, multi1d< unsigned short int > &LinkPattern)
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
void write(XMLWriter &xml, const std::string &path, const InlineNprVertexParams::NamedObject_t &input)
Propagator output.
DPropagator FTpropagator(const LatticePropagator &prop, const multi1d< int > mom, const multi1d< int > t_src)
START_CODE()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
NPR vertex calculations.
Print out basic info about this program.
Double sum
Definition: qtopcor.cc:37
Fourier transform phase factor support.
Propagator parameters.
Definition: qprop_io.h:75
void write(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineNprVertexParams::Param_t param
struct Chroma::InlineNprVertexParams::NamedObject_t named_obj
Propagator source construction parameters.
Definition: qprop_io.h:27
multi1d< int > getMom() const
Definition: qprop_io.cc:161
multi1d< int > getTSrce() const
Definition: qprop_io.cc:120
multi1d< LatticeColorMatrix > U
static INTERNAL_PRECISION F