CHROMA
inline_apply_gaugestate.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline gauge state application
3  */
4 
7 #include "meas/glue/mesplq.h"
9 
11 
14 
15 namespace Chroma
16 {
17 
18  //! GaugeState input
19  void read(XMLReader& xml, const std::string& path, InlineGaugeStateEnv::Params::Param_t& param)
20  {
21  XMLReader paramtop(xml, path);
22 
23  int version;
24  read(paramtop, "version", version);
25 
26  switch (version)
27  {
28  case 1:
29  param.cgs = readXMLGroup(paramtop, "GaugeState", "Name");
30  break;
31 
32  default:
33  QDPIO::cerr << "InlineGaugeStateEnv::Params::Param_t: " << version
34  << " unsupported." << std::endl;
35  QDP_abort(1);
36  }
37  }
38 
39  //! GaugeState output
40  void write(XMLWriter& xml, const std::string& path, const InlineGaugeStateEnv::Params::Param_t& param)
41  {
42  push(xml, path);
43 
44  int version = 2;
45  write(xml, "version", version);
46  xml << param.cgs.xml;
47 
48  pop(xml);
49  }
50 
51 
52  //! GaugeState input
53  void read(XMLReader& xml, const std::string& path, InlineGaugeStateEnv::Params::NamedObject_t& input)
54  {
55  XMLReader inputtop(xml, path);
56 
57  read(inputtop, "gauge_id", input.gauge_id);
58  read(inputtop, "output_id", input.output_id);
59  }
60 
61  //! GaugeState output
62  void write(XMLWriter& xml, const std::string& path, const InlineGaugeStateEnv::Params::NamedObject_t& input)
63  {
64  push(xml, path);
65 
66  write(xml, "gauge_id", input.gauge_id);
67  write(xml, "output_id", input.output_id);
68 
69  pop(xml);
70  }
71 
72 
73  namespace InlineGaugeStateEnv
74  {
75  namespace
76  {
77  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
78  const std::string& path)
79  {
80  return new InlineMeas(Params(xml_in, path));
81  }
82 
83  //! Local registration flag
84  bool registered = false;
85  }
86 
87  const std::string name = "APPLY_GAUGE_STATE";
88 
89  //! Register all the factories
90  bool registerAll()
91  {
92  bool success = true;
93  if (! registered)
94  {
96  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
97  registered = true;
98  }
99  return success;
100  }
101 
102  // Params
104  {
105  frequency = 0;
106  }
107 
108  Params::Params(XMLReader& xml_in, const std::string& path)
109  {
110  try
111  {
112  XMLReader paramtop(xml_in, path);
113 
114  if (paramtop.count("Frequency") == 1)
115  read(paramtop, "Frequency", frequency);
116  else
117  frequency = 1;
118 
119  // Params
120  read(paramtop, "Param", param);
121 
122  // Ids
123  read(paramtop, "NamedObject", named_obj);
124  }
125  catch(const std::string& e)
126  {
127  QDPIO::cerr << "Caught Exception reading XML: " << e << std::endl;
128  QDP_abort(1);
129  }
130  }
131 
132 
133  void
134  Params::writeXML(XMLWriter& xml_out, const std::string& path)
135  {
136  push(xml_out, path);
137 
138  write(xml_out, "Param", param);
139  write(xml_out, "NamedObject", named_obj);
140 
141  pop(xml_out);
142  }
143 
144 
145 
146  void
147  InlineMeas::operator()(unsigned long update_no,
148  XMLWriter& xml_out)
149  {
150  START_CODE();
151 
152  StopWatch snoop;
153  snoop.reset();
154  snoop.start();
155 
156  push(xml_out, "apply_gauge_state");
157  write(xml_out, "update_no", update_no);
158 
159  // Write out the input
160  params.writeXML(xml_out, "Input");
161 
162  push(xml_out, "Output_version");
163  write(xml_out, "out_version", 1);
164  pop(xml_out);
165 
166  // Grab the gauge field
167  multi1d<LatticeColorMatrix> u;
168  XMLBufferWriter gauge_xml;
169 
170  try
171  {
172  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
173  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
174  }
175  catch( std::bad_cast )
176  {
177  QDPIO::cerr << InlineGaugeStateEnv::name << ": caught dynamic cast error"
178  << std::endl;
179  QDP_abort(1);
180  }
181  catch (const std::string& e)
182  {
183  QDPIO::cerr << InlineGaugeStateEnv::name << ": std::map call failed: " << e
184  << std::endl;
185  QDP_abort(1);
186  }
187 
188  // Write out the config header
189  write(xml_out, "Config_info", gauge_xml);
190 
191  // Calculate some gauge invariant observables
192  MesPlq(xml_out, "Observables", u);
193 
194  // Apply the gaugestate
195  try
196  {
197  // Set the construct state and modify the fields
198  {
199  std::istringstream xml_s(params.param.cgs.xml);
200  XMLReader gaugetop(xml_s);
201 
202  Handle<CreateGaugeState< multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> > >
204  gaugetop,
205  params.param.cgs.path));
206 
207  Handle<GaugeState< multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> > >
208  state((*cgs)(u));
209 
210  // Pull the u fields back out from the state since they might have been
211  // munged with gaugeBC's
212  u = state->getLinks();
213  }
214  }
215  catch( std::bad_cast )
216  {
217  QDPIO::cerr << InlineGaugeStateEnv::name << ": caught dynamic cast error"
218  << std::endl;
219  QDP_abort(1);
220  }
221  catch (const std::string& e)
222  {
223  QDPIO::cerr << InlineGaugeStateEnv::name << ": std::map call failed: " << e
224  << std::endl;
225  QDP_abort(1);
226  }
227 
228  // Again calculate some gauge invariant_observables
229  MesPlq(xml_out, "Link_observables", u);
230 
231  // Now store the configuration to a memory object
232  {
233  XMLBufferWriter file_xml, record_xml;
234  push(file_xml, "gauge");
235  write(file_xml, "id", int(0));
236  pop(file_xml);
237  record_xml << gauge_xml;
238 
239  // Store the gauge field
240  TheNamedObjMap::Instance().create< multi1d<LatticeColorMatrix> >(params.named_obj.output_id);
241  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.output_id) = u;
242  TheNamedObjMap::Instance().get(params.named_obj.output_id).setFileXML(file_xml);
243  TheNamedObjMap::Instance().get(params.named_obj.output_id).setRecordXML(record_xml);
244  }
245 
246  pop(xml_out); // apply_gauge_state
247 
248  snoop.stop();
249  QDPIO::cout << InlineGaugeStateEnv::name << ": total time = "
250  << snoop.getTimeInSeconds()
251  << " secs" << std::endl;
252 
253  QDPIO::cout << InlineGaugeStateEnv::name << ": ran successfully" << std::endl;
254 
255  END_CODE();
256  }
257 
258  }
259 
260 }
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
void operator()(unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
static T & Instance()
Definition: singleton.h:432
Functions to set and get default gauge field.
All gauge create-state method.
Gauge create state factory.
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.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Inline gauge state application.
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()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
::std::string string
Definition: gtest.h:1979
struct Chroma::InlineGaugeStateEnv::Params::Param_t param
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineGaugeStateEnv::Params::NamedObject_t named_obj