CHROMA
diluteGrid_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 
13 
16 
19 
22 
23 namespace Chroma
24 {
25  // Read parameters
26  void read(XMLReader& xml, const std::string& path, DiluteGridQuarkSourceConstEnv::Params& param)
27  {
29  param = tmp;
30  }
31 
32  // Writer
33  void write(XMLWriter& xml, const std::string& path, const DiluteGridQuarkSourceConstEnv::Params& param)
34  {
35  param.writeXML(xml, path);
36  }
37 
38 
39 
40  // Hooks to register the class
41  namespace DiluteGridQuarkSourceConstEnv
42  {
43  // Anonymous namespace
44  namespace
45  {
46  //! Callback function
48  const std::string& path)
49  {
50  return new SourceConst<LatticeFermion>(Params(xml_in, path));
51  }
52 
53  //! Local registration flag
54  bool registered = false;
55 
56  //! Name to be used
57  const std::string name("DILUTE_GRID_SOURCE");
58  } // end namespace
59 
60  //! Return the name
61  std::string getName() {return name;}
62 
63  //! Register all the factories
64  bool registerAll()
65  {
66  bool success = true;
67  if (! registered)
68  {
69  success &= LinkSmearingEnv::registerAll();
70  success &= QuarkSmearingEnv::registerAll();
73  registered = true;
74  }
75  return success;
76  }
77 
78 
79  //! Initialize
81  {
82  smear = false ;
83  j_decay = -1;
84  t_source = -1;
85  }
86 
87 
88  //! Read parameters
89  Params::Params(XMLReader& xml, const std::string& path)
90  {
91  XMLReader paramtop(xml, path);
92 
93  int version;
94  read(paramtop, "version", version);
95 
96  switch (version)
97  {
98  case 1:
99  break;
100 
101  default:
102  QDPIO::cerr << __func__ << ": parameter version " << version
103  << " unsupported." << std::endl;
104  QDP_abort(1);
105  }
106 
107  smear = false ;
108  if(paramtop.count("Smearing") !=0 ) {
109  smr = readXMLGroup(paramtop, "Smearing", "wvf_kind");
110  link_smear = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
111  displace = readXMLGroup(paramtop, "Displacement","DisplacementType");
112  smear = true ;
113  }
114 
115  read(paramtop, "j_decay", j_decay);
116  read(paramtop, "t_source", t_source);
117 
118  read(paramtop, "spatial_mask_size", spatial_mask_size);
119  read(paramtop, "spatial_mask", spatial_mask);
120  read(paramtop, "color", color);
121  read(paramtop, "spin", spin);
122  }
123 
124 
125  // Writer
126  void Params::writeXML(XMLWriter& xml, const std::string& path) const
127  {
128  push(xml, path);
129 
130  int version = 1;
131 
132  if(smear){
133  xml << smr.xml;
134  xml << displace.xml ;
135  xml << link_smear.xml ;
136  }
137 
138  write(xml, "version", version);
139  write(xml, "j_decay", j_decay);
140  write(xml, "t_source", t_source);
141 
142  write(xml, "spatial_mask_size", spatial_mask_size);
143  write(xml, "spatial_mask", spatial_mask);
144  write(xml, "color", color);
145  write(xml, "spin", spin);
146 
147  pop(xml);
148  }
149 
150 
151 
152  //! Construct the source
153  template<>
154  LatticeFermion
155  SourceConst<LatticeFermion>::operator()(const multi1d<LatticeColorMatrix>& u) const
156  {
157  QDPIO::cout << "Diluted grid source" << std::endl;
158 
159  //
160  // Sanity checks
161  //
162  if (params.spatial_mask_size.size() != Nd-1)
163  {
164  QDPIO::cerr << name << ": spatial mask size incorrect 1" << std::endl;
165  QDP_abort(1);
166  }
167 
168  if (params.spatial_mask.size() == 0)
169  {
170  QDPIO::cerr << name << ": spatial mask incorrect 2" << std::endl;
171  QDP_abort(1);
172  }
173 
174  multi1d<int> lookup_dir(Nd-1);
175  int mu = 0;
176  for(int j=0; j < params.spatial_mask_size.size(); ++j, ++mu)
177  {
178  if (j == params.j_decay) ++mu; // bump up to next dir
179 
180  lookup_dir[j] = mu;
181  }
182 
183  for(int j=0; j < params.spatial_mask.size(); ++j)
184  {
185  if (params.spatial_mask[j].size() != Nd-1)
186  {
187  QDPIO::cerr << name << ": spatial mask incorrect 3" << std::endl;
188  QDP_abort(1);
189  }
190  }
191 
192  if (params.color < 0 || params.color >= Nc){
193  QDPIO::cerr << name << ": color mask incorrect 6" << std::endl;
194  QDP_abort(1);
195  }
196  //if (params.spin < 0 || params.spin >= Ns){
197  //QDPIO::cerr << name << ": spin mask incorrect 7" << std::endl;
198  //QDP_abort(1);
199  //}
200 
201  //
202  // Finally, do something useful
203  //
204 
205  // Create the noisy quark source on the entire lattice
206  Fermion tt = zero ;
207  ColorVector cc = zero ;
208  Complex z=cmplx(Real(1.0),0.0);
209  pokeColor(cc,z,params.color);
210  if((params.spin>-1)&&(params.spin<Ns)) // single spin selected
211  pokeSpin(tt,cc,params.spin);
212  else{
213  for(int s(0);s<Ns;s++)
214  pokeSpin(tt,cc,s);
215  QDPIO::cout << name << ": NO spin mask used!" << std::endl;
216  }
217  LatticeFermion quark_noise = tt ;
218 
219  LatticeFermion quark_source ;
220  // Filter over the spatial sites
221  LatticeBoolean mask = false; // this is the starting mask
222 
223  for(int n=0; n < params.spatial_mask.size(); ++n)
224  {
225  LatticeBoolean btmp = true;
226 
227  for(int j=0; j < params.spatial_mask[n].size(); ++j)
228  btmp &= (Layout::latticeCoordinate(lookup_dir[j]) % params.spatial_mask_size[j]) == params.spatial_mask[n][j];
229 
230  mask |= btmp;
231  }
232 
233  // Filter over the time slices
234  // params.t_source<0 means no filter over time
235  if(params.t_source>-1) // single time slice is selected
236  mask &= Layout::latticeCoordinate(params.j_decay) == params.t_source;
237  else
238  QDPIO::cout << name << ": NO time mask used!" << std::endl;
239 
240  // Zap the unused sites
241  quark_source = where(mask, quark_noise, Fermion(zero));
242 
243 
244  if(params.smear){// do the smearing
246  try{
247  std::istringstream xml_l(params.smr.xml);
248  XMLReader smrtop(xml_l);
249  QDPIO::cout << "Quark smearing type = " <<params.smr.id ;
250  QDPIO::cout << std::endl;
251 
252  Smearing =
253  TheFermSmearingFactory::Instance().createObject(params.smr.id,smrtop,
254  params.smr.path);
255  }
256  catch(const std::string& e){
257  QDPIO::cerr <<name<< ": Caught Exception creating quark smearing object: " << e << std::endl;
258  QDP_abort(1);
259  }
260  catch(...){
261  QDPIO::cerr <<name<< ": Caught generic exception creating smearing object" << std::endl;
262  QDP_abort(1);
263  }
264  // Smear the gauge field if needed
265  //
266  multi1d<LatticeColorMatrix> u_smr = u;
267 
268  try{
269  std::istringstream xml_l(params.link_smear.xml);
270  XMLReader linktop(xml_l);
271  QDPIO::cout << "Link smearing type = " << params.link_smear.id ;
272  QDPIO::cout << std::endl;
273 
274 
276 
277  (*linkSmearing)(u_smr);
278  //MesPlq(xml_out, "Smeared_Observables", u_smr);
279  }
280  catch(const std::string& e){
281  QDPIO::cerr<<name<<": Caught Exception link smearing: " << e << std::endl;
282  QDP_abort(1);
283  }
284 
285 
286  (*Smearing)(quark_source, u_smr);
287 
288  //
289  // Create the quark displacement object
290  //
291  std::istringstream xml_d(params.displace.xml);
292  XMLReader displacetop(xml_d);
293 
294  try{
296  quarkDisplacement(TheFermDisplacementFactory::Instance().createObject(params.displace.id, displacetop, params.displace.path));
297  QDPIO::cout << "Quark displacement type = " << params.displace.id ;
298  QDPIO::cout << std::endl;
299 
300  // displacement has to be taken along negative direction.
301  // Not sure why MINUS....
302  (*quarkDisplacement)(quark_source, u_smr, MINUS);
303  }
304  catch(const std::string& e){
305  QDPIO::cerr<<name<<": Caught Exception quark displacement: "<<e<< std::endl;
306  QDP_abort(1);
307  }
308  }// if(smear) ends here
309 
310 
311  // Reset the seed
312  //QDP::RNG::setrn(ran_seed);
313 
314  return quark_source;
315  }
316 
317  } // end namespace
318 
319 } // end namespace Chroma
Primary include file for CHROMA library code.
Random complex Z(N) sources using dilution.
T operator()(const multi1d< LatticeColorMatrix > &u) const
Construct the source.
Class for counted reference semantics.
Definition: handle.h:33
Base class for quark source construction.
static T & Instance()
Definition: singleton.h:432
int mu
Definition: cool.cc:24
Random Z(M) source construction using dilution.
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
unsigned j
Definition: ldumul_w.cc:35
unsigned n
Definition: ldumul_w.cc:36
int z
Definition: meslate.cc:36
Nd
Definition: meslate.cc:74
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)
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
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
pop(xml_out)
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > s(Ncb)
::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.
Simple quark displacement.
Factory for producing quark prop sources.
Random complex Z(N) sources using dilution.
void writeXML(XMLWriter &in, const std::string &path) const