CHROMA
inline_npr_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of NPR propagator
3  *
4  * Propagator calculations
5  */
6 
7 #include "fermact.h"
10 #include "meas/glue/mesplq.h"
11 #include "util/ft/sftmom.h"
12 #include "util/info/proginfo.h"
16 
18 
19 namespace Chroma
20 {
21  namespace InlineNprEnv
22  {
23  namespace
24  {
25  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
26  const std::string& path)
27  {
28  return new InlineNpr(InlineNprParams(xml_in, path));
29  }
30 
31  //! Local registration flag
32  bool registered = false;
33  }
34 
35  const std::string name = "NPR";
36 
37  //! Register all the factories
38  bool registerAll()
39  {
40  bool success = true;
41  if (! registered)
42  {
44  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
45  registered = true;
46  }
47  return success;
48  }
49  } // end namespace
50 
51 
52  //! Npr input
53  void read(XMLReader& xml, const std::string& path, InlineNprParams::NamedObject_t& input)
54  {
55  XMLReader inputtop(xml, path);
56 
57  read(inputtop, "gauge_id", input.gauge_id);
58  //read(inputtop, "source_id", input.source_id);
59  read(inputtop, "prop_id", input.prop_id);
60  }
61 
62  //! Npr output
63  void write(XMLWriter& xml, const std::string& path, const InlineNprParams::NamedObject_t& input)
64  {
65  push(xml, path);
66 
67  write(xml, "gauge_id", input.gauge_id);
68  //write(xml, "source_id", input.source_id);
69  write(xml, "prop_id", input.prop_id);
70 
71  pop(xml);
72  }
73 
74 
75  // Param stuff
77 
78  InlineNprParams::InlineNprParams(XMLReader& xml_in, const std::string& path)
79  {
80  try
81  {
82  XMLReader paramtop(xml_in, path);
83 
84  if (paramtop.count("Frequency") == 1)
85  read(paramtop, "Frequency", frequency);
86  else
87  frequency = 1;
88 
89  // Read in the output npr/source configuration info
90  read(paramtop, "max_mom2", max_mom2);
91  output_type = "LIME";
92  if(paramtop.count("output_type")==1)
93  read(paramtop, "output_type", output_type);
94 
95  read(paramtop, "filename", filename);
96 
97  // Read in the output npr/source configuration info
98  read(paramtop, "NamedObject", named_obj);
99 
100  // Possible alternate XML file pattern
101  if (paramtop.count("xml_file") != 0)
102  {
103  read(paramtop, "xml_file", xml_file);
104  }
105  }
106  catch(const std::string& e)
107  {
108  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
109  QDP_abort(1);
110  }
111  }
112 
113 
114  void
115  InlineNprParams::write(XMLWriter& xml_out, const std::string& path)
116  {
117  push(xml_out, path);
118 
119  QDP::write(xml_out, "filename", filename);
120  QDP::write(xml_out, "max_mom2", max_mom2);
121  QDP::write(xml_out, "output_type", output_type);
122  Chroma::write(xml_out, "NamedObject", named_obj);
123 
124  pop(xml_out);
125  }
126 
127  /**
128  void InlineNpr::make_source(LatticePropagator& src,
129  const Handle<const ConnectState>& state,
130  const mult1d<ind>& t_source,
131  int mu){
132  multi1d<LatticeColorMatrix>& u = state.getLinks() ;
133  for(int color_source = 0; color_source < Nc; ++color_source){
134  QDPIO::cout << "color = " << color_source << std::endl;
135  LatticeColorVector cvec = zero;
136  // Make a point source at coordinates t_source
137  srcfil(src_color_vec, t_source, color_source);
138  if((mu>=0)&&(mu<Nd)){
139  LatticeColorVector tt = cvec ;
140  cvec=0.5*(u[mu]*shift(tt,FORWARD,mu) - shift(adj(u[mu])*tt,BACKWARD,mu));
141  }
142  for(int spin_source = 0; spin_source < Ns; ++spin_source){
143  QDPIO::cout << "spin = " << spin_source << std::endl;
144  // Insert a ColorVector into spin index spin_source
145  // This only overwrites sections, so need to initialize first
146  LatticeFermion chi = zero;
147  CvToFerm(cvec, chi, spin_source);
148  FermToProp(chi, src, color_source, spin_source);
149  }
150  }
151  }
152  **/
153 
154  // Function call
155  void
156  InlineNpr::operator()(unsigned long update_no,
157  XMLWriter& xml_out)
158  {
159  // If xml file not empty, then use alternate
160  if (params.xml_file != "")
161  {
162  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
163 
164  push(xml_out, "npr");
165  write(xml_out, "update_no", update_no);
166  write(xml_out, "xml_file", xml_file);
167  pop(xml_out);
168 
169  XMLFileWriter xml(xml_file);
170  func(update_no, xml);
171  }
172  else
173  {
174  func(update_no, xml_out);
175  }
176  }
177 
178 
179  // Real work done here
180  void
181  InlineNpr::func(unsigned long update_no, XMLWriter& xml_out)
182  {
183  START_CODE();
184 
185  StopWatch snoop;
186  snoop.reset();
187  snoop.start();
188 
189  // Test and grab a reference to the gauge field
190  XMLBufferWriter gauge_xml;
191  try
192  {
193  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
194  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
195  }
196  catch( std::bad_cast )
197  {
198  QDPIO::cerr << InlineNprEnv::name << ": caught dynamic cast error"
199  << std::endl;
200  QDP_abort(1);
201  }
202  catch (const std::string& e)
203  {
204  QDPIO::cerr << InlineNprEnv::name << ": std::map call failed: " << e
205  << std::endl;
206  QDP_abort(1);
207  }
208  const multi1d<LatticeColorMatrix>& u =
209  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
210 
211  XMLReader prop_file_xml,prop_xml ;
212  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getFileXML(prop_file_xml);
213  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getRecordXML(prop_xml);
214  LatticePropagator quark_propagator = TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_id);
215 
216  push(xml_out, "npr");
217  write(xml_out, "update_no", update_no);
218  XMLBufferWriter file_xml;
219  push(file_xml, "NPR_W");
220  push(file_xml, "Output_version");
221  write(file_xml, "out_version", 1);
222  pop(file_xml);
223  proginfo(file_xml); // Print out basic program info
224  params.write(file_xml, "Input");
225 
226  QDPIO::cout << InlineNprEnv::name << ": npr calculation" << std::endl;
227 
228  proginfo(xml_out); // Print out basic program info
229 
230  // Write out the input
231  params.write(xml_out, "Input");
232 
233  // Write out the config header
234  write(xml_out, "Config_info", gauge_xml);
235 
236  push(xml_out, "Output_version");
237  write(xml_out, "out_version", 1);
238  pop(xml_out);
239  write(xml_out, "Config_info", gauge_xml);
240  write(xml_out, "Propagator_info", prop_xml);
241 
242  write(file_xml, "Config_info", gauge_xml);
243  write(file_xml, "Propagator_info", prop_xml);
244  pop(file_xml) ; //NPR_W
245 
246  // Calculate some gauge invariant observables just for info.
247  MesPlq(xml_out, "Observables", u);
248 
249  // Make sure that the source location is irrelevant
250  SftMom phases(params.max_mom2, false, Nd); // 4D fourier transform
251 
252  //now need to Fourier transform
253  multi1d<DPropagator> FF(phases.numMom());//= sumMulti(quark_propagator,phases.getSet());
254  for (int m(0); m < FF.size(); m++){
255  multi1d<DPropagator> tt ;
256  tt = sumMulti(phases[m]*quark_propagator, phases.getSet()) ;
257  FF[m] = tt[0] ;
258  }
259 
260  // Either write out prop as text or binary. The options are to set the option
261  if(params.output_type=="XML"){
262  push(xml_out,"FT_prop") ;
263  for(int p(0) ; p<phases.numMom();p++){
264  push(xml_out, "prop_desc");//write out the momemtum of each bit
265  write(xml_out, "mom", phases.numToMom(p));
266  pop(xml_out);//prop_desc
267  write(xml_out,"prop",FF[p]);
268  }
269  pop(xml_out);//FT_prop
270  }
271  else{//Default output is binary
272  QDPFileWriter FFfile(file_xml, params.filename, QDPIO_SINGLEFILE, QDPIO_SERIAL, QDPIO_OPEN);
273  for(int p(0) ; p<phases.numMom();p++){
274  XMLBufferWriter record_xml;
275  push(record_xml, "prop_desc");//write out the momemtum of each bit
276  write(record_xml, "mom", phases.numToMom(p));
277  pop(record_xml);
278  write(FFfile,record_xml,FF[p]);
279  }
280  }
281 
282  // Sanity check - write out the propagator (pion) correlator in the Nd-1 direction
283  {
284  // Initialize the slow Fourier transform phases
285  SftMom ph(0, true, Nd-1);
286 
287  multi1d<Double> prop_corr = sumMulti(localNorm2(quark_propagator),
288  ph.getSet());
289 
290  push(xml_out, "Prop_correlator");
291  write(xml_out, "prop_corr", prop_corr);
292  pop(xml_out);
293  }
294 
295  pop(xml_out); // npr
296 
297  snoop.stop();
298  QDPIO::cout << InlineNprEnv::name << ": total time = "
299  << snoop.getTimeInSeconds()
300  << " secs" << std::endl;
301 
302  QDPIO::cout << InlineNprEnv::name << ": ran successfully" << std::endl;
303 
304  END_CODE();
305  }
306 
307 } //name space Chroma
Inline measurement factory.
Inline measurement of Wilson loops.
Definition: inline_npr_w.h:54
InlineNprParams params
Definition: inline_npr_w.h:72
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
multi1d< int > numToMom(int mom_num) const
Convert momenta id to actual array of momenta.
Definition: sftmom.h:78
int numMom() const
Number of momenta.
Definition: sftmom.h:60
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
static T & Instance()
Definition: singleton.h:432
Class structure for fermion actions.
Fermion action factories.
All Wilson-type fermion actions.
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 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.
Inline construction of Landau gauge propagator.
static int m[4]
Definition: make_seeds.cc:16
Make xml file writer.
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
Definition: inline_npr_w.cc:38
const std::string name
Definition: inline_npr_w.cc:35
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
void write(XMLWriter &xml, const std::string &path, const InlineNprParams::NamedObject_t &input)
Npr output.
Definition: inline_npr_w.cc:63
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.
Fourier transform phase factor support.
Parameter structure.
Definition: inline_npr_w.h:31
unsigned long frequency
Definition: inline_npr_w.h:36
void write(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineNprParams::NamedObject_t named_obj