CHROMA
inline_qqbar_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of qqbar
3  *
4  * QQbar calcs
5  */
6 
9 #include "meas/glue/mesplq.h"
10 #include "meas/hadron/mescomp_w.h"
11 #include "util/ft/sftmom.h"
12 #include "util/info/proginfo.h"
13 #include "util/info/unique_id.h"
14 #include "util/ferm/diractodr.h"
16 
17 namespace Chroma
18 {
19  namespace InlineQQbarEnv
20  {
21  namespace
22  {
23  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
24  const std::string& path)
25  {
26  return new InlineQQbar(InlineQQbarParams(xml_in, path));
27  }
28 
29  //! Local registration flag
30  bool registered = false;
31  }
32 
33  const std::string name = "QQBAR";
34 
35  //! Register all the factories
36  bool registerAll()
37  {
38  bool success = true;
39  if (! registered)
40  {
41  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
42  registered = true;
43  }
44  return success;
45  }
46  }
47 
48 
49  //! Param input
50  void read(XMLReader& xml, const std::string& path, InlineQQbarParams::Param_t& input)
51  {
52  XMLReader paramtop(xml, path);
53 
54  int version;
55  read(paramtop, "version", version);
56 
57  switch (version)
58  {
59  case 4:
60  break;
61 
62  default:
63  /**************************************************************************/
64  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
65  QDP_abort(1);
66  }
67 
68  read(paramtop, "Dirac_basis", input.Dirac_basis);
69  }
70 
71  //! Param output
72  void write(XMLWriter& xml, const std::string& path, const InlineQQbarParams::Param_t& input)
73  {
74  push(xml, path);
75 
76  int version = 4;
77  write(xml, "version", version);
78  write(xml, "Dirac_basis", input.Dirac_basis);
79 
80  pop(xml);
81  }
82 
83  //! Propagator input
84  void read(XMLReader& xml, const std::string& path, InlineQQbarParams::NamedObject_t& input)
85  {
86  XMLReader inputtop(xml, path);
87 
88  read(inputtop, "gauge_id", input.gauge_id);
89  read(inputtop, "prop_ids", input.prop_ids);
90  read(inputtop, "qqbar_file", input.qqbar_file);
91  }
92 
93  //! Propagator output
94  void write(XMLWriter& xml, const std::string& path, const InlineQQbarParams::NamedObject_t& input)
95  {
96  push(xml, path);
97 
98  write(xml, "gauge_id", input.gauge_id);
99  write(xml, "prop_ids", input.prop_ids);
100  write(xml, "qqbar_file", input.qqbar_file);
101 
102  pop(xml);
103  }
104 
105 
106  // Param stuff
108 
109  InlineQQbarParams::InlineQQbarParams(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  // Parameters for source construction
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 << __func__ << ": Caught Exception reading XML: " << e << std::endl;
129  QDP_abort(1);
130  }
131  }
132 
133 
134  void
135  InlineQQbarParams::write(XMLWriter& xml_out, const std::string& path)
136  {
137  push(xml_out, path);
138 
139  // Parameters for source construction
140  Chroma::write(xml_out, "Param", param);
141 
142  // Ids
143  Chroma::write(xml_out, "NamedObject", named_obj);
144 
145  pop(xml_out);
146  }
147 
148 
149  void
150  InlineQQbar::operator()(unsigned long update_no,
151  XMLWriter& xml_out)
152  {
153  START_CODE();
154 
155  StopWatch snoop;
156  snoop.reset();
157  snoop.start();
158 
159  // Test and grab a reference to the gauge field
160  XMLBufferWriter gauge_xml;
161  try
162  {
163  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
164  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
165  }
166  catch( std::bad_cast )
167  {
168  QDPIO::cerr << InlineQQbarEnv::name << ": caught dynamic cast error"
169  << std::endl;
170  QDP_abort(1);
171  }
172  catch (const std::string& e)
173  {
174  QDPIO::cerr << InlineQQbarEnv::name << ": std::map call failed: " << e
175  << std::endl;
176  QDP_abort(1);
177  }
178  const multi1d<LatticeColorMatrix>& u =
179  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
180 
181  push(xml_out,"qqbar");
182  write(xml_out, "update_no", update_no);
183 
184  QDPIO::cout << InlineQQbarEnv::name << ": generalized propagator generation" << std::endl;
185 
186  // Write out the input
187  params.write(xml_out, "Input");
188 
189  proginfo(xml_out); // Print out basic program info
190 
191  // Write out the input
192  params.write(xml_out, "Input");
193 
194  // Write out the config info
195  write(xml_out, "Config_info", gauge_xml);
196 
197  push(xml_out, "Output_version");
198  write(xml_out, "out_version", 1);
199  pop(xml_out);
200 
201  // Calculate some gauge invariant observables just for info.
202  MesPlq(xml_out, "Observables", u);
203 
204  // Check to make sure there are 2 files
205  const int Nprops = 2;
206  if (params.named_obj.prop_ids.size() != Nprops)
207  {
208  QDPIO::cerr << InlineQQbarEnv::name << ": Error on input params - expecting 2 filenames" << std::endl;
209  QDP_abort(1);
210  }
211 
212  write(xml_out, "propIds", params.named_obj.prop_ids);
213  write(xml_out, "mescompFile", params.named_obj.qqbar_file);
214 
215  /*
216  * Read the quark propagators and extract headers
217  */
218  multi1d<LatticePropagator> quark_propagator(Nprops);
219  QQbarMescomp_t qqbar;
220  qqbar.Dirac_basis = false;
221  qqbar.forward_props.resize(Nprops);
222  for(int i=0; i < Nprops; ++i)
223  {
224  try
225  {
226  // Snarf the data into a copy
227  quark_propagator[i] =
228  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_ids[i]);
229 
230  // Snarf the prop info. This is will throw if the prop_id is not there
231  XMLReader prop_file_xml, prop_record_xml;
232  TheNamedObjMap::Instance().get(params.named_obj.prop_ids[i]).getFileXML(prop_file_xml);
233  TheNamedObjMap::Instance().get(params.named_obj.prop_ids[i]).getRecordXML(prop_record_xml);
234 
235  // Try to invert this record XML into a ChromaProp struct
236  // Also pull out the id of this source
237  {
238  read(prop_record_xml, "/SinkSmear/PropSink", qqbar.forward_props[i].sink_header);
239  read(prop_record_xml, "/SinkSmear/ForwardProp", qqbar.forward_props[i].prop_header);
240  read(prop_record_xml, "/SinkSmear/PropSource", qqbar.forward_props[i].source_header);
241  }
242  }
243  catch( std::bad_cast )
244  {
245  QDPIO::cerr << InlineQQbarEnv::name << ": caught dynamic cast error"
246  << std::endl;
247  QDP_abort(1);
248  }
249  catch (const std::string& e)
250  {
251  QDPIO::cerr << InlineQQbarEnv::name << ": std::map call failed: " << e
252  << std::endl;
253  QDP_abort(1);
254  }
255  }
256 
257 
258  // Save prop input
259  write(xml_out, "Propagator_input", qqbar);
260 
261  // Derived from input prop
262  int t0 = qqbar.forward_props[0].source_header.t_source;
263  int j_decay = qqbar.forward_props[0].source_header.j_decay;
264 
265  // Initialize the slow Fourier transform phases
266  SftMom phases(0, true, j_decay);
267 
268  // Sanity check - write out the propagator (pion) correlator in the j_decay direction
269  for(int i=0; i < Nprops; ++i)
270  {
271  multi1d<Double> prop_corr = sumMulti(localNorm2(quark_propagator[i]),
272  phases.getSet());
273 
274  push(xml_out, "SinkSmearedProp_correlator");
275  write(xml_out, "correlator_num", i);
276  write(xml_out, "sink_smeared_prop_corr", prop_corr);
277  pop(xml_out);
278  }
279 
280  /*
281  * Generalized propagator calculation
282  */
283  multiNd<Complex> mesprop;
284 
285  // Switch to Dirac-basis if desired.
287  {
288  qqbar.Dirac_basis = true;
289 
290  // The spin basis matrix
291  SpinMatrix U = DiracToDRMat();
292 
293  LatticePropagator q_tmp;
294  for(int i=0; i < Nprops; ++i)
295  {
296  q_tmp = adj(U) * quark_propagator[i] * U; // DeGrand-Rossi ---> Dirac
297  quark_propagator[i] = q_tmp;
298  }
299  }
300 
301  // Compute generation propagator
302  mescomp(mesprop,
303  quark_propagator[0],
304  quark_propagator[1],
305  phases, t0);
306 
307  // Convert the data into a mult1d
308  multi1d<Complex> mesprop_1d;
309  convertMescomp(mesprop_1d, mesprop, j_decay);
310 
311  // Save the qqbar output
312  // ONLY SciDAC output format is supported!
313  {
314  XMLBufferWriter file_xml;
315  push(file_xml, "qqbar");
316  write(file_xml, "id", uniqueId()); // NOTE: new ID form
317  pop(file_xml);
318 
319  XMLBufferWriter record_xml;
320  push(record_xml, "QQbar");
321  write(record_xml, ".", qqbar); // do not write the outer group
322  write(record_xml, "Config_info", gauge_xml);
323  pop(record_xml); // QQbar
324 
325  // Write the scalar data
326  QDPFileWriter to(file_xml, params.named_obj.qqbar_file,
327  QDPIO_SINGLEFILE, QDPIO_SERIAL, QDPIO_OPEN);
328  write(to,record_xml,mesprop_1d);
329  close(to);
330  }
331 
332  pop(xml_out); // qqbar
333 
334 
335  snoop.stop();
336  QDPIO::cout << InlineQQbarEnv::name << ": total time = "
337  << snoop.getTimeInSeconds()
338  << " secs" << std::endl;
339 
340  QDPIO::cout << InlineQQbarEnv::name << ": ran successfully" << std::endl;
341 
342  END_CODE();
343  }
344 
345 }
Inline measurement factory.
Inline measurement of quark-antiquark 2-pt correlators.
InlineQQbarParams params
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
Fourier transform phase factor support.
Definition: sftmom.h:35
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
static T & Instance()
Definition: singleton.h:432
Basis rotation matrix from Dirac to Degrand-Rossi (and reverse)
SpinMatrixD DiracToDRMat()
The Dirac to Degrand-Rossi spin transformation matrix (and reverse)
Definition: diractodr.cc:22
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 mescomp(multiNd< Complex > &mesprop, const LatticePropagator &quark_propagator_1, const LatticePropagator &quark_propagator_2, const SftMom &phases, int t0)
Construct all components of a meson propagator.
Definition: mescomp_w.cc:50
std::string uniqueId()
Return a unique id.
Definition: unique_id.cc:18
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
Inline construction of qqbar.
Construct all components of a meson propagator.
int j_decay
Definition: meslate.cc:22
Named object function std::map.
static bool registered
Local registration flag.
const std::string name
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
void convertMescomp(multi1d< Complex > &mesprop_1d, const multiNd< Complex > &mesprop, const int j_decay)
Convert generalized correlator object.
Definition: mescomp_w.cc:13
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
START_CODE()
::std::string string
Definition: gtest.h:1979
Print out basic info about this program.
Fourier transform phase factor support.
Parameter structure.
void write(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineQQbarParams::Param_t param
struct Chroma::InlineQQbarParams::NamedObject_t named_obj
Mega structure holding QQbar props.
Definition: qprop_io.h:191
multi1d< ForwardProp_t > forward_props
Definition: qprop_io.h:194
multi1d< LatticeColorMatrix > U
Generate a unique id.