CHROMA
pt_sink_smearing.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Point sink construction
3  */
4 
5 #include "chromabase.h"
6 #include "handle.h"
7 
10 
13 
16 
18 
19 namespace Chroma
20 {
21  // Read parameters
22  void read(XMLReader& xml, const std::string& path, PointQuarkSinkSmearingEnv::Params& param)
23  {
25  param = tmp;
26  }
27 
28  // Writer
29  void write(XMLWriter& xml, const std::string& path, const PointQuarkSinkSmearingEnv::Params& param)
30  {
31  param.writeXML(xml, path);
32  }
33 
34 
35  //! Hooks to register the class
36  namespace PointQuarkSinkSmearingEnv
37  {
38  namespace
39  {
40  //! Callback function
41  QuarkSourceSink<LatticePropagator>* createProp(XMLReader& xml_in,
42  const std::string& path,
43  const multi1d<LatticeColorMatrix>& u)
44  {
45  return new SinkSmear<LatticePropagator>(Params(xml_in, path), u);
46  }
47 
48  //! Callback function
49  QuarkSourceSink<LatticeStaggeredPropagator>* createStagProp(XMLReader& xml_in,
50  const std::string& path,
51  const multi1d<LatticeColorMatrix>& u)
52  {
53  return new SinkSmear<LatticeStaggeredPropagator>(Params(xml_in, path), u);
54  }
55 
56  //! Callback function
58  const std::string& path,
59  const multi1d<LatticeColorMatrix>& u)
60  {
61  return new SinkSmear<LatticeFermion>(Params(xml_in, path), u);
62  }
63 
64  //! Name to be used
65  const std::string name("POINT_SINK");
66 
67  //! Local registration flag
68  bool registered = false;
69  }
70 
71  //! Return the name
72  std::string getName() {return name;}
73 
74  //! Register all the factories
75  bool registerAll()
76  {
77  bool success = true;
78  if (! registered)
79  {
80  success &= LinkSmearingEnv::registerAll();
82  success &= Chroma::ThePropSinkSmearingFactory::Instance().registerObject(name, createProp);
83  success &= Chroma::TheStagPropSinkSmearingFactory::Instance().registerObject(name, createStagProp);
84  success &= Chroma::TheFermSinkSmearingFactory::Instance().registerObject(name, createFerm);
85  registered = true;
86  }
87  return success;
88  }
89 
90 
91  //! Initialize
93  {
94  }
95 
96 
97  //! Read parameters
98  Params::Params(XMLReader& xml, const std::string& path)
99  {
100  XMLReader paramtop(xml, path);
101 
102  int version;
103  read(paramtop, "version", version);
104 
105  switch (version)
106  {
107  case 1:
108  {
111  int disp_length = 0;
112  int disp_dir = 0;
113 
114  XMLBufferWriter xml_tmp;
115  push(xml_tmp, "Displacement");
116  write(xml_tmp, "DisplacementType", quark_displacement.id);
117 
118  if (paramtop.count("disp_length") != 0)
119  read(paramtop, "disp_length", disp_length);
120 
121  if (paramtop.count("disp_dir") != 0)
122  read(paramtop, "disp_dir", disp_dir);
123 
124  write(xml_tmp, "disp_length", disp_length);
125  write(xml_tmp, "disp_dir", disp_dir);
126 
127  pop(xml_tmp); // Displacement
128 
129  quark_displacement.xml = xml_tmp.printCurrentContext();
130  }
131  break;
132 
133  case 2:
134  {
135  if (paramtop.count("Displacement") != 0)
136  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
137  else
139  }
140  break;
141 
142  default:
143  QDPIO::cerr << __func__ << ": parameter version " << version
144  << " unsupported." << std::endl;
145  QDP_abort(1);
146  }
147 
148  if (paramtop.count("LinkSmearing") != 0)
149  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
150  else
152  }
153 
154 
155  // Writer
156  void Params::writeXML(XMLWriter& xml, const std::string& path) const
157  {
158  push(xml, path);
159  int version = 1;
160  write(xml, "version", version);
161 
162  write(xml, "SinkType", PointQuarkSinkSmearingEnv::getName());
163  xml << link_smearing.xml;
164  xml << quark_displacement.xml;
165  pop(xml);
166  }
167 
168 
169  //! Construct the sink smearing
170  template<>
171  void
172  SinkSmear<LatticePropagator>::operator()(LatticePropagator& quark_sink) const
173  {
174  QDPIO::cout << "Point sink" << std::endl;
175 
176  try
177  {
178  //
179  // Create the quark displacement object
180  //
181  std::istringstream xml_d(params.quark_displacement.xml);
182  XMLReader displacetop(xml_d);
183 
185  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
186  displacetop,
188 
189  //
190  // Displace quark source
191  //
192  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
193 
194  }
195  catch(const std::string& e)
196  {
197  QDPIO::cerr << name << ": Caught Exception in displacement: " << e << std::endl;
198  QDP_abort(1);
199  }
200  }
201 
202 
203 
204  //! Construct the sink smearing
205  template<>
206  void
207  SinkSmear<LatticeStaggeredPropagator>::operator()(LatticeStaggeredPropagator& quark_sink) const
208  {
209  QDPIO::cout << "Point sink" << std::endl;
210 
211  try
212  {
213  //
214  // Create the quark displacement object
215  //
216  std::istringstream xml_d(params.quark_displacement.xml);
217  XMLReader displacetop(xml_d);
218 
220  quarkDisplacement(TheStagPropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
221  displacetop,
223 
224  //
225  // Displace quark source
226  //
227  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
228 
229  }
230  catch(const std::string& e)
231  {
232  QDPIO::cerr << name << ": Caught Exception in displacement: " << e << std::endl;
233  QDP_abort(1);
234  }
235  }
236 
237 
238 
239  //! Construct the sink smearing
240  template<>
241  void
242  SinkSmear<LatticeFermion>::operator()(LatticeFermion& quark_sink) const
243  {
244 // QDPIO::cout << "Point sink" << std::endl;
245 
246  try
247  {
248  //
249  // Create the quark displacement object
250  //
251  std::istringstream xml_d(params.quark_displacement.xml);
252  XMLReader displacetop(xml_d);
253 
255  quarkDisplacement(TheFermDisplacementFactory::Instance().createObject(params.quark_displacement.id,
256  displacetop,
258 
259  //
260  // Displace quark source
261  //
262  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
263 
264  }
265  catch(const std::string& e)
266  {
267  QDPIO::cerr << name << ": Caught Exception in displacement: " << e << std::endl;
268  QDP_abort(1);
269  }
270  }
271 
272  }
273 
274 }
Primary include file for CHROMA library code.
Class for counted reference semantics.
Definition: handle.h:33
void operator()(T &obj) const
Smear the sink.
Base class for quark source and sink smearing.
static T & Instance()
Definition: singleton.h:432
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.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Class for counted reference semantics.
Params params
static bool registered
Local registration flag.
const std::string name
Name to be used.
CreateFermState< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > * createFerm(XMLReader &xml, const std::string &path)
GroupXML_t nullXMLGroup()
Returns a no-linksmearing group.
bool registerAll()
Register all the factories.
std::string getName()
Return the name.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
GroupXML_t nullXMLGroup()
Returns a no-displacement group.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
@ PLUS
Definition: chromabase.h:45
pop(xml_out)
::std::string string
Definition: gtest.h:1979
Point sink smearing.
All quark displacement constructors.
Factory for producing quark displacement objects.
Simple quark displacement.
Factory for producing quark prop sinks.
void writeXML(XMLWriter &in, const std::string &path) const