inline_meson_matelem_colorvec_w.cc

Go to the documentation of this file.
00001 // $Id: inline_meson_matelem_colorvec_w.cc,v 1.26 2009/09/14 20:50:14 edwards Exp $
00002 /*! \file
00003  * \brief Inline measurement of meson operators via colorvector matrix elements
00004  */
00005 
00006 
00007 
00008 #include "handle.h"
00009 #include "meas/inline/hadron/inline_meson_matelem_colorvec_w.h"
00010 #include "meas/inline/abs_inline_measurement_factory.h"
00011 #include "meas/smear/link_smearing_aggregate.h"
00012 #include "meas/smear/link_smearing_factory.h"
00013 #include "meas/smear/displace.h"
00014 #include "meas/glue/mesplq.h"
00015 #include "util/ferm/subset_vectors.h"
00016 #include "util/ferm/key_val_db.h"
00017 #include "util/ft/sftmom.h"
00018 #include "util/info/proginfo.h"
00019 #include "meas/inline/make_xml_file.h"
00020 
00021 #include "meas/inline/io/named_objmap.h"
00022 
00023 #define COLORVEC_MATELEM_TYPE_ZERO       0
00024 #define COLORVEC_MATELEM_TYPE_ONE        1
00025 #define COLORVEC_MATELEM_TYPE_MONE       -1
00026 #define COLORVEC_MATELEM_TYPE_GENERIC    10
00027 
00028 namespace Chroma 
00029 { 
00030   /*!
00031    * \ingroup hadron
00032    *
00033    * @{
00034    */
00035   namespace InlineMesonMatElemColorVecEnv 
00036   { 
00037     // Reader for input parameters
00038     void read(XMLReader& xml, const string& path, InlineMesonMatElemColorVecEnv::Params::Param_t& param)
00039     {
00040       XMLReader paramtop(xml, path);
00041     
00042       int version;
00043       read(paramtop, "version", version);
00044 
00045       switch (version) 
00046       {
00047       case 1:
00048         /**************************************************************************/
00049         break;
00050 
00051       default :
00052         /**************************************************************************/
00053 
00054         QDPIO::cerr << "Input parameter version " << version << " unsupported." << endl;
00055         QDP_abort(1);
00056       }
00057 
00058       read(paramtop, "mom2_max", param.mom2_max);
00059       read(paramtop, "displacement_length", param.displacement_length);
00060       read(paramtop, "displacement_list", param.displacement_list);
00061       read(paramtop, "num_vecs", param.num_vecs);
00062       read(paramtop, "decay_dir", param.decay_dir);
00063       read(paramtop, "orthog_basis", param.orthog_basis);
00064 
00065       param.link_smearing  = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
00066     }
00067 
00068 
00069     // Writer for input parameters
00070     void write(XMLWriter& xml, const string& path, const InlineMesonMatElemColorVecEnv::Params::Param_t& param)
00071     {
00072       push(xml, path);
00073 
00074       int version = 1;
00075 
00076       write(xml, "version", version);
00077       write(xml, "mom2_max", param.mom2_max);
00078       write(xml, "displacement_length", param.displacement_length);
00079       write(xml, "displacement_list", param.displacement_list);
00080       write(xml, "num_vecs", param.num_vecs);
00081       write(xml, "decay_dir", param.decay_dir);
00082       write(xml, "orthog_basis", param.orthog_basis);
00083      xml << param.link_smearing.xml;
00084 
00085       pop(xml);
00086     }
00087 
00088     //! Read named objects 
00089     void read(XMLReader& xml, const string& path, InlineMesonMatElemColorVecEnv::Params::NamedObject_t& input)
00090     {
00091       XMLReader inputtop(xml, path);
00092 
00093       read(inputtop, "gauge_id", input.gauge_id);
00094       read(inputtop, "colorvec_id", input.colorvec_id);
00095       read(inputtop, "meson_op_file", input.meson_op_file);
00096     }
00097 
00098     //! Write named objects
00099     void write(XMLWriter& xml, const string& path, const InlineMesonMatElemColorVecEnv::Params::NamedObject_t& input)
00100     {
00101       push(xml, path);
00102 
00103       write(xml, "gauge_id", input.gauge_id);
00104       write(xml, "colorvec_id", input.colorvec_id);
00105       write(xml, "meson_op_file", input.meson_op_file);
00106 
00107       pop(xml);
00108     }
00109 
00110     // Writer for input parameters
00111     void write(XMLWriter& xml, const string& path, const InlineMesonMatElemColorVecEnv::Params& param)
00112     {
00113       param.writeXML(xml, path);
00114     }
00115   }
00116 
00117 
00118   namespace InlineMesonMatElemColorVecEnv 
00119   { 
00120     // Anonymous namespace for registration
00121     namespace
00122     {
00123       AbsInlineMeasurement* createMeasurement(XMLReader& xml_in, 
00124                                               const std::string& path) 
00125       {
00126         return new InlineMeas(Params(xml_in, path));
00127       }
00128 
00129       //! Local registration flag
00130       bool registered = false;
00131     }
00132 
00133     const std::string name = "MESON_MATELEM_COLORVEC";
00134 
00135     //! Register all the factories
00136     bool registerAll() 
00137     {
00138       bool success = true; 
00139       if (! registered)
00140       {
00141         success &= LinkSmearingEnv::registerAll();
00142         success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
00143         registered = true;
00144       }
00145       return success;
00146     }
00147 
00148 
00149     //! Anonymous namespace
00150     /*! Diagnostic stuff */
00151     namespace
00152     {
00153       StandardOutputStream& operator<<(StandardOutputStream& os, const multi1d<int>& d)
00154       {
00155         if (d.size() > 0)
00156         {
00157           os << d[0];
00158 
00159           for(int i=1; i < d.size(); ++i)
00160             os << " " << d[i];
00161         }
00162 
00163         return os;
00164       }
00165     }
00166 
00167 
00168     //----------------------------------------------------------------------------
00169     // Param stuff
00170     Params::Params()
00171     { 
00172       frequency = 0; 
00173       param.mom2_max = 0;
00174     }
00175 
00176     Params::Params(XMLReader& xml_in, const std::string& path) 
00177     {
00178       try 
00179       {
00180         XMLReader paramtop(xml_in, path);
00181 
00182         if (paramtop.count("Frequency") == 1)
00183           read(paramtop, "Frequency", frequency);
00184         else
00185           frequency = 1;
00186 
00187         // Read program parameters
00188         read(paramtop, "Param", param);
00189 
00190         // Read in the output propagator/source configuration info
00191         read(paramtop, "NamedObject", named_obj);
00192 
00193         // Possible alternate XML file pattern
00194         if (paramtop.count("xml_file") != 0) 
00195         {
00196           read(paramtop, "xml_file", xml_file);
00197         }
00198       }
00199       catch(const std::string& e) 
00200       {
00201         QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << endl;
00202         QDP_abort(1);
00203       }
00204     }
00205 
00206 
00207     void
00208     Params::writeXML(XMLWriter& xml_out, const std::string& path) const
00209     {
00210       push(xml_out, path);
00211     
00212       // Parameters for source construction
00213       write(xml_out, "Param", param);
00214 
00215       // Write out the output propagator/source configuration info
00216       write(xml_out, "NamedObject", named_obj);
00217 
00218       pop(xml_out);
00219     }
00220 
00221 
00222     //----------------------------------------------------------------------------
00223     //! Meson operator
00224     struct KeyMesonElementalOperator_t
00225     {
00226       int                t_slice;      /*!< Meson operator time slice */
00227       multi1d<int>       displacement; /*!< Displacement dirs of right colorvector */
00228       multi1d<int>       mom;          /*!< D-1 momentum of this operator */
00229     };
00230 
00231     //! Meson operator
00232     struct ValMesonElementalOperator_t
00233     {
00234       int                type_of_data; /*!< Flag indicating type of data (maybe trivial) */
00235       multi2d<ComplexD>  op;          /*!< Colorvector source and sink with momentum projection */
00236     };
00237 
00238 
00239     //----------------------------------------------------------------------------
00240     //! Holds key and value as temporaries
00241     struct KeyValMesonElementalOperator_t
00242     {
00243       SerialDBKey<KeyMesonElementalOperator_t>  key;
00244       SerialDBData<ValMesonElementalOperator_t> val;
00245     };
00246 
00247 
00248     //----------------------------------------------------------------------------
00249     //! KeyMesonElementalOperator reader
00250     void read(BinaryReader& bin, KeyMesonElementalOperator_t& param)
00251     {
00252       read(bin, param.t_slice);
00253       read(bin, param.displacement);
00254       read(bin, param.mom);
00255     }
00256 
00257     //! MesonElementalOperator write
00258     void write(BinaryWriter& bin, const KeyMesonElementalOperator_t& param)
00259     {
00260       write(bin, param.t_slice);
00261       write(bin, param.displacement);
00262       write(bin, param.mom);
00263     }
00264 
00265     //! MesonElementalOperator reader
00266     void read(XMLReader& xml, const std::string& path, KeyMesonElementalOperator_t& param)
00267     {
00268       XMLReader paramtop(xml, path);
00269     
00270       read(paramtop, "t_slice", param.t_slice);
00271       read(paramtop, "displacement", param.displacement);
00272       read(paramtop, "mom", param.mom);
00273     }
00274 
00275     //! MesonElementalOperator writer
00276     void write(XMLWriter& xml, const std::string& path, const KeyMesonElementalOperator_t& param)
00277     {
00278       push(xml, path);
00279 
00280       write(xml, "t_slice", param.t_slice);
00281       write(xml, "displacement", param.displacement);
00282       write(xml, "mom", param.mom);
00283 
00284       pop(xml);
00285     }
00286 
00287 
00288     //----------------------------------------------------------------------------
00289     //! MesonElementalOperator reader
00290     void read(BinaryReader& bin, ValMesonElementalOperator_t& param)
00291     {
00292       read(bin, param.type_of_data);
00293 
00294       int n;
00295       read(bin, n);    // the size is always written, even if 0
00296       param.op.resize(n,n);
00297   
00298       for(int i=0; i < n; ++i)
00299       {
00300         for(int j=0; j < n; ++j)
00301         {
00302           read(bin, param.op(i,j));
00303         }
00304       }
00305     }
00306 
00307     //! MesonElementalOperator write
00308     void write(BinaryWriter& bin, const ValMesonElementalOperator_t& param)
00309     {
00310       write(bin, param.type_of_data);
00311 
00312       int n = param.op.size1();  // all sizes the same
00313       write(bin, n);
00314       for(int i=0; i < n; ++i)
00315       {
00316         for(int j=0; j < n; ++j)
00317         {
00318           write(bin, param.op(i,j));
00319         }
00320       }
00321     }
00322 
00323 
00324     //----------------------------------------------------------------------------
00325     //! Normalize just one displacement array
00326     multi1d<int> normDisp(const multi1d<int>& orig)
00327     {
00328       START_CODE();
00329 
00330       multi1d<int> disp;
00331       multi1d<int> empty; 
00332       multi1d<int> no_disp(1); no_disp[0] = 0;
00333 
00334       // NOTE: a no-displacement is recorded as a zero-length array
00335       // Convert a length one array with no displacement into a no-displacement array
00336       if (orig.size() == 1)
00337       {
00338         if (orig == no_disp)
00339           disp = empty;
00340         else
00341           disp = orig;
00342       }
00343       else
00344       {
00345         disp = orig;
00346       }
00347 
00348       END_CODE();
00349 
00350       return disp;
00351     } // void normDisp
00352 
00353 
00354     //-------------------------------------------------------------------------------
00355     // Function call
00356     void 
00357     InlineMeas::operator()(unsigned long update_no,
00358                            XMLWriter& xml_out) 
00359     {
00360       // If xml file not empty, then use alternate
00361       if (params.xml_file != "")
00362       {
00363         string xml_file = makeXMLFileName(params.xml_file, update_no);
00364 
00365         push(xml_out, "MesonMatElemColorVec");
00366         write(xml_out, "update_no", update_no);
00367         write(xml_out, "xml_file", xml_file);
00368         pop(xml_out);
00369 
00370         XMLFileWriter xml(xml_file);
00371         func(update_no, xml);
00372       }
00373       else
00374       {
00375         func(update_no, xml_out);
00376       }
00377     }
00378 
00379 
00380     // Function call
00381     void 
00382     InlineMeas::func(unsigned long update_no,
00383                      XMLWriter& xml_out) 
00384     {
00385       START_CODE();
00386 
00387       StopWatch snoop;
00388       snoop.reset();
00389       snoop.start();
00390 
00391       
00392       StopWatch swiss;
00393                         
00394       // Test and grab a reference to the gauge field
00395       XMLBufferWriter gauge_xml;
00396       try
00397       {
00398         TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00399         TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
00400 
00401         TheNamedObjMap::Instance().getData< SubsetVectors<LatticeColorVector> >(params.named_obj.colorvec_id).getEvectors();
00402       }
00403       catch( std::bad_cast ) 
00404       {
00405         QDPIO::cerr << name << ": caught dynamic cast error" << endl;
00406         QDP_abort(1);
00407       }
00408       catch (const string& e) 
00409       {
00410         QDPIO::cerr << name << ": map call failed: " << e << endl;
00411         QDP_abort(1);
00412       }
00413       const multi1d<LatticeColorMatrix>& u = 
00414         TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00415 
00416       const SubsetVectors<LatticeColorVector>& eigen_source = 
00417         TheNamedObjMap::Instance().getData< SubsetVectors<LatticeColorVector> >(params.named_obj.colorvec_id);
00418 
00419       push(xml_out, "MesonMatElemColorVec");
00420       write(xml_out, "update_no", update_no);
00421 
00422       QDPIO::cout << name << ": Meson color-vector matrix element" << endl;
00423 
00424       proginfo(xml_out);    // Print out basic program info
00425 
00426       // Write out the input
00427       params.writeXML(xml_out, "Input");
00428 
00429       // Write out the config info
00430       write(xml_out, "Config_info", gauge_xml);
00431 
00432       push(xml_out, "Output_version");
00433       write(xml_out, "out_version", 1);
00434       pop(xml_out);
00435 
00436       //First calculate some gauge invariant observables just for info.
00437       //This is really cheap.
00438       MesPlq(xml_out, "Observables", u);
00439 
00440       //
00441       // Initialize the slow Fourier transform phases
00442       //
00443       SftMom phases(params.param.mom2_max, false, params.param.decay_dir);
00444 
00445       //
00446       // Smear the gauge field if needed
00447       //
00448       multi1d<LatticeColorMatrix> u_smr = u;
00449 
00450       try
00451       {
00452         std::istringstream  xml_l(params.param.link_smearing.xml);
00453         XMLReader  linktop(xml_l);
00454         QDPIO::cout << "Link smearing type = " << params.param.link_smearing.id << endl;
00455         
00456         
00457         Handle< LinkSmearing >
00458           linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.param.link_smearing.id,
00459                                                                        linktop, 
00460                                                                        params.param.link_smearing.path));
00461 
00462         (*linkSmearing)(u_smr);
00463       }
00464       catch(const std::string& e) 
00465       {
00466         QDPIO::cerr << name << ": Caught Exception link smearing: " << e << endl;
00467         QDP_abort(1);
00468       }
00469 
00470       // Record the smeared observables
00471       MesPlq(xml_out, "Smeared_Observables", u_smr);
00472 
00473       //
00474       // DB storage
00475       //
00476       BinaryStoreDB< SerialDBKey<KeyMesonElementalOperator_t>, SerialDBData<ValMesonElementalOperator_t> > 
00477         qdp_db;
00478 
00479       // Open the file, and write the meta-data and the binary for this operator
00480       if (! qdp_db.fileExists(params.named_obj.meson_op_file))
00481       {
00482         XMLBufferWriter file_xml;
00483 
00484         push(file_xml, "DBMetaData");
00485         write(file_xml, "id", string("mesonElemOp"));
00486         write(file_xml, "lattSize", QDP::Layout::lattSize());
00487 //      write(file_xml, "blockSize", params.param.block_size);
00488         write(file_xml, "decay_dir", params.param.decay_dir);
00489         proginfo(file_xml);    // Print out basic program info
00490         write(file_xml, "Params", params.param);
00491         write(file_xml, "Op_Info", params.param.displacement_list);
00492         write(file_xml, "Config_info", gauge_xml);
00493         write(file_xml, "Weights", eigen_source.getEvalues());
00494         pop(file_xml);
00495 
00496         std::string file_str(file_xml.str());
00497         qdp_db.setMaxUserInfoLen(file_str.size());
00498 
00499         qdp_db.open(params.named_obj.meson_op_file, O_RDWR | O_CREAT, 0664);
00500 
00501         qdp_db.insertUserdata(file_str);
00502       }
00503       else
00504       {
00505         qdp_db.open(params.named_obj.meson_op_file, O_RDWR, 0664);
00506       }
00507 
00508 
00509       // Keep track of no displacements and zero momentum
00510       multi1d<int> no_displacement;
00511       multi1d<int> zero_mom(3); zero_mom = 0;
00512 
00513       //
00514       // Meson operators
00515       //
00516       // The creation and annihilation operators are the same without the
00517       // spin matrices.
00518       //
00519       QDPIO::cout << "Building meson operators" << endl;
00520 
00521       push(xml_out, "ElementalOps");
00522 
00523       // Loop over all time slices for the source. This is the same 
00524       // as the subsets for  phases
00525 
00526       // Loop over each operator 
00527       for(int l=0; l < params.param.displacement_list.size(); ++l)
00528       {
00529         StopWatch watch;
00530 
00531         QDPIO::cout << "Elemental operator: op = " << l << endl;
00532 
00533         // Make sure displacement is something sensible
00534         multi1d<int> disp = normDisp(params.param.displacement_list[l]);
00535 
00536         QDPIO::cout << "displacement = " << disp << endl;
00537 
00538         // Build the operator
00539         swiss.reset();
00540         swiss.start();
00541 
00542         // Big loop over the momentum projection
00543         for(int mom_num = 0 ; mom_num < phases.numMom() ; ++mom_num) 
00544         {
00545           // The keys for the spin and displacements for this particular elemental operator
00546           // No displacement for left colorvector, only displace right colorvector
00547           // Invert the time - make it an independent key
00548           multi1d<KeyValMesonElementalOperator_t> buf(phases.numSubsets());
00549           for(int t=0; t < phases.numSubsets(); ++t)
00550           {
00551             buf[t].key.key().t_slice       = t;
00552             buf[t].key.key().mom           = phases.numToMom(mom_num);
00553             buf[t].key.key().displacement  = disp; // only right colorvector
00554             buf[t].val.data().op.resize(params.param.num_vecs,params.param.num_vecs);
00555 
00556             if ( params.param.orthog_basis && 
00557                  (phases.numToMom(mom_num)) == zero_mom && 
00558                  (disp == no_displacement) )
00559             {
00560               buf[t].val.data().type_of_data = COLORVEC_MATELEM_TYPE_ONE;
00561             }
00562             else
00563             {
00564               buf[t].val.data().type_of_data = COLORVEC_MATELEM_TYPE_GENERIC;
00565             }
00566           }
00567 
00568           for(int j = 0 ; j < params.param.num_vecs; ++j)
00569           {
00570             // Displace the right vector and multiply by the momentum phase
00571             LatticeColorVector shift_vec = phases[mom_num] * displace(u_smr, 
00572                                                                       eigen_source.getEvectors()[j], 
00573                                                                       params.param.displacement_length, 
00574                                                                       disp);
00575 
00576             for(int i = 0 ; i <  params.param.num_vecs; ++i)
00577             {
00578               watch.reset();
00579               watch.start();
00580 
00581               // Contract over color indices
00582               // Do the relevant quark contraction
00583               LatticeComplex lop = localInnerProduct(eigen_source.getEvectors()[i], shift_vec);
00584 
00585               // Slow fourier-transform
00586               multi1d<ComplexD> op_sum = sumMulti(lop, phases.getSet());
00587 
00588               watch.stop();
00589 
00590               for(int t=0; t < op_sum.size(); ++t)
00591               {
00592                 buf[t].val.data().op(i,j) = op_sum[t];
00593               }
00594 
00595 //            write(xml_out, "elem", key.key());  // debugging
00596             } // end for j
00597           } // end for i
00598 
00599           QDPIO::cout << "insert: mom= " << phases.numToMom(mom_num) << " displacement= " << disp << endl; 
00600           for(int t=0; t < phases.numSubsets(); ++t)
00601           {
00602             qdp_db.insert(buf[t].key, buf[t].val);
00603           }
00604 
00605         } // mom_num
00606 
00607         swiss.stop();
00608 
00609         QDPIO::cout << "Meson operator= " << l 
00610                     << "  time= "
00611                     << swiss.getTimeInSeconds() 
00612                     << " secs" << endl;
00613 
00614       } // for l
00615 
00616       pop(xml_out); // ElementalOps
00617 
00618       // Close the namelist output file XMLDAT
00619       pop(xml_out);     // MesonMatElemColorVector
00620 
00621       snoop.stop();
00622       QDPIO::cout << name << ": total time = " 
00623                   << snoop.getTimeInSeconds() 
00624                   << " secs" << endl;
00625 
00626       QDPIO::cout << name << ": ran successfully" << endl;
00627 
00628       END_CODE();
00629     } // func
00630   } // namespace InlineMesonMatElemColorVecEnv
00631 
00632   /*! @} */  // end of group hadron
00633 
00634 } // namespace Chroma
00635 
00636 

Generated on Sun Nov 22 04:32:40 2009 for CHROMA by  doxygen 1.4.7