00001
00002
00003
00004
00005
00006
00007
00008 #include "handle.h"
00009 #include "meas/inline/hadron/inline_genprop_matelem_colorvec_w.h"
00010 #include "meas/inline/abs_inline_measurement_factory.h"
00011 #include "meas/smear/link_smearing_aggregate.h"
00012 #include "meas/smear/link_smearing_factory.h"
00013 #include "meas/smear/displace.h"
00014 #include "meas/glue/mesplq.h"
00015 #include "util/ferm/map_obj.h"
00016 #include "util/ferm/key_val_db.h"
00017 #include "util/ferm/key_prop_colorvec.h"
00018 #include "util/ft/sftmom.h"
00019 #include "util/info/proginfo.h"
00020 #include "meas/inline/make_xml_file.h"
00021
00022 #include "meas/inline/io/named_objmap.h"
00023
00024 namespace Chroma
00025 {
00026
00027
00028
00029
00030
00031 namespace InlineGenPropMatElemColorVecEnv
00032 {
00033
00034 void read(XMLReader& xml, const string& path, Params::Param_t::DispGamma_t& param)
00035 {
00036 XMLReader paramtop(xml, path);
00037
00038 read(paramtop, "gamma", param.gamma);
00039 read(paramtop, "displacement", param.displacement);
00040 }
00041
00042
00043 void read(XMLReader& xml, const string& path, Params::Param_t& param)
00044 {
00045 XMLReader paramtop(xml, path);
00046
00047 int version;
00048 read(paramtop, "version", version);
00049
00050 switch (version)
00051 {
00052 case 1:
00053 param.restrict_plateau = false;
00054 param.avg_equiv_mom = false;
00055 break;
00056
00057 case 2:
00058 read(paramtop, "restrict_plateau", param.restrict_plateau);
00059 read(paramtop, "avg_equiv_mom", param.avg_equiv_mom);
00060 break;
00061
00062 default :
00063 QDPIO::cerr << "Input parameter version " << version << " unsupported." << endl;
00064 QDP_abort(1);
00065 }
00066
00067 read(paramtop, "t_source", param.t_source);
00068 read(paramtop, "t_sink", param.t_sink);
00069 read(paramtop, "mom2_max", param.mom2_max);
00070 read(paramtop, "mom_offset", param.mom_offset);
00071 read(paramtop, "displacement_length", param.displacement_length);
00072 read(paramtop, "DisplacementGammaList", param.disp_gamma_list);
00073 read(paramtop, "num_vecs", param.num_vecs);
00074 read(paramtop, "decay_dir", param.decay_dir);
00075 read(paramtop, "mass_label", param.mass_label);
00076
00077 param.link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
00078 }
00079
00080
00081
00082 void write(XMLWriter& xml, const string& path, const Params::Param_t::DispGamma_t& param)
00083 {
00084 push(xml, path);
00085
00086 write(xml, "gamma", param.gamma);
00087 write(xml, "displacement", param.displacement);
00088
00089 pop(xml);
00090 }
00091
00092
00093 void write(XMLWriter& xml, const string& path, const Params::Param_t& param)
00094 {
00095 push(xml, path);
00096
00097 int version = 2;
00098
00099 write(xml, "version", version);
00100 write(xml, "restrict_plateau", param.restrict_plateau);
00101 write(xml, "avg_equiv_mom", param.avg_equiv_mom);
00102 write(xml, "t_source", param.t_source);
00103 write(xml, "t_sink", param.t_sink);
00104 write(xml, "mom_offset", param.mom_offset);
00105 write(xml, "mom2_max", param.mom2_max);
00106 write(xml, "displacement_length", param.displacement_length);
00107 write(xml, "DisplacementGammaList", param.disp_gamma_list);
00108 write(xml, "num_vecs", param.num_vecs);
00109 write(xml, "decay_dir", param.decay_dir);
00110 write(xml, "mass_label", param.mass_label);
00111
00112 xml << param.link_smearing.xml;
00113
00114 pop(xml);
00115 }
00116
00117
00118 void read(XMLReader& xml, const string& path, Params::NamedObject_t& input)
00119 {
00120 XMLReader inputtop(xml, path);
00121
00122 read(inputtop, "gauge_id", input.gauge_id);
00123 read(inputtop, "source_prop_id", input.source_prop_id);
00124 read(inputtop, "sink_prop_id", input.sink_prop_id);
00125 read(inputtop, "genprop_op_file", input.genprop_op_file);
00126 }
00127
00128
00129 void write(XMLWriter& xml, const string& path, const Params::NamedObject_t& input)
00130 {
00131 push(xml, path);
00132
00133 write(xml, "gauge_id", input.gauge_id);
00134 write(xml, "source_prop_id", input.source_prop_id);
00135 write(xml, "sink_prop_id", input.sink_prop_id);
00136 write(xml, "genprop_op_file", input.genprop_op_file);
00137
00138 pop(xml);
00139 }
00140
00141
00142 void write(XMLWriter& xml, const string& path, const Params& param)
00143 {
00144 param.writeXML(xml, path);
00145 }
00146 }
00147
00148
00149 namespace InlineGenPropMatElemColorVecEnv
00150 {
00151
00152 namespace
00153 {
00154 AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
00155 const std::string& path)
00156 {
00157 return new InlineMeas(Params(xml_in, path));
00158 }
00159
00160
00161 bool registered = false;
00162 }
00163
00164 const std::string name = "GENPROP_MATELEM_COLORVEC";
00165
00166
00167 bool registerAll()
00168 {
00169 bool success = true;
00170 if (! registered)
00171 {
00172 success &= LinkSmearingEnv::registerAll();
00173 success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
00174 registered = true;
00175 }
00176 return success;
00177 }
00178
00179
00180
00181
00182 namespace
00183 {
00184 StandardOutputStream& operator<<(StandardOutputStream& os, const multi1d<int>& d)
00185 {
00186 if (d.size() > 0)
00187 {
00188 os << d[0];
00189
00190 for(int i=1; i < d.size(); ++i)
00191 os << " " << d[i];
00192 }
00193
00194 return os;
00195 }
00196 }
00197
00198
00199
00200
00201 Params::Params()
00202 {
00203 frequency = 0;
00204 param.mom2_max = 0;
00205 }
00206
00207 Params::Params(XMLReader& xml_in, const std::string& path)
00208 {
00209 try
00210 {
00211 XMLReader paramtop(xml_in, path);
00212
00213 if (paramtop.count("Frequency") == 1)
00214 read(paramtop, "Frequency", frequency);
00215 else
00216 frequency = 1;
00217
00218
00219 read(paramtop, "Param", param);
00220
00221
00222 read(paramtop, "NamedObject", named_obj);
00223
00224
00225 if (paramtop.count("xml_file") != 0)
00226 {
00227 read(paramtop, "xml_file", xml_file);
00228 }
00229 }
00230 catch(const std::string& e)
00231 {
00232 QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << endl;
00233 QDP_abort(1);
00234 }
00235 }
00236
00237
00238 void
00239 Params::writeXML(XMLWriter& xml_out, const std::string& path) const
00240 {
00241 push(xml_out, path);
00242
00243
00244 write(xml_out, "Param", param);
00245
00246
00247 write(xml_out, "NamedObject", named_obj);
00248
00249 pop(xml_out);
00250 }
00251
00252
00253
00254
00255 struct KeyGenPropElementalOperator_t
00256 {
00257 int t_slice;
00258 int t_source;
00259 int t_sink;
00260 int spin_l;
00261 int spin_r;
00262 int gamma;
00263 multi1d<int> displacement;
00264 multi1d<int> mom;
00265 std::string mass_label;
00266 };
00267
00268
00269 struct ValGenPropElementalOperator_t
00270 {
00271 multi2d<ComplexD> op;
00272 };
00273
00274
00275
00276
00277 struct KeyValGenPropElementalOperator_t
00278 {
00279 SerialDBKey<KeyGenPropElementalOperator_t> key;
00280 SerialDBData<ValGenPropElementalOperator_t> val;
00281 };
00282
00283
00284
00285
00286 void read(BinaryReader& bin, KeyGenPropElementalOperator_t& param)
00287 {
00288 read(bin, param.t_slice);
00289 read(bin, param.t_source);
00290 read(bin, param.t_sink);
00291 read(bin, param.spin_l);
00292 read(bin, param.spin_r);
00293 read(bin, param.gamma);
00294 read(bin, param.displacement);
00295 read(bin, param.mom);
00296 read(bin, param.mass_label, 32);
00297 }
00298
00299
00300 void write(BinaryWriter& bin, const KeyGenPropElementalOperator_t& param)
00301 {
00302 write(bin, param.t_slice);
00303 write(bin, param.t_source);
00304 write(bin, param.t_sink);
00305 write(bin, param.spin_l);
00306 write(bin, param.spin_r);
00307 write(bin, param.gamma);
00308 write(bin, param.displacement);
00309 write(bin, param.mom);
00310 write(bin, param.mass_label);
00311 }
00312
00313
00314
00315
00316 void read(BinaryReader& bin, ValGenPropElementalOperator_t& param)
00317 {
00318 int n;
00319 read(bin, n);
00320 param.op.resize(n,n);
00321
00322 for(int i=0; i < n; ++i)
00323 {
00324 for(int j=0; j < n; ++j)
00325 {
00326 read(bin, param.op(i,j));
00327 }
00328 }
00329 }
00330
00331
00332 void write(BinaryWriter& bin, const ValGenPropElementalOperator_t& param)
00333 {
00334 int n = param.op.size1();
00335 write(bin, n);
00336 for(int i=0; i < n; ++i)
00337 {
00338 for(int j=0; j < n; ++j)
00339 {
00340 write(bin, param.op(i,j));
00341 }
00342 }
00343 }
00344
00345
00346
00347
00348 multi1d<int> normDisp(const multi1d<int>& orig)
00349 {
00350 START_CODE();
00351
00352 multi1d<int> disp;
00353 multi1d<int> empty;
00354 multi1d<int> no_disp(1); no_disp[0] = 0;
00355
00356
00357
00358 if (orig.size() == 1)
00359 {
00360 if (orig == no_disp)
00361 disp = empty;
00362 else
00363 disp = orig;
00364 }
00365 else
00366 {
00367 disp = orig;
00368 }
00369
00370 END_CODE();
00371
00372 return disp;
00373 }
00374
00375
00376
00377
00378 void
00379 InlineMeas::operator()(unsigned long update_no,
00380 XMLWriter& xml_out)
00381 {
00382
00383 if (params.xml_file != "")
00384 {
00385 string xml_file = makeXMLFileName(params.xml_file, update_no);
00386
00387 push(xml_out, "GenPropMatElemColorVec");
00388 write(xml_out, "update_no", update_no);
00389 write(xml_out, "xml_file", xml_file);
00390 pop(xml_out);
00391
00392 XMLFileWriter xml(xml_file);
00393 func(update_no, xml);
00394 }
00395 else
00396 {
00397 func(update_no, xml_out);
00398 }
00399 }
00400
00401
00402
00403 void
00404 InlineMeas::func(unsigned long update_no,
00405 XMLWriter& xml_out)
00406 {
00407 START_CODE();
00408
00409 StopWatch snoop;
00410 snoop.reset();
00411 snoop.start();
00412
00413 StopWatch swiss;
00414
00415 push(xml_out, "GenPropMatElemColorVec");
00416 write(xml_out, "update_no", update_no);
00417
00418 QDPIO::cout << name << ": Generalized propagator color-vector matrix element" << endl;
00419
00420
00421 XMLBufferWriter gauge_xml;
00422 XMLReader source_prop_file_xml, source_prop_record_xml;
00423 XMLReader sink_prop_file_xml, sink_prop_record_xml;
00424 try
00425 {
00426 TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00427 TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
00428
00429 TheNamedObjMap::Instance().getData< MapObject<KeyPropColorVec_t,LatticeFermion> >(params.named_obj.source_prop_id);
00430 TheNamedObjMap::Instance().getData< MapObject<KeyPropColorVec_t,LatticeFermion> >(params.named_obj.sink_prop_id);
00431
00432
00433 TheNamedObjMap::Instance().get(params.named_obj.source_prop_id).getFileXML(source_prop_file_xml);
00434 TheNamedObjMap::Instance().get(params.named_obj.source_prop_id).getRecordXML(source_prop_record_xml);
00435
00436
00437 TheNamedObjMap::Instance().get(params.named_obj.sink_prop_id).getFileXML(sink_prop_file_xml);
00438 TheNamedObjMap::Instance().get(params.named_obj.sink_prop_id).getRecordXML(sink_prop_record_xml);
00439 }
00440 catch( std::bad_cast )
00441 {
00442 QDPIO::cerr << name << ": caught dynamic cast error" << endl;
00443 QDP_abort(1);
00444 }
00445 catch (const string& e)
00446 {
00447 QDPIO::cerr << name << ": map call failed: " << e << endl;
00448 QDP_abort(1);
00449 }
00450
00451 const multi1d<LatticeColorMatrix>& u =
00452 TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00453
00454 const MapObject<KeyPropColorVec_t,LatticeFermion>& source_ferm_map =
00455 TheNamedObjMap::Instance().getData< MapObject<KeyPropColorVec_t,LatticeFermion> >(params.named_obj.source_prop_id);
00456 const MapObject<KeyPropColorVec_t,LatticeFermion>& sink_ferm_map =
00457 TheNamedObjMap::Instance().getData< MapObject<KeyPropColorVec_t,LatticeFermion> >(params.named_obj.sink_prop_id);
00458
00459 push(xml_out, "Output_version");
00460 write(xml_out, "out_version", 2);
00461 pop(xml_out);
00462
00463 proginfo(xml_out);
00464
00465
00466 params.writeXML(xml_out, "Input");
00467
00468
00469 write(xml_out, "Source_prop_file_info", source_prop_file_xml);
00470 write(xml_out, "Source_prop_record_info", source_prop_record_xml);
00471 write(xml_out, "Sink_prop_file_info", sink_prop_file_xml);
00472 write(xml_out, "Sink_prop_record_info", sink_prop_record_xml);
00473
00474
00475 write(xml_out, "Config_info", gauge_xml);
00476
00477
00478
00479 MesPlq(xml_out, "Observables", u);
00480
00481
00482
00483
00484 multi1d<int> origin_offset(Nd);
00485 origin_offset = 0;
00486 SftMom phases(params.param.mom2_max, origin_offset, params.param.mom_offset,
00487 params.param.avg_equiv_mom, params.param.decay_dir);
00488
00489
00490
00491
00492 multi1d<LatticeColorMatrix> u_smr = u;
00493
00494 try
00495 {
00496 std::istringstream xml_l(params.param.link_smearing.xml);
00497 XMLReader linktop(xml_l);
00498 QDPIO::cout << "Link smearing type = " << params.param.link_smearing.id << endl;
00499
00500
00501 Handle< LinkSmearing >
00502 linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.param.link_smearing.id,
00503 linktop,
00504 params.param.link_smearing.path));
00505
00506 (*linkSmearing)(u_smr);
00507 }
00508 catch(const std::string& e)
00509 {
00510 QDPIO::cerr << name << ": Caught Exception link smearing: " << e << endl;
00511 QDP_abort(1);
00512 }
00513
00514 MesPlq(xml_out, "Smeared_Observables", u_smr);
00515
00516
00517
00518
00519 BinaryStoreDB< SerialDBKey<KeyGenPropElementalOperator_t>, SerialDBData<ValGenPropElementalOperator_t> >
00520 qdp_db;
00521
00522
00523 if (! qdp_db.fileExists(params.named_obj.genprop_op_file))
00524 {
00525 XMLBufferWriter file_xml;
00526
00527 push(file_xml, "DBMetaData");
00528 write(file_xml, "id", string("genPropElemOp"));
00529 write(file_xml, "lattSize", QDP::Layout::lattSize());
00530 write(file_xml, "decay_dir", params.param.decay_dir);
00531 proginfo(file_xml);
00532 write(file_xml, "Params", params.param);
00533 write(file_xml, "Op_Info", params.param.disp_gamma_list);
00534 write(file_xml, "Source_prop_record_info", source_prop_record_xml);
00535 write(file_xml, "Sink_prop_record_info", sink_prop_record_xml);
00536 write(file_xml, "Config_info", gauge_xml);
00537 pop(file_xml);
00538
00539
00540
00541
00542
00543 std::string file_str(file_xml.str());
00544 qdp_db.setMaxUserInfoLen(file_str.size());
00545
00546 qdp_db.open(params.named_obj.genprop_op_file, O_RDWR | O_CREAT, 0664);
00547
00548 qdp_db.insertUserdata(file_str);
00549 }
00550 else
00551 {
00552 qdp_db.open(params.named_obj.genprop_op_file, O_RDWR, 0664);
00553 }
00554
00555
00556
00557
00558
00559 QDPIO::cout << "Building generalized propagators" << endl;
00560
00561 push(xml_out, "ElementalOps");
00562
00563
00564
00565
00566 const bool restrict_plateau = params.param.restrict_plateau;
00567 const int num_vecs = params.param.num_vecs;
00568 const int decay_dir = params.param.decay_dir;
00569 const int t_source = params.param.t_source;
00570 const int t_sink = params.param.t_sink;
00571
00572
00573 int t_start;
00574 int t_end;
00575
00576 if (restrict_plateau)
00577 {
00578 t_start = t_source;
00579 t_end = t_sink;
00580
00581 if (t_source > t_sink)
00582 {
00583 t_end += phases.numSubsets();
00584 }
00585 }
00586 else
00587 {
00588 t_start = 0;
00589 t_end = phases.numSubsets() - 1;
00590 }
00591
00592
00593 for(int l=0; l < params.param.disp_gamma_list.size(); ++l)
00594 {
00595 StopWatch watch;
00596
00597 QDPIO::cout << "Elemental operator: op = " << l << endl;
00598
00599
00600 multi1d<int> disp = normDisp(params.param.disp_gamma_list[l].displacement);
00601
00602
00603
00604 int gamma = params.param.disp_gamma_list[l].gamma;
00605 int gamma_tmp = (Ns*Ns-1) ^ gamma;
00606
00607 QDPIO::cout << "gamma=" << gamma_tmp << " displacement= " << disp << endl;
00608
00609
00610 swiss.reset();
00611 swiss.start();
00612
00613
00614 for(int mom_num = 0 ; mom_num < phases.numMom() ; ++mom_num)
00615 {
00616
00617 for(int spin_r=0; spin_r < Ns; ++spin_r)
00618 {
00619 QDPIO::cout << "spin_r = " << spin_r << endl;
00620
00621 for(int spin_l=0; spin_l < Ns; ++spin_l)
00622 {
00623 QDPIO::cout << "spin_l = " << spin_l << endl;
00624
00625
00626
00627
00628 multi1d<KeyValGenPropElementalOperator_t> buf(phases.numSubsets());
00629 for(int tt=t_start; tt <= t_end; ++tt)
00630 {
00631 int t = tt % phases.numSubsets();
00632
00633 buf[t].key.key().t_slice = t;
00634 buf[t].key.key().t_source = t_source;
00635 buf[t].key.key().t_sink = t_sink;
00636 buf[t].key.key().spin_r = spin_r;
00637 buf[t].key.key().spin_l = spin_l;
00638 buf[t].key.key().mass_label = params.param.mass_label;
00639 buf[t].key.key().mom = phases.numToMom(mom_num);
00640 buf[t].key.key().gamma = gamma;
00641 buf[t].key.key().displacement = disp;
00642
00643 buf[t].val.data().op.resize(num_vecs, num_vecs);
00644 }
00645
00646 for(int j = 0; j < params.param.num_vecs; ++j)
00647 {
00648 KeyPropColorVec_t key_r;
00649 key_r.t_source = t_source;
00650 key_r.colorvec_src = j;
00651 key_r.spin_src = spin_r;
00652
00653
00654 LatticeFermion shift_ferm = Gamma(gamma_tmp) * displace(u_smr,
00655 source_ferm_map[key_r],
00656 params.param.displacement_length,
00657 disp);
00658
00659 for(int i = 0; i < params.param.num_vecs; ++i)
00660 {
00661 KeyPropColorVec_t key_l;
00662 key_l.t_source = t_sink;
00663 key_l.colorvec_src = i;
00664 key_l.spin_src = spin_l;
00665
00666 watch.reset();
00667 watch.start();
00668
00669
00670
00671 LatticeComplex lop = localInnerProduct(sink_ferm_map[key_l], shift_ferm);
00672
00673
00674 Real reweight;
00675 if (phases.multiplicity(mom_num) > 0)
00676 reweight = Real(phases.multiplicity(mom_num));
00677 else
00678 reweight = 1.0;
00679
00680
00681 multi1d<ComplexD> op_sum = sumMulti(reweight * phases[mom_num] * lop, phases.getSet());
00682
00683 watch.stop();
00684
00685 for(int tt=t_start; tt <= t_end; ++tt)
00686 {
00687 int t = tt % phases.numSubsets();
00688 buf[t].val.data().op(i,j) = op_sum[t];
00689 }
00690 }
00691 }
00692
00693 QDPIO::cout << "insert: mom= " << phases.numToMom(mom_num) << " displacement= " << disp << endl;
00694 for(int tt=t_start; tt <= t_end; ++tt)
00695 {
00696 int t = tt % phases.numSubsets();
00697 qdp_db.insert(buf[t].key, buf[t].val);
00698 }
00699
00700 }
00701 }
00702 }
00703
00704 swiss.stop();
00705
00706 QDPIO::cout << "GenProp operator= " << l
00707 << " time= "
00708 << swiss.getTimeInSeconds()
00709 << " secs" << endl;
00710
00711 }
00712
00713 pop(xml_out);
00714
00715
00716 pop(xml_out);
00717
00718 snoop.stop();
00719 QDPIO::cout << name << ": total time = "
00720 << snoop.getTimeInSeconds()
00721 << " secs" << endl;
00722
00723 QDPIO::cout << name << ": ran successfully" << endl;
00724
00725 END_CODE();
00726 }
00727 }
00728
00729
00730
00731 }