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