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