CHROMA
inline_qqq_diquark_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of QQQ's using a diquark
3  *
4  * QQQ calcs using a diquark
5  */
6 
10 #include "meas/glue/mesplq.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 InlineQQQDiquarkEnv
20  {
21  namespace
22  {
23  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
24  const std::string& path)
25  {
26  return new InlineMeas(Params(xml_in, path));
27  }
28 
29  //! Local registration flag
30  bool registered = false;
31  }
32 
33  const std::string name = "QQQ_DIQUARK";
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  //! Param input
49  void read(XMLReader& xml, const std::string& path, InlineQQQDiquarkEnv::Params::Param_t& input)
50  {
51  XMLReader paramtop(xml, path);
52 
53  int version;
54  read(paramtop, "version", version);
55 
56  switch (version)
57  {
58  case 1:
59  break;
60 
61  default:
62  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
63  QDP_abort(1);
64  }
65 
66  read(paramtop, "sparseP", input.sparseP);
67  read(paramtop, "Dirac_basis", input.Dirac_basis);
68  if (input.sparseP)
69  {
70  read(paramtop, "SpinIndices", input.spin_indices);
71  }
72  }
73 
74  //! Param output
75  void write(XMLWriter& xml, const std::string& path, const InlineQQQDiquarkEnv::Params::Param_t& input)
76  {
77  push(xml, path);
78 
79  int version = 1;
80  write(xml, "version", version);
81  write(xml, "sparseP", input.sparseP);
82  write(xml, "Dirac_basis", input.Dirac_basis);
83  if (input.sparseP)
84  {
85  write(xml, "SpinIndices", input.spin_indices);
86  }
87 
88  pop(xml);
89  }
90 
91  //! Propagator input
92  void read(XMLReader& xml, const std::string& path, InlineQQQDiquarkEnv::Params::NamedObject_t& input)
93  {
94  XMLReader inputtop(xml, path);
95 
96  read(inputtop, "gauge_id", input.gauge_id);
97  read(inputtop, "diquark_id", input.diquark_id);
98  read(inputtop, "prop_id", input.prop_id);
99  read(inputtop, "qqq_file", input.qqq_file);
100  }
101 
102  //! Propagator output
103  void write(XMLWriter& xml, const std::string& path, const InlineQQQDiquarkEnv::Params::NamedObject_t& input)
104  {
105  push(xml, path);
106 
107  write(xml, "gauge_id", input.gauge_id);
108  write(xml, "diquark_id", input.diquark_id);
109  write(xml, "prop_id", input.prop_id);
110  write(xml, "qqq_file", input.qqq_file);
111 
112  pop(xml);
113  }
114 
115 
116  // Param stuff
118 
119  Params::Params(XMLReader& xml_in, const std::string& path)
120  {
121  try
122  {
123  XMLReader paramtop(xml_in, path);
124 
125  if (paramtop.count("Frequency") == 1)
126  read(paramtop, "Frequency", frequency);
127  else
128  frequency = 1;
129 
130  // Parameters for source construction
131  read(paramtop, "Param", param);
132 
133  // Read in the output propagator/source configuration info
134  read(paramtop, "NamedObject", named_obj);
135  }
136  catch(const std::string& e)
137  {
138  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
139  QDP_abort(1);
140  }
141  }
142 
143 
144  void
145  Params::writeXML(XMLWriter& xml_out, const std::string& path)
146  {
147  push(xml_out, path);
148 
149  // Parameters for source construction
150  write(xml_out, "Param", param);
151 
152  // Write out the output propagator/source configuration info
153  write(xml_out, "NamedObject", named_obj);
154 
155  pop(xml_out);
156  }
157 
158 
159  // Function call
160  void
161  InlineMeas::operator()(unsigned long update_no,
162  XMLWriter& xml_out)
163  {
164  START_CODE();
165 
166  StopWatch snoop;
167  snoop.reset();
168  snoop.start();
169 
170  // Test and grab a reference to the gauge field
171  XMLBufferWriter gauge_xml;
172  try
173  {
174  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
175  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
176  }
177  catch( std::bad_cast )
178  {
179  QDPIO::cerr << InlineQQQDiquarkEnv::name << ": caught dynamic cast error"
180  << std::endl;
181  QDP_abort(1);
182  }
183  catch (const std::string& e)
184  {
185  QDPIO::cerr << InlineQQQDiquarkEnv::name << ": std::map call failed: " << e
186  << std::endl;
187  QDP_abort(1);
188  }
189  const multi1d<LatticeColorMatrix>& u =
190  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
191 
192  push(xml_out,"qqq_diquark");
193  write(xml_out, "update_no", update_no);
194 
195  QDPIO::cout << InlineQQQDiquarkEnv::name << ": Generalized propagator generation" << std::endl;
196  StopWatch swatch;
197 
198  // Write out the input
199  params.writeXML(xml_out, "Input");
200 
201  proginfo(xml_out); // Print out basic program info
202 
203  // Write out the input
204  params.writeXML(xml_out, "Input");
205 
206  // Write out the config info
207  write(xml_out, "Config_info", gauge_xml);
208 
209  push(xml_out, "Output_version");
210  write(xml_out, "out_version", 5);
211  pop(xml_out);
212 
213  // Calculate some gauge invariant observables just for info.
214  MesPlq(xml_out, "Observables", u);
215 
216  write(xml_out, "diquarkId", params.named_obj.diquark_id);
217  write(xml_out, "propId", params.named_obj.prop_id);
218  write(xml_out, "barcompFile", params.named_obj.qqq_file);
219 
220  /*
221  * Read the quark propagators and extract headers
222  */
223  const int Nprops = 3;
224 
225  LatticePropagator quark_propagator;
226 
227  QQDiquark_t diquark_header;
228  QQQBarcomp_t qqq_header;
229  qqq_header.Dirac_basis = false;
230  qqq_header.forward_props.resize(Nprops);
231 
232  try
233  {
234  // Read diquark
235  QDPIO::cout << InlineQQQDiquarkEnv::name << ": parse id = " << params.named_obj.diquark_id << std::endl;
237  {
238  XMLReader diquark_file_xml, diquark_record_xml;
239  TheNamedObjMap::Instance().get(params.named_obj.diquark_id).getFileXML(diquark_file_xml);
240  TheNamedObjMap::Instance().get(params.named_obj.diquark_id).getRecordXML(diquark_record_xml);
241 
242  read(diquark_record_xml, "/Diquark", diquark_header);
243  }
244  QDPIO::cout << InlineQQQDiquarkEnv::name << ": object successfully parsed" << std::endl;
245 
246  // The QQQ object is composed of the diquark headers
247  qqq_header.forward_props[0] = diquark_header.forward_props[0];
248  qqq_header.forward_props[1] = diquark_header.forward_props[1];
249 
250  // Read 3rd prop
251  QDPIO::cout << InlineQQQDiquarkEnv::name << ": parse id = " << params.named_obj.prop_id << std::endl;
252  quark_propagator = TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_id);
253  {
254  XMLReader prop_file_xml, prop_record_xml;
255  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getFileXML(prop_file_xml);
256  TheNamedObjMap::Instance().get(params.named_obj.prop_id).getRecordXML(prop_record_xml);
257 
258  read(prop_record_xml, "/SinkSmear", qqq_header.forward_props[Nprops-1]);
259  }
260  QDPIO::cout << InlineQQQDiquarkEnv::name << ": object successfully parsed" << std::endl;
261  }
262  catch( std::bad_cast )
263  {
264  QDPIO::cerr << InlineQQQDiquarkEnv::name << ": caught dynamic cast error"
265  << std::endl;
266  QDP_abort(1);
267  }
268  catch (const std::string& e)
269  {
270  QDPIO::cerr << InlineQQQDiquarkEnv::name << ": error message: " << e
271  << std::endl;
272  QDP_abort(1);
273  }
274  const QQDiquarkContract_t& diquark =
276 
277  QDPIO::cout << InlineQQQDiquarkEnv::name << ": finished with gauge, diquark and prop" << std::endl;
278 
279  // Save prop input
280  write(xml_out, "Propagator_input", qqq_header);
281 
282  // Derived from input prop
283  multi1d<int> boundary = getFermActBoundary(qqq_header.forward_props[0].prop_header.fermact);
284  int t0 = qqq_header.forward_props[0].source_header.t_source;
285  int j_decay = qqq_header.forward_props[0].source_header.j_decay;
286  int bc_spec = boundary[j_decay];
287 
288  // Initialize the slow Fourier transform phases
289  SftMom phases(0, true, j_decay);
290 
291  // Sanity check - write out the propagator (pion) correlator in the j_decay direction
292  {
293  multi1d<Double> prop_corr = sumMulti(localNorm2(TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_id)),
294  phases.getSet());
295 
296  push(xml_out, "SinkSmearedProp_correlator");
297  write(xml_out, "sink_smeared_prop_corr", prop_corr);
298  pop(xml_out);
299  }
300 
301  /*
302  * Generalized propagator calculation
303  */
304  multi1d<ComplexF> barprop_1d;
305 
306  // Switch to Dirac-basis if desired.
308  {
309  qqq_header.Dirac_basis = true;
310 
311  // The spin basis matrix
312  SpinMatrix U = DiracToDRMat();
313 
314  LatticePropagator q_tmp = adj(U) * quark_propagator * U; // DeGrand-Rossi ---> Dirac
315  quark_propagator = q_tmp;
316  }
317 
318  // Decide the computational mode depending on whether the data is sparse
319  // or not
320  if (params.param.sparseP)
321  {
322  qqq_header.sparseP = true;
323  qqq_header.spin_indices = params.param.spin_indices;
324  QQQSparse_t barprop;
325 
326  // Compute generation propagator
327  barcompDiquarkSparse(barprop,
328  diquark,
329  quark_propagator,
331  phases, t0, bc_spec);
332 
333  // Convert the data into a mult1d
334  barprop_1d = barprop.serialize();
335  }
336  else
337  {
338  qqq_header.sparseP = false;
339  QQQDense_t barprop;
340 
341  // Compute generation propagator
342  barcompDiquarkDense(barprop,
343  diquark,
344  quark_propagator,
345  phases, t0, bc_spec);
346 
347  // Convert the data into a mult1d
348  barprop_1d = barprop.serialize();
349  }
350 
351  // Save the qqq output
352  // ONLY SciDAC output format is supported!
353  {
354  XMLBufferWriter file_xml;
355  push(file_xml, "qqq");
356  write(file_xml, "id", uniqueId()); // NOTE: new ID form
357  pop(file_xml);
358 
359  XMLBufferWriter record_xml;
360  push(record_xml, "QQQ");
361  write(record_xml, ".", qqq_header); // do not write the outer group
362  write(record_xml, "Config_info", gauge_xml);
363  pop(record_xml); // QQQ
364 
365  // Write the scalar data
366  QDPFileWriter to(file_xml, params.named_obj.qqq_file,
367  QDPIO_SINGLEFILE, QDPIO_SERIAL, QDPIO_OPEN);
368  write(to,record_xml,barprop_1d);
369  close(to);
370  }
371 
372  pop(xml_out); // qqq
373 
374 
375  snoop.stop();
376  QDPIO::cout << InlineQQQDiquarkEnv::name << ": total time = "
377  << snoop.getTimeInSeconds()
378  << " secs" << std::endl;
379 
380  QDPIO::cout << InlineQQQDiquarkEnv::name << ": ran successfully" << std::endl;
381 
382  END_CODE();
383  }
384 
385  }
386 
387 }
Inline measurement factory.
Construct all components of a baryon propagator using a diquark.
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 barcompDiquarkDense(QQQDense_t &barprop, const QQDiquarkContract_t &diquark, const LatticePropagator &quark_propagator_3, const SftMom &phases, int t0, int bc_spec)
Construct all components of a baryon propagator.
void barcompDiquarkSparse(QQQSparse_t &barprop, const QQDiquarkContract_t &diquark, const LatticePropagator &quark_propagator_3, const multi1d< QQQSpinIndices_t > spin_indices, const SftMom &phases, int t0, int bc_spec)
Construct all components of a baryon propagator.
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
int bc_spec
Inline construction of QQQ's using a diquark.
int j_decay
Definition: meslate.cc:22
Named object function std::map.
static bool registered
Local registration flag.
void read(XMLReader &xml, const std::string &path, InlineQQQDiquarkEnv::Params::Param_t &input)
Param input.
bool registerAll()
Register all the factories.
void write(XMLWriter &xml, const std::string &path, const InlineQQQDiquarkEnv::Params::Param_t &input)
Param output.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
multi1d< int > getFermActBoundary(const GroupXML_t &fermact)
Given a fermion action in std::string form, return the boundary.
Definition: qprop_io.cc:61
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.
struct Chroma::InlineQQQDiquarkEnv::Params::Param_t param
struct Chroma::InlineQQQDiquarkEnv::Params::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)
Dense QQDiquark object.
Definition: diquark_w.h:18
Mega structure holding QQ diquark object.
Definition: qprop_io.h:171
multi1d< ForwardProp_t > forward_props
Definition: qprop_io.h:174
Mega structure holding QQQ props.
Definition: qprop_io.h:180
multi1d< ForwardProp_t > forward_props
Definition: qprop_io.h:185
multi1d< QQQSpinIndices_t > spin_indices
Definition: qprop_io.h:182
Dense QQQ object.
Definition: barcomp_w.h:36
multi1d< ComplexF > serialize()
Serialize generalized object.
Definition: barcomp_w.cc:126
Sparse QQQ object.
Definition: barcomp_w.h:18
multi1d< ComplexF > serialize()
Serialize generalized object.
Definition: barcomp_w.cc:13
multi1d< LatticeColorMatrix > U
Generate a unique id.