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