CHROMA
dilute_zN_eigvec_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 
25 
26 #include "util/ft/sftmom.h"
27 
29 namespace Chroma
30 {
31  // Read parameters
32  void read(XMLReader& xml, const std::string& path, DiluteZNEigVecQuarkSourceConstEnv::Params& param)
33  {
35  param = tmp;
36  }
37 
38  // Writer
39  void write(XMLWriter& xml, const std::string& path, const DiluteZNEigVecQuarkSourceConstEnv::Params& param)
40  {
41  param.writeXML(xml, path);
42  }
43 
44 
45 
46  // Hooks to register the class
47  namespace DiluteZNEigVecQuarkSourceConstEnv
48  {
49  // Anonymous namespace
50  namespace
51  {
52  //! Callback function
54  const std::string& path)
55  {
56  return new SourceConst<LatticeFermion>(Params(xml_in, path));
57  }
58 
59  //! Local registration flag
60  bool registered = false;
61 
62  //! Name to be used
63  const std::string name("RAND_DILUTE_EIGVEC_ZN_SOURCE");
64  } // end namespace
65 
66  //! Return the name
67  std::string getName() {return name;}
68 
69  //! Register all the factories
70  bool registerAll()
71  {
72  bool success = true;
73  if (! registered)
74  {
76  registered = true;
77  }
78  return success;
79  }
80 
81 
82  //! Initialize
84  {
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  read(paramtop, "ran_seed", ran_seed);
108  read(paramtop, "N", N);
109  read(paramtop, "j_decay", j_decay);
110  read(paramtop, "t_sources", t_sources);
111 
112  read(paramtop, "eigen_vec_id", eigen_vec_id);
113  read(paramtop, "eigen_vectors", eigen_vectors);
114  read(paramtop, "spin_mask", spin_mask);
115  }
116 
117 
118  // Writer
119  void Params::writeXML(XMLWriter& xml, const std::string& path) const
120  {
121  push(xml, path);
122 
123  int version = 1;
124 
125  write(xml, "version", version);
126  write(xml, "ran_seed", ran_seed);
127  write(xml, "N", N);
128  write(xml, "j_decay", j_decay);
129  write(xml, "t_sources", t_sources);
130 
131  write(xml, "eigen_vec_id", eigen_vec_id);
132  write(xml, "eigen_vectors", eigen_vectors);
133  write(xml, "spin_mask", spin_mask);
134 
135  pop(xml);
136  }
137 
138 
140  const Seed& rng_seed, const int& N)
141  {
142 
143  //Obtain the current seed
144  Seed curr_seed;
145  QDP::RNG::savern(curr_seed);
146 
147  //Seed the random number generator
148  QDP::RNG::setrn(rng_seed);
149 
150 
151  //Fill the struct
152  for (int t = 0 ; t < laph_in.time_slices.size(); ++t)
153  {
154  for (int s = 0 ; s < laph_in.time_slices[t].spins.size() ; ++s)
155  for (int v = 0 ; v < laph_in.time_slices[t].spins[s].lap_eigs.size() ; ++v)
156  {
157  laph_in.time_slices[t].spins[s].lap_eigs[v].val = zN_rng(N);
158  }
159 
160  //Return the seed to its previous value
161  QDP::RNG::setrn(curr_seed);
162 
163  }
164  }
165 
166  //! Construct the source
167  template<>
168  LatticeFermion
169  SourceConst<LatticeFermion>::operator()(const multi1d<LatticeColorMatrix>& u) const
170  {
171  QDPIO::cout << "Eigenstd::vector-Diluted random complex ZN source" << std::endl;
172 
173  int Nt = QDP::Layout::lattSize()[params.j_decay];
174 
175  //
176  // Sanity checks
177  //
178  if (params.spin_mask.size() > Ns)
179  {
180  QDPIO::cerr << name << ": spin mask size incorrect 1" << std::endl;
181  QDP_abort(1);
182  }
183 
184  if (params.spin_mask.size() == 0)
185  {
186  QDPIO::cerr << name << ": spin mask size incorrect 2" << std::endl;
187  QDP_abort(1);
188  }
189 
190  if (params.t_sources.size() > Nt)
191  {
192  QDPIO::cerr << name << ": time sources size incorrect 1" << std::endl;
193  QDP_abort(1);
194  }
195 
196  if (params.t_sources.size() == 0)
197  {
198  QDPIO::cerr << name << ": time sources size incorrect 2" << std::endl;
199  QDP_abort(1);
200  }
201 
202  //check that there are no repeats, and that each is < Nt
203  for (int t = 0 ; t < params.t_sources.size() ; ++t) {
204 
205  if ( (t > 0) && (params.t_sources[t] == params.t_sources[0]) ) {
206  QDPIO::cerr << "ERROR: repeat in t_sources" << std::endl;
207  QDP_abort(1);
208  }
209 
210  if (params.t_sources[t] >= Nt) {
211 
212  QDPIO::cerr << "ERROR: invalid component in t_sources "
213  << params.t_sources[t] << " >= " << Nt << std::endl;
214  QDP_abort(1);
215  }
216  }
217 
218  XMLBufferWriter eig_vecs_xml;
219 
220  //Attempt to get eigenvectors from the named object std::map
221  try {
222 
224 
225  TheNamedObjMap::Instance().get(params.eigen_vec_id).getRecordXML(eig_vecs_xml);
226 
227  }
228  catch( std::bad_cast ) {
229  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
230  QDP_abort(1);
231  }
232  catch (const std::string& e) {
233  QDPIO::cerr << name << ": std::map call failed: " << e << std::endl;
234  QDP_abort(1);
235  }
236 
237  const MapObject<int,EVPair<LatticeColorVector> >& eigen_vecs =
239 
240  int n_ev = eigen_vecs.size();
241 
242  //Sanity checks on the eigenstd::vector dilutions
243  int n_ev_dil = params.eigen_vectors.size();
244 
245  //First, ensure there are not more than n_ev elements
246  if ( n_ev_dil > n_ev) {
247 
248  QDPIO::cerr << "ERROR: n_ev_dil > n_ev" << std::endl;
249  QDP_abort(1);
250  }
251 
252  //Check that there are no repeats in the vectors, also that each
253  //element is not larger than n_ev
254  for (int v = 0 ; v < n_ev_dil ; ++v) {
255  if ( (v > 0) && (params.eigen_vectors[v] == params.eigen_vectors[0]) ) {
256  QDPIO::cerr << "ERROR: repeat in eigen_vectors" << std::endl;
257  QDP_abort(1);
258  }
259 
260  if (params.eigen_vectors[v] >= n_ev) {
261  QDPIO::cerr << "ERROR: invalid component in eigen_vectors" << std::endl;
262  QDP_abort(1);
263  }
264  }
265 
266  //params.writeXML(xml_out, "Input");
267 
268  //params.writeXML(xml_out, "EigVecsXML");
269 
270  //
271  // Finally, do something useful
272  //
273 
274  /*
275  // Save current seed
276  Seed ran_seed;
277  QDP::RNG::savern(ran_seed);
278 
279  // Set the seed to desired value
280  QDP::RNG::setrn(params.ran_seed);
281  */
282 
283 
284  SftMom phases(0, true, params.j_decay);
285 
286  LatticeLAPHSubSpace_t laph_noise(n_ev, Nt);
288 
289  QDPIO::cout << "Created LapH Noise " << std::endl;
290 
291  LatticeFermion dil_source = zero;
292 
293  for (int t0 = 0 ; t0 < params.t_sources.size() ; ++t0) {
294  int curr_t = params.t_sources[t0];
295 
296  for (int s = 0 ; s < params.spin_mask.size() ; ++s) {
297  int curr_s = params.spin_mask[s];
298 
299  for (int v = 0 ; v < params.eigen_vectors.size() ; ++v) {
300  int curr_v = params.eigen_vectors[v];
301 
302  const Complex& curr_n = laph_noise.time_slices[curr_t].spins[curr_s].lap_eigs[curr_v].val;
303 
304  LatticeFermion temp = zero;
305  //Should only be poking on a single timeslice, Robert Help!!!
306 
307  EVPair<LatticeColorVector> tvec; eigen_vecs.get(curr_v, tvec);
308  pokeSpin(temp, curr_n * tvec.eigenVector, curr_s);
309 
310  dil_source[phases.getSet()[curr_t]] += temp;
311  }//v
312 
313  }//s
314 
315  }//t0
316 
317  // Reset the seed
318  //QDP::RNG::setrn(ran_seed);
319 
320  return dil_source;
321  }
322 
323  } // end namespace
324 
325 } // end namespace Chroma
Primary include file for CHROMA library code.
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.
Fourier transform phase factor support.
Definition: sftmom.h:35
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
static T & Instance()
Definition: singleton.h:432
Random Z(N) source construction using dilution in eigenstd::vector space.
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.
Complex zN_rng(int N)
Z(N)-rng.
Definition: zN_src.cc:12
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 t
Definition: meslate.cc:37
Named object function std::map.
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)
void fill_laph_subspace_zN(LatticeLAPHSubSpace_t &laph_in, const Seed &rng_seed, const int &N)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
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.
Fourier transform phase factor support.
Simple quark displacement.
Factory for producing quark prop sources.
void writeXML(XMLWriter &in, const std::string &path) const
A Pair type.
Holds of vectors and weights.
Volume source of Z(N) noise.