00001
00002
00003 #include "fermact.h"
00004 #include "meas/inline/pbp/inline_psibarpsi_w.h"
00005 #include "meas/inline/abs_inline_measurement_factory.h"
00006 #include "actions/ferm/fermacts/fermact_factory_w.h"
00007 #include "actions/ferm/fermacts/fermacts_aggregate_w.h"
00008 #include "util/info/proginfo.h"
00009 #include "meas/inline/io/named_objmap.h"
00010
00011 #include "meas/pbp/pbp.h"
00012
00013
00014 namespace Chroma
00015 {
00016
00017 void read(XMLReader& xml, const string& path, InlinePsiBarPsiEnv::Params::Param_t& param)
00018 {
00019 XMLReader paramtop(xml, path);
00020
00021 int version;
00022 read(paramtop, "version", version);
00023
00024 switch (version)
00025 {
00026 case 1:
00027 param.fermact = readXMLGroup(paramtop, "FermionAction", "FermAct");
00028 param.invParam = readXMLGroup(paramtop, "InvertParam", "invType");
00029
00030 read(paramtop, "Mass", param.mass);
00031 if (paramtop.count("ichiral") == 1) {
00032 read(paramtop, "ichiral", param.ichiral);
00033 } else {
00034 param.ichiral = 0;
00035 }
00036
00037 break;
00038
00039 default:
00040 QDPIO::cerr << "InlinePsiBarPsiParams::Param_t: " << version
00041 << " unsupported." << endl;
00042 QDP_abort(1);
00043 }
00044 }
00045
00046 void write(XMLWriter& xml, const string& path, InlinePsiBarPsiEnv::Params::Param_t& param)
00047 {
00048 push(xml, path);
00049
00050 int version = 1;
00051 write(xml, "version", version);
00052 write(xml, "mass", param.mass);
00053 write(xml, "ichiral", param.ichiral);
00054
00055 xml << param.fermact.xml;
00056 xml << param.invParam.xml;
00057
00058 pop(xml);
00059 }
00060
00061 void read(XMLReader& xml, const string& path, InlinePsiBarPsiEnv::Params::NamedObject_t& input)
00062 {
00063 XMLReader inputtop(xml, path);
00064
00065 read(inputtop, "gauge_id", input.gauge_id);
00066 }
00067
00068 void write(XMLWriter& xml, const string& path, const InlinePsiBarPsiEnv::Params::NamedObject_t& input)
00069 {
00070 push(xml, path);
00071
00072 write(xml, "gauge_id", input.gauge_id);
00073
00074 pop(xml);
00075 }
00076
00077
00078 namespace InlinePsiBarPsiEnv
00079 {
00080 namespace
00081 {
00082 AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
00083 const std::string& path)
00084 {
00085 return new InlineMeas(Params(xml_in, path));
00086 }
00087
00088
00089 bool registered = false;
00090 }
00091
00092 const std::string name = "PSI_BAR_PSI";
00093
00094
00095 bool registerAll()
00096 {
00097 bool success = true;
00098 if (! registered)
00099 {
00100 success &= WilsonTypeFermActsEnv::registerAll();
00101 success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
00102 registered = true;
00103 }
00104 return success;
00105 }
00106
00107 Params::Params()
00108 {
00109 frequency = 0;
00110 }
00111
00112 Params::Params(XMLReader& xml_in, const std::string& path)
00113 {
00114 try
00115 {
00116 XMLReader paramtop(xml_in, path);
00117
00118 if (paramtop.count("Frequency") == 1)
00119 read(paramtop, "Frequency", frequency);
00120 else
00121 frequency = 1;
00122
00123 read(paramtop, "Param", param);
00124
00125 read(paramtop, "NamedObject", named_obj);
00126 }
00127 catch(const std::string& e)
00128 {
00129 QDPIO::cerr << "Caught Exception reading XML: " << e << endl;
00130 QDP_abort(1);
00131 }
00132 }
00133
00134 void InlineMeas::operator()(unsigned long update_no,
00135 XMLWriter& xml_out)
00136 {
00137
00138 push(xml_out, "PsiBarPsi");
00139 write(xml_out, "update_no", update_no);
00140 pop(xml_out);
00141
00142 func(update_no, xml_out);
00143 }
00144
00145 void InlineMeas::func(unsigned long update_no,
00146 XMLWriter& xml_out)
00147 {
00148 START_CODE();
00149
00150 Double pbp;
00151 int maxCG = 0;
00152 int n_congrd = 0;
00153 XMLBufferWriter gauge_xml;
00154
00155 multi1d<LatticeColorMatrix> u;
00156 try {
00157 u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00158 TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
00159 }
00160 catch ( std::bad_cast ) {
00161 QDPIO::cerr << name << ": caught dynamic cast error" << endl;
00162 QDP_abort(1);
00163 }
00164 catch (const string& e) {
00165 QDPIO::cerr << name << ": map call failed: " << e << endl;
00166 QDP_abort(1);
00167 }
00168
00169 proginfo(xml_out);
00170
00171 write(xml_out, "Config_info", gauge_xml);
00172
00173
00174
00175 std::istringstream xml_s(params.param.fermact.xml);
00176 XMLReader fermacttop(xml_s);
00177 QDPIO::cout << "FermAct = " << params.param.fermact.id << endl;
00178
00179
00180 try
00181 {
00182 StopWatch swatch;
00183 swatch.reset();
00184 QDPIO::cout << "Try the various factories" << endl;
00185
00186 typedef LatticeFermion T;
00187 typedef multi1d<LatticeColorMatrix> P;
00188 typedef multi1d<LatticeColorMatrix> Q;
00189
00190 Handle< FermionAction<T,P,Q> >
00191 S_f(TheFermionActionFactory::Instance().createObject(params.param.fermact.id,
00192 fermacttop,
00193 params.param.fermact.path));
00194
00195 Handle< FermState<T,P,Q> > state(S_f->createState(u));
00196
00197 QDPIO::cout << "Suitable factory found: do the measurements" << endl;
00198 Handle< SystemSolver<T> > qprop(S_f->qprop(state, params.param.invParam));
00199
00200 swatch.start();
00201
00202 MesPbp(qprop, state, params.param.mass, params.param.ichiral, xml_out, "PsiBarPsi", params.param.fermact.id);
00203
00204 swatch.stop();
00205 QDPIO::cout << "PsiBarPsi computed: time= "
00206 << swatch.getTimeInSeconds()
00207 << " secs" << endl;
00208 }
00209 catch ( std::bad_cast )
00210 {
00211 QDPIO::cerr << name << ": caught dynamic cast error"
00212 << endl;
00213 QDP_abort(1);
00214 }
00215 catch (const std::string& e)
00216 {
00217 QDPIO::cout << name << ": caught exception with fermion action: " << e << endl;
00218 }
00219
00220 pop(xml_out);
00221
00222 QDPIO::cout << name << ": ran successfully" << endl;
00223
00224 END_CODE();
00225 }
00226
00227 }
00228
00229 }
00230
00231
00232
00233