CHROMA
rndzNwall_source_const.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Random ZN wall source construction
3  */
4 
5 #include "chromabase.h"
6 #include "handle.h"
7 
10 #include "util/ferm/transf.h"
11 
12 
15 
18 
21 
24 
25 namespace Chroma
26 {
27  // Read parameters
28  void read(XMLReader& xml, const std::string& path, RandZNWallQuarkSourceConstEnv::Params& param)
29  {
31  param = tmp;
32  }
33 
34  // Writer
35  void write(XMLWriter& xml, const std::string& path, const RandZNWallQuarkSourceConstEnv::Params& param)
36  {
37  param.writeXML(xml, path);
38  }
39 
40 
41 
42  //! Hooks to register the class
43  namespace RandZNWallQuarkSourceConstEnv
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  //! Local registration flag
55  bool registered = false;
56 
57  //! Name to be used
58  const std::string name("RAND_ZN_WALL_SOURCE");
59  }
60 
61  //! Return the name
62  std::string getName() {return name;}
63 
64  //! Register all the factories
65  bool registerAll()
66  {
67  bool success = true;
68  if (! registered)
69  {
70  success &= LinkSmearingEnv::registerAll();
71  success &= QuarkSmearingEnv::registerAll();
73  success &= Chroma::ThePropSourceConstructionFactory::Instance().registerObject(name, createProp);
74  registered = true;
75  }
76  return success;
77  }
78 
79 
80  //! Initialize
82  {
83  j_decay = -1;
84  t_source = -1;
85  N=4 ;
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  break;
101 
102  default:
103  QDPIO::cerr << __func__ << ": parameter version " << version
104  << " unsupported." << std::endl;
105  QDP_abort(1);
106  }
107 
108  read(paramtop, "ran_seed", ran_seed);
109  read(paramtop, "j_decay", j_decay);
110  read(paramtop, "t_source", t_source);
111  read(paramtop, "N", N);
112 
113  if (paramtop.count("Displacement") != 0)
114  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
115  else
117 
118  read(paramtop, "quark_smear_lastP", quark_smear_lastP);
119  quark_smearing = readXMLGroup(paramtop, "SmearingParam", "wvf_kind");
120 
121  if (paramtop.count("LinkSmearing") != 0)
122  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
123  else
125 
126  }
127 
128 
129  // Writer
130  void Params::writeXML(XMLWriter& xml, const std::string& path) const
131  {
132  push(xml, path);
133 
134  int version = 1;
135  write(xml, "SourceType", RandZNWallQuarkSourceConstEnv::name);
136  xml << quark_smearing.xml;
137  xml << quark_displacement.xml;
138  xml << link_smearing.xml;
139  write(xml, "version", version);
140  write(xml, "ran_seed", ran_seed);
141  write(xml, "j_decay", j_decay);
142  write(xml, "t_source", t_source);
143  write(xml, "N", N);
144  pop(xml);
145  }
146 
147 
148  //! Construct the source
149  template<>
150  LatticePropagator
151  SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
152  {
153  QDPIO::cout << "Rand Z"<<params.N<<" Wall source" << std::endl;
154 
155 
156  // Save current seed
157  Seed ran_seed;
158  QDP::RNG::savern(ran_seed);
159 
160  // Set the seed to desired value
162 
163  // Create the quark source
164  LatticePropagator quark_source;
165 
166  try
167  {
168  //
169  // Smear the gauge field if needed
170  //
171  multi1d<LatticeColorMatrix> u_smr = u;
172  {
173  std::istringstream xml_l(params.link_smearing.xml);
174  XMLReader linktop(xml_l);
175  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
176 
178  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id, linktop, params.link_smearing.path));
179  (*linkSmearing)(u_smr);
180  }
181 
182  //
183  // Create the quark smearing object
184  //
185  std::istringstream xml_s(params.quark_smearing.xml);
186  XMLReader smeartop(xml_s);
187  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
188 
190  quarkSmearing(ThePropSmearingFactory::Instance().createObject(params.quark_smearing.id, smeartop, params.quark_smearing.path));
191 
192  //
193  // Create the quark displacement object
194  //
195  std::istringstream xml_d(params.quark_displacement.xml);
196  XMLReader displacetop(xml_d);
197  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
198 
200  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id, displacetop, params.quark_displacement.path));
201 
202  multi1d<LatticeColorVector> tmp_color_vec(Nc);
203 
204  LatticeReal rnd,theta;
205  LatticeComplex z;
206 
207  random(rnd);
208 
209  Real twopiN = Chroma::twopi / params.N;
210  theta = twopiN * floor(params.N*rnd);
211  z = cmplx(cos(theta),sin(theta));
212 
213 
214  for(int i=0; i<Nc; i++) {
215  tmp_color_vec[i] = zero;
216  pokeColor(tmp_color_vec[i], z, i);
217  }
218 
219  for(int color_source = 0; color_source < Nc; ++color_source)
220  {
221  QDPIO::cout << "color = " << color_source << std::endl;
222  int mu = params.j_decay;
223  int slice = params.t_source;
224  LatticeColorVector src_color_vec ;
225  if((slice>=Layout::lattSize()[mu])||(slice<0)){
226  QDPIO::cout<<"Doing the full Volume source"<<std::endl ;
227  src_color_vec = tmp_color_vec[color_source] ;
228  }
229  else{
230  //QDPIO::cout<<"Doing Wall source on timeslice "<<slice<<std::endl ;
231  src_color_vec = where( Layout::latticeCoordinate(mu) == slice,
232  tmp_color_vec[color_source],
233  LatticeColorVector(zero));
234  }
235  for(int spin_source = 0; spin_source < Ns; ++spin_source)
236  {
237  QDPIO::cout << "spin = " << spin_source << std::endl;
238 
239  // Insert a ColorVector into spin index spin_source
240  // This only overwrites sections, so need to initialize first
241  LatticeFermion chi = zero;
242 
243  CvToFerm(src_color_vec, chi, spin_source);
244 
245 
246  /*
247  * Move the source to the appropriate components
248  * of quark source.
249  */
250  FermToProp(chi, quark_source, color_source, spin_source);
251  }
252  }
253 
254  // Smear and displace
256  // Smear the colour source
257  // displace the point source first, then smear
258  // displacement has to be taken along negative direction.
259  (*quarkDisplacement)(quark_source, u_smr, MINUS);
260 
261  // do the smearing
262  (*quarkSmearing)(quark_source, u_smr);
263  }
264  else{
265  // do the smearing
266  (*quarkSmearing)(quark_source, u_smr);
267 
268  // Smear the colour source
269  // smear the point source first, then displace
270  // displacement has to be taken along negative direction.
271  (*quarkDisplacement)(quark_source, u_smr, MINUS);
272  }
273  }// try
274  catch(const std::string& e){
275  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
276  QDP_abort(1);
277  }
278 
279  // Reset the seed
280  QDP::RNG::setrn(ran_seed);
281 
282  return quark_source;
283  }
284 
285  }
286 
287 }
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
int mu
Definition: cool.cc:24
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.
Class for counted reference semantics.
Params params
void setrn(int iseed[4])
Definition: make_seeds.cc:38
void savern(int iseed[4])
Definition: make_seeds.cc:46
int z
Definition: meslate.cc:36
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")
int i
Definition: pbg5p_w.cc:55
@ MINUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
const Real twopi
Definition: chromabase.h:55
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.
Random Z2 wall source construction.
Simple quark displacement.
Factory for producing quark prop sources.
void writeXML(XMLWriter &in, const std::string &path) const