CHROMA
inline_diquark_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of the diquark within a QQQ
3  *
4  * Diquarks for QQQ calcs
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 InlineDiquarkEnv
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 = "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, InlineDiquarkEnv::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, "Dirac_basis", input.Dirac_basis);
67  }
68 
69  //! Param output
70  void write(XMLWriter& xml, const std::string& path, const InlineDiquarkEnv::Params::Param_t& input)
71  {
72  push(xml, path);
73 
74  int version = 1;
75  write(xml, "version", version);
76  write(xml, "Dirac_basis", input.Dirac_basis);
77 
78  pop(xml);
79  }
80 
81  //! Propagator input
82  void read(XMLReader& xml, const std::string& path, InlineDiquarkEnv::Params::NamedObject_t& input)
83  {
84  XMLReader inputtop(xml, path);
85 
86  read(inputtop, "gauge_id", input.gauge_id);
87  read(inputtop, "prop_ids", input.prop_ids);
88  read(inputtop, "diquark_id", input.diquark_id);
89  }
90 
91  //! Propagator output
92  void write(XMLWriter& xml, const std::string& path, const InlineDiquarkEnv::Params::NamedObject_t& input)
93  {
94  push(xml, path);
95 
96  write(xml, "gauge_id", input.gauge_id);
97  write(xml, "prop_ids", input.prop_ids);
98  write(xml, "diquark_id", input.diquark_id);
99 
100  pop(xml);
101  }
102 
103 
104  // Param stuff
106 
107  Params::Params(XMLReader& xml_in, const std::string& path)
108  {
109  try
110  {
111  XMLReader paramtop(xml_in, path);
112 
113  if (paramtop.count("Frequency") == 1)
114  read(paramtop, "Frequency", frequency);
115  else
116  frequency = 1;
117 
118  // Parameters for source construction
119  read(paramtop, "Param", param);
120 
121  // Read in the output propagator/source configuration info
122  read(paramtop, "NamedObject", named_obj);
123  }
124  catch(const std::string& e)
125  {
126  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
127  QDP_abort(1);
128  }
129  }
130 
131 
132  void
133  Params::writeXML(XMLWriter& xml_out, const std::string& path)
134  {
135  push(xml_out, path);
136 
137  // Parameters for source construction
138  write(xml_out, "Param", param);
139 
140  // Write out the output propagator/source configuration info
141  write(xml_out, "NamedObject", named_obj);
142 
143  pop(xml_out);
144  }
145 
146 
147  // Function call
148  void
149  InlineMeas::operator()(unsigned long update_no,
150  XMLWriter& xml_out)
151  {
152  START_CODE();
153 
154  StopWatch snoop;
155  snoop.reset();
156  snoop.start();
157 
158  // Test and grab a reference to the gauge field
159  XMLBufferWriter gauge_xml;
160  try
161  {
162  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
163  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
164  }
165  catch( std::bad_cast )
166  {
167  QDPIO::cerr << InlineDiquarkEnv::name << ": caught dynamic cast error"
168  << std::endl;
169  QDP_abort(1);
170  }
171  catch (const std::string& e)
172  {
173  QDPIO::cerr << InlineDiquarkEnv::name << ": std::map call failed: " << e
174  << std::endl;
175  QDP_abort(1);
176  }
177  const multi1d<LatticeColorMatrix>& u =
178  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
179 
180  push(xml_out,"diquark");
181  write(xml_out, "update_no", update_no);
182 
183  QDPIO::cout << InlineDiquarkEnv::name << ": Generalized propagator generation" << std::endl;
184  StopWatch swatch;
185 
186  // Write out the input
187  params.writeXML(xml_out, "Input");
188 
189  proginfo(xml_out); // Print out basic program info
190 
191  // Write out the input
192  params.writeXML(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 ids
205  const int Nprops = 2;
206  if (params.named_obj.prop_ids.size() != Nprops)
207  {
208  QDPIO::cerr << "Error on input params - expecting 3 buffers" << std::endl;
209  QDP_abort(1);
210  }
211 
212  write(xml_out, "propIds", params.named_obj.prop_ids);
213  write(xml_out, "diquarkId", params.named_obj.diquark_id);
214 
215  /*
216  * Read the quark propagators and extract headers
217  */
218  multi1d<LatticePropagator> quark_propagator(Nprops);
219  QQDiquark_t diquark_header;
220  diquark_header.Dirac_basis = false;
221  diquark_header.forward_props.resize(Nprops);
222 
223  for(int i=0; i < Nprops; ++i)
224  {
225  QDPIO::cout << InlineDiquarkEnv::name << ": parse id = " << params.named_obj.prop_ids[i] << std::endl;
226  try
227  {
228  // Snarf the data into a copy
229  quark_propagator[i] =
230  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_ids[i]);
231 
232  // Snarf the prop info. This is will throw if the prop_ids is not there.
233  XMLReader prop_file_xml, prop_record_xml;
234  TheNamedObjMap::Instance().get(params.named_obj.prop_ids[i]).getFileXML(prop_file_xml);
235  TheNamedObjMap::Instance().get(params.named_obj.prop_ids[i]).getRecordXML(prop_record_xml);
236 
237  // Try to invert this record XML into a ChromaProp struct
238  // Also pull out the id of this source
239  {
240  read(prop_record_xml, "/SinkSmear", diquark_header.forward_props[i]);
241  }
242  }
243  catch( std::bad_cast )
244  {
245  QDPIO::cerr << InlineDiquarkEnv::name << ": caught dynamic cast error"
246  << std::endl;
247  QDP_abort(1);
248  }
249  catch (const std::string& e)
250  {
251  QDPIO::cerr << InlineDiquarkEnv::name << ": error message: " << e
252  << std::endl;
253  QDP_abort(1);
254  }
255  QDPIO::cout << InlineDiquarkEnv::name << ": object successfully parsed" << std::endl;
256  }
257 
258 
259  // Save prop input
260  write(xml_out, "Propagator_input", diquark_header);
261 
262  // Derived from input prop
263  int j_decay = diquark_header.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  push(xml_out, "SinkSmearedProp_correlator");
270  for(int i=0; i < Nprops; ++i)
271  {
272  multi1d<Double> prop_corr = sumMulti(localNorm2(TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_ids[i])),
273  phases.getSet());
274 
275  push(xml_out, "elem");
276  write(xml_out, "correlator_num", i);
277  write(xml_out, "sink_smeared_prop_corr", prop_corr);
278  pop(xml_out);
279  }
280  pop(xml_out);
281 
282  /*
283  * Generalized propagator calculation
284  */
285  // Switch to Dirac-basis if desired.
287  {
288  diquark_header.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 diquark
302  QQDiquarkContract_t diquark;
303 
304  QQDiquark(diquark,
305  quark_propagator[0],
306  quark_propagator[1]);
307 
308  // Now save the diquark object
309  try
310  {
311  QDPIO::cout << "Attempt to update diquark object" << std::endl;
312 
313  XMLBufferWriter file_xml;
314  push(file_xml, "diquark");
315  write(file_xml, "id", uniqueId()); // NOTE: new ID form
316  pop(file_xml);
317 
318  XMLBufferWriter record_xml;
319  write(record_xml, "Diquark", diquark_header);
320 
321  // Store the source
324  diquark;
325  TheNamedObjMap::Instance().get(params.named_obj.diquark_id).setFileXML(file_xml);
326  TheNamedObjMap::Instance().get(params.named_obj.diquark_id).setRecordXML(record_xml);
327 
328  QDPIO::cout << "Diquark successfully update" << std::endl;
329  }
330  catch (std::bad_cast)
331  {
332  QDPIO::cerr << InlineDiquarkEnv::name << ": dynamic cast error"
333  << std::endl;
334  QDP_abort(1);
335  }
336  catch (const std::string& e)
337  {
338  QDPIO::cerr << InlineDiquarkEnv::name << ": error message: " << e << std::endl;
339  QDP_abort(1);
340  }
341 
342  pop(xml_out); // diquark
343 
344 
345  snoop.stop();
346  QDPIO::cout << InlineDiquarkEnv::name << ": total time = "
347  << snoop.getTimeInSeconds()
348  << " secs" << std::endl;
349 
350  QDPIO::cout << InlineDiquarkEnv::name << ": ran successfully" << std::endl;
351 
352  END_CODE();
353  }
354 
355  }
356 
357 }
Inline measurement factory.
Inline computation of diquarks for QQQ.
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
Construct a diquark object.
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 QQDiquark(QQDiquarkContract_t &diquark, const LatticePropagator &quark_propagator_1, const LatticePropagator &quark_propagator_2)
Construct a QQ diquark object.
Definition: diquark_w.cc:58
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 the diquark within a QQQ.
int j_decay
Definition: meslate.cc:22
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
void read(XMLReader &xml, const std::string &path, InlineDiquarkEnv::Params::Param_t &input)
Param input.
void write(XMLWriter &xml, const std::string &path, const InlineDiquarkEnv::Params::Param_t &input)
Param output.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
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::InlineDiquarkEnv::Params::Param_t param
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineDiquarkEnv::Params::NamedObject_t named_obj
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
multi1d< LatticeColorMatrix > U
Generate a unique id.