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