00001
00002
00003
00004
00005
00006
00007 #include "handle.h"
00008 #include "meas/hadron/dilution_quark_source_const_w.h"
00009 #include "meas/hadron/dilution_scheme_factory.h"
00010 #include "meas/inline/io/named_objmap.h"
00011 #include "meas/sources/dilutezN_source_const.h"
00012 #include "meas/sources/zN_src.h"
00013 #include "util/ft/sftmom.h"
00014
00015
00016 namespace Chroma
00017 {
00018
00019
00020 void read(XMLReader& xml, const string& path, DilutionQuarkSourceConstEnv::Params& param)
00021 {
00022 DilutionQuarkSourceConstEnv::Params tmp(xml, path);
00023 param = tmp;
00024 }
00025
00026
00027
00028 void write(XMLWriter& xml, const string& path, const DilutionQuarkSourceConstEnv::Params& param)
00029 {
00030 param.writeXML(xml, path);
00031 }
00032
00033
00034
00035
00036
00037
00038
00039 namespace DilutionQuarkSourceConstEnv
00040 {
00041
00042 void read(XMLReader& xml, const string& path, DilutionQuarkSourceConstEnv::Params::QuarkFiles_t::TimeSliceFiles_t& input)
00043 {
00044 XMLReader inputtop(xml, path);
00045
00046 read(inputtop, "DilutionFiles", input.dilution_files);
00047 }
00048
00049
00050 void read(XMLReader& xml, const string& path, DilutionQuarkSourceConstEnv::Params::QuarkFiles_t& input)
00051 {
00052 XMLReader inputtop(xml, path);
00053
00054 read(inputtop, "TimeSliceFiles", input.timeslice_files);
00055 }
00056
00057
00058
00059 void write(XMLWriter& xml, const string& path, const DilutionQuarkSourceConstEnv::Params::QuarkFiles_t::TimeSliceFiles_t& input)
00060 {
00061 push(xml, path);
00062 write(xml, "dilution_files", input.dilution_files);
00063 pop(xml);
00064 }
00065
00066
00067 void write(XMLWriter& xml, const string& path, const DilutionQuarkSourceConstEnv::Params::QuarkFiles_t& input)
00068 {
00069 push(xml, path);
00070 write(xml, "timeslice_files", input.timeslice_files);
00071 pop(xml);
00072 }
00073
00074
00075
00076 Params::Params()
00077 {
00078 UseSourceHeaderSmearing = false ;
00079 }
00080
00081
00082
00083 Params::Params(XMLReader& xml, const string& path)
00084 {
00085 XMLReader paramtop(xml, path);
00086
00087 int version;
00088 read(paramtop, "version", version);
00089
00090 switch (version)
00091 {
00092 case 1:
00093
00094 break;
00095
00096 default :
00097
00098
00099 QDPIO::cerr << "Input parameter version " << version << " unsupported." << endl;
00100 QDP_abort(1);
00101 }
00102
00103 UseSourceHeaderSmearing = true ;
00104 read(paramtop, "QuarkFiles", quark_files);
00105 if(paramtop.count("UseSourceHeaderSmearing")!=0)
00106 read(paramtop, "UseSourceHeaderSmearing", UseSourceHeaderSmearing);
00107 }
00108
00109
00110
00111
00112 void Params::writeXML(XMLWriter& xml, const string& path) const
00113 {
00114 push(xml, path);
00115
00116 int version = 1;
00117 write(xml, "version", version);
00118 write(xml, "QuarkFiles", quark_files);
00119 if(!UseSourceHeaderSmearing)
00120 write(xml, "UseSourceHeaderSmearing", UseSourceHeaderSmearing);
00121 pop(xml);
00122 }
00123
00124
00125 namespace
00126 {
00127 DilutionScheme<LatticeFermion>* createScheme(XMLReader& xml_in,
00128 const std::string& path)
00129 {
00130 return new ConstDilutionScheme(Params(xml_in, path));
00131 }
00132
00133
00134 bool registered = false;
00135 }
00136
00137 const std::string name = "DILUTION_QUARK_SOURCE_CONST_FERM";
00138
00139
00140 bool registerAll()
00141 {
00142 bool success = true;
00143
00144 if (! registered)
00145 {
00146 success &= TheFermDilutionSchemeFactory::Instance().registerObject(name, createScheme);
00147 registered = true;
00148 }
00149 return success;
00150 }
00151
00152
00153
00154 bool operator!= (const QuarkSourceSolutions_t::TimeSlices_t::Dilutions_t & dilA,
00155 const QuarkSourceSolutions_t::TimeSlices_t::Dilutions_t & dilB)
00156 {
00157 bool val = false;
00158
00159
00160 Seed seedA, seedB;
00161
00162 std::istringstream xml_a(dilA.source_header.source.xml);
00163 XMLReader rdr_a(xml_a);
00164
00165 std::istringstream xml_b(dilB.source_header.source.xml);
00166 XMLReader rdr_b(xml_b);
00167
00168
00169 read(rdr_a, "/Source/ran_seed" , seedA);
00170 read(rdr_b, "/Source/ran_seed" , seedB);
00171
00172 val |= toBool(seedA != seedB);
00173 if (val)
00174 {
00175 QDPIO::cerr<< "random seeds are not the same." <<endl;
00176 }
00177
00178
00179
00180 multi1d<int> mask_sizeA, mask_sizeB, cmaskA, cmaskB, smaskA, smaskB;
00181 multi1d< multi1d<int> > maskA, maskB;
00182
00183 read(rdr_a, "/Source/spatial_mask_size" , mask_sizeA);
00184 read(rdr_b, "/Source/spatial_mask_size" , mask_sizeB);
00185 val |= toBool(mask_sizeA != mask_sizeB);
00186 if (val)
00187 {
00188 QDPIO::cerr<< "spatial mask sizes are not the same." <<endl;
00189 }
00190
00191 read(rdr_a, "/Source/spatial_mask" , maskA);
00192 read(rdr_b, "/Source/spatial_mask" , maskB);
00193 val |= toBool(maskA != maskB);
00194 if (val)
00195 {
00196 QDPIO::cerr<< "spatial masks are not the same." <<endl;
00197 }
00198
00199 read(rdr_a, "/Source/color_mask" , cmaskA);
00200 read(rdr_b, "/Source/color_mask" , cmaskB);
00201 val |= toBool(maskA != maskB);
00202 if (val)
00203 {
00204 QDPIO::cerr<< "color masks are not the same." <<endl;
00205 }
00206
00207 read(rdr_a, "/Source/spin_mask" , smaskA);
00208 read(rdr_b, "/Source/spin_mask" , smaskB);
00209 val |= toBool(maskA != maskB);
00210 if (val)
00211 {
00212 QDPIO::cerr<< "spin masks are not the same." <<endl;
00213 }
00214
00215 return val;
00216
00217 }
00218
00219
00220 void ConstDilutionScheme::init()
00221 {
00222 START_CODE();
00223
00224 StopWatch snoop;
00225 snoop.reset();
00226 snoop.start();
00227
00228
00229
00230
00231 StopWatch swatch;
00232 swatch.reset();
00233 swatch.start();
00234
00235
00236 int N;
00237
00238 try
00239 {
00240
00241 bool initq = false;
00242 Real kappa;
00243
00244 QDPIO::cout << "Attempt to read solutions " << endl;
00245
00246 quark.time_slices.resize( params.quark_files.timeslice_files.size() );
00247
00248 QDPIO::cout<< "time_slices.size = " << quark.time_slices.size() << endl;
00249
00250 for (int t0 = 0 ; t0 < quark.time_slices.size() ; ++t0 )
00251 {
00252 quark.time_slices[t0].dilutions.resize(
00253 params.quark_files.timeslice_files[t0].dilution_files.size() );
00254
00255 QDPIO::cout << "dilutions.size = " <<
00256 quark.time_slices[t0].dilutions.size() << endl;
00257
00258 int time;
00259
00260 for(int dil = 0; dil < quark.time_slices[t0].dilutions.size(); ++dil)
00261 {
00262 quark.time_slices[t0].dilutions[dil].soln_file =
00263 params.quark_files.timeslice_files[t0].dilution_files[dil];
00264
00265 XMLReader file_xml, record_xml, record_xml_source;
00266
00267 QDPIO::cout << "reading file = " <<
00268 quark.time_slices[t0].dilutions[dil].soln_file << endl;
00269
00270 QDPFileReader from(file_xml,
00271 quark.time_slices[t0].dilutions[dil].soln_file, QDPIO_SERIAL);
00272
00273
00274 LatticeFermion junk;
00275 read(from, record_xml, junk);
00276 close(from);
00277
00278 read(record_xml, "/Propagator/PropSource",
00279 quark.time_slices[t0].dilutions[dil].source_header);
00280 read(record_xml, "/Propagator/ForwardProp",
00281 quark.time_slices[t0].dilutions[dil].prop_header);
00282
00283
00284 int currN;
00285 read(record_xml, "/Propagator/PropSource/Source/N", currN);
00286
00287 if (!initq)
00288 {
00289 read(record_xml, "/Propagator/PropSource/Source/ran_seed",
00290 quark.seed);
00291
00292 read(record_xml, "/Propagator/PropSource/Source/N", N);
00293 quark.decay_dir =
00294 quark.time_slices[t0].dilutions[dil].source_header.j_decay;
00295
00296
00297
00298 std::istringstream xml_k(
00299 quark.time_slices[t0].dilutions[dil].prop_header.fermact.xml);
00300 XMLReader proptop(xml_k);
00301
00302 if ( toBool(proptop.count("/FermionAction/Kappa") != 0) )
00303 {
00304 read(proptop, "/FermionAction/Kappa", kappa);
00305 }
00306 else
00307 {
00308 Real mass;
00309 read(proptop, "/FermionAction/Mass", mass);
00310 kappa = massToKappa(mass);
00311 }
00312
00313
00314 XMLReader xml_tmp(record_xml, "/Propagator/Config_info");
00315 std::ostringstream os;
00316 xml_tmp.print(os);
00317
00318 cfgInfo = os.str();
00319
00320 initq = true;
00321 }
00322
00323 Real kappa2;
00324 std::istringstream xml_k2(
00325 quark.time_slices[t0].dilutions[dil].prop_header.fermact.xml);
00326 XMLReader proptop2(xml_k2);
00327
00328
00329 if ( toBool(proptop2.count("/FermionAction/Kappa") != 0) )
00330 {
00331 read(proptop2, "/FermionAction/Kappa", kappa2);
00332 }
00333 else
00334 {
00335 Real mass;
00336 read(proptop2, "/FermionAction/Mass", mass);
00337 kappa2 = massToKappa(mass);
00338 }
00339
00340 if ( toBool(kappa != kappa2) )
00341 {
00342 QDPIO::cerr << "Kappa is not the same for all dilutions: t0=" <<
00343 t0 << " dil= "<< dil << " kappa2 = "<< kappa2 << endl;
00344
00345 QDP_abort(1);
00346 }
00347
00348 if (currN != N)
00349 {
00350 QDPIO::cerr << "N is not the same for all dilutions: t0 = " <<
00351 t0 << " dil = " << dil << endl;
00352 }
00353
00354
00355
00356
00357 if (dil == 0)
00358 {
00359 time = quark.time_slices[t0].dilutions[dil].source_header.t_source;
00360 }
00361
00362 if (time != quark.time_slices[t0].dilutions[dil].source_header.t_source)
00363 {
00364 QDPIO::cerr << "t0's DO NOT MATCH FOR ALL DILUTIONS ON TIME SLICE "
00365 << t0 << endl;
00366
00367 QDP_abort(1);
00368 }
00369
00370
00371
00372 if ( quark.time_slices[t0].dilutions[dil] !=
00373 quark.time_slices[0].dilutions[dil] )
00374 {
00375 QDPIO::cerr << "Dilutions do not match on time slice " <<
00376 t0 << " dil = "<< dil<< endl;
00377
00378 QDP_abort(1);
00379 }
00380
00381
00382 std::string currCfgInfo;
00383 {
00384 XMLReader xml_tmp(record_xml, "/Propagator/Config_info");
00385 std::ostringstream os;
00386 xml_tmp.print(os);
00387
00388 currCfgInfo = os.str();
00389 }
00390
00391 if (cfgInfo != currCfgInfo)
00392 {
00393 QDPIO::cerr << "Cfgs do not match on time slice " <<
00394 t0 << " dil = "<< dil<< endl;
00395
00396 QDP_abort(1);
00397 }
00398
00399 }
00400
00401 quark.time_slices[t0].t0 = time;
00402
00403 }
00404
00405
00406 #if 0
00407 #warning "Turned off the sanity check that the dilutions summed to a unity operator on a time-slice"
00408
00409
00410
00411
00412 LatticeFermion quark_noise;
00413 QDP::RNG::setrn(quark.seed);
00414 zN_src(quark_noise, N);
00415
00416
00417 for (int dil = 0 ; dil < quark.time_slices[0].dilutions.size() ; ++dil)
00418 {
00419 LatticeFermion source = dilutedSource(0, dil);
00420 quark_noise -= source;
00421 }
00422
00423 SftMom phases_nomom(0, true,
00424 quark.time_slices[0].dilutions[0].source_header.j_decay);
00425
00426 Double dcnt = norm2(quark_noise,
00427 phases_nomom.getSet()[quark.time_slices[0].t0] );
00428
00429 if (toDouble(dcnt) != 0.0)
00430 {
00431 QDPIO::cerr << "Not a complete dilution scheme per timeslice" <<
00432 endl;
00433
00434 QDP_abort(1);
00435 }
00436 #endif
00437
00438 }
00439 catch (const string& e)
00440 {
00441 QDPIO::cerr << "Error extracting headers: " << e << endl;
00442 QDP_abort(1);
00443 }
00444 swatch.stop();
00445
00446 QDPIO::cout << "Source and solution headers successfully read: time = "
00447 << swatch.getTimeInSeconds()
00448 << " secs" << endl;
00449
00450
00451 END_CODE();
00452 }
00453
00454
00455
00456
00457
00458
00459 LatticeFermion ConstDilutionScheme::dilutedSource(int t0, int dil ) const
00460 {
00461 const QuarkSourceSolutions_t::TimeSlices_t::Dilutions_t &qq =
00462 quark.time_slices[t0].dilutions[dil];
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 multi1d<LatticeColorMatrix> dummy;
00486
00487
00488
00489 QDPIO::cout << "Source_id = " << qq.source_header.source.id << endl;
00490 QDPIO::cout << "Source = XX" << qq.source_header.source.xml << "XX" << endl;
00491
00492 std::istringstream xml_s(qq.source_header.source.xml);
00493 XMLReader sourcetop(xml_s);
00494
00495 if (qq.source_header.source.id != DiluteZNQuarkSourceConstEnv::getName())
00496 {
00497 QDPIO::cerr << "Expected source_type = " << DiluteZNQuarkSourceConstEnv::getName() << endl;
00498 QDP_abort(1);
00499 }
00500
00501
00502 DiluteZNQuarkSourceConstEnv::Params srcParams(sourcetop,
00503 qq.source_header.source.path);
00504
00505 if(!params.UseSourceHeaderSmearing){
00506 QDPIO::cout<<name
00507 <<": Will NOT use Smearing/displacement options specified in the header\n"<<endl ;
00508 srcParams.smear = false ;
00509 }
00510 else{
00511 QDPIO::cout<<name<<": Smearing/displacement not implemented\n"<<endl ;
00512 QDPIO::cout<<name
00513 <<": Will NOT use Smearing/displacement options specified in the header\n"<<endl ;
00514 srcParams.smear = false ;
00515 }
00516
00517 DiluteZNQuarkSourceConstEnv::SourceConst<LatticeFermion> srcConst(srcParams);
00518
00519 QDP::RNG::setrn( quark.seed );
00520
00521
00522 LatticeFermion sour = srcConst(dummy);
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 return sour;
00539
00540 }
00541
00542
00543 LatticeFermion ConstDilutionScheme::dilutedSolution(int t0, int dil) const
00544 {
00545
00546 const std::string & filename = quark.time_slices[t0].dilutions[dil].soln_file;
00547
00548 LatticeFermion soln;
00549
00550 XMLReader file_xml, record_xml;
00551
00552 QDPIO::cout << "reading file = " << filename << endl;
00553 QDPFileReader from(file_xml, filename, QDPIO_SERIAL);
00554
00555 read(from, record_xml, soln);
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570 return soln;
00571 }
00572
00573
00574
00575 }
00576
00577 }