CHROMA
inline_psibarpsi_w.cc
Go to the documentation of this file.
1 
2 
3 #include "fermact.h"
8 #include "util/info/proginfo.h"
10 
11 #include "meas/pbp/pbp.h"
12 
13 
14 namespace Chroma
15 {
16 
17  void read(XMLReader& xml, const std::string& path, InlinePsiBarPsiEnv::Params::Param_t& param)
18  {
19  XMLReader paramtop(xml, path);
20 
21  int version;
22  read(paramtop, "version", version);
23 
24  switch (version)
25  {
26  case 1:
27  param.fermact = readXMLGroup(paramtop, "FermionAction", "FermAct");
28  param.invParam = readXMLGroup(paramtop, "InvertParam", "invType");
29 
30  read(paramtop, "Mass", param.mass);
31  if (paramtop.count("ichiral") == 1) {
32  read(paramtop, "ichiral", param.ichiral);
33  } else {
34  param.ichiral = 0;
35  }
36 
37  break;
38 
39  default:
40  QDPIO::cerr << "InlinePsiBarPsiParams::Param_t: " << version
41  << " unsupported." << std::endl;
42  QDP_abort(1);
43  }
44  }
45 
46  void write(XMLWriter& xml, const std::string& path, InlinePsiBarPsiEnv::Params::Param_t& param)
47  {
48  push(xml, path);
49 
50  int version = 1;
51  write(xml, "version", version);
52  write(xml, "mass", param.mass);
53  write(xml, "ichiral", param.ichiral);
54 
55  xml << param.fermact.xml;
56  xml << param.invParam.xml;
57 
58  pop(xml);
59  }
60 
61  void read(XMLReader& xml, const std::string& path, InlinePsiBarPsiEnv::Params::NamedObject_t& input)
62  {
63  XMLReader inputtop(xml, path);
64 
65  read(inputtop, "gauge_id", input.gauge_id);
66  }
67 
68  void write(XMLWriter& xml, const std::string& path, const InlinePsiBarPsiEnv::Params::NamedObject_t& input)
69  {
70  push(xml, path);
71 
72  write(xml, "gauge_id", input.gauge_id);
73 
74  pop(xml);
75  }
76 
77 
78  namespace InlinePsiBarPsiEnv
79  {
80  namespace
81  {
82  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
83  const std::string& path)
84  {
85  return new InlineMeas(Params(xml_in, path));
86  }
87 
88  //! Local registration flag
89  bool registered = false;
90  }
91 
92  const std::string name = "PSI_BAR_PSI";
93 
94  //! Register all the factories
95  bool registerAll()
96  {
97  bool success = true;
98  if (! registered)
99  {
101  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
102  registered = true;
103  }
104  return success;
105  }
106 
108  {
109  frequency = 0;
110  }
111 
112  Params::Params(XMLReader& xml_in, const std::string& path)
113  {
114  try
115  {
116  XMLReader paramtop(xml_in, path);
117 
118  if (paramtop.count("Frequency") == 1)
119  read(paramtop, "Frequency", frequency);
120  else
121  frequency = 1;
122 
123  read(paramtop, "Param", param);
124 
125  read(paramtop, "NamedObject", named_obj);
126  }
127  catch(const std::string& e)
128  {
129  QDPIO::cerr << "Caught Exception reading XML: " << e << std::endl;
130  QDP_abort(1);
131  }
132  }
133 
134  void InlineMeas::operator()(unsigned long update_no,
135  XMLWriter& xml_out)
136  {
137 
138  push(xml_out, "PsiBarPsi");
139  write(xml_out, "update_no", update_no);
140  pop(xml_out);
141 
142  func(update_no, xml_out);
143  }
144 
145  void InlineMeas::func(unsigned long update_no,
146  XMLWriter& xml_out)
147  {
148  START_CODE();
149 
150  Double pbp;
151  int maxCG = 0;
152  int n_congrd = 0;
153  XMLBufferWriter gauge_xml;
154 
155  multi1d<LatticeColorMatrix> u;
156  try {
157  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
158  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
159  }
160  catch ( std::bad_cast ) {
161  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
162  QDP_abort(1);
163  }
164  catch (const std::string& e) {
165  QDPIO::cerr << name << ": std::map call failed: " << e << std::endl;
166  QDP_abort(1);
167  }
168 
169  proginfo(xml_out);
170 
171  write(xml_out, "Config_info", gauge_xml);
172 
173  // Initialize fermion action
174 
175  std::istringstream xml_s(params.param.fermact.xml);
176  XMLReader fermacttop(xml_s);
177  QDPIO::cout << "FermAct = " << params.param.fermact.id << std::endl;
178 
179 
180  try
181  {
182  StopWatch swatch;
183  swatch.reset();
184  QDPIO::cout << "Try the various factories" << std::endl;
185 
186  typedef LatticeFermion T;
187  typedef multi1d<LatticeColorMatrix> P;
188  typedef multi1d<LatticeColorMatrix> Q;
189 
192  fermacttop,
194 
195  Handle< FermState<T,P,Q> > state(S_f->createState(u));
196 
197  QDPIO::cout << "Suitable factory found: do the measurements" << std::endl;
199 
200  swatch.start();
201 
202  MesPbp(qprop, state, params.param.mass, params.param.ichiral, xml_out, "PsiBarPsi", params.param.fermact.id);
203 
204  swatch.stop();
205  QDPIO::cout << "PsiBarPsi computed: time= "
206  << swatch.getTimeInSeconds()
207  << " secs" << std::endl;
208  }
209  catch ( std::bad_cast )
210  {
211  QDPIO::cerr << name << ": caught dynamic cast error"
212  << std::endl;
213  QDP_abort(1);
214  }
215  catch (const std::string& e)
216  {
217  QDPIO::cout << name << ": caught exception with fermion action: " << e << std::endl;
218  }
219 
220  pop(xml_out);
221 
222  QDPIO::cout << name << ": ran successfully" << std::endl;
223 
224  END_CODE();
225  } // end func()
226 
227  } // end namespace InlinePsiBarPsiEnv
228 
229 } // end namespace Chroma
230 
231 
232 
233 
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
void func(unsigned long update_no, XMLWriter &xml_out)
void operator()(unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
static T & Instance()
Definition: singleton.h:432
Class structure for fermion actions.
Fermion action factories.
All Wilson-type fermion actions.
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 proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Named object function std::map.
static bool registered
Local registration flag.
multi1d< LatticeColorMatrix > P
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
LinOpSysSolverMGProtoClover::Q Q
int n_congrd
Definition: mespbg5p_w.cc:24
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
pop(xml_out)
void MesPbp(Handle< SystemSolver< LatticeFermion > > qprop, Handle< FermState< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > > state, const multi1d< Real > &Mass, const int ichiral, XMLWriter &xml_out, const std::string &xml_group, const std::string &FermAct)
Calculates noise estimator for psi_bar_psi.
Definition: mespbp_w.cc:22
START_CODE()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
const WilsonTypeFermAct< multi1d< LatticeFermion > > & S_f
Definition: pbg5p_w.cc:27
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Psibar-psi measurements.
Print out basic info about this program.
struct Chroma::InlinePsiBarPsiEnv::Params::NamedObject_t named_obj
struct Chroma::InlinePsiBarPsiEnv::Params::Param_t param