CHROMA
norm_sh_sink_smearing.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief NormShell sink smearing
3  */
4 
5 #include "chromabase.h"
6 #include "handle.h"
7 
10 
13 
16 
18 
21 
24 
25 namespace Chroma
26 {
27  // Read parameters
28  void read(XMLReader& xml, const std::string& path, NormShellQuarkSinkSmearingEnv::Params& param)
29  {
31  param = tmp;
32  }
33 
34  // Writer
35  void write(XMLWriter& xml, const std::string& path, const NormShellQuarkSinkSmearingEnv::Params& param)
36  {
37  param.writeXML(xml, path);
38  }
39 
40 
41 
42  //! Hooks to register the class
43  namespace NormShellQuarkSinkSmearingEnv
44  {
45  namespace
46  {
47  //! Callback function
48  QuarkSourceSink<LatticePropagator>* createProp(XMLReader& xml_in,
49  const std::string& path,
50  const multi1d<LatticeColorMatrix>& u)
51  {
52  return new SinkSmear<LatticePropagator>(Params(xml_in, path), u);
53  }
54 
55  //! Callback function
56  QuarkSourceSink<LatticeStaggeredPropagator>* createStagProp(XMLReader& xml_in,
57  const std::string& path,
58  const multi1d<LatticeColorMatrix>& u)
59  {
60  return new SinkSmear<LatticeStaggeredPropagator>(Params(xml_in, path), u);
61  }
62 
63  //! Callback function
65  const std::string& path,
66  const multi1d<LatticeColorMatrix>& u)
67  {
68  return new SinkSmear<LatticeFermion>(Params(xml_in, path), u);
69  }
70 
71  //! Name to be used
72  const std::string name("NORM_SHELL_SINK");
73 
74  //! Local registration flag
75  bool registered = false;
76  }
77 
78  //! Return the name
79  std::string getName() {return name;}
80 
81  //! Register all the factories
82  bool registerAll()
83  {
84  bool success = true;
85  if (! registered)
86  {
87  success &= LinkSmearingEnv::registerAll();
88  success &= QuarkSmearingEnv::registerAll();
90  success &= Chroma::ThePropSinkSmearingFactory::Instance().registerObject(name, createProp);
91  success &= Chroma::TheStagPropSinkSmearingFactory::Instance().registerObject(name, createStagProp);
92  success &= Chroma::TheFermSinkSmearingFactory::Instance().registerObject(name, createFerm);
93 
94  registered = true;
95  }
96  return success;
97  }
98 
99 
100  //! Initialize
102  {
103  quark_smear_firstP = true;
104  }
105 
106 
107  //! Read parameters
108  Params::Params(XMLReader& xml, const std::string& path)
109  {
110  XMLReader paramtop(xml, path);
111 
112  int version;
113  read(paramtop, "version", version);
114 
115  quark_smear_firstP = true;
116 
117  switch (version)
118  {
119  case 1:
120  {
123  int disp_length = 0;
124  int disp_dir = 0;
125 
126  XMLBufferWriter xml_tmp;
127  push(xml_tmp, "Displacement");
128  write(xml_tmp, "DisplacementType", quark_displacement.id);
129 
130  if (paramtop.count("disp_length") != 0)
131  read(paramtop, "disp_length", disp_length);
132 
133  if (paramtop.count("disp_dir") != 0)
134  read(paramtop, "disp_dir", disp_dir);
135 
136  write(xml_tmp, "disp_length", disp_length);
137  write(xml_tmp, "disp_dir", disp_dir);
138 
139  pop(xml_tmp); // Displacement
140 
141  quark_displacement.xml = xml_tmp.printCurrentContext();
142  }
143  break;
144 
145  case 2:
146  {
147  if (paramtop.count("Displacement") != 0)
148  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
149  else
151  }
152  break;
153 
154  case 3:
155  {
156  read(paramtop, "quark_smear_firstP", quark_smear_firstP);
157 
158  if (paramtop.count("Displacement") != 0)
159  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
160  else
162  }
163  break;
164 
165  default:
166  QDPIO::cerr << __func__ << ": parameter version " << version
167  << " unsupported." << std::endl;
168  QDP_abort(1);
169  }
170 
171  quark_smearing = readXMLGroup(paramtop, "SmearingParam", "wvf_kind");
172 
173  if (paramtop.count("LinkSmearing") != 0)
174  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
175  else
177 
178  read(paramtop, "Nhits", Nhits);
179 
180  site_normalized = false ;
181  if (paramtop.count("SiteNormalize") != 0){
182  read(paramtop, "SiteNormalize", site_normalized );
183  }
184 
185  }
186 
187 
188  // Writer
189  void Params::writeXML(XMLWriter& xml, const std::string& path) const
190  {
191  push(xml, path);
192 
193  int version = 3;
194  write(xml, "version", version);
195 
196  write(xml, "SinkType", NormShellQuarkSinkSmearingEnv::getName());
197  xml << quark_smearing.xml;
198  xml << quark_displacement.xml;
199  xml << link_smearing.xml;
200  write(xml, "quark_smear_firstP", quark_smear_firstP);
201  write(xml, "Nhits", Nhits);
202  write(xml, "SiteNormalize", site_normalized);
203  pop(xml);
204 
205  pop(xml);
206  }
207 
208 
209 
210  //! Smear the sink
211  template<>
212  void
213  SinkSmear<LatticePropagator>::operator()(LatticePropagator& quark_sink) const
214  {
215  QDPIO::cout << "NormShell sink" << std::endl;
216 
217  try
218  {
219  //
220  // Create the quark smearing object
221  //
222  std::istringstream xml_s(params.quark_smearing.xml);
223  XMLReader smeartop(xml_s);
224  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
225 
227  quarkSmearing(ThePropSmearingFactory::Instance().createObject(params.quark_smearing.id,
228  smeartop,
230 
231  //
232  // Create the quark displacement object
233  //
234  std::istringstream xml_d(params.quark_displacement.xml);
235  XMLReader displacetop(xml_d);
236  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
237 
239  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
240  displacetop,
242 
244  {
245  //
246  // Sink smear quark
247  //
248  for(int hit(0);hit<params.Nhits;hit++){
249  (*quarkSmearing)(quark_sink, u_smr);
250 
251  for(int src_s(0);src_s<Ns;src_s++){
252  for(int snk_s(0);snk_s<Ns;snk_s++){
253  LatticeColorMatrix cm = peekSpin(quark_sink,snk_s,src_s);
254  multi1d<LatticeColorVector> v(Nc) ;
255  for(int c(0);c<Nc;c++){
256  for(int i = 0; i < Nc; ++i)
257  pokeColor(v[c], peekColor(cm, i, c), i) ;
258 
259  // now normalize the vectors
260  for(int k(0);k<c;k++){
261  DComplex cc = innerProduct(v[k],v[c]);
262  v[c] -= cc*v[k] ;
263  }
264  Double nn = sqrt(norm2(v[c])) ;
265  v[c] /= nn ;
266  for(int i = 0; i < Nc; ++i)
267  pokeColor(cm,peekColor(v[c],i),i,c);
268  }//c
269  pokeSpin(quark_sink,cm,snk_s,src_s);
270  }//snk_s
271  }//src_s
272  }
273  //
274  // Displace the sink
275  //
276  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
277  }
278  else
279  {
280  QDPIO::cout<<__func__<<": WARNING! smearing last not implemented...\n" ;
281  //
282  // Displace the sink
283  //
284  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
285 
286  //
287  // Sink smear quark
288  //
289  (*quarkSmearing)(quark_sink, u_smr);
290  }
291 
292  }
293  catch(const std::string& e)
294  {
295  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
296  QDP_abort(1);
297  }
298  }
299 
300 
301 
302 
303  //! Smear the sink
304  template<>
305  void
306  SinkSmear<LatticeStaggeredPropagator>::operator()(LatticeStaggeredPropagator& quark_sink) const
307  {
308  QDPIO::cout << "NormShell sink" << std::endl;
309 
310  try
311  {
312  //
313  // Create the quark smearing object
314  //
315  std::istringstream xml_s(params.quark_smearing.xml);
316  XMLReader smeartop(xml_s);
317  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
318 
320  quarkSmearing(TheStagPropSmearingFactory::Instance().createObject(params.quark_smearing.id,
321  smeartop,
323 
324  //
325  // Create the quark displacement object
326  //
327  std::istringstream xml_d(params.quark_displacement.xml);
328  XMLReader displacetop(xml_d);
329  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
330 
332  quarkDisplacement(TheStagPropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
333  displacetop,
335 
337  {
338  //
339  // Sink smear quark
340  //
341  (*quarkSmearing)(quark_sink, u_smr);
342 
343  //
344  // Displace the sink
345  //
346  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
347  }
348  else
349  {
350  //
351  // Displace the sink
352  //
353  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
354 
355  //
356  // Sink smear quark
357  //
358  (*quarkSmearing)(quark_sink, u_smr);
359  }
360 
361  }
362  catch(const std::string& e)
363  {
364  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
365  QDP_abort(1);
366  }
367  }
368 
369 
370 
371  //! Smear the sink
372  template<>
373  void
374  SinkSmear<LatticeFermion>::operator()(LatticeFermion& quark_sink) const
375  {
376 // QDPIO::cout << "NormShell sink" << std::endl;
377 
378  try
379  {
380  //
381  // Create the quark smearing object
382  //
383  std::istringstream xml_s(params.quark_smearing.xml);
384  XMLReader smeartop(xml_s);
385 
387  quarkSmearing(TheFermSmearingFactory::Instance().createObject(params.quark_smearing.id,
388  smeartop,
390 
391  //
392  // Create the quark displacement object
393  //
394  std::istringstream xml_d(params.quark_displacement.xml);
395  XMLReader displacetop(xml_d);
396 
398  quarkDisplacement(TheFermDisplacementFactory::Instance().createObject(params.quark_displacement.id,
399  displacetop,
401 
402  //
403  // Sink smear quark
404  //
405  (*quarkSmearing)(quark_sink, u_smr);
406 
407 
408  //
409  // Displace the sink
410  //
411  (*quarkDisplacement)(quark_sink, u_smr, PLUS);
412 
413  }
414  catch(const std::string& e)
415  {
416  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
417  QDP_abort(1);
418  }
419  }
420 
421  }
422 
423 }
Primary include file for CHROMA library code.
Class for counted reference semantics.
Definition: handle.h:33
void operator()(T &obj) const
Smear the sink.
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)
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
int i
Definition: pbg5p_w.cc:55
@ PLUS
Definition: chromabase.h:45
pop(xml_out)
int k
Definition: invbicg.cc:119
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
No quark displacement.
NormShell sink smearing.
All quark displacement constructors.
Factory for producing quark displacement objects.
Quark smearing.
All quark smearing constructors.
Factory for producing quark smearing objects.
Simple quark displacement.
Factory for producing quark prop sinks.
void writeXML(XMLWriter &in, const std::string &path) const