CHROMA
inline_rotate_spin_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline task to spin rotate to a Dirac basis
3  *
4  * Spin rotate a named object
5  */
6 
7 #include "singleton.h"
8 #include "funcmap.h"
9 #include "chromabase.h"
10 
14 #include "util/ferm/diractodr.h"
15 
16 namespace Chroma
17 {
18  //! Object buffer
19  void write(XMLWriter& xml, const std::string& path, const InlineRotateSpinEnv::Params::NamedObject_t& input)
20  {
21  push(xml, path);
22 
23  write(xml, "input_id", input.input_id);
24  write(xml, "output_id", input.output_id);
25  write(xml, "object_type", input.object_type);
26 
27  pop(xml);
28  }
29 
30 
31  //! Object buffer
32  void read(XMLReader& xml, const std::string& path, InlineRotateSpinEnv::Params::NamedObject_t& input)
33  {
34  XMLReader inputtop(xml, path);
35 
36  read(inputtop, "input_id", input.input_id);
37  read(inputtop, "output_id", input.output_id);
38  read(inputtop, "object_type", input.object_type);
39  }
40 
41 
42  //! IO function std::map environment
43  /*! \ingroup inlinehadron */
44  namespace RotateSpinObjCallMapEnv
45  {
46  // Anonymous namespace
47  namespace
48  {
49  struct DumbDisambiguator {};
50 
51  //! RotateSpin function std::map
52  /*! \ingroup inlinehadron */
53  typedef SingletonHolder<
54  FunctionMap<DumbDisambiguator,
55  void,
57  TYPELIST_2(const std::string&, const std::string&),
58  void (*)(const std::string& output_id, const std::string& input_id),
60  TheRotateSpinObjFuncMap;
61 
62 
63  //! Transform a wilson-like fermion object. This works only for non-array objects.
64  // This only works for a fermion-like object. A propagator needs 2 spin rotations
65  void rotateDRtoDiracFerm(const std::string& output_id, const std::string& input_id)
66  {
67  // Save some typing
68  typedef LatticeFermion T;
69 
70  // Grab the source
71  const T& input_obj =
72  TheNamedObjMap::Instance().getData<T>(input_id);
73 
74  // The spin basis matrix to go from DR to Dirac
75  SpinMatrix rotate_mat(adj(DiracToDRMat()));
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) = rotate_mat * input_obj;
88  }
89 
90  //! Transform a wilson-like fermion object. This works only for non-array objects.
91  // This only works for a fermion-like object. A propagator needs 2 spin rotations
92  void rotateDiractoDRFerm(const std::string& output_id, const std::string& input_id)
93  {
94  // Save some typing
95  typedef LatticeFermion T;
96 
97  // Grab the source
98  const T& input_obj =
99  TheNamedObjMap::Instance().getData<T>(input_id);
100 
101  // The spin basis matrix to go from Dirac to DR
102  SpinMatrix rotate_mat(DiracToDRMat());
103 
104  XMLReader input_file_xml, input_record_xml;
105  TheNamedObjMap::Instance().get(input_id).getFileXML(input_file_xml);
106  TheNamedObjMap::Instance().get(input_id).getRecordXML(input_record_xml);
107 
108  // Create space for the target
109  TheNamedObjMap::Instance().create<T>(output_id);
110  TheNamedObjMap::Instance().get(output_id).setFileXML(input_file_xml);
111  TheNamedObjMap::Instance().get(output_id).setRecordXML(input_record_xml);
112 
113  // Do the actual rotation
114  TheNamedObjMap::Instance().getData<T>(output_id) = rotate_mat * input_obj;
115  }
116 
117 
118  //! Local registration flag
119  bool registered = false;
120 
121  } // end namespace RotateSpinCallMap
122 
123  //! Register all the factories
124  bool registerAll()
125  {
126  bool success = true;
127  if (! registered)
128  {
129 // success &= TheRotateSpinObjFuncMap::Instance().registerFunction(std::string("LatticePropagator"),
130 // rotateSpinObj<LatticePropagator>);
131  success &= TheRotateSpinObjFuncMap::Instance().registerFunction(std::string("LatticeFermion:DR-to-Dirac"),
132  rotateDRtoDiracFerm);
133  success &= TheRotateSpinObjFuncMap::Instance().registerFunction(std::string("LatticeFermion:Dirac-to-DR"),
134  rotateDRtoDiracFerm);
135  registered = true;
136  }
137  return success;
138  }
139  } // end CallMap namespace
140 
141 
142  namespace InlineRotateSpinEnv
143  {
144  namespace
145  {
146  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
147  const std::string& path)
148  {
149  return new InlineMeas(Params(xml_in, path));
150  }
151 
152  //! Local registration flag
153  bool registered = false;
154  }
155 
156  const std::string name = "ROTATE_SPIN_NAMED_OBJECT";
157 
158  //! Register all the factories
159  bool registerAll()
160  {
161  bool success = true;
162  if (! registered)
163  {
164  // Rotation env
166 
167  // Inline measurement
168  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
169  registered = true;
170  }
171  return success;
172  }
173 
174 
175  // Param stuff
177 
178  Params::Params(XMLReader& xml_in, const std::string& path)
179  {
180  try
181  {
182  XMLReader paramtop(xml_in, path);
183 
184  if (paramtop.count("Frequency") == 1)
185  read(paramtop, "Frequency", frequency);
186  else
187  frequency = 1;
188 
189  // Ids
190  read(paramtop, "NamedObject", named_obj);
191  }
192  catch(const std::string& e)
193  {
194  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
195  QDP_abort(1);
196  }
197  }
198 
199 
200  void
201  Params::writeXML(XMLWriter& xml_out, const std::string& path)
202  {
203  push(xml_out, path);
204 
205  // Ids
206  write(xml_out, "NamedObject", named_obj);
207 
208  pop(xml_out);
209  }
210 
211 
212  void
213  InlineMeas::operator()(unsigned long update_no,
214  XMLWriter& xml_out)
215  {
216  START_CODE();
217 
218  push(xml_out, "rotate_spin_object");
219  write(xml_out, "update_no", update_no);
220 
221  QDPIO::cout << name << ": spin rotate an object of type "
222  << params.named_obj.object_type << std::endl;
223 
224  // Grab the input object
225  try
226  {
227  // Spin rotate the object
228  RotateSpinObjCallMapEnv::TheRotateSpinObjFuncMap::Instance().callFunction(params.named_obj.object_type,
231  }
232  catch (std::bad_cast)
233  {
234  QDPIO::cerr << name << ": cast error"
235  << std::endl;
236  QDP_abort(1);
237  }
238  catch (const std::string& e)
239  {
240  QDPIO::cerr << name << ": error message: " << e
241  << std::endl;
242  QDP_abort(1);
243  }
244 
245  QDPIO::cout << name << ": ran successfully" << std::endl;
246 
247  pop(xml_out);
248 
249  END_CODE();
250  }
251 
252  } // namespace InlineRotateSpinEnv
253 
254 } // namespace Chroma
Inline measurement factory.
Primary include file for CHROMA library code.
Object factory class.
Definition: funcmap.h:89
Gauge transform a named object.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
static T & Instance()
Definition: singleton.h:432
Basis rotation matrix from Dirac to Degrand-Rossi (and reverse)
Map of function calls.
SpinMatrixD DiracToDRMat()
The Dirac to Degrand-Rossi spin transformation matrix (and reverse)
Definition: diractodr.cc:22
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 to spin rotate to a Dirac basis.
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
SpinMatrix rotate_mat(adj(DiracToDRMat()))
bool registerAll()
Register all the factories.
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
Singleton support.
struct Chroma::InlineRotateSpinEnv::Params::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)
#define TYPELIST_2(T1, T2)
Definition: typelist.h:43