00001
00002
00003
00004
00005
00006
00007 #include "handle.h"
00008 #include "meas/inline/hadron/inline_prop_3pt_w.h"
00009 #include "meas/inline/abs_inline_measurement_factory.h"
00010 #include "meas/smear/quark_smearing_factory.h"
00011 #include "meas/smear/quark_smearing_aggregate.h"
00012 #include "meas/smear/displacement.h"
00013 #include "meas/sources/source_smearing_aggregate.h"
00014 #include "meas/sources/source_smearing_factory.h"
00015 #include "meas/sources/dilutezN_source_const.h"
00016 #include "meas/sources/zN_src.h"
00017 #include "meas/sinks/sink_smearing_aggregate.h"
00018 #include "meas/sinks/sink_smearing_factory.h"
00019 #include "meas/hadron/barspinmat_w.h"
00020 #include "meas/hadron/baryon_operator_aggregate_w.h"
00021 #include "meas/hadron/baryon_operator_factory_w.h"
00022 #include "meas/hadron/dilution_scheme_aggregate.h"
00023 #include "meas/hadron/dilution_scheme_factory.h"
00024 #include "meas/glue/mesplq.h"
00025 #include "util/ft/sftmom.h"
00026 #include "util/info/proginfo.h"
00027 #include "meas/inline/make_xml_file.h"
00028 #include "util/info/unique_id.h"
00029 #include "util/ferm/transf.h"
00030 #include "meas/inline/io/named_objmap.h"
00031
00032 namespace Chroma{
00033 namespace InlineProp3ptEnv{
00034 namespace{
00035 AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
00036 const std::string& path)
00037 {
00038 return new InlineMeas(Params(xml_in, path));
00039 }
00040
00041
00042 bool registered = false;
00043 }
00044
00045 const std::string name = "PROPAGATOR_3PT";
00046
00047
00048 bool registerAll()
00049 {
00050 bool success = true;
00051 if (! registered)
00052 {
00053
00054 success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
00055 registered = true;
00056 }
00057 return success;
00058 }
00059
00060 void read(XMLReader& xml, const string& path, Params::Operator_t& op){
00061 XMLReader paramtop(xml, path);
00062
00063 read(paramtop, "gamma", op.gamma);
00064 read(paramtop, "p", op.p);
00065 read(paramtop, "t", op.t);
00066 if(paramtop.count("factor")>0)
00067 read(paramtop, "factor", op.f);
00068 else
00069 op.f = 1.0 ;
00070 }
00071
00072
00073 void write(XMLWriter& xml, const string& path, const Params::Operator_t& op){
00074 push(xml, path);
00075
00076 write(xml, "p", op.p);
00077 write(xml, "t", op.t);
00078 write(xml, "gamma", op.gamma);
00079 write(xml, "factor", op.f);
00080
00081 pop(xml);
00082 }
00083
00084
00085 void read(XMLReader& xml, const string& path, Params::Param_t& param){
00086 XMLReader paramtop(xml, path);
00087
00088 int version;
00089 read(paramtop, "version", version);
00090
00091 switch (version)
00092 {
00093 case 1:
00094
00095 read(paramtop,"op",param.op);
00096 param.chi = readXMLArrayGroup(paramtop, "Quarks", "DilutionType");
00097
00098 break;
00099
00100 default :
00101
00102
00103 QDPIO::cerr << "Input parameter version " << version << " unsupported." << endl;
00104 QDP_abort(1);
00105 }
00106
00107
00108 }
00109
00110
00111
00112 void write(XMLWriter& xml, const string& path, const Params::Param_t& param){
00113 push(xml, path);
00114
00115 int version = 1;
00116
00117 write(xml, "version", version);
00118 write(xml, "op", param.op);
00119
00120 push(xml,"Quarks");
00121 for( int t(0);t<param.chi.size();t++){
00122 push(xml,"elem");
00123 xml<<param.chi[t].xml;
00124 pop(xml);
00125 }
00126 pop(xml);
00127
00128 pop(xml);
00129 }
00130
00131
00132
00133 void read(XMLReader& xml, const string& path, Params::NamedObject_t& input)
00134 {
00135 XMLReader inputtop(xml, path);
00136
00137 read(inputtop, "gauge_id", input.gauge_id);
00138 read(inputtop, "prop_id", input.prop_id);
00139 read(inputtop, "prop3pt_id", input.prop3pt_id);
00140 }
00141
00142
00143 void write(XMLWriter& xml, const string& path, const Params::NamedObject_t& input){
00144 push(xml, path);
00145
00146 write(xml, "gauge_id", input.gauge_id);
00147 write(xml, "prop_id", input.prop_id);
00148 write(xml, "prop3pt_id", input.prop3pt_id);
00149 pop(xml);
00150 }
00151
00152
00153
00154 Params::Params(){
00155 frequency = 0;
00156 param.op.gamma = 0 ;
00157 param.op.f = 1.0 ;
00158 }
00159
00160 Params::Params(XMLReader& xml_in, const std::string& path)
00161 {
00162 try
00163 {
00164 XMLReader paramtop(xml_in, path);
00165
00166 if (paramtop.count("Frequency") == 1)
00167 read(paramtop, "Frequency", frequency);
00168 else
00169 frequency = 1;
00170
00171
00172 read(paramtop, "Param", param);
00173
00174
00175 read(paramtop, "NamedObject", named_obj);
00176
00177
00178 if (paramtop.count("xml_file") != 0)
00179 {
00180 read(paramtop, "xml_file", xml_file);
00181 }
00182 }
00183 catch(const std::string& e)
00184 {
00185 QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << endl;
00186 QDP_abort(1);
00187 }
00188 }
00189
00190
00191 void Params::write(XMLWriter& xml_out, const std::string& path)
00192 {
00193 push(xml_out, path);
00194
00195
00196 InlineProp3ptEnv::write(xml_out, "Param", param);
00197
00198
00199 InlineProp3ptEnv::write(xml_out, "NamedObject", named_obj);
00200
00201 pop(xml_out);
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211 void InlineMeas::operator()(unsigned long update_no,
00212 XMLWriter& xml_out)
00213 {
00214
00215 if (params.xml_file != ""){
00216 string xml_file = makeXMLFileName(params.xml_file, update_no);
00217
00218 push(xml_out, "propagator_3pt");
00219 write(xml_out, "update_no", update_no);
00220 write(xml_out, "xml_file", xml_file);
00221 pop(xml_out);
00222
00223 XMLFileWriter xml(xml_file);
00224 func(update_no, xml);
00225 }
00226 else{
00227 func(update_no, xml_out);
00228 }
00229 }
00230
00231
00232
00233
00234
00235
00236 void InlineMeas::func(unsigned long update_no,
00237 XMLWriter& xml_out)
00238 {
00239 START_CODE();
00240
00241 StopWatch snoop;
00242 snoop.reset();
00243 snoop.start();
00244
00245
00246 XMLBufferWriter gauge_xml;
00247 try
00248 {
00249 TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00250 TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
00251 }
00252 catch( std::bad_cast )
00253 {
00254 QDPIO::cerr << InlineProp3ptEnv::name << ": caught dynamic cast error"
00255 << endl;
00256 QDP_abort(1);
00257 }
00258 catch (const string& e)
00259 {
00260 QDPIO::cerr << name << ": map call failed: " << e
00261 << endl;
00262 QDP_abort(1);
00263 }
00264 const multi1d<LatticeColorMatrix>& u =
00265 TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00266
00267 push(xml_out, "prop_3pt");
00268 write(xml_out, "update_no", update_no);
00269
00270 QDPIO::cout << name << ": Propagator for 3pt functions" << endl;
00271
00272 proginfo(xml_out);
00273
00274
00275 params.write(xml_out, "Input");
00276
00277
00278 write(xml_out, "Config_info", gauge_xml);
00279
00280 push(xml_out, "Output_version");
00281 write(xml_out, "out_version", 1);
00282 pop(xml_out);
00283
00284
00285
00286 MesPlq(xml_out, "Observables", u);
00287
00288
00289 Seed ran_seed;
00290 QDP::RNG::savern(ran_seed);
00291
00292
00293
00294
00295 StopWatch swatch;
00296 swatch.reset();
00297 swatch.start();
00298
00299 int N_quarks = params.param.chi.size() ;
00300
00301 multi1d< Handle< DilutionScheme<LatticeFermion> > > quarks(N_quarks);
00302
00303 try{
00304
00305 for(int n(0); n < params.param.chi.size(); ++n){
00306 const GroupXML_t& dil_xml = params.param.chi[n];
00307 std::istringstream xml_d(dil_xml.xml);
00308 XMLReader diltop(xml_d);
00309 QDPIO::cout << "Dilution type = " << dil_xml.id << endl;
00310 quarks[n] =
00311 TheFermDilutionSchemeFactory::Instance().createObject(dil_xml.id,
00312 diltop,
00313 dil_xml.path);
00314 }
00315 }
00316 catch(const std::string& e){
00317 QDPIO::cerr << name << ": Caught Exception constructing dilution scheme: " << e << endl;
00318 QDP_abort(1);
00319 }
00320
00321
00322
00323
00324
00325
00326
00327 for (int n = 1 ; n < N_quarks ; ++n){
00328 if (quarks[0]->getCfgInfo() != quarks[n]->getCfgInfo()){
00329 QDPIO::cerr << name << " : Quarks do not contain the same cfg info";
00330 QDPIO::cerr << ", quark "<< n << endl;
00331 QDP_abort(1);
00332 }
00333 }
00334
00335
00336
00337
00338 {
00339 std::string cfgInfo;
00340
00341
00342 XMLBufferWriter top;
00343 write(top, "Config_info", gauge_xml);
00344 XMLReader from(top);
00345 XMLReader from2(from, "/Config_info");
00346 std::ostringstream os;
00347 from2.print(os);
00348
00349 cfgInfo = os.str();
00350
00351 if (cfgInfo != quarks[0]->getCfgInfo()){
00352 QDPIO::cerr << name << " : Quarks do not contain the same";
00353 QDPIO::cerr << " cfg info as the gauge field." ;
00354 QDPIO::cerr << "gauge: XX"<<cfgInfo<<"XX quarks: XX" ;
00355 QDPIO::cerr << quarks[0]->getCfgInfo()<<"XX"<< endl;
00356 QDP_abort(1);
00357 }
00358 }
00359
00360
00361 int decay_dir = quarks[0]->getDecayDir();
00362
00363
00364
00365 int mom2(0);
00366 for(int i(0);i<Nd-1;i++)
00367 mom2 += params.param.op.p[i]*params.param.op.p[i] ;
00368
00369
00370 SftMom phases(mom2, false, decay_dir);
00371
00372
00373
00374 for(int n = 1 ; n < quarks.size(); ++n){
00375 if(toBool(quarks[n]->getSeed()==quarks[0]->getSeed())){
00376 QDPIO::cerr << name << ": error, quark seeds are the same" << endl;
00377 QDP_abort(1);
00378 }
00379
00380 if(toBool(quarks[n]->getDecayDir()!=quarks[0]->getDecayDir())){
00381 QDPIO::cerr<<name<< ": error, quark decay dirs do not match" <<endl;
00382 QDP_abort(1);
00383 }
00384 }
00385
00386
00387 ChromaProp_t prop_header;
00388 PropSourceConst_t source_header;
00389 QDPIO::cout << "Attempt to read propagator info" << endl;
00390 try
00391 {
00392
00393 LatticePropagator& tt_prop =
00394 TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_id);
00395
00396
00397
00398 XMLReader prop_file_xml, prop_record_xml;
00399 TheNamedObjMap::Instance().get(params.named_obj.prop_id).getFileXML(prop_file_xml);
00400 TheNamedObjMap::Instance().get(params.named_obj.prop_id).getRecordXML(prop_record_xml);
00401
00402
00403 {
00404 read(prop_record_xml, "/Propagator/ForwardProp", prop_header);
00405 read(prop_record_xml, "/Propagator/PropSource", source_header);
00406 }
00407 }
00408 catch (std::bad_cast){
00409 QDPIO::cerr << name << ": caught dynamic cast error" ;
00410 QDPIO::cerr << endl;
00411 QDP_abort(1);
00412 }
00413 catch (const string& e){
00414 QDPIO::cerr << name << ": error extracting prop_header: " << e << endl;
00415 QDP_abort(1);
00416 }
00417 const LatticePropagator& prop =
00418 TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop_id);
00419
00420 QDPIO::cout << "Propagator successfully read and parsed" << endl;
00421
00422
00423 try{
00424 TheNamedObjMap::Instance().create<LatticePropagator>(params.named_obj.prop3pt_id);
00425 }
00426 catch (std::bad_cast){
00427 QDPIO::cerr << name << ": caught dynamic cast error" << endl;
00428 QDP_abort(1);
00429 }
00430 catch (const string& e){
00431 QDPIO::cerr << name << ": error creating prop: " << e << endl;
00432 QDP_abort(1);
00433 }
00434
00435
00436 LatticePropagator& prop_3pt =
00437 TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.prop3pt_id);
00438
00439
00440
00441
00442
00443 write(xml_out, "op", params.param.op);
00444
00445 {
00446 XMLBufferWriter top;
00447 push(top, "tt");
00448 write(top, "Operator", params.param.op);
00449
00450 pop(top);
00451 XMLReader from(top);
00452 XMLReader from2(from, "/tt/Operator");
00453 std::ostringstream os;
00454 QDPIO::cout<<name<<" Operator: "<<endl ;
00455 from2.print(os);
00456 QDPIO::cout<<os.str()<<endl ;
00457
00458 QDPIO::cout<<name<<" End Operator "<<endl ;
00459 }
00460
00461 LatticePropagator tmp_prop = Gamma(params.param.op.gamma)*prop ;
00462 tmp_prop = params.param.op.f*tmp_prop;
00463
00464 LatticeFermion ferm_3pt = zero ;
00465 LatticeFermion ferm ;
00466 LatticeComplex phase = phases[phases.momToNum(params.param.op.p)];
00467 int t0 = params.param.op.t;
00468 for(int s(0);s<Ns;s++)
00469 for(int c(0);c<Nc;c++){
00470 QDPIO::cout<<" Doing quark color and spin: "<<c<<" "<<s <<endl ;
00471 PropToFerm(tmp_prop,ferm,c,s) ;
00472 ferm_3pt = zero;
00473 int count(0);
00474 for(int n(0);n<quarks.size();n++){
00475 int i_t0(-100) ;
00476 for (int tt(0) ; tt < quarks[n]->getNumTimeSlices() ; ++tt)
00477 if(quarks[n]->getT0(tt) == t0)
00478 i_t0 = tt;
00479 if(i_t0!=-100){
00480 count++;
00481
00482 QDPIO::cout<<" Doing quark: "<<n <<endl ;
00483 QDPIO::cout<<" quark: "<<n <<" has "<<quarks[n]->getDilSize(i_t0);
00484 QDPIO::cout<<" dilutions on time slice "<<t0<<endl ;
00485 for(int i = 0 ; i < quarks[n]->getDilSize(i_t0) ; ++i){
00486 QDPIO::cout<<" Doing dilution : "<<i<<endl ;
00487 LatticeComplex cc =
00488 phase*localInnerProduct(quarks[n]->dilutedSource(i_t0,i),ferm);
00489 ferm_3pt += sum(cc,phases.getSet()[t0])*quarks[n]->dilutedSolution(i_t0,i);
00490 }
00491 QDPIO::cout<<" Done with dilutions for quark: "<<n <<endl ;
00492 }
00493 }
00494 if(count==0){
00495 QDPIO::cerr<<name<< ": error, no appropriate time slice found" <<endl;
00496 QDP_abort(1);
00497
00498 }
00499 ferm_3pt = ferm_3pt/Double(count) ;
00500 FermToProp(ferm_3pt,prop_3pt,c,s);
00501 QDPIO::cout<<" Done with quark color and spin: "<<c<<" "<<s <<endl ;
00502 }
00503
00504
00505
00506 {
00507
00508 SftMom phases(0, true, Nd-1);
00509
00510 multi1d<Double> corr = sumMulti(localNorm2(prop_3pt),phases.getSet());
00511
00512 push(xml_out, "Prop_correlator");
00513 write(xml_out, "prop_corr", corr);
00514 pop(xml_out);
00515 }
00516
00517
00518
00519 try
00520 {
00521 QDPIO::cout << "Start writing propagator info" << endl;
00522
00523 XMLBufferWriter file_xml;
00524 push(file_xml, "propagator");
00525 write(file_xml, "id", uniqueId());
00526 pop(file_xml);
00527
00528 XMLBufferWriter record_xml;
00529 push(record_xml , "Propagator");
00530 write(record_xml, "ForwardProp", prop_header);
00531 write(record_xml, "PropSource", source_header);
00532 write(record_xml, "Config_info", gauge_xml);
00533
00534 write(record_xml, "Operator",params.param.op);
00535 pop(record_xml);
00536
00537 TheNamedObjMap::Instance().get(params.named_obj.prop3pt_id).setFileXML(file_xml);
00538 TheNamedObjMap::Instance().get(params.named_obj.prop3pt_id).setRecordXML(record_xml);
00539
00540 QDPIO::cout << "Propagator successfully updated" << endl;
00541 }
00542 catch (std::bad_cast){
00543 QDPIO::cerr << name << ": caught dynamic cast error" << endl;
00544 QDP_abort(1);
00545 }
00546 catch (const string& e){
00547 QDPIO::cerr << name << ": error extracting prop_header: " << e << endl;
00548 QDP_abort(1);
00549 }
00550
00551
00552
00553 pop(xml_out);
00554
00555 snoop.stop();
00556 QDPIO::cout << name << ": total time = "
00557 << snoop.getTimeInSeconds()
00558 << " secs" << endl;
00559
00560 QDPIO::cout << name << ": ran successfully" << endl;
00561
00562 END_CODE();
00563 }
00564 }
00565 }