CHROMA
inline_wilson_flow.cc
Go to the documentation of this file.
1 //
2 /*! \file
3  * \brief Wilson Flow driver
4  *
5  */
6 
7 #include "inline_wilson_flow.h"
9 #include "meas/glue/mesplq.h"
10 #include "util/info/proginfo.h"
13 
14 // The wilson flow code
16 
17 
18 namespace Chroma
19 {
20 
21  namespace InlineWilsonFlowEnv
22  {
23  //! Read input -- gauge fields
24  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
25  {
26  XMLReader inputtop(xml, path);
27 
28  read(inputtop, "gauge_in", input.gauge_in);
29  read(inputtop, "gauge_out", input.gauge_out);
30  }
31 
32  //! write output -- gauge fields
33  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
34  {
35  push(xml, path);
36 
37  write(xml, "gauge_in", input.gauge_in);
38  write(xml, "gauge_out", input.gauge_out);
39 
40  pop(xml);
41  }
42 
43 
44  //! read input
45  void read(XMLReader& xml, const std::string& path, Params::Param_t& input)
46  {
47  XMLReader inputtop(xml, path);
48 
49  read(inputtop, "version", input.version);
50  read(inputtop, "nstep", input.nstep);
51  read(inputtop, "wtime", input.wtime);
52  read(inputtop, "t_dir",input.t_dir);
53 
54  switch (input.version)
55  {
56  case 1:
57  input.smear_dirs.resize(Nd);
58  input.smear_dirs = true;
59  break;
60 
61  case 2:
62  read(inputtop, "smear_dirs", input.smear_dirs);
63  break;
64 
65  default:
66  QDPIO::cerr << "WILSON_FLOW: Input version " << input.version
67  << " unsupported." << std::endl;
68  QDP_abort(1);
69  }
70 
71  }
72 
73  //! write output
74  void write(XMLWriter& xml, const std::string& path, const Params::Param_t& input)
75  {
76  push(xml, path);
77 
78  write(xml, "version", input.version);
79  write(xml, "nstep", input.nstep);
80  write(xml, "wtime", input.wtime);
81  write(xml, "t_dir",input.t_dir);
82  write(xml, "smear_dirs", input.smear_dirs);
83 
84  pop(xml);
85  }
86 
87 
88  //! read input
89  void read(XMLReader& xml, const std::string& path, Params& input)
90  {
92  input = tmp;
93  }
94 
95  //! write output
96  void write(XMLWriter& xml, const std::string& path, const Params& input)
97  {
98  push(xml, path);
99 
100  write(xml, "Param", input.param);
101  write(xml, "NamedObject", input.named_obj);
102 
103  pop(xml);
104  }
105  } // namespace InlineWilsonFlowEnv
106 
107 
108  namespace InlineWilsonFlowEnv
109  {
110  namespace
111  {
112  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
113  const std::string& path)
114  {
115  return new InlineMeas(Params(xml_in, path));
116  }
117 
118  //! Local registration flag
119  bool registered = false;
120  }
121 
122  const std::string name = "WILSON_FLOW";
123 
124  //! Register all the factories
125  bool registerAll()
126  {
127  bool success = true;
128  if (! registered)
129  {
130  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
131  registered = true;
132  }
133  return success;
134  }
135 
136 
137  //--------------------------------------------------------------------------
138  // Param stuff
140 
141  Params::Params(XMLReader& xml_in, const std::string& path)
142  {
143  try
144  {
145  XMLReader paramtop(xml_in, path);
146 
147  if (paramtop.count("Frequency") == 1)
148  read(paramtop, "Frequency", frequency);
149  else
150  frequency = 1;
151 
152  // Parameters for source construction
153  read(paramtop, "Param", param);
154 
155  // Read in the output propagator/source configuration info
156  read(paramtop, "NamedObject", named_obj);
157 
158  // Possible alternate XML file pattern
159  if (paramtop.count("xml_file") != 0)
160  {
161  read(paramtop, "xml_file", xml_file);
162  }
163  }
164  catch(const std::string& e)
165  {
166  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
167  QDP_abort(1);
168  }
169  }
170 
171 
172 
173  // Function call
174  void
175  InlineMeas::operator()(unsigned long update_no,
176  XMLWriter& xml_out)
177  {
178  // If xml file not empty, then use alternate
179  if (params.xml_file != "")
180  {
181  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
182 
183  push(xml_out, "WilsonFlow");
184  write(xml_out, "update_no", update_no);
185  write(xml_out, "xml_file", xml_file);
186  pop(xml_out);
187 
188  XMLFileWriter xml(xml_file);
189  func(update_no, xml);
190  }
191  else
192  {
193  func(update_no, xml_out);
194  }
195  }
196 
197 
198  // Real work done here
199  // Create the diluted source and apply Lanczos quarature
200  void
201  InlineMeas::func(unsigned long update_no,
202  XMLWriter& xml_out)
203  {
204  START_CODE();
205 
206  StopWatch snoop;
207  snoop.reset();
208  snoop.start();
209 
210  push(xml_out, "WilsonFlow");
211  write(xml_out, "update_no", update_no);
212 
213  QDPIO::cout << name << ": Wilson Flowing a configuration" << std::endl;
214 
215  proginfo(xml_out); // Print out basic program info
216 
217  push(xml_out, "Output_version");
218  write(xml_out, "out_version", 1);
219  pop(xml_out);
220 
221  // Write out the input
222  write(xml_out, "Input", params);
223 
224  // Test and grab a reference to the gauge field
225  // -- we really need only two gauge fields --
226  multi1d<LatticeColorMatrix> u ;
227 
228  push(xml_out,"GaugeFieldInfo");
229  XMLBufferWriter gauge_xml;
230  try
231  {
232  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_in);
233  TheNamedObjMap::Instance().get(params.named_obj.gauge_in).getRecordXML(gauge_xml);
234  }
235  catch( std::bad_cast )
236  {
237  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
238  QDP_abort(1);
239  }
240  catch (const std::string& e)
241  {
242  QDPIO::cerr << name << ": std::map call failed: " << e << std::endl;
243  QDP_abort(1);
244  }
245  // Write out the config header
246  write(xml_out, "Config_info", gauge_xml);
247 
248  pop(xml_out);
249 
250 
251  // Calculate some gauge invariant observables just for info.
252  MesPlq(xml_out, "GaugeObservables", u);
253 
254 
255 
256  multi1d<LatticeColorMatrix> wf_u = u ;
258 
260 
261 
262  // Calculate some gauge invariant observables just for info.
263  MesPlq(xml_out, "WilsonFlowGaugeObservables", wf_u);
264 
265 
266  // Now store the configuration to a memory object
267  {
268  XMLBufferWriter file_xml, record_xml;
269  push(file_xml, "gauge");
270  write(file_xml, "id", int(0));
271  write(file_xml, "WilsonFlowParams", params.param);
272  pop(file_xml);
273  record_xml << gauge_xml;
274 
275  // Store the gauge field
276  TheNamedObjMap::Instance().create< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_out);
277  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_out) = wf_u;
278  TheNamedObjMap::Instance().get(params.named_obj.gauge_out).setFileXML(file_xml);
279  TheNamedObjMap::Instance().get(params.named_obj.gauge_out).setRecordXML(record_xml);
280  }
281 
282  pop(xml_out); // WilsonFlow
283 
284  snoop.stop();
285  QDPIO::cout << name << ": total time = "
286  << snoop.getTimeInSeconds()
287  << " secs" << std::endl;
288 
289  QDPIO::cout << name << ": ran successfully" << std::endl;
290 
291  END_CODE();
292  }
293 
294  }
295 
296 
297 } // namespace Chroma
Inline measurement factory.
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.
static T & Instance()
Definition: singleton.h:432
void wilson_flow(XMLWriter &xml, multi1d< LatticeColorMatrix > &u, int nstep, Real wflow_eps, int t_dir, const multi1d< bool > &smear_dirs)
Compute the Wilson flow.
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.
Wilson Flow a configuration.
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.
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
write output – gauge fields
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Read input – gauge fields.
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.
struct Chroma::InlineWilsonFlowEnv::Params::Param_t param
struct Chroma::InlineWilsonFlowEnv::Params::NamedObject_t named_obj