CHROMA
sh_source_const.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 
10 #include "meas/sources/srcfil.h"
11 #include "util/ferm/transf.h"
12 
15 
18 
21 
24 
25 namespace Chroma
26 {
27  // Read parameters
28  void read(XMLReader& xml, const std::string& path, ShellQuarkSourceConstEnv::Params& param)
29  {
31  param = tmp;
32  }
33 
34  // Writer
35  void write(XMLWriter& xml, const std::string& path, const ShellQuarkSourceConstEnv::Params& param)
36  {
37  param.writeXML(xml, path);
38  }
39 
40 
41 
42  //! Hooks to register the class
43  namespace ShellQuarkSourceConstEnv
44  {
45  namespace
46  {
47  //! Callback function
48  QuarkSourceConstruction<LatticePropagator>* createProp(XMLReader& xml_in,
49  const std::string& path)
50  {
51  return new SourceConst<LatticePropagator>(Params(xml_in, path));
52  }
53 
54  //! Callback function
55  QuarkSourceConstruction<LatticeStaggeredPropagator>* createStagProp(XMLReader& xml_in,
56  const std::string& path)
57  {
58  return new SourceConst<LatticeStaggeredPropagator>(Params(xml_in, path));
59  }
60 
61  //! Local registration flag
62  bool registered = false;
63 
64  //! Name to be used
65  const std::string name("SHELL_SOURCE");
66  }
67 
68  //! Return the name
69  std::string getName() {return name;}
70 
71  //! Register all the factories
72  bool registerAll()
73  {
74  bool success = true;
75  if (! registered)
76  {
77  success &= LinkSmearingEnv::registerAll();
78  success &= QuarkSmearingEnv::registerAll();
80  success &= Chroma::ThePropSourceConstructionFactory::Instance().registerObject(name, createProp);
81  success &= Chroma::TheStagPropSourceConstructionFactory::Instance().registerObject(name, createStagProp);
82 
83  registered = true;
84  }
85  return success;
86  }
87 
88 
89  //! Read parameters
91  {
92  j_decay = -1;
93  t_srce.resize(Nd);
94  t_srce = 0;
95  quark_smear_lastP = true;
96  }
97 
98  //! Read parameters
99  Params::Params(XMLReader& xml, const std::string& path)
100  {
101  XMLReader paramtop(xml, path);
102 
103  int version;
104  read(paramtop, "version", version);
105 
106  quark_smear_lastP = true;
107 
108  switch (version)
109  {
110  case 1:
111  {
114  int disp_length = 0;
115  int disp_dir = 0;
116 
117  XMLBufferWriter xml_tmp;
118  push(xml_tmp, "Displacement");
119  write(xml_tmp, "DisplacementType", quark_displacement.id);
120 
121  if (paramtop.count("disp_length") != 0)
122  read(paramtop, "disp_length", disp_length);
123 
124  if (paramtop.count("disp_dir") != 0)
125  read(paramtop, "disp_dir", disp_dir);
126 
127  write(xml_tmp, "disp_length", disp_length);
128  write(xml_tmp, "disp_dir", disp_dir);
129 
130  pop(xml_tmp); // Displacement
131 
132  quark_displacement.xml = xml_tmp.printCurrentContext();
133  }
134  break;
135 
136  case 2:
137  {
138  if (paramtop.count("Displacement") != 0)
139  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
140  else
142  }
143  break;
144 
145  case 3:
146  {
147  read(paramtop, "quark_smear_lastP", quark_smear_lastP);
148 
149  if (paramtop.count("Displacement") != 0)
150  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
151  else
153  }
154  break;
155 
156  default:
157  QDPIO::cerr << __func__ << ": parameter version " << version
158  << " unsupported." << std::endl;
159  QDP_abort(1);
160  }
161 
162  quark_smearing = readXMLGroup(paramtop, "SmearingParam", "wvf_kind");
163 
164  if (paramtop.count("LinkSmearing") != 0)
165  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
166  else
168 
169  read(paramtop, "t_srce", t_srce);
170  read(paramtop, "j_decay", j_decay);
171  }
172 
173 
174  // Writer
175  void Params::writeXML(XMLWriter& xml, const std::string& path) const
176  {
177  push(xml, path);
178 
179  int version = 3;
180  QDP::write(xml, "version", version);
181 
182  write(xml, "SourceType", ShellQuarkSourceConstEnv::name);
183  xml << quark_smearing.xml;
184  xml << quark_displacement.xml;
185  xml << link_smearing.xml;
186 
187  write(xml, "t_srce", t_srce);
188  write(xml, "j_decay", j_decay);
189  write(xml, "quark_smear_lastP", quark_smear_lastP);
190 
191  pop(xml);
192  }
193 
194 
195 
196  //! Construct the source
197  template<>
198  LatticePropagator
199  SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
200  {
201  QDPIO::cout << "Shell source" << std::endl;
202 
203  LatticePropagator quark_source;
204 
205  try
206  {
207  //
208  // Smear the gauge field if needed
209  //
210  multi1d<LatticeColorMatrix> u_smr = u;
211  {
212  std::istringstream xml_l(params.link_smearing.xml);
213  XMLReader linktop(xml_l);
214  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
215 
217  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
218  linktop,
220  (*linkSmearing)(u_smr);
221  }
222 
223  //
224  // Create the quark smearing object
225  //
226  std::istringstream xml_s(params.quark_smearing.xml);
227  XMLReader smeartop(xml_s);
228  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
229 
231  quarkSmearing(ThePropSmearingFactory::Instance().createObject(params.quark_smearing.id,
232  smeartop,
234 
235  //
236  // Create the quark displacement object
237  //
238  std::istringstream xml_d(params.quark_displacement.xml);
239  XMLReader displacetop(xml_d);
240  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
241 
243  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
244  displacetop,
246 
247  //
248  // Create quark source
249  //
250  for(int color_source = 0; color_source < Nc; ++color_source)
251  {
252  QDPIO::cout << "color = " << color_source << std::endl;
253 
254  LatticeColorVector src_color_vec = zero;
255 
256  // Make a point source at coordinates t_srce
257  srcfil(src_color_vec, params.t_srce, color_source);
258 
259  for(int spin_source = 0; spin_source < Ns; ++spin_source)
260  {
261  QDPIO::cout << "spin = " << spin_source << std::endl;
262 
263  // Insert a ColorVector into spin index spin_source
264  // This only overwrites sections, so need to initialize first
265  LatticeFermion chi = zero;
266 
267  CvToFerm(src_color_vec, chi, spin_source);
268 
269  /*
270  * Move the source to the appropriate components
271  * of quark source.
272  */
273  FermToProp(chi, quark_source, color_source, spin_source);
274  }
275  }
276 
277 
278  // Smear and displace
280  {
281  // Smear the colour source
282  // displace the point source first, then smear
283  // displacement has to be taken along negative direction.
284  (*quarkDisplacement)(quark_source, u_smr, MINUS);
285 
286  // do the smearing
287  (*quarkSmearing)(quark_source, u_smr);
288  }
289  else
290  {
291  // do the smearing
292  (*quarkSmearing)(quark_source, u_smr);
293 
294  // Smear the colour source
295  // smear the point source first, then displace
296  // displacement has to be taken along negative direction.
297  (*quarkDisplacement)(quark_source, u_smr, MINUS);
298  }
299 
300  }
301  catch(const std::string& e)
302  {
303  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
304  QDP_abort(1);
305  }
306 
307  return quark_source;
308  }
309 
310 
311 
312  //! Construct the source
313  template<>
314  LatticeStaggeredPropagator
315  SourceConst<LatticeStaggeredPropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
316  {
317  QDPIO::cout << "Shell source" << std::endl;
318 
319  LatticeStaggeredPropagator quark_source;
320 
321  try
322  {
323  //
324  // Smear the gauge field if needed
325  //
326  multi1d<LatticeColorMatrix> u_smr = u;
327  {
328  std::istringstream xml_l(params.link_smearing.xml);
329  XMLReader linktop(xml_l);
330  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
331 
333  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
334  linktop,
336  (*linkSmearing)(u_smr);
337  }
338 
339  //
340  // Create the quark smearing object
341  //
342  std::istringstream xml_s(params.quark_smearing.xml);
343  XMLReader smeartop(xml_s);
344  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
345 
347  quarkSmearing(TheStagPropSmearingFactory::Instance().createObject(params.quark_smearing.id,
348  smeartop,
350 
351  //
352  // Create the quark displacement object
353  //
354  std::istringstream xml_d(params.quark_displacement.xml);
355  XMLReader displacetop(xml_d);
356  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
357 
359  quarkDisplacement(TheStagPropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
360  displacetop,
362 
363  //
364  // Create quark source
365  //
366  for(int color_source = 0; color_source < Nc; ++color_source)
367  {
368  QDPIO::cout << "color = " << color_source << std::endl;
369 
370  LatticeColorVector src_color_vec = zero;
371 
372  // Make a point source at coordinates t_srce
373  srcfil(src_color_vec, params.t_srce, color_source);
374 
375  // Insert a ColorVector into spin index spin_source
376  // This only overwrites sections, so need to initialize first
377  LatticeStaggeredFermion chi = zero;
378 
379  CvToFerm(src_color_vec, chi);
380 
381  /*
382  * Move the source to the appropriate components
383  * of quark source.
384  */
385  FermToProp(chi, quark_source, color_source);
386  }
387 
388 
389  // Smear and displace
391  {
392  // Smear the colour source
393  // displace the point source first, then smear
394  // displacement has to be taken along negative direction.
395  (*quarkDisplacement)(quark_source, u_smr, MINUS);
396 
397  // do the smearing
398  (*quarkSmearing)(quark_source, u_smr);
399  }
400  else
401  {
402  // do the smearing
403  (*quarkSmearing)(quark_source, u_smr);
404 
405  // Smear the colour source
406  // smear the point source first, then displace
407  // displacement has to be taken along negative direction.
408  (*quarkDisplacement)(quark_source, u_smr, MINUS);
409  }
410 
411  }
412  catch(const std::string& e)
413  {
414  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
415  QDP_abort(1);
416  }
417 
418  return quark_source;
419  }
420 
421  }
422 }
Primary include file for CHROMA library code.
Class for counted reference semantics.
Definition: handle.h:33
Base class for quark source construction.
T operator()(const multi1d< LatticeColorMatrix > &u) const
Construct the source.
static T & Instance()
Definition: singleton.h:432
void CvToFerm(const LatticeColorVectorF &a, LatticeFermionF &b, int spin_index)
Convert (insert) a LatticeColorVector into a LatticeFermion.
Definition: transf.cc:18
void FermToProp(const LatticeFermionF &a, LatticePropagatorF &b, int color_index, int spin_index)
Insert a LatticeFermion into a LatticePropagator.
Definition: transf.cc:98
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 ShellQuarkSourceConstEnv::Params &param)
Writer.
void srcfil(LatticeFermion &a, const multi1d< int > &coord, int color_index, int spin_index)
Fill a specific color and spin index with 1.0.
Definition: srcfil.cc:23
Class for counted reference semantics.
Params params
Nd
Definition: meslate.cc:74
static bool registered
Local registration flag.
const std::string name
Name to be used.
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
multi1d< LatticeFermion > chi(Ncb)
pop(xml_out)
Double zero
Definition: invbicg.cc:106
::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 construction.
Simple quark displacement.
Factory for producing quark prop sources.
Point source construction.
void writeXML(XMLWriter &out, const std::string &path) const