CHROMA
collect_multi_propcomp.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Main code for propagator generation
3  */
4 
5 #include <iostream>
6 #include <cstdio>
7 #include <iomanip>
8 #include "chroma.h"
9 
10 using namespace Chroma;
11 
12 
13 
14 /*
15  * Input
16  */
17 struct Prop_t
18 {
20  std::string prop_file;
21  QDP_volfmt_t prop_volfmt;
22 };
23 
24 
25 struct Component_t {
26  int color;
27  int spin;
28 };
29 
31 {
35  multi1d<Component_t> components;
36 };
37 
38 
39 void read(XMLReader& xml, const std::string& path, Component_t &comp)
40 {
41  XMLReader top(xml,path);
42  try {
43  read(top, "color", comp.color);
44  read(top, "spin", comp.spin);
45  }
46  catch( const std::string& e ) {
47  QDPIO::cerr << "Caught Exception : " << e << std::endl;
48  QDP_abort(1);
49  }
50  if( comp.color < 0 || comp.color >= Nc ) {
51  QDPIO::cerr << "Component color >= Nc. color = " << comp.color << std::endl;
52  QDP_abort(1);
53  }
54 
55  if( comp.spin < 0 || comp.spin >= Ns ) {
56  QDPIO::cerr << "Component spin >= Ns. spin = " << comp.spin << std::endl;
57  QDP_abort(1);
58  }
59 }
60 
61 void write(XMLWriter& xml, const std::string& path, const Component_t &comp)
62 {
63 
64  push( xml, path );
65 
66  write(xml, "color", comp.color);
67  write(xml, "spin", comp.spin);
68 
69  pop( xml );
70 }
71 
72 
73 // Propagator parameters
74 void read(XMLReader& xml, const std::string& path, Prop_t& input)
75 {
76  XMLReader inputtop(xml, path);
77 
78  read(inputtop, "source_file", input.source_file);
79  read(inputtop, "prop_file", input.prop_file);
80  read(inputtop, "prop_volfmt", input.prop_volfmt); // singlefile or multifile
81 }
82 
83 
84 // Reader for input parameters
85 void read(XMLReader& xml, const std::string& path, PropagatorComponent_input_t& input)
86 {
87  XMLReader inputtop(xml, path);
88 
89  // Read the input
90  try
91  {
92  // The parameters holds the version number
93  read(inputtop, "Param", input.param);
94 
95  // Read in the gauge configuration info
96  read(inputtop, "Cfg", input.cfg);
97 
98  // Read in the source/propagator info
99  read(inputtop, "Prop", input.prop);
100 
101  read(inputtop, "Components", input.components);
102  }
103  catch (const std::string& e)
104  {
105  QDPIO::cerr << "Error reading data: " << e << std::endl;
106  throw;
107  }
108 }
109 
110 /*!
111  * Main program for propagator generation.
112  */
113 
114 int main(int argc, char **argv)
115 {
116  // Put the machine into a known state
117  Chroma::initialize(&argc, &argv);
118 
119  START_CODE();
120 
121  // Input parameter structure
123 
124  // Instantiate xml reader for DATA
125  XMLReader xml_in(Chroma::getXMLInputFileName());
126 
127  // Read data
128  read(xml_in, "/multiPropagatorComp", input);
129 
130  // Specify lattice size, shape, etc.
131  Layout::setLattSize(input.param.nrow);
132  Layout::create();
133 
134  QDPIO::cout << "multiPropagatorComp" << std::endl;
135 
136  // Read in the configuration along with relevant information.
137  multi1d<LatticeColorMatrix> u(Nd);
138  XMLReader gauge_file_xml, gauge_xml;
139 
140  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
141 
142 
143  // Read in the source along with relevant information.
144  LatticePropagator quark_prop_source;
145  XMLReader source_file_xml, source_record_xml;
146 
147  // ONLY SciDAC mode is supported for propagators!!
148  readQprop(source_file_xml,
149  source_record_xml, quark_prop_source,
150  input.prop.source_file, QDPIO_SERIAL);
151 
152  // Try to invert this record XML into a source struct
153  // Also pull out the id of this source
154  bool make_sourceP = false;;
155  bool seqsourceP = false;
156  {
157  // ONLY SciDAC mode is supported for propagators!!
158  QDPIO::cout << "Attempt to read source" << std::endl;
159  readQprop(source_file_xml,
160  source_record_xml, quark_prop_source,
161  input.prop.source_file, QDPIO_SERIAL);
162  QDPIO::cout << "Forward propagator successfully read" << std::endl;
163 
164  // Try to invert this record XML into a source struct
165  try
166  {
167  // First identify what kind of source might be here
168  if (source_record_xml.count("/MakeSource") != 0)
169  {
170  PropSourceConst_t source_header;
171 
172  read(source_record_xml, "/MakeSource/PropSource", source_header);
173  make_sourceP = true;
174  }
175  else if (source_record_xml.count("/SequentialSource") != 0)
176  {
177  SeqSource_t seqsource_header;
178 
179  read(source_record_xml, "/SequentialSource/SeqSource", seqsource_header);
180  seqsourceP = true;
181  }
182  else
183  throw std::string("No appropriate header found");
184  }
185  catch (const std::string& e)
186  {
187  QDPIO::cerr << "Error extracting source_header: " << e << std::endl;
188  QDP_abort(1);
189  }
190  }
191 
192  // Sanity check
193  if (seqsourceP)
194  {
195  QDPIO::cerr << "Sequential propagator not supportd under multi-mass " << std::endl;
196  QDPIO::cerr << "since source is not mass independent " << std::endl;
197  QDP_abort(1);
198 
199  }
200 
201  // Instantiate XML writer for XMLDAT
202 // XMLFileWriter xml_out(Chroma::getXMLOutputFileName());
203  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
204  push(xml_out, "collectPropcomp");
205 
206  proginfo(xml_out); // Print out basic program info
207 
208  // Write out the input
209  write(xml_out, "Input", xml_in);
210 
211  // Write out the config header
212  write(xml_out, "Config_info", gauge_xml);
213 
214  // Write out the source header
215  write(xml_out, "Source_file_info", source_file_xml);
216  write(xml_out, "Source_record_info", source_record_xml);
217 
218  push(xml_out, "Output_version");
219  write(xml_out, "out_version", 1);
220  pop(xml_out);
221 
222  xml_out.flush();
223 
224 
225  // Check if the gauge field configuration is unitarized
226  unitarityCheck(u);
227 
228  // Calculate some gauge invariant observables just for info.
229  MesPlq(xml_out, "Observables", u);
230  xml_out.flush();
231 
232  // Sanity check - write out the norm2 of the source in the Nd-1 direction
233  // Use this for any possible verification
234  {
235  // Initialize the slow Fourier transform phases
236  SftMom phases(0, true, Nd-1);
237 
238  multi1d<Double> source_corr = sumMulti(localNorm2(quark_prop_source),
239  phases.getSet());
240 
241  push(xml_out, "Source_correlator");
242  write(xml_out, "source_corr", source_corr);
243  pop(xml_out);
244  }
245 
246  xml_out.flush();
247 
248  // Loop over the source color and spin, creating the source
249  // and calling the relevant propagator routines. The QDP
250  // terminology is that a propagator is a matrix in color
251  // and spin space
252  //
253  int num_mass = input.param.MultiMasses.size();
254 
255  LatticeFermion psi;
256  LatticePropagator quark_prop;
257 
258  XMLReader file_xml;
259  XMLReader record_xml;
260 
261  for(int m =0; m < num_mass; m++) {
262  for(int spin=0; spin < Ns; spin++) {
263  for(int color=0; color < Nc; color++) {
264  std::ostringstream filename ;
265  filename << input.prop.prop_file << "_component_s" << spin
266  << "_c" << color << "_"
267  << std::setw(3) << std::setfill('0') << m;
268 
269  QDPIO::cout << "Attempting to read " << filename.str() << std::endl;
270 
271  // Write the source
272  readFermion(file_xml, record_xml, psi,
273  filename.str(), QDPIO_SERIAL);
274 
275  FermToProp(psi, quark_prop, color, spin);
276  }
277  }
278 
279  SftMom phases(0, true, Nd-1);
280 
281  multi1d<Double> prop_corr = sumMulti(localNorm2(quark_prop),
282  phases.getSet());
283 
284  push(xml_out, "Prop_correlator");
285  write(xml_out, "Number", m);
286  write(xml_out, "Mass", input.param.MultiMasses[m]);
287  write(xml_out, "prop_corr", prop_corr);
288  pop(xml_out);
289 
290 
291  xml_out.flush();
292 
293  XMLBufferWriter file_xml;
294  push(file_xml, "propagator");
295  int id = 0; // NEED TO FIX THIS - SOMETHING NON-TRIVIAL NEEDED
296  write(file_xml, "id", id);
297  pop(file_xml);
298 
299 
300 
301  XMLBufferWriter record_xml;
302  push(record_xml, "Propagator");
303 
304  // Jiggery pokery. Substitute the ChromaMultiProp_t with a
305  // ChromaProp. This is a pisser because of the FermActParams
306  // THIS IS NOT TOTALLY KOSHER AS IT CHANGES THE MASS IN INPUT
307  // PARAM as well. However, at this stage we have no further need
308  // for input param.
309  // I Will eventually write Copy Constructors.
310 
311  ChromaProp_t out_param(input.param, m);
312  write(record_xml, "ForwardProp", out_param);
313  XMLReader xml_tmp(source_record_xml, "/MakeSource");
314  record_xml << xml_tmp;
315  pop(record_xml);
316 
317  std::ostringstream outfile;
318  outfile << input.prop.prop_file << "_" << std::setw(3) << std::setfill('0') << m;
319 
320  QDPIO::cout << "Attempting to write " << outfile.str() << std::endl;
321 
322  // Write the source
323  writeQprop(file_xml, record_xml, quark_prop,
324  outfile.str(), input.prop.prop_volfmt, QDPIO_SERIAL);
325  }
326 
327 
328 
329  pop(xml_out); // propagator
330 
331  xml_out.close();
332  xml_in.close();
333 
334  END_CODE();
335 
336  // Time to bolt
338 
339  exit(0);
340 }
341 
342 
Primary include file for CHROMA in application codes.
Fourier transform phase factor support.
Definition: sftmom.h:35
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
int main(int argc, char **argv)
void FermToProp(const LatticeFermionF &a, LatticePropagatorF &b, int color_index, int spin_index)
Insert a LatticeFermion into a LatticePropagator.
Definition: transf.cc:98
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 unitarityCheck(const multi1d< LatticeColorMatrixF3 > &u)
Check the unitarity of color matrix in SU(N)
Definition: unit_check.cc:20
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
static int m[4]
Definition: make_seeds.cc:16
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
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
void writeQprop(XMLBufferWriter &file_xml, XMLBufferWriter &record_xml, const LatticePropagator &quark_prop, const std::string &file, QDP_volfmt_t volfmt, QDP_serialparallel_t serpar)
Write a Chroma propagator.
Definition: qprop_io.cc:1532
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
LatticeFermion psi
Definition: mespbg5p_w.cc:35
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
void readFermion(XMLReader &file_xml, XMLReader &record_xml, LatticeFermion &fermion, const std::string &file, QDP_serialparallel_t serpar)
Definition: qprop_io.cc:1631
START_CODE()
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
::std::string string
Definition: gtest.h:1979
Gauge configuration structure.
Definition: cfgtype_io.h:16
Multi-propagator parameters.
Definition: qprop_io.h:61
multi1d< Real > MultiMasses
Definition: qprop_io.h:69
Propagator parameters.
Definition: qprop_io.h:75
Propagator source construction parameters.
Definition: qprop_io.h:27
Sequential source parameters.
Definition: qprop_io.h:90
Propagators.
std::string source_file
QDP_volfmt_t prop_volfmt
std::string prop_file
multi1d< Component_t > components