CHROMA
inline_stoch_hadron_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline measurement of stochastic hadron operator (mesons and baryons).
3  *
4  */
5 
6 
7 #include "handle.h"
16 #include "meas/sources/zN_src.h"
24 #include "meas/glue/mesplq.h"
25 #include "util/ft/sftmom.h"
26 #include "util/info/proginfo.h"
28 
30 
31 #include "util/ferm/key_val_db.h"
32 
33 namespace Chroma{
34  namespace InlineStochHadronEnv{
36 
37  namespace{
38  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
39  const std::string& path)
40  {
41  return new InlineMeas(Params(xml_in, path));
42  }
43 
44  //! Local registration flag
45  bool registered = false;
46  }
47 
48  const std::string name = "STOCH_HADRON";
49 
50  //! Register all the factories
51  bool registerAll()
52  {
53  bool success = true;
54  if (! registered)
55  {
56  success &= BaryonOperatorEnv::registerAll();
57  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
58  registered = true;
59  }
60  return success;
61  }
62 
63  // Reader for input parameters
64  void read(XMLReader& xml, const std::string& path, Params::Param_t& param){
65  XMLReader paramtop(xml, path);
66 
67  int version;
68  read(paramtop, "version", version);
69 
70  switch (version)
71  {
72  case 1:
73  /************************************************************/
74  read(paramtop, "mom2_max", param.mom2_max);
75 
76  param.smearing = readXMLGroup(paramtop, "Smearing", "wvf_kind");
77  param.displace = readXMLArrayGroup(paramtop, "Displacement","DisplacementType");
78  param.link_smear = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
79 
80  param.ops = readXMLArrayGroup(paramtop, "HadronOperators", "Type");
81  param.quarks = readXMLArrayGroup(paramtop, "Quarks", "DilutionType");
82 
83  break;
84 
85  default :
86  /**************************************************************/
87 
88  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
89  QDP_abort(1);
90  }
91 
92 
93  }
94 
95 
96  // Writter for input parameters
97  void write(XMLWriter& xml, const std::string& path, const Params::Param_t& param){
98  push(xml, path);
99 
100  int version = 1;
101 
102  write(xml, "version", version);
103  write(xml, "mom2_max", param.mom2_max);
104  xml << param.link_smear.xml;
105 
106  push(xml,"Smearing");
107  xml<<param.smearing.xml;
108  pop(xml);
109 
110  push(xml,"Displacement");
111  for( int t(0);t<param.displace.size();t++){
112  push(xml,"elem");
113  xml<<param.displace[t].xml;
114  pop(xml);
115  }
116  pop(xml);
117 
118  push(xml,"Quarks");
119  for( int t(0);t<param.quarks.size();t++){
120  push(xml,"elem");
121  xml<<param.quarks[t].xml;
122  pop(xml);
123  }
124  pop(xml);
125 
126  push(xml,"HadronOperators");
127  for( int t(0);t<param.ops.size();t++){
128  push(xml,"elem");
129  xml<<param.ops[t].xml;
130  pop(xml);
131  }
132  pop(xml);
133 
134 
135  pop(xml);
136  }
137 
138 
139  //! Gauge field parameters
140  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
141  {
142  XMLReader inputtop(xml, path);
143 
144  read(inputtop, "gauge_id", input.gauge_id);
145  //read(inputtop, "meson_DB_file", input.meson_db);
146  //read(inputtop, "baryon_DB_file", input.baryon_db);
147  }
148 
149  //! Gauge field parameters
150  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input){
151  push(xml, path);
152  write(xml, "gauge_id", input.gauge_id);
153  //write(xml, "meson_DB_file", input.meson_db);
154  //write(xml, "baryon_DB_file", input.baryon_db);
155  pop(xml);
156  }
157 
158 
159  // Param stuff
161  frequency = 0;
162  param.mom2_max = 0 ;
163  }
164 
165  Params::Params(XMLReader& xml_in, const std::string& path)
166  {
167  try
168  {
169  XMLReader paramtop(xml_in, path);
170 
171  if (paramtop.count("Frequency") == 1)
172  read(paramtop, "Frequency", frequency);
173  else
174  frequency = 1;
175 
176  // Read program parameters
177  read(paramtop, "Param", param);
178 
179  // Read in the output propagator/source configuration info
180  read(paramtop, "NamedObject", named_obj);
181 
182  // Possible alternate XML file pattern
183  if (paramtop.count("xml_file") != 0)
184  {
185  read(paramtop, "xml_file", xml_file);
186  }
187  }
188  catch(const std::string& e)
189  {
190  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
191  QDP_abort(1);
192  }
193  }
194 
195 
196  void Params::write(XMLWriter& xml_out, const std::string& path)
197  {
198  push(xml_out, path);
199 
200  // Parameters for source construction
201  InlineStochHadronEnv::write(xml_out, "Param", param);
202 
203  // Write out the output propagator/source configuration info
204  InlineStochHadronEnv::write(xml_out, "NamedObject", named_obj);
205 
206  pop(xml_out);
207  }
208 
209 
210  void ParseMeson(MesonOp& m, const GroupXML_t& grpXML){
211  QDPIO::cout<<"I am a meson!\n" ;
212  std::istringstream xml_l(grpXML.xml);
213  XMLReader xmltop(xml_l);
214  XMLReader xml(xmltop,"/elem");
215  QDPIO::cout << "Meson state is = " <<grpXML.id ;
216  QDPIO::cout << std::endl;
217  QDPIO::cout << " XML =" <<grpXML.xml ;
218  QDPIO::cout << std::endl;
219  read(xml,"Gamma",m.g);
220  read(xml,"File",m.file);
221  }
222 
223  void ParseBaryon(BaryonOp& m, const GroupXML_t& grpXML){
224  QDPIO::cout<<"I am a Baryon!\n" ;
225  std::istringstream xml_l(grpXML.xml);
226  XMLReader xmltop(xml_l);
227  XMLReader xml(xmltop,"/elem");
228  QDPIO::cout << "Baryon state is = " <<grpXML.id ;
229  QDPIO::cout << std::endl;
230  QDPIO::cout << " XML =" <<grpXML.xml ;
231  QDPIO::cout << std::endl;
232  read(xml,"Gamma",m.g);
233  read(xml,"File",m.file);
234  }
235 
236  void meson(DComplex& corr,
237  const int& g,
238  const LatticeComplex& phase,
239  const LatticeFermion& eta,
240  const LatticeFermion& chi,
241  const Subset& s){
242  corr = sum(localInnerProduct(eta,Gamma(g)*chi)*phase,s) ;
243  }
244 
245 
246  void baryon(multi1d<DComplex>& d,
247  const int& g,
248  const LatticeComplex& phase,
249  const LatticeFermion& eta1,
250  const LatticeFermion& eta2,
251  const LatticeFermion& eta3,
252  const Subset& s){
253  //QDPIO::cout<<"I am a baryon!\n" ;
254  if ( Nc != 3 ){ /* Code is specific to Ns=4 and Nc=3. */
255  QDPIO::cerr<<"baryon code only works for Nc=3 and Ns=4\n";
256  QDP_abort(111) ;
257  }
258 #if QDP_NC == 3
259 
260  START_CODE();
261 
262  d.resize(Ns) ;
263 
264  d = zero;
265 
266  // C gamma_5 = Gamma(5)
267  SpinMatrix g_one = 1.0 ;
268  SpinMatrix Cg5 = Gamma(g)*g_one ; //BaryonSpinMats::Cg5();
269 
270  for(int k=0; k < Ns; ++k)
271  {
272  LatticeSpinMatrix di_quark = zero;
273 
274  for(int j=0; j < Ns; ++j)
275  {
276  for(int i=0; i < Ns; ++i)
277  {
278  // Contract over color indices with antisym tensors
279  LatticeComplex b_oper = colorContract(peekSpin(eta1, i),
280  peekSpin(eta2, j),
281  peekSpin(eta3, k));
282 
283  pokeSpin(di_quark, b_oper, j, i);
284  }
285  }
286 
287  d[k] += sum(traceSpin(Cg5 * di_quark)*phase,s);
288  }
289 
290  END_CODE();
291 #endif
292  }
293 
294  class Key{
295  public:
296  multi1d<int> k;
297 
298  Key& set(int i,int j, int l,int s){
299  k.resize(4);
300  k[0]=i ; k[1]=j ; k[2]=l ; k[3]=s;
301  return *this ;
302  }
303 
304  Key& set(int i,int j, int l){
305  k.resize(3);
306  k[0]=i ; k[1]=j ; k[2]=l ;
307  return *this ;
308  }
309 
310  Key& set(int i,int j){
311  k.resize(2);
312  k[0]=i ; k[1]=j ;
313  return *this ;
314  }
315 
316  Key(){
317  k.resize(1);
318  k[0]=0;
319  }
320  Key(int i,int j, int l){
321  set(i,j,l);
322  }
323  Key(int i,int j, int l,int s){
324  set(i,j,l,s);
325  }
326  Key(int i,int j){
327  set(i,j);
328  }
329 
330  Key(const Key& klidi){
331  k.resize(klidi.k.size()) ;
332  for(int i(0);i<k.size();i++) k[i] = klidi.k[i] ;
333  }
334  // int operator[](const int i){return k[i];} const
335 
336  ~Key(){} ;
337  };
338 
339 
340  bool operator<(const Key& a, const Key& b){
341  return (a.k<b.k) ;
342  }
343  //! Key binary writer
344  void write(BinaryWriter& bin, const Key& klidi){
345  write(bin, klidi.k);
346  }
347 
348  //! Key binary reader
349  void read(BinaryReader& bin, Key& klidi){
350  read(bin, klidi.k);
351  }
352 
353 
354  struct HadronKey{
355  // for the moment ignore displacements
356  int type ; // creation: 0 or anihilation: 1
357  int t ; // time slice
358  int t0 ; // source time slice
359  //if size of qn is 3 then it's a baryon if it is 2 then it's a meson
360  multi1d<int> qn ; // the quark noise id
361  multi1d<int> p ;
362  int gamma ; // the meson gamma matrix or the diquark baryon gamma matrix
363  } ;
364 
365  //! HadronKey binary writer
366  void write(BinaryWriter& bin, const HadronKey& h){
367  write(bin, h.type);
368  write(bin, h.t);
369  write(bin, h.t0);
370  write(bin, h.qn);
371  write(bin, h.p);
372  write(bin, h.gamma);
373  }
374 
375  //! HadronKey binary reader
376  void read(BinaryReader& bin, HadronKey& h){
377  read(bin, h.type);
378  read(bin, h.t);
379  read(bin, h.t0);
380  read(bin, h.qn);
381  read(bin, h.p);
382  read(bin, h.gamma);
383  }
384 
385  /*
386  intented use:
387  HadronOperator foo ;
388  foo.data(Key(1,2)) ; // should return the 1,2 dilution of a meson
389  foo.data(Key(1,2,3,s); for baryons where s is the spin index...
390  */
392  std::map<Key,DComplex> data ; // the Key has size 4 for a baryon of 2 for a hadron
393  } ;
394 
395  //! HadronKey binary writer
396  void write(BinaryWriter& bin, HadronOperator& h){
397  std::map<Key,DComplex>::iterator it;
398  int count(0);
399  for(it=h.data.begin();it!=h.data.end();it++){
400  count++;
401  }
402  write(bin,count);
403  for(it=h.data.begin();it!=h.data.end();it++){
404  write(bin, it->first);
405  write(bin, it->second);
406  }
407  }
408 
409  //! HadronKey binary reader
410  void read(BinaryReader& bin, HadronOperator& h){
411  int count ;
412  read(bin,count);
413  Key k ;
414  for(int i(0);i<count;i++){
415  read(bin, k);
416  read(bin, h.data[k]);
417  }
418  }
419 
420  class MesonOpData{
421  public:
422  multi2d<DComplex> data ;
424  MesonOpData(int n ){
425  data.resize(n,n) ;
426  }
427  void resize(int n){
428  data.resize(n,n);
429  }
430  } ;
432  public:
433  multi3d< multi1d<DComplex> > data ;
436  data.resize(n,n,n) ;
437  }
438  void resize(int n){
439  data.resize(n,n,n);
440  }
441  } ;
442 
443 
444  //! MesonOp reader
445  void read(BinaryReader& bin, MesonOpData& param)
446  {
447  int n;
448  read(bin, n);
449  param.data.resize(n,n);
450 
451  for(int i=0; i < n; ++i)
452  {
453  for(int j=0; j < n; ++j)
454  {
455  read(bin, param.data(i,j));
456  }
457  }
458  }
459 
460  //! MesonOp write
461  void write(BinaryWriter& bin, const MesonOpData& param)
462  {
463  int n = param.data.size1(); // all sizes the same
464  write(bin, n);
465  for(int i=0; i < n; ++i)
466  {
467  for(int j=0; j < n; ++j)
468  {
469  write(bin, param.data(i,j));
470  }
471  }
472  }
473 
474 
475 
476  //! BaryonOp reader
477  void read(BinaryReader& bin, BaryonOpData& param)
478  {
479  int n;
480  read(bin, n);
481  param.data.resize(n,n,n);
482 
483  for(int i=0; i < n; ++i)
484  {
485  for(int j=0; j < n; ++j)
486  {
487  for(int k=0; k < n; ++k)
488  {
489  read(bin, param.data(i,j,k));
490  }
491  }
492  }
493  }
494 
495  //! BaryonOp write
496  void write(BinaryWriter& bin, const BaryonOpData& param)
497  {
498  int n = param.data.size1(); // all sizes the same
499  write(bin, n);
500  for(int i=0; i < n; ++i)
501  {
502  for(int j=0; j < n; ++j)
503  {
504  for(int k=0; k < n; ++k)
505  {
506  write(bin, param.data(i,j,k));
507  }
508  }
509  }
510  }
511 
512 
513  //--------------------------------------------------------------
514  // Function call
515  // void
516  //InlineStochHadron::operator()(unsigned long update_no,
517  // XMLWriter& xml_out)
518  void InlineMeas::operator()(unsigned long update_no,
519  XMLWriter& xml_out)
520  {
521  // If xml file not empty, then use alternate
522  if (params.xml_file != ""){
523  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
524 
525  push(xml_out, "stoch_hadron");
526  write(xml_out, "update_no", update_no);
527  write(xml_out, "xml_file", xml_file);
528  pop(xml_out);
529 
530  XMLFileWriter xml(xml_file);
531  func(update_no, xml);
532  }
533  else{
534  func(update_no, xml_out);
535  }
536  }
537 
538 
539  // Function call
540  //void
541  //InlineStochHadron::func(unsigned long update_no,
542  // XMLWriter& xml_out)
543  void InlineMeas::func(unsigned long update_no,
544  XMLWriter& xml_out)
545  {
546  START_CODE();
547 
548  StopWatch snoop;
549  snoop.reset();
550  snoop.start();
551 
552  XMLBufferWriter UserData_xml;
553 
554  push(UserData_xml, "StochHadron");
555  proginfo(UserData_xml);
556 
557  // Test and grab a reference to the gauge field
558  XMLBufferWriter gauge_xml;
559  try
560  {
561  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
562  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
563  }
564  catch( std::bad_cast )
565  {
566  QDPIO::cerr << InlineStochHadronEnv::name << ": caught dynamic cast error"
567  << std::endl;
568  QDP_abort(1);
569  }
570  catch (const std::string& e)
571  {
572  QDPIO::cerr << name << ": std::map call failed: " << e
573  << std::endl;
574  QDP_abort(1);
575  }
576  const multi1d<LatticeColorMatrix>& u =
577  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
578 
579  push(xml_out, "stoch_hadron");
580  write(xml_out, "update_no", update_no);
581 
582 
583  QDPIO::cout << name << ": Stochastic Hadron Operator" << std::endl;
584 
585  proginfo(xml_out); // Print out basic program info
586 
587  // Write out the input
588  params.write(xml_out, "Input");
589  params.write(UserData_xml, "Input");
590 
591  // Write out the config info
592  write(xml_out, "Config_info", gauge_xml);
593  write(UserData_xml,"Config_info",gauge_xml);
594 
595  push(xml_out, "Output_version");
596  write(xml_out, "out_version", 1);
597  pop(xml_out);
598 
599  // First calculate some gauge invariant observables just for info.
600  // This is really cheap.
601  MesPlq(xml_out, "Observables", u);
602 
603  // Save current seed
604  Seed ran_seed;
605  QDP::RNG::savern(ran_seed);
606 
607  //
608  // Read the source and solutions
609  //
610  StopWatch swatch;
611  swatch.reset();
612  swatch.start();
613 
614  int N_quarks = params.param.quarks.size() ;
615  int NumBarOrd(N_quarks*(N_quarks-1)*(N_quarks-2)) ;
616  int NumMesOrd(N_quarks*N_quarks) ; // to allow for flavor singlets
617  if(N_quarks<2){
618  QDPIO::cout << name << ": Need at least 2" << std::endl;
619  QDP_abort(1);
620  }
621  bool BuildMesons(NumMesOrd>0);
622  if(BuildMesons){
623  QDPIO::cout << name << ": Can build mesons" << std::endl;
624  QDPIO::cout<<name<< ": Number of meson orderings: "<<NumMesOrd<<std::endl;
625  }
626  else
627  NumMesOrd=0;
628 
629  bool BuildBaryons(NumBarOrd>0);
630  if(BuildBaryons){
631  QDPIO::cout << name << ": Can build baryons" << std::endl;
632  QDPIO::cout<<name<< ": Number of baryon orderings: "<<NumBarOrd<<std::endl;
633  }
634  else
635  NumBarOrd=0;
636 
637  multi1d< Handle< DilutionScheme<LatticeFermion> > > quarks(N_quarks);
638 
639  try{
640  // Loop over quark dilutions
641  for(int n(0); n < params.param.quarks.size(); ++n){
642  const GroupXML_t& dil_xml = params.param.quarks[n];
643  std::istringstream xml_d(dil_xml.xml);
644  XMLReader diltop(xml_d);
645  QDPIO::cout << "Dilution type = " << dil_xml.id << std::endl;
646  quarks[n] =
647  TheFermDilutionSchemeFactory::Instance().createObject(dil_xml.id,
648  diltop,
649  dil_xml.path);
650  }
651  }
652  catch(const std::string& e){
653  QDPIO::cerr << name << ": Caught Exception constructing dilution scheme: " << e << std::endl;
654  QDP_abort(1);
655  }
656 
657 
658  //-------------------------------------------------------------------
659  //Sanity checks
660 
661  //The participating timeslices must match for each quark
662  //grab info from first quark to prime the work
663 
664  multi1d<int> participating_timeslices(quarks[0]->getNumTimeSlices());
665 
666  for (int t0 = 0 ; t0 < participating_timeslices.size() ; ++t0){
667  participating_timeslices[t0] = quarks[0]->getT0(t0);
668  }
669 
670  for (int n = 1 ; n < N_quarks ; ++n){
671  if(quarks[n]->getNumTimeSlices() != participating_timeslices.size()){
672  QDPIO::cerr << name ;
673  QDPIO::cerr << " : Quarks do not contain the same number";
674  QDPIO::cerr << "of dilution timeslices: Quark " << n << std::endl;
675  QDP_abort(1);
676  }
677 
678  for (int t0 = 0 ; t0 < participating_timeslices.size() ; ++t0){
679  if(quarks[n]->getT0(t0) != participating_timeslices[t0]){
680  QDPIO::cerr << name << " : Quarks do not contain the same";
681  QDPIO::cerr << "participating timeslices: Quark ";
682  QDPIO::cerr << n << " timeslice "<< t0 << std::endl;
683  QDP_abort(1);
684  }
685  }
686  }
687 
688  //Another Sanity check, the three quarks must all be
689  //inverted on the same cfg
690  for (int n = 1 ; n < N_quarks ; ++n){
691  if (quarks[0]->getCfgInfo() != quarks[n]->getCfgInfo()){
692  QDPIO::cerr << name << " : Quarks do not contain the same cfg info";
693  QDPIO::cerr << ", quark "<< n << std::endl;
694  QDP_abort(1);
695  }
696  }
697 
698  //Also ensure that the cfg on which the inversions were performed
699  //is the same as the cfg that we are using
700  {
701  std::string cfgInfo;
702 
703  //Really ugly way of doing this(Robert Heeeelp!!)
704  XMLBufferWriter top;
705  write(top, "Config_info", gauge_xml);
706  XMLReader from(top);
707  XMLReader from2(from, "/Config_info");
708  std::ostringstream os;
709  from2.print(os);
710 
711  cfgInfo = os.str();
712 
713  if (cfgInfo != quarks[0]->getCfgInfo()){
714  QDPIO::cerr << name << " : Quarks do not contain the same";
715  QDPIO::cerr << " cfg info as the gauge field." ;
716  QDPIO::cerr << "gauge: XX"<<cfgInfo<<"XX quarks: XX" ;
717  QDPIO::cerr << quarks[0]->getCfgInfo()<<"XX"<< std::endl;
718  QDP_abort(1);
719  }
720  }
721 
722  //
723  // Initialize the slow Fourier transform phases
724  //
725  int decay_dir = quarks[0]->getDecayDir();
726 
727  SftMom phases(params.param.mom2_max, false, decay_dir);
728 
729  // Sanity check - if this doesn't work we have serious problems
730  if (phases.numSubsets() != QDP::Layout::lattSize()[decay_dir]){
731  QDPIO::cerr << name << ": number of time slices not equal to that";
732  QDPIO::cerr << " in the decay direction: "
733  << QDP::Layout::lattSize()[decay_dir]
734  << std::endl;
735  QDP_abort(1);
736  }
737 
738  write(UserData_xml,"decay_dir",decay_dir);
739  push(UserData_xml,"Quarks");
740  for(int k(0);k<quarks.size();k++){
741  push(UserData_xml,"elem");
742  //write(UserData_xml,"Seed",quarks[0]->getSeed());
743  UserData_xml<<quarks[k]->getSeed();
744  pop(UserData_xml);
745  }
746  pop(UserData_xml);
747  // Another sanity check. The seeds of all the quarks must be different
748  // and thier decay directions must be the same
749  for(int n = 1 ; n < quarks.size(); ++n){
750  if(toBool(quarks[n]->getSeed()==quarks[0]->getSeed())){
751  QDPIO::cerr << name << ": error, quark seeds are the same" << std::endl;
752  QDP_abort(1);
753  }
754 
755  if(toBool(quarks[n]->getDecayDir()!=quarks[0]->getDecayDir())){
756  QDPIO::cerr<<name<< ": error, quark decay dirs do not match" <<std::endl;
757  QDP_abort(1);
758  }
759  }
760 
761  // Smear the gauge field if needed
762  //
763  multi1d<LatticeColorMatrix> u_smr = u;
764 
765  try{
766  std::istringstream xml_l(params.param.link_smear.xml);
767  XMLReader linktop(xml_l);
768  QDPIO::cout << "Link smearing type = " << params.param.link_smear.id ;
769  QDPIO::cout << std::endl;
770 
771 
773 
774  (*linkSmearing)(u_smr);
775  }
776  catch(const std::string& e){
777  QDPIO::cerr<<name<<": Caught Exception link smearing: " << e << std::endl;
778  QDP_abort(1);
779  }
780 
781  MesPlq(xml_out, "Smeared_Observables", u_smr);
782 
783  // Parse the Hadron operators
784  std::map<std::string, MesonOp> LocalMesonOps ;
785  std::map<std::string, BaryonOp> LocalBaryonOps ;
786  for(int o(0);o<params.param.ops.size();o++){
787  QDPIO::cout<<"Found Hadron: "<<params.param.ops[o].id<<std::endl ;
788  std::map<std::string, void (*)(MesonOp&,const GroupXML_t& )>::iterator
789  iter=mesons.find(params.param.ops[o].id);
790  if(iter != mesons.end()){
791  iter->second(LocalMesonOps[params.param.ops[o].id],
792  params.param.ops[o]);
793  }
794  else{// Maybe it's a baryon
795  std::map<std::string, void (*)(BaryonOp&, const GroupXML_t&)>::iterator
796  it=baryons.find(params.param.ops[o].id);
797  if(it != baryons.end())
798  it->second(LocalBaryonOps[params.param.ops[o].id],
799  params.param.ops[o]);
800 
801  else{
802  QDPIO::cout<<" Operator: "<<params.param.ops[o].id ;
803  QDPIO::cout<<" is unkown " <<std::endl ;
804  }
805  }
806  }
807 
808  //We only do diagonal one smearing smearing
809  // I could read off the smearing from the source header so that
810  // it is guaranteed to be the same as the one in the source...
811  // set up the smearing and then do it
813  try{
814  std::istringstream xml_l(params.param.smearing.xml);
815  XMLReader smrtop(xml_l);
816  QDPIO::cout << "Quark smearing type = " <<params.param.smearing.id ;
817  QDPIO::cout << std::endl;
818 
819  Smearing = TheFermSmearingFactory::Instance().createObject(params.param.smearing.id, smrtop, params.param.smearing.path);
820  }
821  catch(const std::string& e){
822  QDPIO::cerr <<name<< ": Caught Exception creating quark smearing object: " << e << std::endl;
823  QDP_abort(1);
824  }
825  catch(...){
826  QDPIO::cerr <<name<< ": Caught generic exception creating smearing object" << std::endl;
827  QDP_abort(1);
828  }
829 
830  multi1d< multi1d< multi1d<LatticeFermion> > > smearedSol(quarks.size());
831  multi1d< multi1d< multi1d<LatticeFermion> > > src(quarks.size());
832  for(int q(0);q< quarks.size() ;q++){
833  smearedSol[q].resize(participating_timeslices.size());
834  src[q].resize(participating_timeslices.size());
835  for (int t0 = 0 ; t0 < participating_timeslices.size() ; ++t0){
836  smearedSol[q][t0].resize(quarks[q]->getDilSize(t0)) ;
837  src[q][t0].resize(quarks[q]->getDilSize(t0)) ;
838  for(int i = 0 ; i < quarks[q]->getDilSize(t0) ; ++i){
839  smearedSol[q][t0][i] = quarks[q]->dilutedSolution(t0,i) ;
840  src[q][t0][i] = quarks[q]->dilutedSource(t0, i) ;
841  (*Smearing)(smearedSol[q][t0][i], u_smr);
842  }
843  }
844  }
845  // Solution vectors are now smeared
846 
847  QDPIO::cout<<" Doing " << phases.numMom()<< " momenta "<<std::endl ;
848  pop(UserData_xml);//done with UserData_xml
849  //First do all the mesons
850  //Make a loop over meson operators
851  //source source creation
852  {
853  std::map<std::string, MesonOp>::iterator it ;
854  for(it=LocalMesonOps.begin();it!=LocalMesonOps.end();it++){
855  MesonOp op = it->second ;
856  // DB storage
857  //BinaryFxStoreDB< SerialDBKey<HadronKey>, SerialDBData<HadronOperator > >
858  BinaryStoreDB< SerialDBKey<HadronKey>, SerialDBData<MesonOpData > > qdp_db;
859  qdp_db.setMaxUserInfoLen(UserData_xml.str().size());
860  qdp_db.open(op.file, O_RDWR | O_CREAT, 0664);
861  qdp_db.insertUserdata(UserData_xml.str());
862 
864  //HadronKey key ;
865  key.key().gamma = op.g ;
866  // loop over the momentum projection
867  for(int mom_num = 0 ; mom_num < phases.numMom() ; ++mom_num){
868  key.key().p = phases.numToMom(mom_num);
869  for (int t0 = 0 ; t0 < participating_timeslices.size() ; ++t0){
870  key.key().t0 = participating_timeslices[t0] ;
871  key.key().t = key.key().t0 ; // creation ops leave on one time slice only
872  key.key().qn.resize(2);
873  //first do the sources
874  key.key().type = MESON_SRC_SRC ;
875  QDPIO::cout<<" Doing MESON_SRC_SRC"<<std::endl ;
876  for(int q(0);q< quarks.size() ;q++){
877  key.key().qn[0]=q;
878  for(int q1(0);q1< quarks.size() ;q1++)
879  if(q!=q1){
880  key.key().qn[1] = q1 ;
882  val.data().resize(quarks[q]->getDilSize(t0));
883  //SerialDBData< HadronOperator > val ;
884  QDPIO::cout<<" quarks: "<<q<<" "<<q1 <<std::endl ;
885  for ( int d(0) ; d < quarks[q]->getDilSize(t0); d++){
886  //LatticeFermion quark_bar = quarks[q]->dilutedSource(t0,d);
887  LatticeFermion quark_bar = src[q][t0][d];
888  quark_bar = Gamma(Ns-1)*quark_bar ;
889  for ( int d1(0) ; d1 < quarks[q1]->getDilSize(t0); d1++){
890  //QDPIO::cout<<" quark: "<<q<<" "<<q1 ;
891  //QDPIO::cout<<" dilution: "<<d<<" "<<d1<<std::endl ;
892  //LatticeFermion quark = quarks[q1]->dilutedSource(t0,d1);
893  LatticeFermion quark = src[q1][t0][d1];
894  DComplex cc ;
895  //meson(cc,op.g,phases[mom_num],quark_bar,quark,
896  // phases.getSet()[key.key().t]);
897  //if(toBool(real(cc)!=0.0) && toBool(imag(cc)!=0.0))
898  // val.data().data[Key(d,d1)] = cc ;
899  meson(val.data().data(d,d1),op.g,phases[mom_num],
900  quark_bar,quark, phases.getSet()[key.key().t]);
901  }// dilutions d
902  }// dilutions d1
903  qdp_db.insert(key, val);
904  } // quark 2
905  } // quark 1
906 
907  key.key().type = MESON_SOL_SOL ;
908  QDPIO::cout<<" Doing MESON_SOL_SOL"<<std::endl ;
909  for(int q(0);q< quarks.size() ;q++){
910  key.key().qn[0]=q;
911  for(int q1(q+1);q1< quarks.size() ;q1++){
912  key.key().qn[1] = q1 ;
913  QDPIO::cout<<" quarks: "<<q<<" "<<q1<<std::endl ;
915  val.data().resize(quarks[q]->getDilSize(t0));
916  //SerialDBData< HadronOperator > val ;
917  for(int t(0);t<phases.numSubsets();t++){
918  key.key().t = t ;
919  for ( int d(0) ; d < quarks[q]->getDilSize(t0); d++){
920  LatticeFermion quark_bar = smearedSol[q][t0][d] ;
921  quark_bar = Gamma(Ns-1)*quark_bar ;
922  for ( int d1(0) ; d1 < quarks[q1]->getDilSize(t0); d1++){
923  //QDPIO::cout<<" quark: "<<q<<" "<<q1 ;
924  //QDPIO::cout<<" dilution: "<<d<<" "<<d1<<std::endl ;
925  LatticeFermion quark = smearedSol[q1][t0][d1] ;
926  meson(val.data().data(d,d1),op.g,phases[mom_num],
927  quark_bar,quark, phases.getSet()[key.key().t]);
928  //DComplex cc ;
929  //meson(cc,op.g,phases[mom_num],quark_bar,quark,
930  // phases.getSet()[key.key().t]);
931  //if(toBool(real(cc)!=0.0)&&toBool(imag(cc)!=0.0))
932  // val.data().data[Key(d,d1)] = cc ;
933  }// dilutions d
934  }// dilutions d1
935  qdp_db.insert(key, val);
936  } // loop over time
937  } // quark 2
938  } // quark 1
939 
940 
941  key.key().type = MESON_SRC_SOL ;
942  QDPIO::cout<<" Doing MESON_SRC_SOL"<<std::endl ;
943  for(int q(0);q< quarks.size() ;q++){
944  key.key().qn[0]=q;
945  for(int q1(0);q1< quarks.size() ;q1++){
946  key.key().qn[1] = q1 ;
947  QDPIO::cout<<" quarks: "<<q<<" "<<q1<<std::endl ;
949  val.data().resize(quarks[q]->getDilSize(t0));
950  //SerialDBData< HadronOperator > val ;
951  for (int tt = 0 ; tt < participating_timeslices.size() ; ++tt){
952  int t = participating_timeslices[tt] ;
953  key.key().t = t ;
954  for ( int d(0) ; d < quarks[q]->getDilSize(tt); d++){
955  //LatticeFermion quark_bar = quarks[q]->dilutedSource(tt,d);
956  LatticeFermion quark_bar = src[q][tt][d] ;
957  for ( int d1(0) ; d1 < quarks[q1]->getDilSize(t0); d1++){
958  //QDPIO::cout<<" quark: "<<q<<" "<<q1 ;
959  //QDPIO::cout<<" dilution: "<<d<<" "<<d1<<std::endl ;
960  LatticeFermion quark = smearedSol[q1][t0][d1] ;
961  //DComplex cc ;
962  meson(val.data().data(d,d1),op.g,phases[mom_num],quark_bar,quark,
963  phases.getSet()[key.key().t]);
964  //if(toBool(real(cc)!=0.0)&&toBool(imag(cc)!=0.0))
965  //val.data().data[Key(d,d1)] = cc ;
966  }// dilutions d1
967  }// dilutions d
968  qdp_db.insert(key, val);
969  } // loop over time
970  } // quark 2
971  } // quark 1
972 
973  }// t0
974  }//mom
975  }// ops
976  }// Done with Mesons
977 
978  //Now the Baryons
979  {
980  std::map<std::string, BaryonOp>::iterator it ;
981  for(it=LocalBaryonOps.begin();it!=LocalBaryonOps.end();it++){
982  BaryonOp op = it->second ;
983  BinaryStoreDB< SerialDBKey<HadronKey>, SerialDBData<BaryonOpData > > qdp_db;
984  qdp_db.setMaxUserInfoLen(UserData_xml.str().size());
985  qdp_db.open(op.file, O_RDWR | O_CREAT, 0664);
986  qdp_db.insertUserdata(UserData_xml.str());
987 
989  //HadronKey key ;
990  key.key().gamma = op.g ;
991  // loop over the momentum projection
992  for(int mom_num = 0 ; mom_num < phases.numMom() ; ++mom_num){
993  key.key().p = phases.numToMom(mom_num);
994  for (int t0 = 0 ; t0 < participating_timeslices.size() ; ++t0){
995  key.key().t0 = participating_timeslices[t0] ;
996  key.key().t = key.key().t0 ; // creation ops leave on one time slice only
997  key.key().qn.resize(3);
998  //first do the sources
999  key.key().type = BARYON_SRC ;
1000  QDPIO::cout<<" Doing BARYON_SRC "<<std::endl ;
1001  for(int q0(0);q0< quarks.size() ;q0++){
1002  key.key().qn[0]=q0;
1003  for(int q1(0);q1< quarks.size() ;q1++)
1004  if(q0!=q1){
1005  key.key().qn[1]=q1;
1006  for(int q2(0);q2< quarks.size() ;q2++)
1007  if((q1!=q2)&&(q0!=q2)){
1008  key.key().qn[2] = q2 ;
1009  QDPIO::cout<<" quarks: "<<q0<<" "<<q1<<" "<<q2<<std::endl ;
1010  //SerialDBData< HadronOperator > val ;
1012  val.data().resize(quarks[q0]->getDilSize(t0));
1013  for ( int d0(0) ; d0 < quarks[q0]->getDilSize(t0); d0++){
1014  //LatticeFermion quark0 = quarks[q0]->dilutedSource(t0,d0);
1015  LatticeFermion quark0 = src[q0][t0][d0];
1016  for ( int d1(0) ; d1 < quarks[q1]->getDilSize(t0); d1++){
1017  //LatticeFermion quark1 = quarks[q1]->dilutedSource(t0,d1);
1018  LatticeFermion quark1 = src[q1][t0][d1];
1019  for ( int d2(0) ; d2 < quarks[q2]->getDilSize(t0); d2++){
1020  //QDPIO::cout<<" quarks: "<<q0<<" "<<q1<<" "<<q2 ;
1021  //QDPIO::cout<<" dilution: "<<d0<<" "<<d1<<" "<<d2<<std::endl ;
1022  //LatticeFermion quark2 = quarks[q2]->dilutedSource(t0,d2);
1023  LatticeFermion quark2 = src[q2][t0][d2];
1024  multi1d<DComplex> cc ;
1025  baryon(cc,op.g,phases[mom_num],quark0,quark1,quark2,
1026  phases.getSet()[key.key().t]);
1027  val.data().data(d0,d1,d2) = cc ;
1028  //for(int s(0);s<Ns;s++)
1029  //if(toBool(real(cc[s])!=0.0) && toBool(imag(cc[s])!=0.0))
1030  // val.data().data[Key(d0,d1,d2,s)] = cc[s] ;
1031  }// dilutions d2
1032  }//dilutions d1
1033  }// dilutions d0
1034  qdp_db.insert(key, val);
1035  } // quark 2
1036  } // quark 1
1037  } // quark 0
1038 
1039 
1040  // Then next block needs work
1041  key.key().type = BARYON_SOL ;
1042  QDPIO::cout<<" Doing BARYON_SOL "<<std::endl ;
1043  for(int q0(0);q0< quarks.size() ;q0++){
1044  key.key().qn[0]=q0;
1045  for(int q1(q0+1);q1< quarks.size() ;q1++){
1046  key.key().qn[1] = q1 ;
1047  for(int q2(q1+1);q2< quarks.size() ;q2++){
1048  key.key().qn[2] = q2 ;
1049  QDPIO::cout<<" quarks: "<<q0<<" "<<q1<<" "<<q2 <<std::endl ;
1050  //SerialDBData< HadronOperator > val ;
1052  val.data().resize(quarks[q0]->getDilSize(t0));
1053  for(int t(0);t<phases.numSubsets();t++){
1054  key.key().t = t ;
1055  for ( int d0(0) ; d0 < quarks[q0]->getDilSize(t0); d0++){
1056  LatticeFermion quark0 = smearedSol[q0][t0][d0] ;
1057  for ( int d1(0) ; d1 < quarks[q1]->getDilSize(t0); d1++){
1058  LatticeFermion quark1 = smearedSol[q1][t0][d1] ;
1059  for ( int d2(0) ; d2 < quarks[q2]->getDilSize(t0); d2++){
1060  //QDPIO::cout<<" quarks: "<<q0<<" "<<q1<<" "<<q2 ;
1061  //QDPIO::cout<<" dilution: "<<d0<<" "<<d1<<" "<<d2<<std::endl ;
1062  LatticeFermion quark2 = smearedSol[q2][t0][d2] ;
1063 
1064  multi1d<DComplex> cc ;
1065  baryon(cc,op.g,phases[mom_num],quark0,quark1,quark2,
1066  phases.getSet()[key.key().t]);
1067  val.data().data(d0,d1,d2) = cc ;
1068  //for(int s(0);s<Ns;s++)
1069  // if(toBool(real(cc[s])!=0.0) && toBool(imag(cc[s])!=0.0))
1070  // val.data().data[Key(d0,d1,d2,s)] = cc[s] ;
1071  }// dilutions d0
1072  }// dilutions d1
1073  }//dilutions d2
1074  qdp_db.insert(key, val);
1075  } // loop over time
1076  } // quark 2
1077  } // quark 1
1078  }// quark 0
1079 
1080  }// t0
1081  }//mom
1082  }// ops
1083 
1084  }// done with baryons
1085 
1086 
1087  swatch.stop();
1088 
1089  QDPIO::cout << "Operators written: time= "
1090  << swatch.getTimeInSeconds()
1091  << " secs" << std::endl;
1092 
1093  // Close the namelist output file XMLDAT
1094  pop(xml_out); // StochHadron
1095 
1096  snoop.stop();
1097  QDPIO::cout << name << ": total time = "
1098  << snoop.getTimeInSeconds()
1099  << " secs" << std::endl;
1100 
1101  QDPIO::cout << name << ": ran successfully" << std::endl;
1102 
1103  END_CODE();
1104  }
1105  } // namespace InlineHadronEnv
1106 }// namespace chroma
1107 
Inline measurement factory.
Baryon spin and projector matrices.
All baryon operators.
Factory for producing baryon operators.
Class for counted reference semantics.
Definition: handle.h:33
void func(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
std::map< std::string, void(*)(MesonOp &, const GroupXML_t &)> mesons
std::map< std::string, void(*)(BaryonOp &, const GroupXML_t &)> baryons
Key & set(int i, int j, int l, int s)
Serializable value harness.
Definition: key_val_db.h:69
D & data()
Setter.
Definition: key_val_db.h:78
Serializable key harness.
Definition: key_val_db.h:21
K & key()
Setter.
Definition: key_val_db.h:30
Fourier transform phase factor support.
Definition: sftmom.h:35
int numSubsets() const
Number of subsets - length in decay direction.
Definition: sftmom.h:63
multi1d< int > numToMom(int mom_num) const
Convert momenta id to actual array of momenta.
Definition: sftmom.h:78
int numMom() const
Number of momenta.
Definition: sftmom.h:60
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
static T & Instance()
Definition: singleton.h:432
Random Z(N) source construction using dilution.
All dilution scheme factories.
Factory for dilution schemes.
Parallel transport a lattice field.
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
std::string makeXMLFileName(std::string xml_file, unsigned long update_no)
Return a xml file name for inline measurements.
multi1d< GroupXML_t > readXMLArrayGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Class for counted reference semantics.
Inline measurement of stochastic hadron operator (mesons and baryons).
Key and values for DB.
unsigned j
Definition: ldumul_w.cc:35
unsigned n
Definition: ldumul_w.cc:36
static int m[4]
Definition: make_seeds.cc:16
void savern(int iseed[4])
Definition: make_seeds.cc:46
Make xml file writer.
int it
Definition: meslate.cc:33
int t
Definition: meslate.cc:37
Double q
Definition: mesq.cc:17
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
SpinMatrix Cg5()
C g_5 = C gamma_5 = Gamma(5)
QDPSubTypeTrait< typename BinaryReturn< C1, C2, FnLocalInnerProduct >::Type_t >::Type_t localInnerProduct(const QDPSubType< T1, C1 > &l, const QDPType< T2, C2 > &r)
const int N_quarks
Number of quarks to be used in this construction.
void ParseMeson(MesonOp &m, const GroupXML_t &grpXML)
void baryon(multi1d< DComplex > &d, const int &g, const LatticeComplex &phase, const LatticeFermion &eta1, const LatticeFermion &eta2, const LatticeFermion &eta3, const Subset &s)
void meson(DComplex &corr, const int &g, const LatticeComplex &phase, const LatticeFermion &eta, const LatticeFermion &chi, const Subset &s)
void read(XMLReader &xml, const std::string &path, Params::Param_t &param)
void ParseBaryon(BaryonOp &m, const GroupXML_t &grpXML)
void write(XMLWriter &xml, const std::string &path, const Params::Param_t &param)
bool operator<(const Key &a, const Key &b)
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
multi1d< LatticeFermion > chi(Ncb)
Complex a
Definition: invbicg.cc:95
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
LatticeFermion eta
Definition: mespbg5p_w.cc:37
DComplex d
Definition: invbicg.cc:99
START_CODE()
Complex b
Definition: invbicg.cc:96
Double zero
Definition: invbicg.cc:106
int k
Definition: invbicg.cc:119
multi1d< LatticeFermion > s(Ncb)
int count
Definition: octave.h:14
::std::string string
Definition: gtest.h:1979
int l
Definition: pade_trln_w.cc:111
Print out basic info about this program.
Double sum
Definition: qtopcor.cc:37
All quark smearing constructors.
Factory for producing quark smearing objects.
Fourier transform phase factor support.
All make sink constructors.
Factory for producing quark prop sinks.
All source smearing.
Factory for producing quark smearing objects.
Hold group xml and type id.
struct Chroma::InlineStochHadronEnv::Params::Param_t param
struct Chroma::InlineStochHadronEnv::Params::NamedObject_t named_obj
void write(XMLWriter &xml_out, const std::string &path)
Volume source of Z(N) noise.