00001
00002
00003
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/dilutezN_source_const.h"
00023 #include "meas/sources/zN_src.h"
00024
00025 namespace Chroma
00026 {
00027
00028 void read(XMLReader& xml, const string& path, DiluteZNQuarkSourceConstEnv::Params& param)
00029 {
00030 DiluteZNQuarkSourceConstEnv::Params tmp(xml, path);
00031 param = tmp;
00032 }
00033
00034
00035 void write(XMLWriter& xml, const string& path, const DiluteZNQuarkSourceConstEnv::Params& param)
00036 {
00037 param.writeXML(xml, path);
00038 }
00039
00040
00041
00042
00043 namespace DiluteZNQuarkSourceConstEnv
00044 {
00045
00046 namespace
00047 {
00048
00049 QuarkSourceConstruction<LatticeFermion>* createFerm(XMLReader& xml_in,
00050 const std::string& path)
00051 {
00052 return new SourceConst<LatticeFermion>(Params(xml_in, path));
00053 }
00054
00055
00056 bool registered = false;
00057
00058
00059 const std::string name("RAND_DILUTE_ZN_SOURCE");
00060 }
00061
00062
00063 std::string getName() {return name;}
00064
00065
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
00075 success &= Chroma::TheFermSourceConstructionFactory::Instance().registerObject(name, createFerm);
00076 registered = true;
00077 }
00078 return success;
00079 }
00080
00081
00082
00083 Params::Params()
00084 {
00085 smear = false ;
00086 j_decay = -1;
00087 t_source = -1;
00088 }
00089
00090
00091
00092 Params::Params(XMLReader& xml, const string& path)
00093 {
00094 XMLReader paramtop(xml, path);
00095
00096 int version;
00097 read(paramtop, "version", version);
00098
00099 switch (version)
00100 {
00101 case 1:
00102 break;
00103
00104 default:
00105 QDPIO::cerr << __func__ << ": parameter version " << version
00106 << " unsupported." << endl;
00107 QDP_abort(1);
00108 }
00109
00110 smear = false ;
00111 if(paramtop.count("Smearing") !=0 ) {
00112 smr = readXMLGroup(paramtop, "Smearing", "wvf_kind");
00113 link_smear = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
00114 displace = readXMLGroup(paramtop, "Displacement","DisplacementType");
00115 smear = true ;
00116 }
00117
00118 read(paramtop, "ran_seed", ran_seed);
00119 read(paramtop, "N", N);
00120 read(paramtop, "j_decay", j_decay);
00121 read(paramtop, "t_source", t_source);
00122
00123 read(paramtop, "spatial_mask_size", spatial_mask_size);
00124 read(paramtop, "spatial_mask", spatial_mask);
00125 read(paramtop, "color_mask", color_mask);
00126 read(paramtop, "spin_mask", spin_mask);
00127 }
00128
00129
00130
00131 void Params::writeXML(XMLWriter& xml, const string& path) const
00132 {
00133 push(xml, path);
00134
00135 int version = 1;
00136
00137 if(smear){
00138 xml << smr.xml;
00139 xml << displace.xml ;
00140 xml << link_smear.xml ;
00141 }
00142
00143 write(xml, "version", version);
00144 write(xml, "ran_seed", ran_seed);
00145 write(xml, "N", N);
00146 write(xml, "j_decay", j_decay);
00147 write(xml, "t_source", t_source);
00148
00149 write(xml, "spatial_mask_size", spatial_mask_size);
00150 write(xml, "spatial_mask", spatial_mask);
00151 write(xml, "color_mask", color_mask);
00152 write(xml, "spin_mask", spin_mask);
00153
00154 pop(xml);
00155 }
00156
00157
00158
00159
00160 template<>
00161 LatticeFermion
00162 SourceConst<LatticeFermion>::operator()(const multi1d<LatticeColorMatrix>& u) const
00163 {
00164 QDPIO::cout << "Diluted random complex ZN source" << endl;
00165
00166
00167
00168
00169 if (params.spatial_mask_size.size() != Nd-1)
00170 {
00171 QDPIO::cerr << name << ": spatial mask size incorrect 1" << endl;
00172 QDP_abort(1);
00173 }
00174
00175 if (params.spatial_mask.size() == 0)
00176 {
00177 QDPIO::cerr << name << ": spatial mask incorrect 2" << endl;
00178 QDP_abort(1);
00179 }
00180
00181 multi1d<int> lookup_dir(Nd-1);
00182 int mu = 0;
00183 for(int j=0; j < params.spatial_mask_size.size(); ++j, ++mu)
00184 {
00185 if (j == params.j_decay) ++mu;
00186
00187 lookup_dir[j] = mu;
00188 }
00189
00190 for(int j=0; j < params.spatial_mask.size(); ++j)
00191 {
00192 if (params.spatial_mask[j].size() != Nd-1)
00193 {
00194 QDPIO::cerr << name << ": spatial mask incorrect 3" << endl;
00195 QDP_abort(1);
00196 }
00197 }
00198
00199
00200 for(int c=0; c < params.color_mask.size(); ++c)
00201 {
00202 if (params.color_mask[c] < 0 || params.color_mask[c] >= Nc)
00203 {
00204 QDPIO::cerr << name << ": color mask incorrect 6" << endl;
00205 QDP_abort(1);
00206 }
00207 }
00208
00209 for(int s=0; s < params.spin_mask.size(); ++s)
00210 {
00211 if (params.spin_mask[s] < 0 || params.spin_mask[s] >= Ns)
00212 {
00213 QDPIO::cerr << name << ": spin mask incorrect 7" << endl;
00214 QDP_abort(1);
00215 }
00216 }
00217
00218
00219
00220
00221
00222
00223 Seed ran_seed;
00224 QDP::RNG::savern(ran_seed);
00225
00226
00227 QDP::RNG::setrn(params.ran_seed);
00228
00229
00230 LatticeFermion quark_noise;
00231 zN_src(quark_noise, params.N);
00232
00233
00234 LatticeFermion quark_source = zero;
00235
00236
00237 for(int s=0; s < params.spin_mask.size(); ++s)
00238 {
00239 int spin_source = params.spin_mask[s];
00240 LatticeColorVector colvec = peekSpin(quark_noise, spin_source);
00241 LatticeColorVector dest = zero;
00242
00243 for(int c=0; c < params.color_mask.size(); ++c)
00244 {
00245 int color_source = params.color_mask[c];
00246 LatticeComplex comp = peekColor(colvec, color_source);
00247
00248 pokeColor(dest, comp, color_source);
00249 }
00250
00251 pokeSpin(quark_source, dest, spin_source);
00252 }
00253
00254 quark_noise = quark_source;
00255
00256
00257 LatticeBoolean mask = false;
00258
00259 for(int n=0; n < params.spatial_mask.size(); ++n)
00260 {
00261 LatticeBoolean btmp = true;
00262
00263 for(int j=0; j < params.spatial_mask[n].size(); ++j)
00264 btmp &= (Layout::latticeCoordinate(lookup_dir[j]) % params.spatial_mask_size[j]) == params.spatial_mask[n][j];
00265
00266 mask |= btmp;
00267 }
00268
00269
00270 mask &= Layout::latticeCoordinate(params.j_decay) == params.t_source;
00271
00272
00273 quark_source = where(mask, quark_noise, Fermion(zero));
00274
00275
00276 if(params.smear){
00277 Handle< QuarkSmearing<LatticeFermion> > Smearing ;
00278 try{
00279 std::istringstream xml_l(params.smr.xml);
00280 XMLReader smrtop(xml_l);
00281 QDPIO::cout << "Quark smearing type = " <<params.smr.id ;
00282 QDPIO::cout << endl;
00283
00284 Smearing =
00285 TheFermSmearingFactory::Instance().createObject(params.smr.id,smrtop,
00286 params.smr.path);
00287 }
00288 catch(const std::string& e){
00289 QDPIO::cerr <<name<< ": Caught Exception creating quark smearing object: " << e << endl;
00290 QDP_abort(1);
00291 }
00292 catch(...){
00293 QDPIO::cerr <<name<< ": Caught generic exception creating smearing object" << endl;
00294 QDP_abort(1);
00295 }
00296
00297
00298 multi1d<LatticeColorMatrix> u_smr = u;
00299
00300 try{
00301 std::istringstream xml_l(params.link_smear.xml);
00302 XMLReader linktop(xml_l);
00303 QDPIO::cout << "Link smearing type = " << params.link_smear.id ;
00304 QDPIO::cout << endl;
00305
00306
00307 Handle<LinkSmearing> linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smear.id, linktop, params.link_smear.path));
00308
00309 (*linkSmearing)(u_smr);
00310
00311 }
00312 catch(const std::string& e){
00313 QDPIO::cerr<<name<<": Caught Exception link smearing: " << e << endl;
00314 QDP_abort(1);
00315 }
00316
00317
00318 (*Smearing)(quark_source, u_smr);
00319
00320
00321
00322
00323 std::istringstream xml_d(params.displace.xml);
00324 XMLReader displacetop(xml_d);
00325
00326 try{
00327 Handle< QuarkDisplacement<LatticeFermion> >
00328 quarkDisplacement(TheFermDisplacementFactory::Instance().createObject(params.displace.id, displacetop, params.displace.path));
00329 QDPIO::cout << "Quark displacement type = " << params.displace.id ;
00330 QDPIO::cout << endl;
00331
00332
00333
00334 (*quarkDisplacement)(quark_source, u_smr, MINUS);
00335 }
00336 catch(const std::string& e){
00337 QDPIO::cerr<<name<<": Caught Exception quark displacement: "<<e<< endl;
00338 QDP_abort(1);
00339 }
00340 }
00341
00342
00343
00344 QDP::RNG::setrn(ran_seed);
00345
00346 return quark_source;
00347 }
00348
00349 }
00350
00351 }