CHROMA
inline_make_source_s.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of make_source
3  *
4  * Construct source for propagator calculations
5  */
6 
7 #include "handle.h"
10 #include "meas/glue/mesplq.h"
13 
14 #include "util/ft/sftmom.h"
15 #include "util/info/proginfo.h"
16 #include "util/info/unique_id.h"
18 
20 
21 namespace Chroma
22 {
23  //! MakeSource input
24  void read(XMLReader& xml, const std::string& path, InlineStaggeredMakeSourceEnv::Params::NamedObject_t& input)
25  {
26  XMLReader inputtop(xml, path);
27 
28  read(inputtop, "gauge_id", input.gauge_id);
29  read(inputtop, "source_id", input.source_id);
30  }
31 
32  //! MakeSource output
33  void write(XMLWriter& xml, const std::string& path, const InlineStaggeredMakeSourceEnv::Params::NamedObject_t& input)
34  {
35  push(xml, path);
36 
37  write(xml, "gauge_id", input.gauge_id);
38  write(xml, "source_id", input.source_id);
39 
40  pop(xml);
41  }
42 
43 
44  namespace InlineStaggeredMakeSourceEnv
45  {
46  namespace
47  {
48  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
49  const std::string& path)
50  {
51  return new InlineMeas(Params(xml_in, path));
52  }
53 
54  //! Local registration flag
55  bool registered = false;
56  }
57 
58  const std::string name = "MAKE_SOURCE_STAG";
59 
60  //! Register all the factories
61  bool registerAll()
62  {
63  bool success = true;
64  if (! registered)
65  {
67  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
68  registered = true;
69  }
70  return success;
71  }
72 
73 
74 
75  // Param stuff
77 
78  Params::Params(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  // Parameters for source construction
90  read(paramtop, "Param", param);
91 
92  // Named object output location
93  read(paramtop, "NamedObject", named_obj);
94 
95  // Possible alternate XML file pattern
96  if (paramtop.count("xml_file") != 0)
97  {
98  read(paramtop, "xml_file", xml_file);
99  }
100  }
101  catch(const std::string& e)
102  {
103  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
104  QDP_abort(1);
105  }
106  }
107 
108 
109  // Writer
110  void
111  Params::writeXML(XMLWriter& xml_out, const std::string& path)
112  {
113  push(xml_out, path);
114 
115  // Parameters for source construction
116  write(xml_out, "Param", param);
117 
118  // Write out the buffer ids
119  write(xml_out, "NamedObject", named_obj);
120 
121  pop(xml_out);
122  }
123 
124 
125  // Function call
126  void
127  InlineMeas::operator()(unsigned long update_no,
128  XMLWriter& xml_out)
129  {
130  // If xml file not empty, then use alternate
131  if (params.xml_file != "")
132  {
133  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
134 
135  push(xml_out, "make_source_stag");
136  write(xml_out, "update_no", update_no);
137  write(xml_out, "xml_file", xml_file);
138  pop(xml_out);
139 
140  XMLFileWriter xml(xml_file);
141  func(update_no, xml);
142  }
143  else
144  {
145  func(update_no, xml_out);
146  }
147  }
148 
149 
150  // Real work done here
151  void
152  InlineMeas::func(unsigned long update_no,
153  XMLWriter& xml_out)
154  {
155  START_CODE();
156 
157  StopWatch snoop;
158  snoop.reset();
159  snoop.start();
160 
161  // Grab the gauge field
162  multi1d<LatticeColorMatrix> u;
163  XMLBufferWriter gauge_xml;
164  try
165  {
166  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
167  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
168  }
169  catch( std::bad_cast )
170  {
171  QDPIO::cerr << name << ": caught dynamic cast error"
172  << std::endl;
173  QDP_abort(1);
174  }
175  catch (const std::string& e)
176  {
177  QDPIO::cerr << name << ": std::map call failed: " << e
178  << std::endl;
179  QDP_abort(1);
180  }
181 
182  // Save the initial state of the RNG
183  QDP::Seed ran_seed;
184  QDP::RNG::savern(ran_seed);
185 
186  push(xml_out, "make_source_stag");
187  write(xml_out, "update_no", update_no);
188 
189  QDPIO::cout << name << ": propagator source constructor" << std::endl;
190 
191  proginfo(xml_out); // Print out basic program info
192 
193  // Current state of the seed
194  write(xml_out, "RNG", ran_seed);
195 
196  // Write out the input
197  params.writeXML(xml_out, "Input");
198 
199  // Write out the config header
200  write(xml_out, "Config_info", gauge_xml);
201 
202  // Calculate some gauge invariant observables just for info.
203  MesPlq(xml_out, "Observables", u);
204 
205  //
206  // Initialize source
207  //
208  LatticeStaggeredPropagator quark_source;
209 
210  try
211  {
212  std::istringstream xml_s(params.param.source.xml);
213  XMLReader sourcetop(xml_s);
214  QDPIO::cout << "Source = " << params.param.source.id << std::endl;
215 
217  sourceConstruction(TheStagPropSourceConstructionFactory::Instance().createObject(params.param.source.id,
218  sourcetop,
220  quark_source = (*sourceConstruction)(u);
221  }
222  catch(const std::string& e)
223  {
224  QDPIO::cerr << name << ": Caught Exception creating source: " << e << std::endl;
225  QDP_abort(1);
226  }
227 
228 
229  // Sanity check - write out the norm2 of the source in the Nd-1 direction.
230  // Use this for any possible verification.
231  {
232  // Initialize the slow Fourier transform phases
233  SftMom phases(0, true, Nd-1);
234 
235  multi1d<Double> source_corr = sumMulti(localNorm2(quark_source),
236  phases.getSet());
237 
238  push(xml_out, "Source_correlator");
239  write(xml_out, "source_corr", source_corr);
240  pop(xml_out);
241  }
242 
243 
244  // Now write the source
245  try
246  {
247  QDPIO::cout << "Attempt to update source" << std::endl;
248 
249  XMLBufferWriter file_xml;
250  push(file_xml, "make_source");
251  write(file_xml, "id", uniqueId()); // NOTE: new ID form
252  pop(file_xml);
253 
254  XMLBufferWriter record_xml;
255  push(record_xml, "MakeSource");
256  write(record_xml, "PropSource", params.param);
257  write(record_xml, "RNG", ran_seed);
258  write(record_xml, "Config_info", gauge_xml);
259  pop(record_xml);
260 
261  // Store the source
262  TheNamedObjMap::Instance().create<LatticeStaggeredPropagator>(params.named_obj.source_id);
263  TheNamedObjMap::Instance().getData<LatticeStaggeredPropagator>(params.named_obj.source_id) = quark_source;
264  TheNamedObjMap::Instance().get(params.named_obj.source_id).setFileXML(file_xml);
265  TheNamedObjMap::Instance().get(params.named_obj.source_id).setRecordXML(record_xml);
266 
267  QDPIO::cout << "Source successfully update" << std::endl;
268  }
269  catch (std::bad_cast)
270  {
271  QDPIO::cerr << name << ": dynamic cast error"
272  << std::endl;
273  QDP_abort(1);
274  }
275  catch (const std::string& e)
276  {
277  QDPIO::cerr << name << ": error message: " << e << std::endl;
278  QDP_abort(1);
279  }
280 
281  pop(xml_out); // make_source
282 
283 // // Reset the seed
284 // QDP::RNG::setrn(ran_seed);
285 
286  snoop.stop();
287  QDPIO::cout << name << ": total time = "
288  << snoop.getTimeInSeconds()
289  << " secs" << std::endl;
290 
291  QDPIO::cout << name << ": ran successfully" << std::endl;
292 
293  END_CODE();
294  }
295 
296  }
297 
298 }
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
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
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
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.
Class for counted reference semantics.
Inline construction of make_source.
void savern(int iseed[4])
Definition: make_seeds.cc:46
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.
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.
Fourier transform phase factor support.
All make source constructors.
Factory for producing quark prop sources.
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineStaggeredMakeSourceEnv::Params::NamedObject_t named_obj
Generate a unique id.