CHROMA
pt_source_const.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 
10 #include "meas/sources/srcfil.h"
15 #include "util/ferm/transf.h"
16 
18 
19 namespace Chroma
20 {
21  // Read parameters
22  void read(XMLReader& xml, const std::string& path, PointQuarkSourceConstEnv::Params& param)
23  {
25  param = tmp;
26  }
27 
28  // Writer
29  void write(XMLWriter& xml, const std::string& path, const PointQuarkSourceConstEnv::Params& param)
30  {
31  param.writeXML(xml, path);
32  }
33 
34 
35 
36  //! Hooks to register the class
37  namespace PointQuarkSourceConstEnv
38  {
39  namespace
40  {
41  //! Callback function
42  QuarkSourceConstruction<LatticePropagator>* createProp(XMLReader& xml_in,
43  const std::string& path)
44  {
45  return new SourceConst<LatticePropagator>(Params(xml_in, path));
46  }
47 
48  //! Callback function
49  QuarkSourceConstruction<LatticeStaggeredPropagator>* createStagProp(XMLReader& xml_in,
50  const std::string& path)
51  {
52  return new SourceConst<LatticeStaggeredPropagator>(Params(xml_in, path));
53  }
54 
55  //! Local registration flag
56  bool registered = false;
57 
58  //! Name to be used
59  const std::string name("POINT_SOURCE");
60  }
61 
62  //! Return the name
63  std::string getName() {return name;}
64 
65  //! Register all the factories
66  bool registerAll()
67  {
68  bool success = true;
69  if (! registered)
70  {
71  success &= LinkSmearingEnv::registerAll();
73  success &= Chroma::ThePropSourceConstructionFactory::Instance().registerObject(name, createProp);
74  success &= Chroma::TheStagPropSourceConstructionFactory::Instance().registerObject(name, createStagProp);
75  registered = true;
76  }
77  return success;
78  }
79 
80  //! Initialize
82  {
83  j_decay = -1;
84  t_srce.resize(Nd);
85  t_srce = 0;
86  }
87 
88 
89  //! Read parameters
90  Params::Params(XMLReader& xml, const std::string& path)
91  {
92  XMLReader paramtop(xml, path);
93 
94  int version;
95  read(paramtop, "version", version);
96 
97  switch (version)
98  {
99  case 1:
100  {
103  int disp_length = 0;
104  int disp_dir = 0;
105 
106  XMLBufferWriter xml_tmp;
107  push(xml_tmp, "Displacement");
108  write(xml_tmp, "DisplacementType", quark_displacement.id);
109 
110  if (paramtop.count("disp_length") != 0)
111  read(paramtop, "disp_length", disp_length);
112 
113  if (paramtop.count("disp_dir") != 0)
114  read(paramtop, "disp_dir", disp_dir);
115 
116  write(xml_tmp, "disp_length", disp_length);
117  write(xml_tmp, "disp_dir", disp_dir);
118 
119  pop(xml_tmp); // Displacement
120 
121  quark_displacement.xml = xml_tmp.printCurrentContext();
122  }
123  break;
124 
125  case 2:
126  {
127  if (paramtop.count("Displacement") != 0)
128  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
129  else
131  }
132  break;
133 
134  default:
135  QDPIO::cerr << __func__ << ": parameter version " << version
136  << " unsupported." << std::endl;
137  QDP_abort(1);
138  }
139 
140  read(paramtop, "j_decay", j_decay);
141  read(paramtop, "t_srce", t_srce);
142 
143  if (paramtop.count("LinkSmearing") != 0)
144  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
145  else
147  }
148 
149 
150  // Writer
151  void Params::writeXML(XMLWriter& xml, const std::string& path) const
152  {
153  push(xml, path);
154 
155  int version = 2;
156  write(xml, "version", version);
157 
158  write(xml, "SourceType", PointQuarkSourceConstEnv::name);
159  write(xml, "j_decay", j_decay);
160  write(xml, "t_srce", t_srce);
161  xml << link_smearing.xml;
162  xml << quark_displacement.xml;
163  pop(xml);
164  }
165 
166 
167 
168  //! Construct the source
169  template<>
170  LatticePropagator
171  SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
172  {
173  QDPIO::cout << "Point source" << std::endl;
174 
175  // Create the quark source
176  LatticePropagator quark_source;
177 
178  try
179  {
180  //
181  // Smear the gauge field if needed
182  //
183  multi1d<LatticeColorMatrix> u_smr = u;
184  {
185  std::istringstream xml_l(params.link_smearing.xml);
186  XMLReader linktop(xml_l);
187  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
188 
190  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
191  linktop,
193  (*linkSmearing)(u_smr);
194  }
195 
196  //
197  // Create the quark displacement object
198  //
199  std::istringstream xml_d(params.quark_displacement.xml);
200  XMLReader displacetop(xml_d);
201 
203  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
204  displacetop,
206 
207  for(int color_source = 0; color_source < Nc; ++color_source)
208  {
209  QDPIO::cout << "color = " << color_source << std::endl;
210 
211  LatticeColorVector src_color_vec = zero;
212 
213  // Make a point source at coordinates t_source
214  srcfil(src_color_vec, params.t_srce, color_source);
215 
216  for(int spin_source = 0; spin_source < Ns; ++spin_source)
217  {
218  QDPIO::cout << "spin = " << spin_source << std::endl;
219 
220  // Insert a ColorVector into spin index spin_source
221  // This only overwrites sections, so need to initialize first
222  LatticeFermion chi = zero;
223 
224  CvToFerm(src_color_vec, chi, spin_source);
225 
226  /*
227  * Move the source to the appropriate components
228  * of quark source.
229  */
230  FermToProp(chi, quark_source, color_source, spin_source);
231  }
232  }
233 
234  // displace the point source first, then smear
235  // displacement has to be taken along negative direction.
236  (*quarkDisplacement)(quark_source, u_smr, MINUS);
237 
238  }
239  catch(const std::string& e)
240  {
241  QDPIO::cerr << name << ": Caught Exception in source construction: " << e << std::endl;
242  QDP_abort(1);
243  }
244 
245  return quark_source;
246  }
247 
248 
249 
250  //! Construct the source
251  template<>
252  LatticeStaggeredPropagator
253  SourceConst<LatticeStaggeredPropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
254  {
255  QDPIO::cout << "Point source" << std::endl;
256 
257  // Create the quark source
258  LatticeStaggeredPropagator quark_source;
259 
260  try
261  {
262  //
263  // Smear the gauge field if needed
264  //
265  multi1d<LatticeColorMatrix> u_smr = u;
266  {
267  std::istringstream xml_l(params.link_smearing.xml);
268  XMLReader linktop(xml_l);
269  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
270 
272  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
273  linktop,
275  (*linkSmearing)(u_smr);
276  }
277 
278  //
279  // Create the quark displacement object
280  //
281  std::istringstream xml_d(params.quark_displacement.xml);
282  XMLReader displacetop(xml_d);
283 
285  quarkDisplacement(TheStagPropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
286  displacetop,
288 
289  for(int color_source = 0; color_source < Nc; ++color_source)
290  {
291  QDPIO::cout << "color = " << color_source << std::endl;
292 
293  LatticeColorVector src_color_vec = zero;
294 
295  // Make a point source at coordinates t_source
296  srcfil(src_color_vec, params.t_srce, color_source);
297 
298  // Insert a ColorVector into spin index spin_source
299  // This only overwrites sections, so need to initialize first
300  LatticeStaggeredFermion chi = zero;
301 
302  CvToFerm(src_color_vec, chi);
303 
304  /*
305  * Move the source to the appropriate components
306  * of quark source.
307  */
308  FermToProp(chi, quark_source, color_source);
309  }
310 
311  // displace the point source first, then smear
312  // displacement has to be taken along negative direction.
313  (*quarkDisplacement)(quark_source, u_smr, MINUS);
314 
315  }
316  catch(const std::string& e)
317  {
318  QDPIO::cerr << name << ": Caught Exception in source construction: " << e << std::endl;
319  QDP_abort(1);
320  }
321 
322  return quark_source;
323  }
324 
325  }
326 
327 }
Primary include file for CHROMA library code.
Class for counted reference semantics.
Definition: handle.h:33
T operator()(const multi1d< LatticeColorMatrix > &u) const
Construct the source.
Base class for quark source construction.
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 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.
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")
@ 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
Point source construction.
All quark displacement constructors.
Factory for producing quark displacement objects.
Simple quark displacement.
Factory for producing quark prop sources.
Point source construction.
void writeXML(XMLWriter &in, const std::string &path) const