CHROMA
sh_source_smearing.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Shell source construction
3  */
4 
5 #include "chromabase.h"
6 #include "handle.h"
7 
11 
14 
17 
20 
23 
24 namespace Chroma
25 {
26  // Read parameters
27  void read(XMLReader& xml, const std::string& path, ShellQuarkSourceSmearingEnv::Params& param)
28  {
30  param = tmp;
31  }
32 
33  // Writer
34  void write(XMLWriter& xml, const std::string& path, const ShellQuarkSourceSmearingEnv::Params& param)
35  {
36  param.writeXML(xml, path);
37  }
38 
39 
40 
41  //! Hooks to register the class
42  namespace ShellQuarkSourceSmearingEnv
43  {
44  namespace
45  {
46  //! Callback function
47  QuarkSourceSink<LatticePropagator>* createProp(XMLReader& xml_in,
48  const std::string& path,
49  const multi1d<LatticeColorMatrix>& u)
50  {
51  return new SourceSmearing<LatticePropagator>(Params(xml_in, path), u);
52  }
53 
54  //! Callback function
55  QuarkSourceSink<LatticeStaggeredPropagator>* createStagProp(XMLReader& xml_in,
56  const std::string& path,
57  const multi1d<LatticeColorMatrix>& u)
58  {
59  return new SourceSmearing<LatticeStaggeredPropagator>(Params(xml_in, path), u);
60  }
61 
62  //! Callback function
64  const std::string& path,
65  const multi1d<LatticeColorMatrix>& u)
66  {
67  return new SourceSmearing<LatticeFermion>(Params(xml_in, path), u);
68  }
69 
70  //! Local registration flag
71  bool registered = false;
72 
73  //! Name to be used
74  const std::string name("SHELL_SOURCE");
75  }
76 
77  //! Return the name
78  std::string getName() {return name;}
79 
80  //! Register all the factories
81  bool registerAll()
82  {
83  bool success = true;
84  if (! registered)
85  {
86  success &= LinkSmearingEnv::registerAll();
87  success &= QuarkSmearingEnv::registerAll();
89  success &= Chroma::ThePropSourceSmearingFactory::Instance().registerObject(name, createProp);
90  success &= Chroma::TheStagPropSourceSmearingFactory::Instance().registerObject(name, createStagProp);
92  registered = true;
93  }
94  return success;
95  }
96 
97 
98  //! Read parameters
100  {
101  j_decay = -1;
102  quark_smear_lastP = true;
103  }
104 
105  //! Read parameters
106  Params::Params(XMLReader& xml, const std::string& path)
107  {
108  XMLReader paramtop(xml, path);
109 
110  int version;
111  read(paramtop, "version", version);
112 
113  quark_smear_lastP = true;
114 
115  switch (version)
116  {
117  case 1:
118  {
120  int disp_length = 0;
121  int disp_dir = 0;
122 
123  XMLBufferWriter xml_tmp;
124  push(xml_tmp, "Displacement");
125  write(xml_tmp, "DisplacementType", quark_displacement.id);
126 
127  if (paramtop.count("disp_length") != 0)
128  read(paramtop, "disp_length", disp_length);
129 
130  if (paramtop.count("disp_dir") != 0)
131  read(paramtop, "disp_dir", disp_dir);
132 
133  write(xml_tmp, "disp_length", disp_length);
134  write(xml_tmp, "disp_dir", disp_dir);
135 
136  pop(xml_tmp); // Displacement
137 
138  quark_displacement.xml = xml_tmp.printCurrentContext();
139  }
140  break;
141 
142  case 2:
143  {
144  if (paramtop.count("Displacement") != 0)
145  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
146  else
148  }
149  break;
150 
151  case 3:
152  {
153  read(paramtop, "quark_smear_lastP", quark_smear_lastP);
154 
155  if (paramtop.count("Displacement") != 0)
156  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
157  else
159  }
160  break;
161 
162  default:
163  QDPIO::cerr << __func__ << ": parameter version " << version
164  << " unsupported." << std::endl;
165  QDP_abort(1);
166  }
167 
168  quark_smearing = readXMLGroup(paramtop, "SmearingParam", "wvf_kind");
169 
170  if (paramtop.count("LinkSmearing") != 0)
171  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
172  else
174 
175  read(paramtop, "j_decay", j_decay);
176  }
177 
178 
179  // Writer
180  void Params::writeXML(XMLWriter& xml, const std::string& path) const
181  {
182  push(xml, path);
183 
184  int version = 3;
185  QDP::write(xml, "version", version);
186 
187  write(xml, "SourceType", ShellQuarkSourceSmearingEnv::name);
188  xml << quark_smearing.xml;
189  xml << quark_displacement.xml;
190  xml << link_smearing.xml;
191 
192  write(xml, "j_decay", j_decay);
193  write(xml, "quark_smear_lastP", quark_smear_lastP);
194 
195  pop(xml);
196  }
197 
198 
199  //! Smear the source
200  template<>
201  void
202  SourceSmearing<LatticePropagator>::operator()(LatticePropagator& quark_source) const
203  {
204 // QDPIO::cout << "Shell source smearing" << std::endl;
205 
206  try
207  {
208  //
209  // Create the quark smearing object
210  //
211  std::istringstream xml_s(params.quark_smearing.xml);
212  XMLReader smeartop(xml_s);
213 // const std::string smear_path = "/SmearingParam";
214 
216  quarkSmearing(ThePropSmearingFactory::Instance().createObject(params.quark_smearing.id,
217  smeartop,
219 
220  //
221  // Create the quark displacement object
222  //
223  std::istringstream xml_d(params.quark_displacement.xml);
224  XMLReader displacetop(xml_d);
225 // const std::string displace_path = "/Displacement";
226 
228  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
229  displacetop,
231 
232  // Smear and displace
234  {
235  // Smear the colour source
236  // displace the point source first, then smear
237  // displacement has to be taken along negative direction.
238  (*quarkDisplacement)(quark_source, u_smr, MINUS);
239 
240  // do the smearing
241  (*quarkSmearing)(quark_source, u_smr);
242  }
243  else
244  {
245  // do the smearing
246  (*quarkSmearing)(quark_source, u_smr);
247 
248  // Smear the colour source
249  // smear the point source first, then displace
250  // displacement has to be taken along negative direction.
251  (*quarkDisplacement)(quark_source, u_smr, MINUS);
252  }
253  }
254  catch(const std::string& e)
255  {
256  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
257  QDP_abort(1);
258  }
259  }
260 
261 
262 
263 
264  //! Smear the source
265  template<>
266  void
267  SourceSmearing<LatticeStaggeredPropagator>::operator()(LatticeStaggeredPropagator& quark_source) const
268  {
269 // QDPIO::cout << "Shell source smearing" << std::endl;
270 
271  try
272  {
273  //
274  // Create the quark smearing object
275  //
276  std::istringstream xml_s(params.quark_smearing.xml);
277  XMLReader smeartop(xml_s);
278 // const std::string smear_path = "/SmearingParam";
279 
281  quarkSmearing(TheStagPropSmearingFactory::Instance().createObject(params.quark_smearing.id,
282  smeartop,
284 
285  //
286  // Create the quark displacement object
287  //
288  std::istringstream xml_d(params.quark_displacement.xml);
289  XMLReader displacetop(xml_d);
290 // const std::string displace_path = "/Displacement";
291 
293  quarkDisplacement(TheStagPropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
294  displacetop,
296 
297  // Smear and displace
299  {
300  // Smear the colour source
301  // displace the point source first, then smear
302  // displacement has to be taken along negative direction.
303  (*quarkDisplacement)(quark_source, u_smr, MINUS);
304 
305  // do the smearing
306  (*quarkSmearing)(quark_source, u_smr);
307  }
308  else
309  {
310  // do the smearing
311  (*quarkSmearing)(quark_source, u_smr);
312 
313  // Smear the colour source
314  // smear the point source first, then displace
315  // displacement has to be taken along negative direction.
316  (*quarkDisplacement)(quark_source, u_smr, MINUS);
317  }
318  }
319  catch(const std::string& e)
320  {
321  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
322  QDP_abort(1);
323  }
324  }
325 
326 
327 
328  //! Smear the source
329  template<>
330  void
331  SourceSmearing<LatticeFermion>::operator()(LatticeFermion& quark_source) const
332  {
333 // QDPIO::cout << "Shell source smearing" << std::endl;
334 
335  try
336  {
337  //
338  // Create the quark smearing object
339  //
340  std::istringstream xml_s(params.quark_smearing.xml);
341  XMLReader smeartop(xml_s);
342 // const std::string smear_path = "/SmearingParam";
343 
345  quarkSmearing(TheFermSmearingFactory::Instance().createObject(params.quark_smearing.id,
346  smeartop,
348 
349  //
350  // Create the quark displacement object
351  //
352  std::istringstream xml_d(params.quark_displacement.xml);
353  XMLReader displacetop(xml_d);
354 // const std::string displace_path = "/Displacement";
355 
357  quarkDisplacement(TheFermDisplacementFactory::Instance().createObject(params.quark_displacement.id,
358  displacetop,
360 
361  // Smear and displace
363  {
364  // Smear the colour source
365  // displace the point source first, then smear
366  // displacement has to be taken along negative direction.
367  (*quarkDisplacement)(quark_source, u_smr, MINUS);
368 
369  // do the smearing
370  (*quarkSmearing)(quark_source, u_smr);
371  }
372  else
373  {
374  // do the smearing
375  (*quarkSmearing)(quark_source, u_smr);
376 
377  // Smear the colour source
378  // smear the point source first, then displace
379  // displacement has to be taken along negative direction.
380  (*quarkDisplacement)(quark_source, u_smr, MINUS);
381  }
382  }
383  catch(const std::string& e)
384  {
385  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
386  QDP_abort(1);
387  }
388  }
389 
390  }
391 }
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
Construct the source.
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.
void write(XMLWriter &xml, const std::string &path, const ShellQuarkSourceSmearingEnv::Params &param)
Writer.
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.
bool registerAll()
Register all the factories.
std::string getName()
Return the name.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
@ MINUS
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.
All quark smearing constructors.
Factory for producing quark smearing objects.
Shell source smearing.
Simple quark displacement.
Factory for producing quark prop sources.
Factory for producing quark smearing objects.
void writeXML(XMLWriter &in, const std::string &path) const