CHROMA
sh_zN_grid_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 #include "meas/sources/zN_src.h"
25 #include "util/ft/single_phase.h"
26 
27 namespace Chroma
28 {
29  // Read parameters
30  void read(XMLReader& xml, const std::string& path, ShellZnGridQuarkSourceConstEnv::Params& param)
31  {
33  param = tmp;
34  }
35 
36  // Writer
37  void write(XMLWriter& xml, const std::string& path, const ShellZnGridQuarkSourceConstEnv::Params& param)
38  {
39  param.writeXML(xml, path);
40  }
41 
42 
43 
44  //! Hooks to register the class
45  namespace ShellZnGridQuarkSourceConstEnv
46  {
47  namespace
48  {
49  //! Callback function
50  QuarkSourceConstruction<LatticePropagator>* createProp(XMLReader& xml_in,
51  const std::string& path)
52  {
53  return new SourceConst<LatticePropagator>(Params(xml_in, path));
54  }
55 
56  //! Callback function
57  QuarkSourceConstruction<LatticeStaggeredPropagator>* createStagProp(XMLReader& xml_in,
58  const std::string& path)
59  {
60  return new SourceConst<LatticeStaggeredPropagator>(Params(xml_in, path));
61  }
62 
63  //! Local registration flag
64  bool registered = false;
65 
66  //! Name to be used
67  const std::string name("ZNC_GRID_SHELL_SOURCE");
68  }
69 
70  //! Return the name
71  std::string getName() {return name;}
72 
73  //! Register all the factories
74  bool registerAll()
75  {
76  bool success = true;
77  if (! registered)
78  {
79  success &= LinkSmearingEnv::registerAll();
80  success &= QuarkSmearingEnv::registerAll();
82  success &= Chroma::ThePropSourceConstructionFactory::Instance().registerObject(name, createProp);
83  success &= Chroma::TheStagPropSourceConstructionFactory::Instance().registerObject(name, createStagProp);
84 
85  registered = true;
86  }
87  return success;
88  }
89 
90 
91  //! Read parameters
93  {
94  j_decay = -1;
95  t_srce.resize(Nd);
96  t_srce = 0;
97  quark_smear_lastP = true;
98  }
99 
100  //! Read parameters
101  Params::Params(XMLReader& xml, const std::string& path)
102  {
103  XMLReader paramtop(xml, path);
104 
105  int version;
106  read(paramtop, "version", version);
107 
108  quark_smear_lastP = true;
109 
110  switch (version)
111  {
112  case 1:
113  {
116  int disp_length = 0;
117  int disp_dir = 0;
118 
119  XMLBufferWriter xml_tmp;
120  push(xml_tmp, "Displacement");
121  write(xml_tmp, "DisplacementType", quark_displacement.id);
122 
123  if (paramtop.count("disp_length") != 0)
124  read(paramtop, "disp_length", disp_length);
125 
126  if (paramtop.count("disp_dir") != 0)
127  read(paramtop, "disp_dir", disp_dir);
128 
129  write(xml_tmp, "disp_length", disp_length);
130  write(xml_tmp, "disp_dir", disp_dir);
131 
132  pop(xml_tmp); // Displacement
133 
134  quark_displacement.xml = xml_tmp.printCurrentContext();
135  }
136  break;
137 
138  case 2:
139  {
140  if (paramtop.count("Displacement") != 0)
141  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
142  else
144  }
145  break;
146 
147  case 3:
148  {
149  read(paramtop, "quark_smear_lastP", quark_smear_lastP);
150 
151  if (paramtop.count("Displacement") != 0)
152  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
153  else
155  }
156  break;
157 
158  default:
159  QDPIO::cerr << __func__ << ": parameter version " << version
160  << " unsupported." << std::endl;
161  QDP_abort(1);
162  }
163 
164  quark_smearing = readXMLGroup(paramtop, "SmearingParam", "wvf_kind");
165 
166  if (paramtop.count("LinkSmearing") != 0)
167  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
168  else
170 
171  read(paramtop, "t_srce", t_srce);
172  read(paramtop, "grd", grd);
173  read(paramtop, "moms", moms);
174  read(paramtop, "j_decay", j_decay);
175  read(paramtop, "ran_seed", ran_seed);
176  }
177 
178 
179  // Writer
180  void Params::writeXML(XMLWriter& xml, const std::string& path) const
181  {
182  push(xml, path);
183 
184  int version = 3;
185  QDP::write(xml, "version", version);
186 
187  write(xml, "SourceType", ShellZnGridQuarkSourceConstEnv::name);
188  xml << quark_smearing.xml;
189  xml << quark_displacement.xml;
190  xml << link_smearing.xml;
191 
192  write(xml, "t_srce", t_srce);
193  write(xml, "j_decay", j_decay);
194  write(xml, "quark_smear_lastP", quark_smear_lastP);
195  write(xml, "grd", grd);
196  write(xml, "moms", moms);
197  write(xml, "ran_seed", ran_seed);
198 
199  pop(xml);
200  }
201 
202 
203 
204  //! Construct the source
205  template<>
206  LatticePropagator
207  SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
208  {
209  QDPIO::cout << "ZNc random Shell source" << std::endl;
210 
211  Seed curr_seed;
212  QDP::RNG::savern(curr_seed);
213 
214  //Seed the random number generator
216 
217  LatticePropagator quark_source;
218 
219  try
220  {
221  //
222  // Smear the gauge field if needed
223  //
224  multi1d<LatticeColorMatrix> u_smr = u;
225  {
226  std::istringstream xml_l(params.link_smearing.xml);
227  XMLReader linktop(xml_l);
228  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
229 
231  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
232  linktop,
234  (*linkSmearing)(u_smr);
235  }
236 
237  //
238  // Create the quark smearing object
239  //
240  LatticeComplex noise ;
241 
242  std::istringstream xml_s(params.quark_smearing.xml);
243  XMLReader smeartop(xml_s);
244  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
245 
247  quarkSmearing(ThePropSmearingFactory::Instance().createObject(params.quark_smearing.id,
248  smeartop,
250 
251  //
252  // Create the quark displacement object
253  //
254  std::istringstream xml_d(params.quark_displacement.xml);
255  XMLReader displacetop(xml_d);
256  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
257 
259  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
260  displacetop,
262 
263  //
264  // Create quark source
265  //
266 
267  //setup mask
268  LatticeBoolean mask = false ;
269  LatticeBoolean btmp = true;
270  for(int j=0; j < params.grd.size(); ++j){
271  LatticeInteger X= Layout::latticeCoordinate(j) - params.t_srce[j];
272  if(params.grd[j] > 0)
273  X = X % params.grd[j];
274  btmp &= (X==0) ;
275  }
276  mask |= btmp;
277 
278  //setup phases
279  LatticeComplex phases = 1.0 ;
280  if(params.moms.size()>0){
281  //add phases for the given list of momenta
282  for (int k(0);k<params.moms.size();k++){
284  }
285  }
286  for(int color_source = 0; color_source < Nc; ++color_source)
287  {
288  QDPIO::cout << "color = " << color_source << std::endl;
289 
290 
291 
292  // Make a point source at coordinates t_srce
293  //srcfil(src_color_vec, params.t_srce, color_source);
294 
295  for(int spin_source = 0; spin_source < Ns; ++spin_source)
296  {
297  QDPIO::cout << "spin = " << spin_source << std::endl;
298 
299  LatticeColorVector src_color_vec = zero;
300  LatticeColorVector cv=zero ;
301  LatticeComplex ZNc = zN_rng(Nc);
302  ZNc *= phases ; // add the phases
303  pokeColor(cv,ZNc,color_source) ;
304  src_color_vec = where(mask,cv,LatticeColorVector(zero));
305  // Insert a ColorVector into spin index spin_source
306  // This only overwrites sections, so need to initialize first
307  LatticeFermion chi = zero;
308 
309  CvToFerm(src_color_vec, chi, spin_source);
310 
311  /*
312  * Move the source to the appropriate components
313  * of quark source.
314  */
315  FermToProp(chi, quark_source, color_source, spin_source);
316  }
317  }
318 
319 
320  // Smear and displace
322  {
323  // Smear the colour source
324  // displace the point source first, then smear
325  // displacement has to be taken along negative direction.
326  (*quarkDisplacement)(quark_source, u_smr, MINUS);
327 
328  // do the smearing
329  (*quarkSmearing)(quark_source, u_smr);
330  }
331  else
332  {
333  // do the smearing
334  (*quarkSmearing)(quark_source, u_smr);
335 
336  // Smear the colour source
337  // smear the point source first, then displace
338  // displacement has to be taken along negative direction.
339  (*quarkDisplacement)(quark_source, u_smr, MINUS);
340  }
341 
342  }
343  catch(const std::string& e)
344  {
345  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
346  QDP_abort(1);
347  }
348 
349  //Return the seed to its previous value
350  QDP::RNG::setrn(curr_seed);
351 
352  return quark_source;
353  }
354 
355 
356 
357  //! Construct the source
358  template<>
359  LatticeStaggeredPropagator
360  SourceConst<LatticeStaggeredPropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
361  {
362  QDPIO::cout << "Shell source" << std::endl;
363 
364  LatticeStaggeredPropagator quark_source;
365  QDPIO::cout << "IT ONLY does one point here. I will not bother with staggered"<<std::endl;
366  try
367  {
368  //
369  // Smear the gauge field if needed
370  //
371  multi1d<LatticeColorMatrix> u_smr = u;
372  {
373  std::istringstream xml_l(params.link_smearing.xml);
374  XMLReader linktop(xml_l);
375  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
376 
378  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
379  linktop,
381  (*linkSmearing)(u_smr);
382  }
383 
384  //
385  // Create the quark smearing object
386  //
387  std::istringstream xml_s(params.quark_smearing.xml);
388  XMLReader smeartop(xml_s);
389  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
390 
392  quarkSmearing(TheStagPropSmearingFactory::Instance().createObject(params.quark_smearing.id,
393  smeartop,
395 
396  //
397  // Create the quark displacement object
398  //
399  std::istringstream xml_d(params.quark_displacement.xml);
400  XMLReader displacetop(xml_d);
401  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
402 
404  quarkDisplacement(TheStagPropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
405  displacetop,
407 
408  //
409  // Create quark source
410  //
411  for(int color_source = 0; color_source < Nc; ++color_source)
412  {
413  QDPIO::cout << "color = " << color_source << std::endl;
414 
415  LatticeColorVector src_color_vec = zero;
416 
417  // Make a point source at coordinates t_srce
418  srcfil(src_color_vec, params.t_srce, color_source);
419 
420  // Insert a ColorVector into spin index spin_source
421  // This only overwrites sections, so need to initialize first
422  LatticeStaggeredFermion chi = zero;
423 
424  CvToFerm(src_color_vec, chi);
425 
426  /*
427  * Move the source to the appropriate components
428  * of quark source.
429  */
430  FermToProp(chi, quark_source, color_source);
431  }
432 
433 
434  // Smear and displace
436  {
437  // Smear the colour source
438  // displace the point source first, then smear
439  // displacement has to be taken along negative direction.
440  (*quarkDisplacement)(quark_source, u_smr, MINUS);
441 
442  // do the smearing
443  (*quarkSmearing)(quark_source, u_smr);
444  }
445  else
446  {
447  // do the smearing
448  (*quarkSmearing)(quark_source, u_smr);
449 
450  // Smear the colour source
451  // smear the point source first, then displace
452  // displacement has to be taken along negative direction.
453  (*quarkDisplacement)(quark_source, u_smr, MINUS);
454  }
455 
456  }
457  catch(const std::string& e)
458  {
459  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
460  QDP_abort(1);
461  }
462 
463  return quark_source;
464  }
465 
466  }
467 }
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.
LatticeComplex singlePhase(const multi1d< int > &t_srce, const multi1d< int > &sink_mom, int j_decay)
A single exp(ip.x) phase used in hadron construction.
Definition: single_phase.cc:13
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Complex zN_rng(int N)
Z(N)-rng.
Definition: zN_src.cc:12
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
void write(XMLWriter &xml, const std::string &path, const ShellZnGridQuarkSourceConstEnv::Params &param)
Writer.
Class for counted reference semantics.
Params params
unsigned j
Definition: ldumul_w.cc:35
void setrn(int iseed[4])
Definition: make_seeds.cc:38
void savern(int iseed[4])
Definition: make_seeds.cc:46
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.
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
int k
Definition: invbicg.cc:119
::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 this source implements a ZN (were N = Nc) for baryonic states It also works...
Simple quark displacement.
Compute a single phase factor.
Factory for producing quark prop sources.
Point source construction.
void writeXML(XMLWriter &out, const std::string &path) const
Volume source of Z(N) noise.