CHROMA
inline_apply_fermstate_s.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  namespace InlineStaggeredFermStateEnv
19  {
20  //! FermState input
21  void read(XMLReader& xml, const std::string& path, InlineStaggeredFermStateEnv::Params::Param_t& param)
22  {
23  XMLReader paramtop(xml, path);
24 
25  int version;
26  read(paramtop, "version", version);
27 
28  switch (version)
29  {
30  case 1:
31  param.cfs = readXMLGroup(paramtop, "FermState", "Name");
32  break;
33 
34  default:
35  QDPIO::cerr << "InlineMeasParams::Param_t: " << version
36  << " unsupported." << std::endl;
37  QDP_abort(1);
38  }
39  }
40 
41  //! FermState output
42  void write(XMLWriter& xml, const std::string& path, const InlineStaggeredFermStateEnv::Params::Param_t& param)
43  {
44  push(xml, path);
45 
46  int version = 2;
47  write(xml, "version", version);
48  xml << param.cfs.xml;
49 
50  pop(xml);
51  }
52 
53 
54  //! FermState input
55  void read(XMLReader& xml, const std::string& path, InlineStaggeredFermStateEnv::Params::NamedObject_t& input)
56  {
57  XMLReader inputtop(xml, path);
58 
59  read(inputtop, "gauge_id", input.gauge_id);
60  read(inputtop, "output_id", input.output_id);
61  }
62 
63  //! FermState output
64  void write(XMLWriter& xml, const std::string& path, const InlineStaggeredFermStateEnv::Params::NamedObject_t& input)
65  {
66  push(xml, path);
67 
68  write(xml, "gauge_id", input.gauge_id);
69  write(xml, "output_id", input.output_id);
70 
71  pop(xml);
72  }
73 
74 
75  namespace
76  {
77  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
78  const std::string& path)
79  {
80  Params p(xml_in, path);
81  return new InlineMeas(p);
82  }
83 
84  //! Local registration flag
85  bool registered = false;
86  }
87 
88  const std::string name = "APPLY_FERM_STATE";
89 
90  //! Register all the factories
91  bool registerAll()
92  {
93  bool success = true;
94  if (! registered)
95  {
96  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
97  registered = true;
98  }
99  return success;
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  // Operator
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 << name << ": caught dynamic cast error"
179  << std::endl;
180  QDP_abort(1);
181  }
182  catch (const std::string& e)
183  {
184  QDPIO::cerr << 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 
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 << name << ": caught dynamic cast error"
219  << std::endl;
220  QDP_abort(1);
221  }
222  catch (const std::string& e)
223  {
224  QDPIO::cerr << 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 << name << ": total time = "
251  << snoop.getTimeInSeconds()
252  << " secs" << std::endl;
253 
254  QDPIO::cout << name << ": ran successfully" << std::endl;
255 
256  END_CODE();
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 ferm create-state method.
Fermion create state factory.
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.
void read(XMLReader &xml, const std::string &path, InlineStaggeredFermStateEnv::Params::Param_t &param)
FermState input.
bool registerAll()
Register all the factories.
void write(XMLWriter &xml, const std::string &path, const InlineStaggeredFermStateEnv::Params::Param_t &param)
FermState output.
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
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineStaggeredFermStateEnv::Params::Param_t param
struct Chroma::InlineStaggeredFermStateEnv::Params::NamedObject_t named_obj