CHROMA
inline_link_smear.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline Link smearing
3  */
4 
5 #include "handle.h"
8 #include "meas/glue/mesplq.h"
12 
13 
14 namespace Chroma
15 {
16  // Reader for out gauge file
17  void read(XMLReader& xml, const std::string& path, InlineLinkSmearEnv::Params::NamedObject_t& input)
18  {
19  XMLReader inputtop(xml, path);
20  read(inputtop, "gauge_id", input.gauge_id);
21  read(inputtop, "linksmear_id", input.linksmear_id);
22  }
23 
24  // Reader for out gauge file
25  void write(XMLWriter& xml, const std::string& path, const InlineLinkSmearEnv::Params::NamedObject_t& input)
26  {
27  push(xml, path);
28 
29  write(xml, "gauge_id", input.gauge_id);
30  write(xml, "linksmear_id", input.linksmear_id);
31 
32  pop(xml);
33  }
34 
35 
36  namespace InlineLinkSmearEnv
37  {
38  namespace
39  {
40  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
41  const std::string& path)
42  {
43  return new InlineMeas(Params(xml_in, path));
44  }
45 
46  //! Local registration flag
47  bool registered = false;
48  }
49 
50  const std::string name = "LINK_SMEAR";
51 
52  //! Register all the factories
53  bool registerAll()
54  {
55  bool success = true;
56  if (! registered)
57  {
58  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
59  registered = true;
60  }
61  return success;
62  }
63 
64 
65  // Param stuff
67  {
68  frequency = 0;
69  }
70 
71  Params::Params(XMLReader& xml_in, const std::string& path)
72  {
73  try
74  {
75  XMLReader paramtop(xml_in, path);
76 
77  if (paramtop.count("Frequency") == 1)
78  read(paramtop, "Frequency", frequency);
79  else
80  frequency = 1;
81 
82  // Read program parameters
83  link_smearing = readXMLGroup(paramtop, "Param", "LinkSmearingType");
84 
85  // Read in the linksmear outfile
86  read(paramtop, "NamedObject", named_obj);
87  }
88  catch(const std::string& e)
89  {
90  QDPIO::cerr << "Caught Exception reading XML: " << e << std::endl;
91  QDP_abort(1);
92  }
93  }
94 
95 
96  // Write params
97  void
98  Params::writeXML(XMLWriter& xml, const std::string& path)
99  {
100  push(xml, path);
101 
102  xml << link_smearing.xml;
103  write(xml, "NamedObject", named_obj);
104 
105  pop(xml);
106  }
107 
108 
109  void
110  InlineMeas::operator()(unsigned long update_no,
111  XMLWriter& xml_out)
112  {
113  START_CODE();
114 
115  StopWatch snoop;
116  snoop.reset();
117  snoop.start();
118 
119  // Grab the gauge field
120  XMLBufferWriter gauge_xml;
121  multi1d<LatticeColorMatrix> u =
122  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
123  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
124 
125  push(xml_out, "linksmear");
126  write(xml_out, "update_no", update_no);
127 
128  // Write out the input
129  params.writeXML(xml_out, "Input");
130 
131  // Write out the config header
132  write(xml_out, "Config_info", gauge_xml);
133 
134  push(xml_out, "Output_version");
135  write(xml_out, "out_version", 1);
136  pop(xml_out);
137 
138  // Calculate some gauge invariant observables
139  MesPlq(xml_out, "Observables", u);
140 
141  //
142  // Smear the gauge field if needed
143  //
144  multi1d<LatticeColorMatrix> u_smr = u;
145  try
146  {
147  std::istringstream xml_l(params.link_smearing.xml);
148  XMLReader linktop(xml_l);
149 // const std::string link_path = "/Param";
150  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
151 
153  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
154  linktop,
156  (*linkSmearing)(u_smr);
157  }
158  catch(const std::string& e)
159  {
160  QDPIO::cerr << InlineLinkSmearEnv::name << ": error creating link smearing: " << e << std::endl;
161  QDP_abort(1);
162  }
163 
164  // Check if the smeared gauge field is unitary
165  unitarityCheck(u_smr);
166 
167  // Again calculate some gauge invariant observables
168  MesPlq(xml_out, "Link_observables", u_smr);
169 
170  // Now store the configuration to a memory object
171  {
172  XMLBufferWriter file_xml, record_xml;
173  push(file_xml, "gauge");
174  write(file_xml, "id", int(0));
175  pop(file_xml);
176  record_xml << gauge_xml;
177 
178  // Store the gauge field
179  TheNamedObjMap::Instance().create< multi1d<LatticeColorMatrix> >(params.named_obj.linksmear_id);
180  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.linksmear_id) = u_smr;
181  TheNamedObjMap::Instance().get(params.named_obj.linksmear_id).setFileXML(file_xml);
182  TheNamedObjMap::Instance().get(params.named_obj.linksmear_id).setRecordXML(record_xml);
183  }
184 
185  pop(xml_out);
186 
187 
188  snoop.stop();
189  QDPIO::cout << InlineLinkSmearEnv::name << ": total time = "
190  << snoop.getTimeInSeconds()
191  << " secs" << std::endl;
192 
193  QDPIO::cout << InlineLinkSmearEnv::name << ": ran successfully" << std::endl;
194 
195  END_CODE();
196  }
197 
198  }
199 
200 }
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.
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.
void unitarityCheck(const multi1d< LatticeColorMatrixF3 > &u)
Check the unitarity of color matrix in SU(N)
Definition: unit_check.cc:20
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Class for counted reference semantics.
Named object function std::map.
static bool registered
Local registration flag.
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
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineLinkSmearEnv::Params::NamedObject_t named_obj