CHROMA
inline_qpropdiff_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline measurement of qpropadd
3  *
4  * Addition of props
5  */
6 
9 
11 #include "util/ferm/transf.h"
12 
13 namespace Chroma
14 {
15  //! Propagator parameters
16  void read(XMLReader& xml, const std::string& path, InlineQpropDiffEnv::Params::NamedObject_t& input)
17  {
18  XMLReader inputtop(xml, path);
19 
20 
21  read(inputtop, "propA", input.propA);
22  read(inputtop, "propB", input.propB);
23 
24  }
25 
26  //! Propagator parameters
27  void write(XMLWriter& xml, const std::string& path, const InlineQpropDiffEnv::Params::NamedObject_t& input)
28  {
29  push(xml, path);
30 
31 
32  write(xml, "propA", input.propA);
33  write(xml, "propB", input.propB);
34 
35  pop(xml);
36  }
37 
38 
39  namespace InlineQpropDiffEnv
40  {
41  namespace
42  {
43  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
44  const std::string& path)
45  {
46  return new InlineMeas(Params(xml_in, path));
47  }
48 
49  //! Local registration flag
50  bool registered = false;
51  }
52 
53  const std::string name = "QPROP_DIFF";
54 
55  //! Register all the factories
56  bool registerAll()
57  {
58  bool success = true;
59  if (! registered)
60  {
61  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
62  registered = true;
63  }
64  return success;
65  }
66 
67 
68  // Param stuff
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  if ( paramtop.count("Label") == 1)
83  read(paramtop, "Label", label);
84  else
85  label = "";
86 
87  // Parameters for source construction
88  // Read in the output propagator/source configuration info
89  read(paramtop, "NamedObject", named_obj);
90  }
91  catch(const std::string& e)
92  {
93  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
94  QDP_abort(1);
95  }
96  }
97 
98 
99  void
100  Params::writeXML(XMLWriter& xml_out, const std::string& path)
101  {
102  push(xml_out, path);
103 
104  // Write out the output propagator/source configuration info
105  write(xml_out, "NamedObject", named_obj);
106 
107  pop(xml_out);
108  }
109 
110  //--------------------------------------------------------------
111 
112 
113  // Function call
114  void
115  InlineMeas::operator()(unsigned long update_no,
116  XMLWriter& xml_out)
117  {
118  START_CODE();
119 
120  push(xml_out, "qprop_diff");
121  write(xml_out, "update_no", update_no);
122 
123  QDPIO::cout << "QPROP_DIFF: Check differnce of two props component by component" << std::endl;
124 
125  // Write out the input
126  params.writeXML(xml_out, "Input");
127 
128  //
129  // Read in the source along with relevant information.
130  //
131  XMLReader propA_file_xml, propA_record_xml;
132 
133  LatticePropagator propA ;
134  LatticePropagator propB ;
135 
136  QDPIO::cout << "Snarf the props from a named buffer" << std::endl;
137  try
138  {
139  // Try the cast to see if this is a valid source
140  propA = TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.propA);
141 
142  TheNamedObjMap::Instance().get(params.named_obj.propA).getFileXML(propA_file_xml);
143  TheNamedObjMap::Instance().get(params.named_obj.propA).getRecordXML(propA_record_xml);
144 
145  propB = TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.propB);
146  }
147  catch (std::bad_cast)
148  {
149  QDPIO::cerr << name << ": caught dynamic cast error"
150  << std::endl;
151  QDP_abort(1);
152  }
153  catch (const std::string& e)
154  {
155  QDPIO::cerr << name << ": error extracting source_header: " << e << std::endl;
156  QDP_abort(1);
157  }
158 
159  for(int spin=0; spin < Ns; ++spin){
160  for(int color=0; color < Nc; ++color ) {
161  LatticeFermion fermA=zero;
162  LatticeFermion fermB=zero;
163  PropToFerm(propA, fermA, color, spin);
164  PropToFerm(propB, fermB, color, spin);
165  LatticeFermion diff = fermA - fermB;
166  Double diff_L2=sqrt(norm2(diff));
167  // Double diff_Linf=toDouble(globalMax(diff));
168  Double A_L2 = sqrt(norm2(fermA));
169  // Double A_Linf=toDouble(globalMax(fermA));
170  Double B_L2 = sqrt(norm2(fermB));
171  // Double B_Linf=toDouble(globalMax(fermB));
172  QDPIO::cout << "QPROP_DIFF: "<< params.label <<": spin="<<spin<<" col="<<color
173  << " ||diff||="<<diff_L2
174  << " ||diff||/||A||=" << diff_L2/A_L2
175  << " ||diff||/||B||="<<diff_L2/B_L2 << std::endl;
176 
177 #if 0
178  QDPIO::cout << "QPROP_DIFF: spin="<<spin<<" col="<<color
179  << " ||diff||_inf="<<diff_Linf
180  << " ||diff||_inf/||A||_inf=" << diff_Linf/A_Linf
181  << " ||diff||_inf/||B||_inf="<<diff_Linf/B_Linf << std::endl;
182 
183 #endif
184  QDPIO::cout << std::endl;
185  }
186  }
187 
188 
189  pop(xml_out); // qpropdiff
190 
191  QDPIO::cout << "QPROP_DIFF: ran successfully" << std::endl;
192 
193  END_CODE();
194  }
195 
196  }
197 
198 }
Inline measurement factory.
Inline measurement of to add two props.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
static T & Instance()
Definition: singleton.h:432
void PropToFerm(const LatticePropagatorF &b, LatticeFermionF &a, int color_index, int spin_index)
Extract a LatticeFermion from a LatticePropagator.
Definition: transf.cc:226
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.
Inline measurement of qpropadd.
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
push(xml_out,"Condensates")
pop(xml_out)
START_CODE()
Double zero
Definition: invbicg.cc:106
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineQpropDiffEnv::Params::NamedObject_t named_obj