CHROMA
sh_sink_smearing.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Shell sink smearing
3  */
4 
5 #include "chromabase.h"
6 #include "handle.h"
7 
10 
13 
16 
18 
21 
24 
25 namespace Chroma
26 {
27  // Read parameters
28  void read(XMLReader& xml, const std::string& path, ShellQuarkSinkSmearingEnv::Params& param)
29  {
31  param = tmp;
32  }
33 
34  // Writer
35  void write(XMLWriter& xml, const std::string& path, const ShellQuarkSinkSmearingEnv::Params& param)
36  {
37  param.writeXML(xml, path);
38  }
39 
40 
41 
42  //! Hooks to register the class
43  namespace ShellQuarkSinkSmearingEnv
44  {
45  namespace
46  {
47  //! Callback function
48  QuarkSourceSink<LatticePropagator>* createProp(XMLReader& xml_in,
49  const std::string& path,
50  const multi1d<LatticeColorMatrix>& u)
51  {
52  return new SinkSmear<LatticePropagator>(Params(xml_in, path), u);
53  }
54 
55  //! Callback function
56  QuarkSourceSink<LatticeStaggeredPropagator>* createStagProp(XMLReader& xml_in,
57  const std::string& path,
58  const multi1d<LatticeColorMatrix>& u)
59  {
60  return new SinkSmear<LatticeStaggeredPropagator>(Params(xml_in, path), u);
61  }
62 
63  //! Callback function
65  const std::string& path,
66  const multi1d<LatticeColorMatrix>& u)
67  {
68  return new SinkSmear<LatticeFermion>(Params(xml_in, path), u);
69  }
70 
71  //! Name to be used
72  const std::string name("SHELL_SINK");
73 
74  //! Local registration flag
75  bool registered = false;
76  }
77 
78  //! Return the name
79  std::string getName() {return name;}
80 
81  //! Register all the factories
82  bool registerAll()
83  {
84  bool success = true;
85  if (! registered)
86  {
87  success &= LinkSmearingEnv::registerAll();
88  success &= QuarkSmearingEnv::registerAll();
90  success &= Chroma::ThePropSinkSmearingFactory::Instance().registerObject(name, createProp);
91  success &= Chroma::TheStagPropSinkSmearingFactory::Instance().registerObject(name, createStagProp);
92  success &= Chroma::TheFermSinkSmearingFactory::Instance().registerObject(name, createFerm);
93 
94  registered = true;
95  }
96  return success;
97  }
98 
99 
100  //! Initialize
102  {
103  quark_smear_firstP = true;
104  }
105 
106 
107  //! Read parameters
108  Params::Params(XMLReader& xml, const std::string& path)
109  {
110  XMLReader paramtop(xml, path);
111 
112  int version;
113  read(paramtop, "version", version);
114 
115  quark_smear_firstP = true;
116 
117  switch (version)
118  {
119  case 1:
120  {
123  int disp_length = 0;
124  int disp_dir = 0;
125 
126  XMLBufferWriter xml_tmp;
127  push(xml_tmp, "Displacement");
128  write(xml_tmp, "DisplacementType", quark_displacement.id);
129 
130  if (paramtop.count("disp_length") != 0)
131  read(paramtop, "disp_length", disp_length);
132 
133  if (paramtop.count("disp_dir") != 0)
134  read(paramtop, "disp_dir", disp_dir);
135 
136  write(xml_tmp, "disp_length", disp_length);
137  write(xml_tmp, "disp_dir", disp_dir);
138 
139  pop(xml_tmp); // Displacement
140 
141  quark_displacement.xml = xml_tmp.printCurrentContext();
142  }
143  break;
144 
145  case 2:
146  {
147  if (paramtop.count("Displacement") != 0)
148  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
149  else
151  }
152  break;
153 
154  case 3:
155  {
156  read(paramtop, "quark_smear_firstP", quark_smear_firstP);
157 
158  if (paramtop.count("Displacement") != 0)
159  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
160  else
162  }
163  break;
164 
165  default:
166  QDPIO::cerr << __func__ << ": parameter version " << version
167  << " unsupported." << std::endl;
168  QDP_abort(1);
169  }
170 
171  quark_smearing = readXMLGroup(paramtop, "SmearingParam", "wvf_kind");
172 
173  if (paramtop.count("LinkSmearing") != 0)
174  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
175  else
177  }
178 
179 
180  // Writer
181  void Params::writeXML(XMLWriter& xml, const std::string& path) const
182  {
183  push(xml, path);
184 
185  int version = 3;
186  write(xml, "version", version);
187 
188  write(xml, "SinkType", ShellQuarkSinkSmearingEnv::getName());
189  xml << quark_smearing.xml;
190  xml << quark_displacement.xml;
191  xml << link_smearing.xml;
192  write(xml, "quark_smear_firstP", quark_smear_firstP);
193  pop(xml);
194 
195  pop(xml);
196  }
197 
198 
199 
200  //! Smear the sink
201  template<>
202  void
203  SinkSmear<LatticePropagator>::operator()(LatticePropagator& quark_sink) const
204  {
205  QDPIO::cout << "Shell sink" << std::endl;
206 
207  try
208  {
209  //
210  // Create the quark smearing object
211  //
212  std::istringstream xml_s(params.quark_smearing.xml);
213  XMLReader smeartop(xml_s);
214  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
215 
217  quarkSmearing(ThePropSmearingFactory::Instance().createObject(params.quark_smearing.id,
218  smeartop,
220 
221  //
222  // Create the quark displacement object
223  //
224  std::istringstream xml_d(params.quark_displacement.xml);
225  XMLReader displacetop(xml_d);
226  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
227 
229  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
230  displacetop,
232 
234  {
235  //
236  // Sink smear quark
237  //
238  (*quarkSmearing)(quark_sink, u_smr);
239 
240  //
241  // Displace the sink
242  //
243  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
244  }
245  else
246  {
247  //
248  // Displace the sink
249  //
250  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
251 
252  //
253  // Sink smear quark
254  //
255  (*quarkSmearing)(quark_sink, u_smr);
256  }
257 
258  }
259  catch(const std::string& e)
260  {
261  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
262  QDP_abort(1);
263  }
264  }
265 
266 
267 
268 
269  //! Smear the sink
270  template<>
271  void
272  SinkSmear<LatticeStaggeredPropagator>::operator()(LatticeStaggeredPropagator& quark_sink) const
273  {
274  QDPIO::cout << "Shell sink" << std::endl;
275 
276  try
277  {
278  //
279  // Create the quark smearing object
280  //
281  std::istringstream xml_s(params.quark_smearing.xml);
282  XMLReader smeartop(xml_s);
283  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
284 
286  quarkSmearing(TheStagPropSmearingFactory::Instance().createObject(params.quark_smearing.id,
287  smeartop,
289 
290  //
291  // Create the quark displacement object
292  //
293  std::istringstream xml_d(params.quark_displacement.xml);
294  XMLReader displacetop(xml_d);
295  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
296 
298  quarkDisplacement(TheStagPropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
299  displacetop,
301 
303  {
304  //
305  // Sink smear quark
306  //
307  (*quarkSmearing)(quark_sink, u_smr);
308 
309  //
310  // Displace the sink
311  //
312  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
313  }
314  else
315  {
316  //
317  // Displace the sink
318  //
319  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
320 
321  //
322  // Sink smear quark
323  //
324  (*quarkSmearing)(quark_sink, u_smr);
325  }
326 
327  }
328  catch(const std::string& e)
329  {
330  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
331  QDP_abort(1);
332  }
333  }
334 
335 
336 
337  //! Smear the sink
338  template<>
339  void
340  SinkSmear<LatticeFermion>::operator()(LatticeFermion& quark_sink) const
341  {
342 // QDPIO::cout << "Shell sink" << std::endl;
343 
344  try
345  {
346  //
347  // Create the quark smearing object
348  //
349  std::istringstream xml_s(params.quark_smearing.xml);
350  XMLReader smeartop(xml_s);
351 
353  quarkSmearing(TheFermSmearingFactory::Instance().createObject(params.quark_smearing.id,
354  smeartop,
356 
357  //
358  // Create the quark displacement object
359  //
360  std::istringstream xml_d(params.quark_displacement.xml);
361  XMLReader displacetop(xml_d);
362 
364  quarkDisplacement(TheFermDisplacementFactory::Instance().createObject(params.quark_displacement.id,
365  displacetop,
367 
368  //
369  // Sink smear quark
370  //
371  (*quarkSmearing)(quark_sink, u_smr);
372 
373 
374  //
375  // Displace the sink
376  //
377  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
378 
379  }
380  catch(const std::string& e)
381  {
382  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
383  QDP_abort(1);
384  }
385  }
386 
387  }
388 
389 }
Primary include file for CHROMA library code.
Class for counted reference semantics.
Definition: handle.h:33
Base class for quark source and sink smearing.
void operator()(T &obj) const
Smear the sink.
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.
bool registerAll()
Register all the factories.
GroupXML_t nullXMLGroup()
Returns a no-displacement group.
bool registerAll()
Register all the factories.
std::string getName()
Return the name.
bool registerAll()
Register all the factories.
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
No quark displacement.
All quark displacement constructors.
Factory for producing quark displacement objects.
Quark smearing.
All quark smearing constructors.
Factory for producing quark smearing objects.
Shell sink smearing.
Simple quark displacement.
Factory for producing quark prop sinks.
void writeXML(XMLWriter &in, const std::string &path) const