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