CHROMA
dilutezN_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 #include "meas/sources/zN_src.h"
23 
24 namespace Chroma
25 {
26  // Read parameters
27  void read(XMLReader& xml, const std::string& path, DiluteZNQuarkSourceConstEnv::Params& param)
28  {
30  param = tmp;
31  }
32 
33  // Writer
34  void write(XMLWriter& xml, const std::string& path, const DiluteZNQuarkSourceConstEnv::Params& param)
35  {
36  param.writeXML(xml, path);
37  }
38 
39 
40 
41  // Hooks to register the class
42  namespace DiluteZNQuarkSourceConstEnv
43  {
44  // Anonymous namespace
45  namespace
46  {
47  //! Callback function
49  const std::string& path)
50  {
51  return new SourceConst<LatticeFermion>(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_DILUTE_ZN_SOURCE");
59  } // end namespace
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::TheFermSourceSmearingFactory::Instance().registerObject(name, createFerm);
75  registered = true;
76  }
77  return success;
78  }
79 
80 
81  //! Initialize
83  {
84  smear = false ;
85  j_decay = -1;
86  t_source = -1;
87  }
88 
89 
90  //! Read parameters
91  Params::Params(XMLReader& xml, const std::string& path)
92  {
93  XMLReader paramtop(xml, path);
94 
95  int version;
96  read(paramtop, "version", version);
97 
98  switch (version)
99  {
100  case 1:
101  break;
102 
103  default:
104  QDPIO::cerr << __func__ << ": parameter version " << version
105  << " unsupported." << std::endl;
106  QDP_abort(1);
107  }
108 
109  smear = false ;
110  if(paramtop.count("Smearing") !=0 ) {
111  smr = readXMLGroup(paramtop, "Smearing", "wvf_kind");
112  link_smear = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
113  displace = readXMLGroup(paramtop, "Displacement","DisplacementType");
114  smear = true ;
115  }
116 
117  read(paramtop, "ran_seed", ran_seed);
118  read(paramtop, "N", N);
119  read(paramtop, "j_decay", j_decay);
120  read(paramtop, "t_source", t_source);
121 
122  read(paramtop, "spatial_mask_size", spatial_mask_size);
123  read(paramtop, "spatial_mask", spatial_mask);
124  read(paramtop, "color_mask", color_mask);
125  read(paramtop, "spin_mask", spin_mask);
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 
136  if(smear){
137  xml << smr.xml;
138  xml << displace.xml ;
139  xml << link_smear.xml ;
140  }
141 
142  write(xml, "version", version);
143  write(xml, "ran_seed", ran_seed);
144  write(xml, "N", N);
145  write(xml, "j_decay", j_decay);
146  write(xml, "t_source", t_source);
147 
148  write(xml, "spatial_mask_size", spatial_mask_size);
149  write(xml, "spatial_mask", spatial_mask);
150  write(xml, "color_mask", color_mask);
151  write(xml, "spin_mask", spin_mask);
152 
153  pop(xml);
154  }
155 
156 
157 
158  //! Construct the source
159  template<>
160  LatticeFermion
161  SourceConst<LatticeFermion>::operator()(const multi1d<LatticeColorMatrix>& u) const
162  {
163  QDPIO::cout << "Diluted random complex ZN source" << std::endl;
164 
165  //
166  // Sanity checks
167  //
168  if (params.spatial_mask_size.size() != Nd-1)
169  {
170  QDPIO::cerr << name << ": spatial mask size incorrect 1" << std::endl;
171  QDP_abort(1);
172  }
173 
174  if (params.spatial_mask.size() == 0)
175  {
176  QDPIO::cerr << name << ": spatial mask incorrect 2" << std::endl;
177  QDP_abort(1);
178  }
179 
180  multi1d<int> lookup_dir(Nd-1);
181  int mu = 0;
182  for(int j=0; j < params.spatial_mask_size.size(); ++j, ++mu)
183  {
184  if (j == params.j_decay) ++mu; // bump up to next dir
185 
186  lookup_dir[j] = mu;
187  }
188 
189  for(int j=0; j < params.spatial_mask.size(); ++j)
190  {
191  if (params.spatial_mask[j].size() != Nd-1)
192  {
193  QDPIO::cerr << name << ": spatial mask incorrect 3" << std::endl;
194  QDP_abort(1);
195  }
196  }
197 
198  // More sanity checks
199  for(int c=0; c < params.color_mask.size(); ++c)
200  {
201  if (params.color_mask[c] < 0 || params.color_mask[c] >= Nc)
202  {
203  QDPIO::cerr << name << ": color mask incorrect 6" << std::endl;
204  QDP_abort(1);
205  }
206  }
207 
208  for(int s=0; s < params.spin_mask.size(); ++s)
209  {
210  if (params.spin_mask[s] < 0 || params.spin_mask[s] >= Ns)
211  {
212  QDPIO::cerr << name << ": spin mask incorrect 7" << std::endl;
213  QDP_abort(1);
214  }
215  }
216 
217  //
218  // Finally, do something useful
219  //
220 
221  // Save current seed
222  Seed ran_seed;
223  QDP::RNG::savern(ran_seed);
224 
225  // Set the seed to desired value
227 
228  // Create the noisy quark source on the entire lattice
229  LatticeFermion quark_noise;
230  zN_src(quark_noise, params.N);
231 
232  // This is the filtered noise source to return
233  LatticeFermion quark_source = zero;
234 
235  // Filter over the color and spin indices first
236  for(int s=0; s < params.spin_mask.size(); ++s)
237  {
238  int spin_source = params.spin_mask[s];
239  LatticeColorVector colvec = peekSpin(quark_noise, spin_source);
240  LatticeColorVector dest = zero;
241 
242  for(int c=0; c < params.color_mask.size(); ++c)
243  {
244  int color_source = params.color_mask[c];
245  LatticeComplex comp = peekColor(colvec, color_source);
246 
247  pokeColor(dest, comp, color_source);
248  }
249 
250  pokeSpin(quark_source, dest, spin_source);
251  }
252 
253  quark_noise = quark_source; // reset
254 
255  // Filter over the spatial sites
256  LatticeBoolean mask = false; // this is the starting mask
257 
258  for(int n=0; n < params.spatial_mask.size(); ++n)
259  {
260  LatticeBoolean btmp = true;
261 
262  for(int j=0; j < params.spatial_mask[n].size(); ++j)
263  btmp &= (Layout::latticeCoordinate(lookup_dir[j]) % params.spatial_mask_size[j]) == params.spatial_mask[n][j];
264 
265  mask |= btmp;
266  }
267 
268  // Filter over the time slices
269  mask &= Layout::latticeCoordinate(params.j_decay) == params.t_source;
270 
271  // Zap the unused sites
272  quark_source = where(mask, quark_noise, Fermion(zero));
273 
274 
275  if(params.smear){// do the smearing
277  try{
278  std::istringstream xml_l(params.smr.xml);
279  XMLReader smrtop(xml_l);
280  QDPIO::cout << "Quark smearing type = " <<params.smr.id ;
281  QDPIO::cout << std::endl;
282 
283  Smearing =
284  TheFermSmearingFactory::Instance().createObject(params.smr.id,smrtop,
285  params.smr.path);
286  }
287  catch(const std::string& e){
288  QDPIO::cerr <<name<< ": Caught Exception creating quark smearing object: " << e << std::endl;
289  QDP_abort(1);
290  }
291  catch(...){
292  QDPIO::cerr <<name<< ": Caught generic exception creating smearing object" << std::endl;
293  QDP_abort(1);
294  }
295  // Smear the gauge field if needed
296  //
297  multi1d<LatticeColorMatrix> u_smr = u;
298 
299  try{
300  std::istringstream xml_l(params.link_smear.xml);
301  XMLReader linktop(xml_l);
302  QDPIO::cout << "Link smearing type = " << params.link_smear.id ;
303  QDPIO::cout << std::endl;
304 
305 
307 
308  (*linkSmearing)(u_smr);
309  //MesPlq(xml_out, "Smeared_Observables", u_smr);
310  }
311  catch(const std::string& e){
312  QDPIO::cerr<<name<<": Caught Exception link smearing: " << e << std::endl;
313  QDP_abort(1);
314  }
315 
316 
317  (*Smearing)(quark_source, u_smr);
318 
319  //
320  // Create the quark displacement object
321  //
322  std::istringstream xml_d(params.displace.xml);
323  XMLReader displacetop(xml_d);
324 
325  try{
327  quarkDisplacement(TheFermDisplacementFactory::Instance().createObject(params.displace.id, displacetop, params.displace.path));
328  QDPIO::cout << "Quark displacement type = " << params.displace.id ;
329  QDPIO::cout << std::endl;
330 
331  // displacement has to be taken along negative direction.
332  // Not sure why MINUS....
333  (*quarkDisplacement)(quark_source, u_smr, MINUS);
334  }
335  catch(const std::string& e){
336  QDPIO::cerr<<name<<": Caught Exception quark displacement: "<<e<< std::endl;
337  QDP_abort(1);
338  }
339  }// if(smear) ends here
340 
341 
342  // Reset the seed
343  QDP::RNG::setrn(ran_seed);
344 
345  return quark_source;
346  }
347 
348  } // end namespace
349 
350 } // 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(N) 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.
void zN_src(LatticeFermion &a, int N)
Volume source of Z(N) noise.
Definition: zN_src.cc:41
Class for counted reference semantics.
Params params
unsigned j
Definition: ldumul_w.cc:35
unsigned n
Definition: ldumul_w.cc:36
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.
CreateFermState< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > * createFerm(XMLReader &xml, const std::string &path)
std::string getName()
Return the name.
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")
Double c
Definition: invbicg.cc:108
@ 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
Volume source of Z(N) noise.