CHROMA
stoch_cond_cont_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Stoch quark condensates
3  */
4 
8 #include "meas/sources/zN_src.h"
9 
11 
12 
13 namespace Chroma
14 {
15 
16  // Read parameters
17  void read(XMLReader& xml, const std::string& path, StochCondContEnv::Params& param)
18  {
19  StochCondContEnv::Params tmp(xml, path);
20  param = tmp;
21  }
22 
23  // Writer
24  void write(XMLWriter& xml, const std::string& path, const StochCondContEnv::Params& param)
25  {
26  param.writeXML(xml, path);
27  }
28 
29 
30  namespace StochCondContEnv
31  {
32  namespace
33  {
34  HadronContract* mesStochCondCont(XMLReader& xml_in,
35  const std::string& path)
36  {
37  return new StochCondCont(Params(xml_in, path));
38  }
39 
40  //! Local registration flag
41  bool registered = false;
42 
43  } // end anonymous namespace
44 
45 
46  //! Initialize
48  {
49  }
50 
51 
52  //! Read parameters
53  Params::Params(XMLReader& xml, const std::string& path)
54  {
55  XMLReader paramtop(xml, path);
56 
57  int version;
58  read(paramtop, "version", version);
59 
60  switch (version)
61  {
62  case 1:
63  /**************************************************************************/
64  break;
65 
66  default :
67  /**************************************************************************/
68 
69  QDPIO::cerr << "StochCond: Input parameter version " << version << " unsupported." << std::endl;
70  QDP_abort(1);
71  }
72 
73  read(paramtop, "mom2_max", mom2_max);
74  read(paramtop, "avg_equiv_mom", avg_equiv_mom);
75  read(paramtop, "mom_origin", mom_origin);
76  read(paramtop, "soln_files", soln_files);
77  }
78 
79 
80  // Reader for input parameters
81  void Params::writeXML(XMLWriter& xml, const std::string& path) const
82  {
83  push(xml, path);
84 
85  int version = 1;
86 
87  write(xml, "version", version);
88  write(xml, "mom2_max", mom2_max);
89  write(xml, "avg_equiv_mom", avg_equiv_mom);
90  write(xml, "mom_origin", mom_origin);
91  write(xml, "soln_files", soln_files);
92 
93  pop(xml);
94  }
95 
96 
97  //--------------------------------------------------------------
98 
99  //! Structure holding a source and its solutions
101  {
102  //! Structure holding solutions
104  {
105  LatticeFermion source;
106  LatticeFermion soln;
109  };
110 
111  int j_decay;
112  Seed seed;
113  multi1d<QuarkSolution_t> dilutions;
114  };
115 
116 
117  //--------------------------------------------------------------
118  // Construct some condensates
119  std::list< Handle<HadronContractResult_t> >
120  StochCondCont::operator()(const multi1d<LatticeColorMatrix>& u,
121  const std::string& xml_group,
122  const std::string& id_tag)
123  {
124  START_CODE();
125 
126  QDPIO::cout << "Stochastic Condensates" << std::endl;
127 
128  StopWatch snoop;
129  snoop.reset();
130  snoop.start();
131 
132  StopWatch swatch;
133 
134  // Save current seed
135  Seed ran_seed;
136  QDP::RNG::savern(ran_seed);
137 
138  //
139  // Read the source and solutions
140  //
141  swatch.reset();
142  swatch.start();
144 
145  try
146  {
147  QDPIO::cout << "Attempt to read solutions" << std::endl;
148  quark.dilutions.resize(params.soln_files.size());
149 
150  QDPIO::cout << "dilutions.size= " << quark.dilutions.size() << std::endl;
151  for(int i=0; i < quark.dilutions.size(); ++i)
152  {
153  XMLReader file_xml, record_xml;
154 
155  QDPIO::cout << "reading file= " << params.soln_files[i] << std::endl;
156  QDPFileReader from(file_xml, params.soln_files[i], QDPIO_SERIAL);
157  read(from, record_xml, quark.dilutions[i].soln);
158  close(from);
159 
160  read(record_xml, "/Propagator/PropSource", quark.dilutions[i].source_header);
161  read(record_xml, "/Propagator/ForwardProp", quark.dilutions[i].prop_header);
162  }
163  }
164  catch (const std::string& e)
165  {
166  QDPIO::cerr << "Error extracting headers: " << e << std::endl;
167  QDP_abort(1);
168  }
169  swatch.stop();
170 
171  QDPIO::cout << "Sources and solutions successfully read: time= "
172  << swatch.getTimeInSeconds()
173  << " secs" << std::endl;
174 
175 
176 
177  //
178  // Check for each quark source that the solutions have their diluted
179  // on every site only once
180  //
181  swatch.reset();
182  swatch.start();
183 
184  try
185  {
186  bool first = true;
187  int N;
188  LatticeFermion quark_noise; // noisy source on entire lattice
189 
190  for(int i=0; i < quark.dilutions.size(); ++i)
191  {
192  std::istringstream xml_s(quark.dilutions[i].source_header.source.xml);
193  XMLReader sourcetop(xml_s);
194 // QDPIO::cout << "Source = " << quark.dilutions[i].source_header.source.id << std::endl;
195 
196  if (quark.dilutions[i].source_header.source.id != DiluteZNQuarkSourceConstEnv::getName())
197  {
198  QDPIO::cerr << "Expected source_type = " << DiluteZNQuarkSourceConstEnv::getName() << std::endl;
199  QDP_abort(1);
200  }
201 
202  QDPIO::cout << "Dilution num= " << i << std::endl;
203 
204  // Manually create the params so I can peek into them and use the source constructor
205  DiluteZNQuarkSourceConstEnv::Params srcParams(sourcetop,
206  quark.dilutions[i].source_header.source.path);
208 
209  if (first)
210  {
211  first = false;
212 
213  quark.j_decay = srcParams.j_decay;
214 
215  // Grab N
216  N = srcParams.N;
217 
218  // Set the seed to desired value
219  quark.seed = srcParams.ran_seed;
220  QDP::RNG::setrn(quark.seed);
221 
222  // Create the noisy quark source on the entire lattice
223  zN_src(quark_noise, N);
224  }
225 
226  // The seeds must always agree - here the seed is the unique id of the source
227  if ( toBool(srcParams.ran_seed != quark.seed) )
228  {
229  QDPIO::cerr << "dilution=" << i << " seed does not match" << std::endl;
230  QDP_abort(1);
231  }
232 
233  // The N's must always agree
234  if ( toBool(srcParams.N != N) )
235  {
236  QDPIO::cerr << "dilution=" << i << " N does not match" << std::endl;
237  QDP_abort(1);
238  }
239 
240  // Use a trick here, create the source and subtract it from the global noisy
241  // Check at the end that the global noisy is zero everywhere.
242  // NOTE: the seed will be set every call
243  quark.dilutions[i].source = srcConst(u);
244  quark_noise -= quark.dilutions[i].source;
245 
246 #if 0
247  // Diagnostic
248  {
249  // Keep a copy of the phases with NO momenta
250  SftMom phases_nomom(0, true, quark.dilutions[i].source_header.j_decay);
251 
252  multi1d<Double> source_corr = sumMulti(localNorm2(quark.dilutions[i].source),
253  phases_nomom.getSet());
254 
255  multi1d<Double> soln_corr = sumMulti(localNorm2(quark.dilutions[i].soln),
256  phases_nomom.getSet());
257 
258  }
259 #endif
260  } // end for i
261 
262  Double dcnt = norm2(quark_noise);
263  if (toDouble(dcnt) != 0.0) // problematic - seems to work with unnormalized sources
264  {
265  QDPIO::cerr << "Noise not saturated by all potential solutions: dcnt=" << dcnt << std::endl;
266  QDP_abort(1);
267  }
268  } // end try
269  catch(const std::string& e)
270  {
271  QDPIO::cerr << ": Caught Exception creating source: " << e << std::endl;
272  QDP_abort(1);
273  }
274 
275  swatch.stop();
276 
277  QDPIO::cout << "Sources saturated: time= "
278  << swatch.getTimeInSeconds()
279  << " secs" << std::endl;
280 
281  //
282  // Condensates
283  //
284  // Parameters needed for the momentum projection
285  SftMomParams_t sft_params;
286 
287  sft_params.origin_offset.resize(Nd);
288  sft_params.origin_offset = 0;
289  sft_params.mom2_max = params.mom2_max;
290  sft_params.mom_offset = params.mom_origin;
291  sft_params.avg_equiv_mom = params.avg_equiv_mom;
292  sft_params.decay_dir = quark.j_decay;
293 
294  // Start operator contractions
295  swatch.reset();
296  swatch.start();
297 
298  std::list< Handle<Hadron2PtContract_t> > hadron; // holds the contract lattice correlator
299 
300  for(int gamma_value=0; gamma_value < Ns*Ns; ++gamma_value)
301  {
303 
304  push(had->xml, xml_group);
305  write(had->xml, id_tag, "stoch_diagonal_gamma_condensates");
306  write(had->xml, "gamma_value", gamma_value);
307  write(had->xml, "mom2_max", sft_params.mom2_max);
308  write(had->xml, "avg_equiv_mom", sft_params.avg_equiv_mom);
309  write(had->xml, "decay_dir", sft_params.decay_dir);
310  pop(had->xml);
311 
312  had->corr = zero;
313  for(int i=0; i < quark.dilutions.size(); ++i)
314  {
315  had->corr +=
316  localInnerProduct(quark.dilutions[i].source, Gamma(gamma_value) * quark.dilutions[i].soln);
317  } // end for i
318 
319  hadron.push_back(had); // push onto end of list
320  }
321 
322  END_CODE();
323 
324  return this->project(hadron, sft_params);
325  }
326 
327 
328  //! Register all the factories
329  bool registerAll()
330  {
331  bool success = true;
332  if (! registered)
333  {
334  //! Register all the factories
335  success &= Chroma::TheHadronContractFactory::Instance().registerObject(std::string("stoch_diagonal_gamma_condensates"),
336  mesStochCondCont);
337 
338  registered = true;
339  }
340  return success;
341  }
342 
343  } // namespace StochCondContEnv
344 
345 } // namespace Chroma
Random complex Z(N) sources using dilution.
virtual std::list< Handle< HadronContractResult_t > > project(const std::list< Handle< Hadron2PtContract_t > > &had_list, const SftMomParams_t &p) const
Convenience function to project onto fixed momenta.
Definition: hadron_2pt.cc:33
Construct hadron correlators.
Class for counted reference semantics.
Definition: handle.h:33
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
Stochastic quark condensates.
std::list< Handle< HadronContractResult_t > > operator()(const multi1d< LatticeColorMatrix > &u, const std::string &xml_group, const std::string &id_tag)
Construct the correlators.
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.
void zN_src(LatticeFermion &a, int N)
Volume source of Z(N) noise.
Definition: zN_src.cc:41
Factory for producing hadron correlator objects.
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
Named object function std::map.
static bool registered
Local registration flag.
std::string getName()
Return the name.
QDPSubTypeTrait< typename BinaryReturn< C1, C2, FnLocalInnerProduct >::Type_t >::Type_t localInnerProduct(const QDPSubType< T1, C1 > &l, const QDPType< T2, C2 > &r)
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
pop(xml_out)
START_CODE()
Double zero
Definition: invbicg.cc:106
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Stoch quark condensates.
Propagator parameters.
Definition: qprop_io.h:75
Random complex Z(N) sources using dilution.
The result of hadron 2pt correlators.
Definition: hadron_2pt.h:17
Propagator source construction parameters.
Definition: qprop_io.h:27
Param struct for SftMom.
Definition: sftmom.h:20
multi1d< int > mom_offset
Definition: sftmom.h:23
multi1d< int > origin_offset
Definition: sftmom.h:25
multi1d< std::string > soln_files
void writeXML(XMLWriter &xml_out, const std::string &path) const
Structure holding a source and its solutions.
Volume source of Z(N) noise.