CHROMA
inline_sink_smear_s.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of sink_smear
3  *
4  * Sink smear propagators
5  */
6 
7 #include "handle.h"
12 #include "meas/glue/mesplq.h"
13 #include "util/ft/sftmom.h"
14 #include "util/info/unique_id.h"
15 
17 
18 namespace Chroma
19 {
20  //! Propagator input
21  void read(XMLReader& xml, const std::string& path, InlineStaggeredSinkSmearEnv::Params::NamedObject_t& input)
22  {
23  XMLReader inputtop(xml, path);
24 
25  read(inputtop, "gauge_id", input.gauge_id);
26  read(inputtop, "prop_id", input.prop_id);
27  read(inputtop, "smeared_prop_id", input.smeared_prop_id);
28  }
29 
30  //! Propagator output
31  void write(XMLWriter& xml, const std::string& path, const InlineStaggeredSinkSmearEnv::Params::NamedObject_t& input)
32  {
33  push(xml, path);
34 
35  write(xml, "gauge_id", input.gauge_id);
36  write(xml, "prop_id", input.prop_id);
37  write(xml, "smeared_prop_id", input.smeared_prop_id);
38 
39  pop(xml);
40  }
41 
42 
43  namespace InlineStaggeredSinkSmearEnv
44  {
45  namespace
46  {
47  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
48  const std::string& path)
49  {
50  return new InlineMeas(Params(xml_in, path));
51  }
52 
53  //! Local registration flag
54  bool registered = false;
55  }
56 
57  const std::string name = "SINK_SMEAR_STAG";
58 
59  //! Register all the factories
60  bool registerAll()
61  {
62  bool success = true;
63  if (! registered)
64  {
66  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
67  registered = true;
68  }
69  return success;
70  }
71 
72 
73  // Param stuff
75 
76  Params::Params(XMLReader& xml_in, const std::string& path)
77  {
78  try
79  {
80  XMLReader paramtop(xml_in, path);
81 
82  if (paramtop.count("Frequency") == 1)
83  read(paramtop, "Frequency", frequency);
84  else
85  frequency = 1;
86 
87  // Parameters for source construction
88  read(paramtop, "Param", param);
89 
90  // Read in the output propagator/source configuration info
91  read(paramtop, "NamedObject", named_obj);
92  }
93  catch(const std::string& e)
94  {
95  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
96  QDP_abort(1);
97  }
98  }
99 
100 
101  void
102  Params::write(XMLWriter& xml_out, const std::string& path)
103  {
104  push(xml_out, path);
105 
106  // Parameters for source construction
107  Chroma::write(xml_out, "Param", param);
108 
109  // Write out the output propagator/source configuration info
110  Chroma::write(xml_out, "NamedObject", named_obj);
111 
112  pop(xml_out);
113  }
114 
115 
116  void
117  InlineMeas::operator()(unsigned long update_no,
118  XMLWriter& xml_out)
119  {
120  START_CODE();
121 
122  StopWatch snoop;
123  snoop.reset();
124  snoop.start();
125 
126  // Test and grab a reference to the gauge field
127  XMLBufferWriter gauge_xml;
128  try
129  {
130  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
131  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
132  }
133  catch( std::bad_cast )
134  {
135  QDPIO::cerr << name << ": caught dynamic cast error"
136  << std::endl;
137  QDP_abort(1);
138  }
139  catch (const std::string& e)
140  {
141  QDPIO::cerr << name << ": std::map call failed: " << e
142  << std::endl;
143  QDP_abort(1);
144  }
145  const multi1d<LatticeColorMatrix>& u =
146  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
147 
148  push(xml_out, "sink_smear_stag");
149  write(xml_out, "update_no", update_no);
150 
151  QDPIO::cout << name << ": Sink smearing for propagators" << std::endl;
152 
153  // Write out the input
154  params.write(xml_out, "Input");
155 
156  // Write out the config header
157  write(xml_out, "Config_info", gauge_xml);
158 
159  // Calculate some gauge invariant observables just for info.
160  MesPlq(xml_out, "Observables", u);
161 
162  //
163  // Read the quark propagator and extract headers
164  //
165  XMLReader prop_file_xml, prop_record_xml;
166  LatticeStaggeredPropagator quark_propagator;
167 
168  int j_decay; // need this for diagnostics
169 
170  QDPIO::cout << "Attempt to read forward propagator" << std::endl;
171  try
172  {
173  // Grab a copy of the propagator. Will modify it later.
174  quark_propagator =
175  TheNamedObjMap::Instance().getData<LatticeStaggeredPropagator>(params.named_obj.prop_id);
176 
177  // Snarf the prop info. This is will throw if the prop_id is not there
178  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getFileXML(prop_file_xml);
179  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getRecordXML(prop_record_xml);
180 
181  // Snarf out the first j_decay
182  read(prop_record_xml, "/descendant::j_decay[1]", j_decay);
183 
184  // Write out the propagator header
185  write(xml_out, "Prop_file_info", prop_file_xml);
186  write(xml_out, "Prop_record_info", prop_record_xml);
187  }
188  catch (std::bad_cast)
189  {
190  QDPIO::cerr << name << ": caught dynamic cast error"
191  << std::endl;
192  QDP_abort(1);
193  }
194  catch (const std::string& e)
195  {
196  QDPIO::cerr << name << ": error extracting prop_header: " << e << std::endl;
197  QDP_abort(1);
198  }
199 
200  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
201  // Use this for any possible verification
202  {
203  // Initialize the slow Fourier transform phases
204  SftMom phases(0, true, j_decay);
205 
206  multi1d<Double> forward_prop_corr = sumMulti(localNorm2(quark_propagator),
207  phases.getSet());
208 
209  push(xml_out, "Forward_prop_correlator");
210  write(xml_out, "forward_prop_corr", forward_prop_corr);
211  pop(xml_out);
212  }
213 
214 
215  //
216  // Sink smear the propagator
217  //
218  try
219  {
220  QDPIO::cout << "Sink_xml = " << params.param.sink.xml << std::endl;
221 
222  std::istringstream xml_s(params.param.sink.xml);
223  XMLReader sinktop(xml_s);
224  QDPIO::cout << "Sink = " << params.param.sink.id << std::endl;
225 
227  sinkSmearing(TheStagPropSinkSmearingFactory::Instance().createObject(params.param.sink.id,
228  sinktop,
230  u));
231  (*sinkSmearing)(quark_propagator);
232  }
233  catch(const std::string& e)
234  {
235  QDPIO::cerr << name << ": Caught Exception creating sink: " << e << std::endl;
236  QDP_abort(1);
237  }
238 
239 
240  // Sanity check - write out the propagator (pion) correlator in the Nd-1 direction
241  {
242  // Initialize the slow Fourier transform phases
243  SftMom phases(0, true, j_decay);
244 
245  multi1d<Double> prop_corr = sumMulti(localNorm2(quark_propagator),
246  phases.getSet());
247 
248  push(xml_out, "SinkSmearedProp_correlator");
249  write(xml_out, "sink_smeared_prop_corr", prop_corr);
250  pop(xml_out);
251  }
252 
253 
254  // Save the propagator
255  try
256  {
257  XMLBufferWriter file_xml;
258  push(file_xml, "sink_smear");
259  write(file_xml, "id", uniqueId()); // NOTE: new ID form
260  pop(file_xml);
261 
262  XMLBufferWriter record_xml;
263 
264  // Construct an appropriate record_xml based on the input type
265  if (prop_record_xml.count("/Propagator") != 0)
266  {
267  Propagator_t orig_header;
268  read(prop_record_xml, "/Propagator", orig_header);
269 
270  ForwardProp_t new_header;
271  new_header.sink_header = params.param;
272  new_header.prop_header = orig_header.prop_header;
273  new_header.source_header = orig_header.source_header;
274  new_header.gauge_header = orig_header.gauge_header;
275  write(record_xml, "SinkSmear", new_header);
276  }
277  else
278  {
279  throw std::string("No appropriate header found");
280  }
281 
282  // Write the smeared prop xml info
283  TheNamedObjMap::Instance().create<LatticeStaggeredPropagator>(params.named_obj.smeared_prop_id);
284  TheNamedObjMap::Instance().getData<LatticeStaggeredPropagator>(params.named_obj.smeared_prop_id)
285  = quark_propagator;
286  TheNamedObjMap::Instance().get(params.named_obj.smeared_prop_id).setFileXML(file_xml);
287  TheNamedObjMap::Instance().get(params.named_obj.smeared_prop_id).setRecordXML(record_xml);
288 
289  QDPIO::cout << "Sink successfully updated" << std::endl;
290  }
291  catch (std::bad_cast)
292  {
293  QDPIO::cerr << name << ": dynamic cast error"
294  << std::endl;
295  QDP_abort(1);
296  }
297  catch (const std::string& e)
298  {
299  QDPIO::cerr << name << ": error message: " << e << std::endl;
300  QDP_abort(1);
301  }
302 
303  pop(xml_out); // sink_smear
304 
305 
306  snoop.stop();
307  QDPIO::cout << name << ": total time = "
308  << snoop.getTimeInSeconds()
309  << " secs" << std::endl;
310 
311  QDPIO::cout << name << ": ran successfully" << std::endl;
312 
313  END_CODE();
314  }
315 
316  }
317 }
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
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.
std::string uniqueId()
Return a unique id.
Definition: unique_id.cc:18
Class for counted reference semantics.
Inline sink_smear propagators.
int j_decay
Definition: meslate.cc:22
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
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
Fourier transform phase factor support.
All make sink constructors.
Factory for producing quark prop sinks.
Mega structure holding a full forward sink-smeared prop.
Definition: qprop_io.h:120
ChromaProp_t prop_header
Definition: qprop_io.h:122
PropSinkSmear_t sink_header
Definition: qprop_io.h:121
PropSourceConst_t source_header
Definition: qprop_io.h:123
std::string gauge_header
Definition: qprop_io.h:124
struct Chroma::InlineStaggeredSinkSmearEnv::Params::NamedObject_t named_obj
void write(XMLWriter &xml_out, const std::string &path)
Mega structure holding a full forward prop (not sink smeared)
Definition: qprop_io.h:111
ChromaProp_t prop_header
Definition: qprop_io.h:112
std::string gauge_header
Definition: qprop_io.h:114
PropSourceConst_t source_header
Definition: qprop_io.h:113
Generate a unique id.