00001
00002
00003
00004
00005
00006 #include "meas/hadron/stoch_cond_cont_w.h"
00007 #include "meas/hadron/hadron_contract_factory.h"
00008 #include "meas/sources/dilutezN_source_const.h"
00009 #include "meas/sources/zN_src.h"
00010
00011 #include "meas/inline/io/named_objmap.h"
00012
00013
00014 namespace Chroma
00015 {
00016
00017
00018 void read(XMLReader& xml, const string& path, StochCondContEnv::Params& param)
00019 {
00020 StochCondContEnv::Params tmp(xml, path);
00021 param = tmp;
00022 }
00023
00024
00025 void write(XMLWriter& xml, const string& path, const StochCondContEnv::Params& param)
00026 {
00027 param.writeXML(xml, path);
00028 }
00029
00030
00031 namespace StochCondContEnv
00032 {
00033 namespace
00034 {
00035 HadronContract* mesStochCondCont(XMLReader& xml_in,
00036 const std::string& path)
00037 {
00038 return new StochCondCont(Params(xml_in, path));
00039 }
00040
00041
00042 bool registered = false;
00043
00044 }
00045
00046
00047
00048 Params::Params()
00049 {
00050 }
00051
00052
00053
00054 Params::Params(XMLReader& xml, const string& path)
00055 {
00056 XMLReader paramtop(xml, path);
00057
00058 int version;
00059 read(paramtop, "version", version);
00060
00061 switch (version)
00062 {
00063 case 1:
00064
00065 break;
00066
00067 default :
00068
00069
00070 QDPIO::cerr << "StochCond: Input parameter version " << version << " unsupported." << endl;
00071 QDP_abort(1);
00072 }
00073
00074 read(paramtop, "mom2_max", mom2_max);
00075 read(paramtop, "avg_equiv_mom", avg_equiv_mom);
00076 read(paramtop, "mom_origin", mom_origin);
00077 read(paramtop, "soln_files", soln_files);
00078 }
00079
00080
00081
00082 void Params::writeXML(XMLWriter& xml, const string& path) const
00083 {
00084 push(xml, path);
00085
00086 int version = 1;
00087
00088 write(xml, "version", version);
00089 write(xml, "mom2_max", mom2_max);
00090 write(xml, "avg_equiv_mom", avg_equiv_mom);
00091 write(xml, "mom_origin", mom_origin);
00092 write(xml, "soln_files", soln_files);
00093
00094 pop(xml);
00095 }
00096
00097
00098
00099
00100
00101 struct QuarkSourceSolutions_t
00102 {
00103
00104 struct QuarkSolution_t
00105 {
00106 LatticeFermion source;
00107 LatticeFermion soln;
00108 PropSourceConst_t source_header;
00109 ChromaProp_t prop_header;
00110 };
00111
00112 int j_decay;
00113 Seed seed;
00114 multi1d<QuarkSolution_t> dilutions;
00115 };
00116
00117
00118
00119
00120 std::list< Handle<HadronContractResult_t> >
00121 StochCondCont::operator()(const multi1d<LatticeColorMatrix>& u,
00122 const std::string& xml_group,
00123 const std::string& id_tag)
00124 {
00125 START_CODE();
00126
00127 QDPIO::cout << "Stochastic Condensates" << endl;
00128
00129 StopWatch snoop;
00130 snoop.reset();
00131 snoop.start();
00132
00133 StopWatch swatch;
00134
00135
00136 Seed ran_seed;
00137 QDP::RNG::savern(ran_seed);
00138
00139
00140
00141
00142 swatch.reset();
00143 swatch.start();
00144 QuarkSourceSolutions_t quark;
00145
00146 try
00147 {
00148 QDPIO::cout << "Attempt to read solutions" << endl;
00149 quark.dilutions.resize(params.soln_files.size());
00150
00151 QDPIO::cout << "dilutions.size= " << quark.dilutions.size() << endl;
00152 for(int i=0; i < quark.dilutions.size(); ++i)
00153 {
00154 XMLReader file_xml, record_xml;
00155
00156 QDPIO::cout << "reading file= " << params.soln_files[i] << endl;
00157 QDPFileReader from(file_xml, params.soln_files[i], QDPIO_SERIAL);
00158 read(from, record_xml, quark.dilutions[i].soln);
00159 close(from);
00160
00161 read(record_xml, "/Propagator/PropSource", quark.dilutions[i].source_header);
00162 read(record_xml, "/Propagator/ForwardProp", quark.dilutions[i].prop_header);
00163 }
00164 }
00165 catch (const string& e)
00166 {
00167 QDPIO::cerr << "Error extracting headers: " << e << endl;
00168 QDP_abort(1);
00169 }
00170 swatch.stop();
00171
00172 QDPIO::cout << "Sources and solutions successfully read: time= "
00173 << swatch.getTimeInSeconds()
00174 << " secs" << endl;
00175
00176
00177
00178
00179
00180
00181
00182 swatch.reset();
00183 swatch.start();
00184
00185 try
00186 {
00187 bool first = true;
00188 int N;
00189 LatticeFermion quark_noise;
00190
00191 for(int i=0; i < quark.dilutions.size(); ++i)
00192 {
00193 std::istringstream xml_s(quark.dilutions[i].source_header.source.xml);
00194 XMLReader sourcetop(xml_s);
00195
00196
00197 if (quark.dilutions[i].source_header.source.id != DiluteZNQuarkSourceConstEnv::getName())
00198 {
00199 QDPIO::cerr << "Expected source_type = " << DiluteZNQuarkSourceConstEnv::getName() << endl;
00200 QDP_abort(1);
00201 }
00202
00203 QDPIO::cout << "Dilution num= " << i << endl;
00204
00205
00206 DiluteZNQuarkSourceConstEnv::Params srcParams(sourcetop,
00207 quark.dilutions[i].source_header.source.path);
00208 DiluteZNQuarkSourceConstEnv::SourceConst<LatticeFermion> srcConst(srcParams);
00209
00210 if (first)
00211 {
00212 first = false;
00213
00214 quark.j_decay = srcParams.j_decay;
00215
00216
00217 N = srcParams.N;
00218
00219
00220 quark.seed = srcParams.ran_seed;
00221 QDP::RNG::setrn(quark.seed);
00222
00223
00224 zN_src(quark_noise, N);
00225 }
00226
00227
00228 if ( toBool(srcParams.ran_seed != quark.seed) )
00229 {
00230 QDPIO::cerr << "dilution=" << i << " seed does not match" << endl;
00231 QDP_abort(1);
00232 }
00233
00234
00235 if ( toBool(srcParams.N != N) )
00236 {
00237 QDPIO::cerr << "dilution=" << i << " N does not match" << endl;
00238 QDP_abort(1);
00239 }
00240
00241
00242
00243
00244 quark.dilutions[i].source = srcConst(u);
00245 quark_noise -= quark.dilutions[i].source;
00246
00247 #if 0
00248
00249 {
00250
00251 SftMom phases_nomom(0, true, quark.dilutions[i].source_header.j_decay);
00252
00253 multi1d<Double> source_corr = sumMulti(localNorm2(quark.dilutions[i].source),
00254 phases_nomom.getSet());
00255
00256 multi1d<Double> soln_corr = sumMulti(localNorm2(quark.dilutions[i].soln),
00257 phases_nomom.getSet());
00258
00259 }
00260 #endif
00261 }
00262
00263 Double dcnt = norm2(quark_noise);
00264 if (toDouble(dcnt) != 0.0)
00265 {
00266 QDPIO::cerr << "Noise not saturated by all potential solutions: dcnt=" << dcnt << endl;
00267 QDP_abort(1);
00268 }
00269 }
00270 catch(const std::string& e)
00271 {
00272 QDPIO::cerr << ": Caught Exception creating source: " << e << endl;
00273 QDP_abort(1);
00274 }
00275
00276 swatch.stop();
00277
00278 QDPIO::cout << "Sources saturated: time= "
00279 << swatch.getTimeInSeconds()
00280 << " secs" << endl;
00281
00282
00283
00284
00285
00286 SftMomParams_t sft_params;
00287
00288 sft_params.origin_offset.resize(Nd);
00289 sft_params.origin_offset = 0;
00290 sft_params.mom2_max = params.mom2_max;
00291 sft_params.mom_offset = params.mom_origin;
00292 sft_params.avg_equiv_mom = params.avg_equiv_mom;
00293 sft_params.decay_dir = quark.j_decay;
00294
00295
00296 swatch.reset();
00297 swatch.start();
00298
00299 std::list< Handle<Hadron2PtContract_t> > hadron;
00300
00301 for(int gamma_value=0; gamma_value < Ns*Ns; ++gamma_value)
00302 {
00303 Handle<Hadron2PtContract_t> had(new Hadron2PtContract_t);
00304
00305 push(had->xml, xml_group);
00306 write(had->xml, id_tag, "stoch_diagonal_gamma_condensates");
00307 write(had->xml, "gamma_value", gamma_value);
00308 write(had->xml, "mom2_max", sft_params.mom2_max);
00309 write(had->xml, "avg_equiv_mom", sft_params.avg_equiv_mom);
00310 write(had->xml, "decay_dir", sft_params.decay_dir);
00311 pop(had->xml);
00312
00313 had->corr = zero;
00314 for(int i=0; i < quark.dilutions.size(); ++i)
00315 {
00316 had->corr +=
00317 localInnerProduct(quark.dilutions[i].source, Gamma(gamma_value) * quark.dilutions[i].soln);
00318 }
00319
00320 hadron.push_back(had);
00321 }
00322
00323 END_CODE();
00324
00325 return this->project(hadron, sft_params);
00326 }
00327
00328
00329
00330 bool registerAll()
00331 {
00332 bool success = true;
00333 if (! registered)
00334 {
00335
00336 success &= Chroma::TheHadronContractFactory::Instance().registerObject(string("stoch_diagonal_gamma_condensates"),
00337 mesStochCondCont);
00338
00339 registered = true;
00340 }
00341 return success;
00342 }
00343
00344 }
00345
00346 }