rndzNwall_source_const.cc

Go to the documentation of this file.
00001 // $Id: rndzNwall_source_const.cc,v 1.3 2009/05/01 22:52:02 kostas Exp $
00002 /*! \file
00003  *  \brief Random ZN wall source construction
00004  */
00005 
00006 #include "chromabase.h"
00007 #include "handle.h"
00008 
00009 #include "meas/sources/source_const_factory.h"
00010 #include "meas/sources/rndzNwall_source_const.h"
00011 #include "util/ferm/transf.h"
00012 
00013 
00014 #include "meas/smear/quark_smearing_factory.h"
00015 #include "meas/smear/quark_smearing_aggregate.h"
00016 
00017 #include "meas/smear/link_smearing_aggregate.h"
00018 #include "meas/smear/link_smearing_factory.h"
00019 
00020 #include "meas/smear/quark_displacement_aggregate.h"
00021 #include "meas/smear/quark_displacement_factory.h"
00022 
00023 #include "meas/smear/simple_quark_displacement.h"
00024 #include "meas/smear/no_quark_displacement.h"
00025 
00026 namespace Chroma
00027 {
00028   // Read parameters
00029   void read(XMLReader& xml, const string& path, RandZNWallQuarkSourceConstEnv::Params& param)
00030   {
00031     RandZNWallQuarkSourceConstEnv::Params tmp(xml, path);
00032     param = tmp;
00033   }
00034 
00035   // Writer
00036   void write(XMLWriter& xml, const string& path, const RandZNWallQuarkSourceConstEnv::Params& param)
00037   {
00038     param.writeXML(xml, path);
00039   }
00040 
00041 
00042 
00043   //! Hooks to register the class
00044   namespace RandZNWallQuarkSourceConstEnv
00045   {
00046     namespace
00047     {
00048       //! Callback function
00049       QuarkSourceConstruction<LatticePropagator>* createProp(XMLReader& xml_in,
00050                                                              const std::string& path)
00051       {
00052         return new SourceConst<LatticePropagator>(Params(xml_in, path));
00053       }
00054       
00055       //! Local registration flag
00056       bool registered = false;
00057 
00058       //! Name to be used
00059       const std::string name("RAND_ZN_WALL_SOURCE");
00060     }
00061 
00062     //! Return the name
00063     std::string getName() {return name;}
00064 
00065     //! Register all the factories
00066     bool registerAll() 
00067     {
00068       bool success = true; 
00069       if (! registered)
00070       {
00071         success &= LinkSmearingEnv::registerAll();
00072         success &= QuarkSmearingEnv::registerAll();
00073         success &= QuarkDisplacementEnv::registerAll();
00074         success &= Chroma::ThePropSourceConstructionFactory::Instance().registerObject(name, createProp);
00075         registered = true;
00076       }
00077       return success;
00078     }
00079 
00080 
00081     //! Initialize
00082     Params::Params()
00083     {
00084       j_decay = -1;
00085       t_source = -1;
00086       N=4 ;
00087     }
00088 
00089 
00090     //! Read parameters
00091     Params::Params(XMLReader& xml, const string& path)
00092     {
00093       XMLReader paramtop(xml, path);
00094 
00095       int version;
00096       read(paramtop, "version", version);
00097 
00098       switch (version) 
00099       {
00100       case 1:
00101         break;
00102 
00103       default:
00104         QDPIO::cerr << __func__ << ": parameter version " << version 
00105                     << " unsupported." << endl;
00106         QDP_abort(1);
00107       }
00108 
00109       read(paramtop, "ran_seed", ran_seed);
00110       read(paramtop, "j_decay", j_decay);
00111       read(paramtop, "t_source", t_source);
00112       read(paramtop, "N", N);
00113       
00114       if (paramtop.count("Displacement") != 0)
00115         quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
00116       else
00117         quark_displacement = QuarkDisplacementEnv::nullXMLGroup();
00118 
00119       read(paramtop, "quark_smear_lastP", quark_smear_lastP);
00120       quark_smearing = readXMLGroup(paramtop, "SmearingParam", "wvf_kind");
00121 
00122       if (paramtop.count("LinkSmearing") != 0)
00123         link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
00124       else
00125         link_smearing = LinkSmearingEnv::nullXMLGroup();
00126 
00127     }
00128 
00129 
00130     // Writer
00131     void Params::writeXML(XMLWriter& xml, const string& path) const
00132     {
00133       push(xml, path);
00134 
00135       int version = 1;
00136       write(xml, "SourceType", RandZNWallQuarkSourceConstEnv::name);
00137       xml << quark_smearing.xml;
00138       xml << quark_displacement.xml;
00139       xml << link_smearing.xml;
00140       write(xml, "version", version);
00141       write(xml, "ran_seed", ran_seed);
00142       write(xml, "j_decay", j_decay);
00143       write(xml, "t_source", t_source);
00144       write(xml, "N", N);
00145       pop(xml);
00146     }
00147 
00148 
00149     //! Construct the source
00150     template<>
00151     LatticePropagator
00152     SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
00153     {
00154       QDPIO::cout << "Rand Z"<<params.N<<" Wall source" << endl;
00155 
00156       
00157       // Save current seed
00158       Seed ran_seed;
00159       QDP::RNG::savern(ran_seed);
00160 
00161       // Set the seed to desired value
00162       QDP::RNG::setrn(params.ran_seed);
00163       
00164       
00165 
00166       // Create the quark source
00167       LatticePropagator quark_source;
00168 
00169       try
00170         {
00171           //
00172           // Smear the gauge field if needed
00173           //
00174           multi1d<LatticeColorMatrix> u_smr = u;
00175           {
00176             std::istringstream  xml_l(params.link_smearing.xml);
00177             XMLReader  linktop(xml_l);
00178             QDPIO::cout << "Link smearing type = " << params.link_smearing.id << endl;
00179             
00180             Handle< LinkSmearing >
00181               linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,  linktop,   params.link_smearing.path));
00182             (*linkSmearing)(u_smr);
00183           }
00184           
00185           //
00186           // Create the quark smearing object
00187           //
00188           std::istringstream  xml_s(params.quark_smearing.xml);
00189           XMLReader  smeartop(xml_s);
00190           QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << endl;
00191           
00192           Handle< QuarkSmearing<LatticePropagator> >
00193             quarkSmearing(ThePropSmearingFactory::Instance().createObject(params.quark_smearing.id, smeartop, params.quark_smearing.path));
00194           
00195           //
00196           // Create the quark displacement object
00197           //
00198           std::istringstream  xml_d(params.quark_displacement.xml);
00199           XMLReader  displacetop(xml_d);
00200           QDPIO::cout << "Displacement type = " << params.quark_displacement.id << endl;
00201           
00202           Handle< QuarkDisplacement<LatticePropagator> >
00203             quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,   displacetop,    params.quark_displacement.path));
00204           
00205           multi1d<LatticeColorVector> tmp_color_vec(Nc);
00206           
00207           LatticeReal rnd,theta;
00208           LatticeComplex z;
00209 
00210           random(rnd);
00211           
00212           Real twopiN = Chroma::twopi / params.N;
00213           theta = twopiN * floor(params.N*rnd);
00214           z = cmplx(cos(theta),sin(theta));
00215           
00216           
00217           for(int i=0; i<Nc; i++) {
00218             tmp_color_vec[i] = zero;
00219             pokeColor(tmp_color_vec[i], z, i);
00220           }
00221           
00222           for(int color_source = 0; color_source < Nc; ++color_source)
00223             {
00224               QDPIO::cout << "color = " << color_source << endl; 
00225               
00226               LatticeColorVector src_color_vec = zero;
00227               
00228               int mu = params.j_decay;
00229               int slice = params.t_source;
00230               src_color_vec = where( Layout::latticeCoordinate(mu) == slice,
00231                                      tmp_color_vec[color_source],
00232                                      LatticeColorVector(zero));
00233               
00234               for(int spin_source = 0; spin_source < Ns; ++spin_source)
00235                 {
00236                   QDPIO::cout << "spin = " << spin_source << endl; 
00237                   
00238                   // Insert a ColorVector into spin index spin_source
00239                   // This only overwrites sections, so need to initialize first
00240                   LatticeFermion chi = zero;
00241                   
00242                   CvToFerm(src_color_vec, chi, spin_source);
00243                   
00244                   
00245                   /*
00246                    *  Move the source to the appropriate components
00247                    *  of quark source.
00248                    */
00249                   FermToProp(chi, quark_source, color_source, spin_source);
00250                 }
00251             }
00252 
00253           // Smear and displace
00254           if (params.quark_smear_lastP){
00255             // Smear the colour source
00256             // displace the point source first, then smear
00257             // displacement has to be taken along negative direction.
00258             (*quarkDisplacement)(quark_source, u_smr, MINUS);
00259             
00260             // do the smearing
00261             (*quarkSmearing)(quark_source, u_smr);
00262           }
00263           else{
00264             // do the smearing
00265             (*quarkSmearing)(quark_source, u_smr);
00266             
00267             // Smear the colour source
00268             // smear the point source first, then displace
00269             // displacement has to be taken along negative direction.
00270             (*quarkDisplacement)(quark_source, u_smr, MINUS);
00271           }
00272         }// try
00273       catch(const std::string& e){
00274         QDPIO::cerr << name << ": Caught Exception smearing: " << e << endl;
00275         QDP_abort(1);
00276       }
00277 
00278       // Reset the seed
00279       QDP::RNG::setrn(ran_seed);
00280 
00281       return quark_source;
00282     }
00283 
00284   }
00285 
00286 }

Generated on Sun Nov 22 04:34:20 2009 for CHROMA by  doxygen 1.4.7