CHROMA
norm_sh_source_const.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Normalized 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, NormShellQuarkSourceConstEnv::Params& param)
29  {
31  param = tmp;
32  }
33 
34  // Writer
35  void write(XMLWriter& xml, const std::string& path, const NormShellQuarkSourceConstEnv::Params& param)
36  {
37  param.writeXML(xml, path);
38  }
39 
40 
41 
42  //! Hooks to register the class
43  namespace NormShellQuarkSourceConstEnv
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("NORM_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  read(paramtop, "Nhits", Nhits);
173 
174  site_normalized = false ;
175  if (paramtop.count("SiteNormalize") != 0){
176  read(paramtop, "SiteNormalize", site_normalized );
177  }
178 
179  }
180 
181 
182  // Writer
183  void Params::writeXML(XMLWriter& xml, const std::string& path) const
184  {
185  push(xml, path);
186 
187  int version = 3;
188  QDP::write(xml, "version", version);
189 
190  write(xml, "SourceType", NormShellQuarkSourceConstEnv::name);
191  xml << quark_smearing.xml;
192  xml << quark_displacement.xml;
193  xml << link_smearing.xml;
194 
195  write(xml, "t_srce", t_srce);
196  write(xml, "j_decay", j_decay);
197  write(xml, "Nhits", Nhits);
198  write(xml, "quark_smear_lastP", quark_smear_lastP);
199  write(xml, "SiteNormalize", site_normalized);
200 
201  pop(xml);
202  }
203 
204 
205 
206  //! Construct the source
207  template<>
208  LatticePropagator
209  SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
210  {
211  QDPIO::cout << "NormShell source" << std::endl;
212 
213  LatticePropagator quark_source;
214 
215  try
216  {
217  //
218  // Smear the gauge field if needed
219  //
220  multi1d<LatticeColorMatrix> u_smr = u;
221  {
222  std::istringstream xml_l(params.link_smearing.xml);
223  XMLReader linktop(xml_l);
224  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
225 
227  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
228  linktop,
230  (*linkSmearing)(u_smr);
231  }
232 
233  //
234  // Create the quark smearing object
235  //
236  std::istringstream xml_s(params.quark_smearing.xml);
237  XMLReader smeartop(xml_s);
238  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
239 
241  quarkSmearing(TheColorVecSmearingFactory::Instance().createObject(params.quark_smearing.id,
242  smeartop,
244 
245  //
246  // Create the quark displacement object
247  //
248  std::istringstream xml_d(params.quark_displacement.xml);
249  XMLReader displacetop(xml_d);
250  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
251 
253  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
254  displacetop,
256 
257  //
258  // Create quark source
259  //
260  multi1d<LatticeColorVector> v(Nc);
261  for(int c = 0; c < Nc; ++c){
262  QDPIO::cout << "color = " << c << std::endl;
263  v[c] = zero;
264  srcfil(v[c], params.t_srce, c);
265  }
266  for(int hit(0);hit<params.Nhits;hit++){
267  QDPIO::cout << "smearing hit = " << hit << std::endl;
268  for(int c = 0; c < Nc; ++c){
269  (*quarkSmearing)(v[c], u_smr);
270  for(int k(0);k<c;k++){
271  DComplex cc = innerProduct(v[k],v[c]);
272  v[c] -= cc*v[k] ;
273  }
274  Double nn = sqrt(norm2(v[c])) ;
275  v[c] /= nn ;
276  }
277  }
278  for(int color_source = 0; color_source < Nc; ++color_source)
279  {
280  QDPIO::cout << "color = " << color_source << std::endl;
281 
282  for(int spin_source = 0; spin_source < Ns; ++spin_source)
283  {
284  QDPIO::cout << "spin = " << spin_source << std::endl;
285 
286  // Insert a ColorVector into spin index spin_source
287  // This only overwrites sections, so need to initialize first
288  LatticeFermion chi = zero;
289 
290  CvToFerm(v[color_source], chi, spin_source);
291 
292  /*
293  * Move the source to the appropriate components
294  * of quark source.
295  */
296  FermToProp(chi, quark_source, color_source, spin_source);
297  }
298  }
299 
300  //DISABLE this for the moment. I will always first smear and then
301  //displace in the MINUS direction
302  (*quarkDisplacement)(quark_source, u_smr, MINUS);
303 #if 0
304  // Smear and displace
306  {
307  // Smear the colour source
308  // displace the point source first, then smear
309  // displacement has to be taken along negative direction.
310  QDPIO::cout<<__func__
311  <<": WARNING: The quark_smear_lastP not implemented!!"
312  <<std::endl ;
313  }
314  else
315  {
316  // Smear the colour source
317  // smear the point source first, then displace
318  // displacement has to be taken along negative direction.
319  (*quarkDisplacement)(quark_source, u_smr, MINUS);
320  }
321 #endif
322 
323  }
324  catch(const std::string& e)
325  {
326  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
327  QDP_abort(1);
328  }
329 
330  return quark_source;
331  }
332 
333 
334 
335  //! Construct the source
336  template<>
337  LatticeStaggeredPropagator
338  SourceConst<LatticeStaggeredPropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
339  {
340  QDPIO::cout << "NormShell source" << std::endl;
341 
342  LatticeStaggeredPropagator quark_source;
343 
344  try
345  {
346  //
347  // Smear the gauge field if needed
348  //
349  multi1d<LatticeColorMatrix> u_smr = u;
350  {
351  std::istringstream xml_l(params.link_smearing.xml);
352  XMLReader linktop(xml_l);
353  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
354 
356  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
357  linktop,
359  (*linkSmearing)(u_smr);
360  }
361 
362  //
363  // Create the quark smearing object
364  //
365  std::istringstream xml_s(params.quark_smearing.xml);
366  XMLReader smeartop(xml_s);
367  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
368 
370  quarkSmearing(TheStagPropSmearingFactory::Instance().createObject(params.quark_smearing.id,
371  smeartop,
373 
374  //
375  // Create the quark displacement object
376  //
377  std::istringstream xml_d(params.quark_displacement.xml);
378  XMLReader displacetop(xml_d);
379  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
380 
382  quarkDisplacement(TheStagPropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
383  displacetop,
385 
386  //
387  // Create quark source
388  //
389  for(int color_source = 0; color_source < Nc; ++color_source)
390  {
391  QDPIO::cout << "color = " << color_source << std::endl;
392 
393  LatticeColorVector src_color_vec = zero;
394 
395  // Make a point source at coordinates t_srce
396  srcfil(src_color_vec, params.t_srce, color_source);
397 
398  // Insert a ColorVector into spin index spin_source
399  // This only overwrites sections, so need to initialize first
400  LatticeStaggeredFermion chi = zero;
401 
402  CvToFerm(src_color_vec, chi);
403 
404  /*
405  * Move the source to the appropriate components
406  * of quark source.
407  */
408  FermToProp(chi, quark_source, color_source);
409  }
410 
411 
412  // Smear and displace
414  {
415  // Smear the colour source
416  // displace the point source first, then smear
417  // displacement has to be taken along negative direction.
418  (*quarkDisplacement)(quark_source, u_smr, MINUS);
419 
420  // do the smearing
421  (*quarkSmearing)(quark_source, u_smr);
422  }
423  else
424  {
425  // do the smearing
426  (*quarkSmearing)(quark_source, u_smr);
427 
428  // Smear the colour source
429  // smear the point source first, then displace
430  // displacement has to be taken along negative direction.
431  (*quarkDisplacement)(quark_source, u_smr, MINUS);
432  }
433 
434  }
435  catch(const std::string& e)
436  {
437  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
438  QDP_abort(1);
439  }
440 
441  return quark_source;
442  }
443 
444  }
445 }
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 write(XMLWriter &xml, const std::string &path, const NormShellQuarkSourceConstEnv::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.
BinaryReturn< C1, C2, FnInnerProduct >::Type_t innerProduct(const QDPSubType< T1, C1 > &s1, const QDPType< T2, C2 > &s2)
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.
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")
Double c
Definition: invbicg.cc:108
@ MINUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
pop(xml_out)
Double zero
Definition: invbicg.cc:106
int k
Definition: invbicg.cc:119
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
No quark displacement.
Normalized Shell source construction.
All quark displacement constructors.
Factory for producing quark displacement objects.
All quark smearing constructors.
Factory for producing quark smearing objects.
Simple quark displacement.
Factory for producing quark prop sources.
Point source construction.
void writeXML(XMLWriter &out, const std::string &path) const