CHROMA
inline_gauge_transf_obj.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline task gauge transform some fermion object
3  *
4  * Gauge transform a named object
5  */
6 
7 #include "singleton.h"
8 #include "funcmap.h"
9 #include "chromabase.h"
10 
15 
16 #include "qdp_map_obj_memory.h"
17 
18 namespace Chroma
19 {
20  using namespace QDP;
21 
22  //! Object buffer
23  void write(XMLWriter& xml, const std::string& path, const InlineGaugeTransfNamedObjEnv::Params::NamedObject_t& input)
24  {
25  push(xml, path);
26 
27  write(xml, "gauge_rot_id", input.gauge_rot_id);
28  write(xml, "input_id", input.input_id);
29  write(xml, "output_id", input.output_id);
30  write(xml, "object_type", input.object_type);
31 
32  pop(xml);
33  }
34 
35 
36  //! Object buffer
37  void read(XMLReader& xml, const std::string& path, InlineGaugeTransfNamedObjEnv::Params::NamedObject_t& input)
38  {
39  XMLReader inputtop(xml, path);
40 
41  read(inputtop, "gauge_rot_id", input.gauge_rot_id);
42  read(inputtop, "input_id", input.input_id);
43  read(inputtop, "output_id", input.output_id);
44  read(inputtop, "object_type", input.object_type);
45  }
46 
47 
48  //! IO function std::map environment
49  /*! \ingroup inlinehadron */
50  namespace GaugeTransfObjCallMapEnv
51  {
52  // Anonymous namespace
53  namespace
54  {
55  struct DumbDisambiguator {};
56 
57  //! GaugeTransf function std::map
58  /*! \ingroup inlinehadron */
59  typedef SingletonHolder<
60  FunctionMap<DumbDisambiguator,
61  void,
63  TYPELIST_3(const std::string&, const LatticeColorMatrix&, const std::string&),
64  void (*)(const std::string& output_id, const LatticeColorMatrix& g, const std::string& input_id),
66  TheGaugeTransfObjFuncMap;
67 
68 
69  //! Transform a generic object. This works only for non-array objects.
70  template<typename T>
71  void gaugeTransfObj(const std::string& output_id, const LatticeColorMatrix& g, const std::string& input_id)
72  {
73  // Grab the source
74  const T& input_obj =
75  TheNamedObjMap::Instance().getData<T>(input_id);
76 
77  XMLReader input_file_xml, input_record_xml;
78  TheNamedObjMap::Instance().get(input_id).getFileXML(input_file_xml);
79  TheNamedObjMap::Instance().get(input_id).getRecordXML(input_record_xml);
80 
81  // Create space for the target
82  TheNamedObjMap::Instance().create<T>(output_id);
83  TheNamedObjMap::Instance().get(output_id).setFileXML(input_file_xml);
84  TheNamedObjMap::Instance().get(output_id).setRecordXML(input_record_xml);
85 
86  // Do the actual rotation
87  TheNamedObjMap::Instance().getData<T>(output_id) = g * input_obj;
88  }
89 
90  //! Transform a generic object. This works only for non-array objects.
91  template<typename T>
92  void gaugeTransfGaugeField(const std::string& output_id, const LatticeColorMatrix& g, const std::string& input_id)
93  {
94 
95  T g_prec = g;
96  // Grab the source
97  const multi1d<T>& input_obj =
98  TheNamedObjMap::Instance().getData< multi1d<T> >(input_id);
99 
100  XMLReader input_file_xml, input_record_xml;
101  TheNamedObjMap::Instance().get(input_id).getFileXML(input_file_xml);
102  TheNamedObjMap::Instance().get(input_id).getRecordXML(input_record_xml);
103 
104  // Create space for the target
105  TheNamedObjMap::Instance().create< multi1d<T> >(output_id);
106  TheNamedObjMap::Instance().get(output_id).setFileXML(input_file_xml);
107  TheNamedObjMap::Instance().get(output_id).setRecordXML(input_record_xml);
108 
109  // Do the actual rotation
110  multi1d<T>& dest_gauge = TheNamedObjMap::Instance().getData< multi1d<T> >(output_id);
111  dest_gauge.resize(Nd);
112  for(int mu=0; mu < Nd; ++mu) {
113  // r_mu = g * u * g^\dagger(x + mu)
114  dest_gauge[mu] = g_prec*input_obj[mu]*adj(shift(g_prec,FORWARD,mu));
115  }
116  }
117  //! Transform a subset_vectors object. This only works for non-array objects
118  void gaugeTransfSubsetVectors(const std::string& output_id, const LatticeColorMatrix& g, const std::string& input_id)
119  {
120  // A shorthand for the object
123 
124  XMLReader input_file_xml, input_record_xml;
125  TheNamedObjMap::Instance().get(input_id).getFileXML(input_file_xml);
126  TheNamedObjMap::Instance().get(input_id).getRecordXML(input_record_xml);
127 
128  // Create space for the target
129  Handle< QDP::MapObject<int,EVPair<LatticeColorVector> > > output_obj(new MapObjectMemory<int,EVPair<LatticeColorVector> >());
130 
132  TheNamedObjMap::Instance().get(output_id).setFileXML(input_file_xml);
133  TheNamedObjMap::Instance().get(output_id).setRecordXML(input_record_xml);
134 
135 
136  // Do the actual rotation. The evs stay the same
137  for(int n=0; n < input_obj->size(); n++) {
139  input_obj->get(n,pair);
140 
141  EVPair<LatticeColorVector> pair2 = pair;
142  pair2.eigenVector = g*pair.eigenVector;
143  output_obj->insert(n, pair2);
144  }
145  }
146 
147 
148  //! Local registration flag
149  bool registered = false;
150 
151  } // end namespace GaugeTransfCallMap
152 
153  //! Register all the factories
154  bool registerAll()
155  {
156  bool success = true;
157  if (! registered)
158  {
159  success &= TheGaugeTransfObjFuncMap::Instance().registerFunction(std::string("LatticePropagator"),
160  gaugeTransfObj<LatticePropagator>);
161  success &= TheGaugeTransfObjFuncMap::Instance().registerFunction(std::string("LatticeFermion"),
162  gaugeTransfObj<LatticeFermion>);
163  success &= TheGaugeTransfObjFuncMap::Instance().registerFunction(std::string("LatticeStaggeredPropagator"),
164  gaugeTransfObj<LatticeStaggeredPropagator>);
165  success &= TheGaugeTransfObjFuncMap::Instance().registerFunction(std::string("LatticeStaggeredFermion"),
166  gaugeTransfObj<LatticeStaggeredFermion>);
167  success &= TheGaugeTransfObjFuncMap::Instance().registerFunction(std::string("SubsetVectorsLatticeColorVector"),
168  gaugeTransfSubsetVectors);
169  success &= TheGaugeTransfObjFuncMap::Instance().registerFunction(std::string("Multi1dLatticeColorMatrix"),
170  gaugeTransfGaugeField<LatticeColorMatrix>);
171 
172  registered = true;
173  }
174  return success;
175  }
176  } // end CallMap namespace
177 
178 
179  namespace InlineGaugeTransfNamedObjEnv
180  {
181  namespace
182  {
183  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
184  const std::string& path)
185  {
186  return new InlineMeas(Params(xml_in, path));
187  }
188 
189  //! Local registration flag
190  bool registered = false;
191  }
192 
193  const std::string name = "GAUGE_TRANSFORM_NAMED_OBJECT";
194 
195  //! Register all the factories
196  bool registerAll()
197  {
198  bool success = true;
199  if (! registered)
200  {
201  // Gaussian init functions
203 
204  // Inline measurement
205  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
206  registered = true;
207  }
208  return success;
209  }
210 
211 
212  // Param stuff
213  Params::Params() { frequency = 0; }
214 
215  Params::Params(XMLReader& xml_in, const std::string& path)
216  {
217  try
218  {
219  XMLReader paramtop(xml_in, path);
220 
221  if (paramtop.count("Frequency") == 1)
222  read(paramtop, "Frequency", frequency);
223  else
224  frequency = 1;
225 
226  // Ids
227  read(paramtop, "NamedObject", named_obj);
228  }
229  catch(const std::string& e)
230  {
231  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
232  QDP_abort(1);
233  }
234  }
235 
236 
237  void
238  Params::writeXML(XMLWriter& xml_out, const std::string& path)
239  {
240  push(xml_out, path);
241 
242  // Ids
243  write(xml_out, "NamedObject", named_obj);
244 
245  pop(xml_out);
246  }
247 
248 
249  void
250  InlineMeas::operator()(unsigned long update_no,
251  XMLWriter& xml_out)
252  {
253  START_CODE();
254 
255  push(xml_out, "gauge_transf_object");
256  write(xml_out, "update_no", update_no);
257 
258  QDPIO::cout << name << ": gauge transform an object of type "
259  << params.named_obj.object_type << std::endl;
260 
261  // Grab the input object
262  try
263  {
264  const LatticeColorMatrix& g =
265  TheNamedObjMap::Instance().getData<LatticeColorMatrix>(params.named_obj.gauge_rot_id);
266 
267  // Gaussian init the object
268  GaugeTransfObjCallMapEnv::TheGaugeTransfObjFuncMap::Instance().callFunction(params.named_obj.object_type,
269  params.named_obj.output_id,
270  g,
271  params.named_obj.input_id);
272  }
273  catch (std::bad_cast)
274  {
275  QDPIO::cerr << name << ": cast error"
276  << std::endl;
277  QDP_abort(1);
278  }
279  catch (const std::string& e)
280  {
281  QDPIO::cerr << name << ": error message: " << e
282  << std::endl;
283  QDP_abort(1);
284  }
285 
286  QDPIO::cout << name << ": ran successfully" << std::endl;
287 
288  pop(xml_out); // gaussian_init_named_obj
289 
290  END_CODE();
291  }
292 
293  } // namespace InlineGaugeTransfNamedObjEnv
294 
295 } // namespace Chroma
Inline measurement factory.
Primary include file for CHROMA library code.
Object factory class.
Definition: funcmap.h:89
Class for counted reference semantics.
Definition: handle.h:33
static T & Instance()
Definition: singleton.h:432
int mu
Definition: cool.cc:24
Map of function calls.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
Inline task gauge transform some fermion object.
Params params
unsigned n
Definition: ldumul_w.cc:36
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
multi1d< Hadron2PtContraction_t > operator()(const multi1d< LatticeColorMatrix > &u)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
#define FORWARD
Definition: primitives.h:82
Singleton support.
A Pair type.
Holds of vectors and weights.
#define TYPELIST_3(T1, T2, T3)
Definition: typelist.h:45