CHROMA
t_seqsource.cc
Go to the documentation of this file.
1 //! \file
2 // \brief Test the sequential-source and resulting seqprop
3 //
4 
5 #include <iostream>
6 #include <cstdio>
7 
8 #include "chroma.h"
9 
10 using namespace Chroma;
11 
12 /*
13  * Input
14  */
15 //! Parameters for running program
16 struct Param_t
17 {
18  multi1d<int> nrow;
19 };
20 
21 //! Propagators
22 struct Prop_t
23 {
24  std::string prop_file; // The files is expected to be in SciDAC format!
25  multi1d<std::string> seqprop_files; // The files is expected to be in SciDAC format!
26 };
27 
28 
29 //! Mega-structure of all input
31 {
33 // Cfg_t cfg;
35 };
36 
37 
38 //! Propagator parameters
39 void read(XMLReader& xml, const std::string& path, Prop_t& input)
40 {
41  XMLReader inputtop(xml, path);
42 
43  read(inputtop, "prop_file", input.prop_file);
44  read(inputtop, "seqprop_files", input.seqprop_files);
45 }
46 
47 
48 // Reader for input parameters
49 void read(XMLReader& xml, const std::string& path, Param_t& param)
50 {
51  XMLReader paramtop(xml, path);
52 
53  read(paramtop, "nrow", param.nrow);
54 }
55 
56 
57 // Reader for input parameters
58 void read(XMLReader& xml, const std::string& path, Seqsource_input_t& input)
59 {
60  XMLReader inputtop(xml, path);
61 
62  // Read all the input groups
63  try
64  {
65  // Read program parameters
66  read(inputtop, "Param", input.param);
67 
68 // // Read in the gauge configuration info
69 // read(inputtop, "Cfg", input.cfg);
70 
71  // Read in the propagator(s) info
72  read(inputtop, "Prop", input.prop);
73  }
74  catch (const std::string& e)
75  {
76  QDPIO::cerr << "Error reading prop data: " << e << std::endl;
77  QDP_abort(1);
78  }
79 }
80 
81 
82 
83 int main(int argc, char *argv[])
84 {
85  // Put the machine into a known state
86  Chroma::initialize(&argc, &argv);
87 
88  START_CODE();
89 
90  // Input parameter structure
91  Seqsource_input_t input;
92 
93  // Instantiate xml reader for DATA
94  XMLReader xml_in(Chroma::getXMLInputFileName());
95 
96  // Read data
97  read(xml_in, "/t_seqsource", input);
98 
99  // Specify lattice size, shape, etc.
100  Layout::setLattSize(input.param.nrow);
101  Layout::create();
102 
103  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
104  push(xml_out, "t_seqsource");
105 
106  proginfo(xml_out); // Print out basic program info
107 
108  //
109  // Read the quark propagator and extract headers
110  //
111  XMLReader prop_file_xml, prop_record_xml;
112  LatticePropagator quark_propagator;
114  PropSourceConst_t source_header;
115  {
116  QDPIO::cout << "Attempt to read forward propagator" << std::endl;
117  readQprop(prop_file_xml,
118  prop_record_xml, quark_propagator,
119  input.prop.prop_file, QDPIO_SERIAL);
120 
121  // Try to invert this record XML into a ChromaProp struct
122  // Also pull out the id of this source
123  try
124  {
125  read(prop_record_xml, "/Propagator/ForwardProp", prop_header);
126  read(prop_record_xml, "/Propagator/PropSource", source_header);
127  }
128  catch (const std::string& e)
129  {
130  QDPIO::cerr << "Error extracting forward_prop header: " << e << std::endl;
131  QDP_abort(1);
132  }
133 
134  // Save propagator input
135  write(xml_out, "Propagator_file_info", prop_file_xml);
136  write(xml_out, "Propagator_record_info", prop_record_xml);
137  }
138  QDPIO::cout << "Forward propagator successfully read" << std::endl;
139 
140  // Derived from input prop
141  int j_decay = source_header.j_decay;
142  multi1d<int> t_source = source_header.t_source;
143 
144  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
145  // Use this for any possible verification
146  {
147  // Initialize the slow Fourier transform phases
148  SftMom phases(0, true, j_decay);
149 
150  multi1d<Double> forward_prop_corr = sumMulti(localNorm2(quark_propagator),
151  phases.getSet());
152 
153  push(xml_out, "Forward_prop_correlator");
154  write(xml_out, "forward_prop_corr", forward_prop_corr);
155  pop(xml_out);
156  }
157 
158 
159 
160  XMLArrayWriter xml_seq_src(xml_out, input.prop.seqprop_files.size());
161  push(xml_seq_src, "Sequential_source");
162 
163  for (int seq_src_ctr = 0; seq_src_ctr < input.prop.seqprop_files.size(); ++seq_src_ctr)
164  {
165  push(xml_seq_src);
166  write(xml_seq_src, "seq_src_ctr", seq_src_ctr);
167 
168  // Read the sequential propagator
169  // Read the quark propagator and extract headers
170  LatticePropagator seq_quark_prop;
171  SeqSource_t seqsource_header;
172  {
173  XMLReader seqprop_file_xml, seqprop_record_xml;
174  readQprop(seqprop_file_xml,
175  seqprop_record_xml, seq_quark_prop,
176  input.prop.seqprop_files[seq_src_ctr], QDPIO_SERIAL);
177 
178  // Try to invert this record XML into a ChromaProp struct
179  // Also pull out the id of this source
180  // NEED SECURITY HERE - need a way to cross check props. Use the ID.
181  try
182  {
183  read(seqprop_record_xml, "/SequentialProp/SeqSource", seqsource_header);
184  }
185  catch (const std::string& e)
186  {
187  QDPIO::cerr << "Error extracting seqprop header: " << e << std::endl;
188  QDP_abort(1);
189  }
190 
191  // Save seqprop input
192  write(xml_seq_src, "SequentialProp_file_info", seqprop_file_xml);
193  write(xml_seq_src, "SequentialProp_record_info", seqprop_record_xml);
194  }
195  QDPIO::cout << "Sequential propagator successfully read" << std::endl;
196 
197  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
198  // Use this for any possible verification
199  {
200  // Initialize the slow Fourier transform phases
201  SftMom phases(0, true, Nd-1);
202 
203  multi1d<Double> backward_prop_corr = sumMulti(localNorm2(seq_quark_prop),
204  phases.getSet());
205 
206  push(xml_seq_src, "Backward_prop_correlator");
207  write(xml_seq_src, "backward_prop_corr", backward_prop_corr);
208  pop(xml_seq_src);
209  }
210 
211  xml_out.flush();
212 
213  // Derived from input seqprop
214  std::string seq_src = seqsource_header.seq_src;
215  QDPIO::cout << "Seqsource name = " << seqsource_header.seq_src << std::endl;
216  int t_sink = seqsource_header.t_sink;
217  multi1d<int> sink_mom = seqsource_header.sink_mom;
218 
219  write(xml_seq_src, "seq_src", seq_src);
220  write(xml_seq_src, "t_source", t_source);
221  write(xml_seq_src, "t_sink", t_sink);
222  write(xml_seq_src, "sink_mom", sink_mom);
223 
224  // Now
225 
226  int mom2_max = 0;
227  for(int i=0; i < sink_mom.size(); ++i)
228  mom2_max += sink_mom[i]*sink_mom[i];
229 
230  SftMom phases(mom2_max, sink_mom, false, j_decay);
231 
232  int G5 = Ns*Ns-1;
233  int gamma_src = 0;
234  int gamma_snk = 0;
235  if (seq_src == "PION-A0_1")
236  {
237  gamma_src = G5;
238  gamma_snk = 0;
239  }
240  else if (seq_src == "PION-A0_2")
241  {
242  gamma_src = G5;
243  gamma_snk = 8;
244  }
245  else if (seq_src == "PION-RHO_X_1")
246  {
247  gamma_src = G5;
248  gamma_snk = 1;
249  }
250  else if (seq_src == "PION-RHO_X_2")
251  {
252  gamma_src = G5;
253  gamma_snk = 9;
254  }
255  else if (seq_src == "PION-RHO_Y_1")
256  {
257  gamma_src = G5;
258  gamma_snk = 2;
259  }
260  else if (seq_src == "PION")
261  {
262  gamma_src = G5;
263  gamma_snk = G5;
264  }
265  else if (seq_src == "PION-PION_2")
266  {
267  gamma_src = G5;
268  gamma_snk = 7;
269  }
270  else
271  {
272  QDP_error_exit("unknown seq_src: %s", seq_src.c_str());
273  }
274 
275  int gamma_insertion = G5 ^ gamma_src;
276 
277  push(xml_seq_src,"Corr_test");
278 
279  {
280  Complex seq_src_corr = trace(peekSite(Gamma(G5)*adj(seq_quark_prop)*Gamma(G5)*Gamma(gamma_insertion), t_source));
281  write(xml_seq_src,"gamma_insertion",gamma_insertion);
282  write(xml_seq_src,"seq_src_corr",seq_src_corr);
283  }
284 
285  {
286  LatticePropagator anti_quark_prop = Gamma(G5) * quark_propagator * Gamma(G5);
287  LatticeComplex corr_fn = trace(adj(anti_quark_prop) * Gamma(gamma_snk) *
288  quark_propagator * Gamma(gamma_src));
289 
290  multi2d<DComplex> hsum;
291  hsum = phases.sft(corr_fn);
292 // for (int sink_mom_num=0; sink_mom_num < phases.numMom(); ++sink_mom_num
293 // multi1d<int> mom = phases.numToMom(sink_mom_num);
294 
295  Complex mesprop_0 = hsum[0][t_sink];
296  write(xml_seq_src,"gamma_src",gamma_src);
297  write(xml_seq_src,"gamma_snk",gamma_snk);
298  write(xml_seq_src,"mesprop_0",mesprop_0);
299  }
300 
301  pop(xml_seq_src);
302 
303 
304  pop(xml_seq_src); // elem
305  } // end loop over sequential sources
306 
307  pop(xml_seq_src); // Sequential_source
308 
309  pop(xml_out); // t_seqsource
310 
311  END_CODE();
312 
313  // Time to bolt
315 
316  exit(0);
317 }
318 
Primary include file for CHROMA in application codes.
Fourier transform phase factor support.
Definition: sftmom.h:35
multi2d< DComplex > sft(const LatticeComplex &cf) const
Do a sumMulti(cf*phases,getSet())
Definition: sftmom.cc:524
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
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 proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
ForwardProp_t prop_header
int j_decay
Definition: meslate.cc:22
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
QDP_error_exit("too many BiCG iterations", n_count, rsd_sq, cp, c, re_rvr, im_rvr, re_a, im_a, re_b, im_b)
int G5
Definition: pbg5p_w.cc:57
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
void readQprop(XMLReader &file_xml, XMLReader &record_xml, LatticePropagator &quark_prop, const std::string &file, QDP_serialparallel_t serpar)
Read a Chroma propagator.
Definition: qprop_io.cc:1573
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
pop(xml_out)
START_CODE()
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
::std::string string
Definition: gtest.h:1979
Propagator parameters.
Definition: qprop_io.h:75
Propagator source construction parameters.
Definition: qprop_io.h:27
Sequential source parameters.
Definition: qprop_io.h:90
multi1d< int > sink_mom
Definition: qprop_io.h:95
Parameters for running program.
Definition: qpropadd.cc:17
multi1d< int > nrow
Definition: qpropadd.cc:18
Propagators.
std::string prop_file
multi1d< std::string > seqprop_files
Definition: t_seqsource.cc:25
Mega-structure of all input.
Definition: t_seqsource.cc:31
int main(int argc, char *argv[])
Definition: t_seqsource.cc:83