dilute_zN_eigvec_source_const.cc

Go to the documentation of this file.
00001 // $Id: dilute_zN_eigvec_source_const.cc,v 3.2 2009/07/12 00:45:36 jbulava Exp $
00002 /*! \file
00003  *  \brief Random ZN wall source construction
00004  */
00005 
00006 #include "chromabase.h"
00007 #include "handle.h"
00008 
00009 #include "meas/smear/link_smearing_aggregate.h"
00010 #include "meas/smear/link_smearing_factory.h"
00011 
00012 #include "meas/smear/quark_smearing_aggregate.h"
00013 #include "meas/smear/quark_smearing_factory.h"
00014 
00015 #include "meas/smear/quark_displacement_aggregate.h"
00016 #include "meas/smear/quark_displacement_factory.h"
00017 
00018 #include "meas/smear/simple_quark_displacement.h"
00019 #include "meas/smear/no_quark_displacement.h"
00020 
00021 #include "meas/sources/source_const_factory.h"
00022 #include "meas/sources/dilute_zN_eigvec_source_const.h"
00023 #include "meas/sources/zN_src.h"
00024 
00025 #include "meas/inline/io/named_objmap.h"
00026 
00027 #include "util/ft/sftmom.h"
00028 
00029 #include "util/ferm/subset_vectors.h"
00030 namespace Chroma
00031 {
00032   // Read parameters
00033   void read(XMLReader& xml, const string& path, DiluteZNEigVecQuarkSourceConstEnv::Params& param)
00034   {
00035     DiluteZNEigVecQuarkSourceConstEnv::Params tmp(xml, path);
00036     param = tmp;
00037   }
00038 
00039   // Writer
00040   void write(XMLWriter& xml, const string& path, const DiluteZNEigVecQuarkSourceConstEnv::Params& param)
00041   {
00042     param.writeXML(xml, path);
00043   }
00044 
00045 
00046 
00047   // Hooks to register the class
00048   namespace DiluteZNEigVecQuarkSourceConstEnv
00049   {
00050     // Anonymous namespace
00051     namespace
00052     {
00053       //! Callback function
00054       QuarkSourceConstruction<LatticeFermion>* createFerm(XMLReader& xml_in,
00055                                                           const std::string& path)
00056       {
00057         return new SourceConst<LatticeFermion>(Params(xml_in, path));
00058       }
00059 
00060       //! Local registration flag
00061       bool registered = false;
00062 
00063       //! Name to be used
00064       const std::string name("RAND_DILUTE_EIGVEC_ZN_SOURCE");
00065     }  // end namespace
00066 
00067     //! Return the name
00068     std::string getName() {return name;}
00069 
00070     //! Register all the factories
00071     bool registerAll() 
00072     {
00073       bool success = true; 
00074       if (! registered)
00075       {
00076         success &= Chroma::TheFermSourceConstructionFactory::Instance().registerObject(name, createFerm);
00077         registered = true;
00078       }
00079       return success;
00080     }
00081 
00082 
00083     //! Initialize
00084     Params::Params()
00085     {
00086     }
00087 
00088 
00089     //! Read parameters
00090     Params::Params(XMLReader& xml, const string& path)
00091     {
00092       XMLReader paramtop(xml, path);
00093 
00094       int version;
00095       read(paramtop, "version", version);
00096 
00097       switch (version) 
00098       {
00099       case 1:
00100         break;
00101 
00102       default:
00103         QDPIO::cerr << __func__ << ": parameter version " << version 
00104                     << " unsupported." << endl;
00105         QDP_abort(1);
00106       }
00107 
00108                         read(paramtop, "ran_seed", ran_seed);
00109       read(paramtop, "N", N);
00110       read(paramtop, "j_decay", j_decay);
00111       read(paramtop, "t_sources", t_sources);
00112 
00113       read(paramtop, "eigen_vec_id", eigen_vec_id);
00114       read(paramtop, "eigen_vectors", eigen_vectors);
00115       read(paramtop, "spin_mask", spin_mask);
00116     }
00117 
00118 
00119     // Writer
00120     void Params::writeXML(XMLWriter& xml, const string& path) const
00121     {
00122       push(xml, path);
00123 
00124       int version = 1;
00125 
00126       write(xml, "version", version);
00127       write(xml, "ran_seed", ran_seed);
00128       write(xml, "N", N);
00129       write(xml, "j_decay", j_decay);
00130       write(xml, "t_sources", t_sources);
00131 
00132       write(xml, "eigen_vec_id", eigen_vec_id);
00133       write(xml, "eigen_vectors", eigen_vectors);
00134       write(xml, "spin_mask", spin_mask);
00135 
00136       pop(xml);
00137     }
00138 
00139         
00140                 void fill_laph_subspace_zN( LatticeLAPHSubSpace_t& laph_in, 
00141                                 const Seed& rng_seed, const int& N)
00142                 {
00143 
00144                 //Obtain the current seed
00145                 Seed curr_seed;
00146                 QDP::RNG::savern(curr_seed);
00147 
00148                 //Seed the random number generator
00149                 QDP::RNG::setrn(rng_seed);
00150         
00151 
00152                 //Fill the struct
00153                 for (int t = 0 ; t < laph_in.time_slices.size(); ++t)
00154                 {
00155                         for (int s = 0 ; s < laph_in.time_slices[t].spins.size() ; ++s)
00156                                 for (int v = 0 ; v < laph_in.time_slices[t].spins[s].lap_eigs.size() ; ++v)
00157                                 {
00158                                         laph_in.time_slices[t].spins[s].lap_eigs[v].val = zN_rng(N);
00159                                 }
00160 
00161                 //Return the seed to its previous value
00162                 QDP::RNG::setrn(curr_seed);
00163 
00164         }
00165                 }
00166 
00167     //! Construct the source
00168     template<>
00169     LatticeFermion
00170     SourceConst<LatticeFermion>::operator()(const multi1d<LatticeColorMatrix>& u) const
00171     {
00172       QDPIO::cout << "Eigenvector-Diluted random complex ZN source" << endl;
00173 
00174                         int Nt = QDP::Layout::lattSize()[params.j_decay];
00175       
00176                         //
00177       // Sanity checks
00178       //
00179       if (params.spin_mask.size() > Ns)
00180       {
00181         QDPIO::cerr << name << ": spin mask size incorrect 1" << endl;
00182         QDP_abort(1);
00183       }
00184 
00185       if (params.spin_mask.size() == 0)
00186       {
00187         QDPIO::cerr << name << ": spin mask size incorrect 2" << endl;
00188         QDP_abort(1);
00189       }
00190 
00191                          if (params.t_sources.size() > Nt)
00192       {
00193         QDPIO::cerr << name << ": time sources size incorrect 1" << endl;
00194         QDP_abort(1);
00195       }
00196 
00197       if (params.t_sources.size() == 0)
00198       {
00199         QDPIO::cerr << name << ": time sources size incorrect 2" << endl;
00200         QDP_abort(1);
00201       }
00202 
00203                         //check that there are no repeats, and that each is < Nt
00204                         for (int t = 0 ; t < params.t_sources.size() ; ++t)
00205                         {
00206                                 if ( (t > 0) && (params.t_sources[t] == params.t_sources[0]) )
00207                                 {
00208                                         QDPIO::cerr << "ERROR: repeat in t_sources" << endl;
00209                                         QDP_abort(1);
00210                                 }
00211 
00212                                 if (params.t_sources[t] >= Nt)
00213                                 {
00214                                         QDPIO::cerr << "ERROR: invalid component in t_sources "  
00215                                                 << params.t_sources[t] <<  " >= " << Nt << endl;
00216                                         QDP_abort(1);
00217                                 }
00218                         }
00219 
00220                         XMLBufferWriter eig_vecs_xml;
00221                         
00222                         //Attempt to get eigenvectors from the named object map
00223                         try
00224       {
00225                                 TheNamedObjMap::Instance().getData< SubsetVectors<LatticeColorVector> >(params.eigen_vec_id).getEvectors();     
00226 
00227                                 TheNamedObjMap::Instance().get(params.eigen_vec_id).getRecordXML(eig_vecs_xml);
00228 
00229                         }
00230                         catch( std::bad_cast ) 
00231       {
00232         QDPIO::cerr << name << ": caught dynamic cast error" << endl;
00233         QDP_abort(1);
00234       }
00235       catch (const string& e) 
00236       {
00237         QDPIO::cerr << name << ": map call failed: " << e << endl;
00238         QDP_abort(1);
00239       }
00240 
00241 
00242                         const SubsetVectors<LatticeColorVector>& eigen_vecs = 
00243         TheNamedObjMap::Instance().getData< SubsetVectors<LatticeColorVector> >(params.eigen_vec_id);
00244 
00245                         int n_ev = eigen_vecs.getEvectors().size();
00246 
00247                         //Sanity checks on the eigenvector dilutions
00248                         int n_ev_dil = params.eigen_vectors.size();
00249                         
00250                         //First, ensure there are not more than n_ev elements
00251                         if ( n_ev_dil > n_ev)
00252                         {
00253                                 QDPIO::cerr << "ERROR: n_ev_dil > n_ev" << endl;
00254                                 QDP_abort(1);
00255                         }
00256 
00257                         //Check that there are no repeats in the vectors, also that each 
00258                         //element is not larger than n_ev
00259                         for (int v = 0 ; v < n_ev_dil ; ++v)
00260                         {
00261                                 if ( (v > 0) && (params.eigen_vectors[v] == params.eigen_vectors[0]) )
00262                                 {
00263                                         QDPIO::cerr << "ERROR: repeat in eigen_vectors" << endl;
00264                                         QDP_abort(1);
00265                                 }
00266 
00267                                 if (params.eigen_vectors[v] >= n_ev)
00268                                 {
00269                                         QDPIO::cerr << "ERROR: invalid component in eigen_vectors" << endl;
00270                                         QDP_abort(1);
00271                                 }
00272                         }
00273 
00274                         //params.writeXML(xml_out, "Input");
00275 
00276                         //params.writeXML(xml_out, "EigVecsXML");
00277 
00278                         //
00279       // Finally, do something useful
00280       //
00281 
00282                         /*
00283       // Save current seed
00284       Seed ran_seed;
00285       QDP::RNG::savern(ran_seed);
00286 
00287       // Set the seed to desired value
00288       QDP::RNG::setrn(params.ran_seed);
00289                         */
00290 
00291 
00292                         SftMom phases(0, true, params.j_decay);
00293 
00294                         LatticeLAPHSubSpace_t laph_noise(n_ev, Nt);
00295                         fill_laph_subspace_zN(laph_noise, params.ran_seed, params.N);
00296 
00297                         QDPIO::cout << "Created LapH Noise " << endl;
00298 
00299                         LatticeFermion dil_source = zero;
00300 
00301                         for (int t0 = 0 ; t0 < params.t_sources.size() ; ++t0)
00302                         {
00303                                 int curr_t = params.t_sources[t0];
00304 
00305                                 for (int s = 0 ; s < params.spin_mask.size() ; ++s)
00306                                 {
00307                                         
00308                                         int curr_s = params.spin_mask[s];
00309 
00310                                         for (int v = 0 ; v < params.eigen_vectors.size() ; ++v)
00311                                         {
00312                                                 int curr_v = params.eigen_vectors[v];
00313 
00314                                                 const Complex& curr_n = laph_noise.time_slices[curr_t].spins[ 
00315                                                         curr_s].lap_eigs[curr_v].val;
00316                                         
00317                                                 LatticeFermion temp = zero;
00318                                                 //Should only be poking on a single timeslice, Robert Help!!!
00319                                                 pokeSpin(temp, curr_n * eigen_vecs.getEvectors()[curr_v], curr_s);
00320 
00321                                                 dil_source[phases.getSet()[curr_t]] += temp;
00322                                         }//v
00323 
00324                                 }//s
00325 
00326                         }//t0
00327 
00328       // Reset the seed
00329       //QDP::RNG::setrn(ran_seed);
00330 
00331       return dil_source;
00332     }
00333 
00334   } // end namespace
00335 
00336 } // end namespace Chroma

Generated on Sun Nov 22 04:29:06 2009 for CHROMA by  doxygen 1.4.7