CHROMA
pt_source_smearing.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Point source construction
3  */
4 
5 #include "chromabase.h"
6 #include "handle.h"
7 
14 
16 
17 namespace Chroma
18 {
19 
20  // Read parameters
21  void read(XMLReader& xml, const std::string& path, PointQuarkSourceSmearingEnv::Params& param)
22  {
24  param = tmp;
25  }
26 
27  // Writer
28  void write(XMLWriter& xml, const std::string& path, const PointQuarkSourceSmearingEnv::Params& param)
29  {
30  param.writeXML(xml, path);
31  }
32 
33 
34 
35  //! Hooks to register the class with the fermact factory
36  namespace PointQuarkSourceSmearingEnv
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 SourceSmear<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 SourceSmear<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 SourceSmear<LatticeFermion>(Params(xml_in, path), u);
62  }
63 
64  //! Local registration flag
65  bool registered = false;
66 
67  //! Name to be used
68  const std::string name("POINT_SOURCE");
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::ThePropSourceSmearingFactory::Instance().registerObject(name, createProp);
83  success &= Chroma::TheStagPropSourceSmearingFactory::Instance().registerObject(name, createStagProp);
85  registered = true;
86  }
87  return success;
88  }
89 
90 
91  //! Read parameters
93  {
94  j_decay = -1;
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  {
110  int disp_length = 0;
111  int disp_dir = 0;
112 
113  XMLBufferWriter xml_tmp;
114  push(xml_tmp, "Displacement");
115  write(xml_tmp, "DisplacementType", quark_displacement.id);
116 
117  if (paramtop.count("disp_length") != 0)
118  read(paramtop, "disp_length", disp_length);
119 
120  if (paramtop.count("disp_dir") != 0)
121  read(paramtop, "disp_dir", disp_dir);
122 
123  write(xml_tmp, "disp_length", disp_length);
124  write(xml_tmp, "disp_dir", disp_dir);
125 
126  pop(xml_tmp); // Displacement
127 
128  quark_displacement.xml = xml_tmp.printCurrentContext();
129  }
130  break;
131 
132  case 2:
133  {
134  if (paramtop.count("Displacement") != 0)
135  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
136  else
138  }
139  break;
140 
141  default:
142  QDPIO::cerr << __func__ << ": parameter version " << version
143  << " unsupported." << std::endl;
144  QDP_abort(1);
145  }
146 
147  read(paramtop, "j_decay", j_decay);
148 
149  if (paramtop.count("LinkSmearing") != 0)
150  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
151  else
153  }
154 
155 
156  // Writer
157  void Params::writeXML(XMLWriter& xml, const std::string& path) const
158  {
159  push(xml, path);
160 
161  int version = 2;
162  write(xml, "version", version);
163 
164  write(xml, "SourceType", PointQuarkSourceSmearingEnv::name);
165  write(xml, "j_decay", j_decay);
166  xml << link_smearing.xml;
167  xml << quark_displacement.xml;
168  pop(xml);
169  }
170 
171 
172 
173  //! Construct the source smearing
174  template<>
175  void
176  SourceSmear<LatticePropagator>::operator()(LatticePropagator& quark_source) const
177  {
178 // QDPIO::cout << "Point source" << std::endl;
179 
180  // displace the point source first, then smear
181  // displacement has to be taken along negative direction.
182 
183  try
184  {
185  //
186  // Create the quark displacement object
187  //
188  std::istringstream xml_d(params.quark_displacement.xml);
189  XMLReader displacetop(xml_d);
190 // const std::string displace_path = "/Displacement";
191 
193  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
194  displacetop,
196 
197  //
198  // Displace quark source
199  //
200  (*quarkDisplacement)(quark_source, u_smr, MINUS);
201 
202  }
203  catch(const std::string& e)
204  {
205  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
206  QDP_abort(1);
207  }
208  }
209 
210 
211 
212  //! Construct the source smearing
213  template<>
214  void
215  SourceSmear<LatticeStaggeredPropagator>::operator()(LatticeStaggeredPropagator& quark_source) const
216  {
217 // QDPIO::cout << "Point source" << std::endl;
218 
219  // displace the point source first, then smear
220  // displacement has to be taken along negative direction.
221 
222  try
223  {
224  //
225  // Create the quark displacement object
226  //
227  std::istringstream xml_d(params.quark_displacement.xml);
228  XMLReader displacetop(xml_d);
229 // const std::string displace_path = "/Displacement";
230 
232  quarkDisplacement(TheStagPropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
233  displacetop,
235 
236  //
237  // Displace quark source
238  //
239  (*quarkDisplacement)(quark_source, u_smr, MINUS);
240 
241  }
242  catch(const std::string& e)
243  {
244  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
245  QDP_abort(1);
246  }
247  }
248 
249 
250 
251  //! Construct the source smearing
252  template<>
253  void
254  SourceSmear<LatticeFermion>::operator()(LatticeFermion& quark_source) const
255  {
256 // QDPIO::cout << "Point source" << std::endl;
257 
258  // displace the point source first, then smear
259  // displacement has to be taken along negative direction.
260 
261  try
262  {
263  //
264  // Create the quark displacement object
265  //
266  std::istringstream xml_d(params.quark_displacement.xml);
267  XMLReader displacetop(xml_d);
268 // const std::string displace_path = "/Displacement";
269 
271  quarkDisplacement(TheFermDisplacementFactory::Instance().createObject(params.quark_displacement.id,
272  displacetop,
274 
275  //
276  // Displace quark source
277  //
278  (*quarkDisplacement)(quark_source, u_smr, MINUS);
279 
280  }
281  catch(const std::string& e)
282  {
283  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
284  QDP_abort(1);
285  }
286  }
287 
288  } // end namespace
289 
290 } // end namespace Chroma
Primary include file for CHROMA library code.
Class for counted reference semantics.
Definition: handle.h:33
void operator()(T &obj) const
Construct the source.
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.
bool registerAll()
Register all the factories.
std::string getName()
Return the name.
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")
@ MINUS
Definition: chromabase.h:45
pop(xml_out)
::std::string string
Definition: gtest.h:1979
Point source construction.
All quark displacement constructors.
Factory for producing quark displacement objects.
Simple quark displacement.
Factory for producing quark smearing objects.
void writeXML(XMLWriter &in, const std::string &path) const