CHROMA
qproptransf.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Converts quark propagators in one format into another format.
3  */
4 
5 #include "chroma.h"
6 
7 using namespace Chroma;
8 
9 /*
10  * Input
11  */
12 
13 //! Propagator type
19 };
20 
21 //! Read a SciDACPropType enum
22 void read(XMLReader& xml, const std::string& path, SciDACPropType& param)
23 {
24  std::string prop_type_str;
25  read(xml, path, prop_type_str);
26  if (prop_type_str == "PROPAGATOR")
27  param = SCIDAC_PROP;
28  else if (prop_type_str == "SOURCE")
29  param = SCIDAC_SOURCE;
30  else if (prop_type_str == "SEQSOURCE")
31  param = SCIDAC_SEQSOURCE;
32  else if (prop_type_str == "SEQPROP")
33  param = SCIDAC_SEQPROP;
34  else
35  {
36  QDPIO::cerr << "Unsupported propagator type" << std::endl;
37  QDP_abort(1);
38  }
39 }
40 
41 
42 
43 // Parameters which must be determined from the XML input
44 // and written to the XML output
45 struct Param_t
46 {
47  multi1d<int> nrow; // Lattice dimension
48 };
49 
50 struct Prop_t
51 {
52  PropType prop_in_type; // propagator format
53  std::string prop_in_file;
54 
55  PropType prop_out_type; // propagator format
56  std::string prop_out_file;
57  QDP_volfmt_t prop_out_volfmt; // volume format (SINGLEFILE or MULTIFILE)
58 
59  SciDACPropType scidac_prop_type; // Either "PROPAGATOR", or "SEQPROP", etc.
60 };
61 
63 {
66 };
67 
68 
69 
70 //! Propagator parameters
71 void read(XMLReader& xml, const std::string& path, Prop_t& input)
72 {
73  XMLReader inputtop(xml, path);
74 
75  read(inputtop, "prop_in_type", input.prop_in_type);
76  read(inputtop, "prop_in_file", input.prop_in_file);
77 
78  read(inputtop, "prop_out_type", input.prop_out_type);
79  read(inputtop, "prop_out_file", input.prop_out_file);
80  read(inputtop, "prop_out_volfmt", input.prop_out_volfmt); // singlefile or multifile
81 
82  if (inputtop.count("scidac_prop_type") != 0)
83  read(inputtop, "scidac_prop_type", input.scidac_prop_type);
84 }
85 
86 
87 //! Parameters for running code
88 void read(XMLReader& xml, const std::string& path, Param_t& param)
89 {
90  XMLReader paramtop(xml, path);
91 
92  int version;
93  read(paramtop, "version", version);
94 
95  switch (version)
96  {
97  case 1:
98  case 2:
99  case 3:
100  /**************************************************************************/
101  break;
102 
103  default :
104  /**************************************************************************/
105  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
106  QDP_abort(1);
107  }
108 
109 
110  read(paramtop, "nrow", param.nrow);
111 }
112 
113 
114 // Reader for input parameters
115 void read(XMLReader& xml, const std::string& path, QpropTransf_input_t& input)
116 {
117  XMLReader inputtop(xml, path);
118 
119  // Read all the input groups
120  try
121  {
122  // Read program parameters
123  read(inputtop, "Param", input.param);
124 
125  // Read in the propagator file info
126  read(inputtop, "Prop", input.prop);
127  }
128  catch (const std::string& e)
129  {
130  QDPIO::cerr << "Error reading qproptransf data: " << e << std::endl;
131  throw;
132  }
133 }
134 
135 
136 //! Many-to-many propagator transformation routine
137 /*! \defgroup qproptransf Tranformation routine
138  * \ingroup main
139  *
140  * Main program for transforming propagator formats
141  */
142 
143 int main(int argc, char *argv[])
144 {
145  // Put the machine into a known state
146  Chroma::initialize(&argc, &argv);
147 
148  START_CODE();
149 
150  // Parameter structure for the input
151  QpropTransf_input_t input;
152 
153  // Instantiate xml reader for DATA
154  XMLReader xml_in(Chroma::getXMLInputFileName());
155 
156  // Read data
157  read(xml_in, "/qproptransf", input);
158 
159  // Setup QDP
160  Layout::setLattSize(input.param.nrow);
161  Layout::create();
162 
163  QDPIO::cout << "QPROPTRANSF: propagator transformation utility" << std::endl;
164 
165  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
166  push(xml_out, "qproptransf");
167 
168  proginfo(xml_out); // Print out basic program info
169 
170  write(xml_out, "input", xml_in); // save a copy of the input
171  xml_out.flush();
172 
173  /*
174  * Now read them thangs...
175  */
176  XMLReader prop_in_xml, prop_in_file_xml;
177  LatticePropagator prop;
178 
179  switch (input.prop.prop_in_type)
180  {
181  case PROP_TYPE_SZIN:
182  // SZIN
183  push(xml_out,"SZIN_propagator");
184  write(xml_out, "prop_in_type", input.prop.prop_in_type);
185  write(xml_out, "prop_in_file", input.prop.prop_in_file);
186 
187  readSzinQprop(prop_in_xml, prop, input.prop.prop_in_file);
188 
189  write(xml_out, "propagator_info", prop_in_xml);
190  pop(xml_out);
191  break;
192 
193  case PROP_TYPE_SCIDAC:
194  // SciDAC
195  push(xml_out,"SciDAC_propagator");
196  write(xml_out, "input_type", input.prop.prop_in_type);
197  write(xml_out, "prop_in_file", input.prop.prop_in_file);
198 
199  readQprop(prop_in_file_xml, prop_in_xml, prop,
200  input.prop.prop_in_file, QDPIO_SERIAL);
201 
202  write(xml_out, "File_xml", prop_in_file_xml);
203  write(xml_out, "Record_xml", prop_in_xml);
204  pop(xml_out);
205  break;
206 
207  case PROP_TYPE_KYU:
208  // Kentucky
209  push(xml_out,"KYU_propagator");
210  write(xml_out, "prop_in_type", input.prop.prop_in_type);
211  write(xml_out, "prop_in_file", input.prop.prop_in_file);
212 
214 
215  pop(xml_out);
216  break;
217 
218  default:
219  QDP_error_exit("unknown input type", input.prop.prop_in_type);
220  }
221 
222 
223  // Sanity check - write out the propagator (pion) correlator in the Nd-1 direction
224  {
225  // Initialize the slow Fourier transform phases
226  SftMom phases(0, true, Nd-1);
227 
228  multi1d<Double> prop_corr = sumMulti(localNorm2(prop),
229  phases.getSet());
230 
231  push(xml_out, "Prop_correlator");
232  write(xml_out, "prop_corr", prop_corr);
233  pop(xml_out);
234  }
235 
236  xml_out.flush();
237 
238  /*
239  * Now write them thangs...
240  */
241  switch (input.prop.prop_out_type)
242  {
243  case PROP_TYPE_SZIN:
244  {
245  // SZIN
246  Real Kappa(3.14159265359);
247 
248  push(xml_out,"SZIN_propagator");
249  write(xml_out, "output_type", input.prop.prop_out_type);
250  write(xml_out, "prop_out_file", input.prop.prop_out_file);
251  pop(xml_out);
252 
253  writeSzinQprop(prop, input.prop.prop_out_file, Kappa);
254  }
255  break;
256 
257  case PROP_TYPE_SCIDAC:
258  {
259  // SciDAC
260  // SciDAC output expects to find the relevant structures in the xml input.
261  // xml input file
262  // There are various forms of SciDAC prop types
263  std::string propHeaderTag;
264  std::string fileHeaderTag;
265 
266  switch (input.prop.scidac_prop_type)
267  {
268  case SCIDAC_SOURCE:
269  {
270  propHeaderTag = "MakeSource";
271  fileHeaderTag = "make_source";
272  }
273  break;
274 
275  case SCIDAC_PROP:
276  {
277  propHeaderTag = "Propagator";
278  fileHeaderTag = "propagator";
279  }
280  break;
281 
282  case SCIDAC_SEQSOURCE:
283  {
284  propHeaderTag = "SequentialSource";
285  fileHeaderTag = "seqsource";
286  }
287  break;
288 
289  case SCIDAC_SEQPROP:
290  {
291  propHeaderTag = "SequentialProp";
292  fileHeaderTag = "seqprop";
293  }
294  break;
295 
296  default:
297  QDPIO::cerr << "Unknown SciDAC prop type" << std::endl;
298  QDP_abort(1);
299  }
300 
301  //
302  // Suck the header into a std::string
303  //
304  std::string header;
305 
306  QDPIO::cout << "Read " << propHeaderTag << std::endl;
307 
308  try
309  {
310  XMLReader header_xml(xml_in, "/qproptransf/" + propHeaderTag);
311  std::ostringstream header_os;
312  header_xml.print(header_os);
313  header = header_os.str();
314  }
315  catch (const std::string& e)
316  {
317  QDPIO::cerr << "Error extracting " << propHeaderTag << ": " << e << std::endl;
318  throw;
319  }
320 
321  QDPIO::cout << "Header = " << header << std::endl;
322 
323  {
324  XMLBufferWriter prop_out_file_xml;
325  push(prop_out_file_xml, fileHeaderTag);
326  int id = 0; // NEED TO FIX THIS - SOMETHING NON-TRIVIAL NEEDED
327  write(prop_out_file_xml, "id", id);
328  pop(prop_out_file_xml);
329 
330  std::istringstream header_is(header);
331  XMLReader xml_header(header_is);
332  XMLBufferWriter prop_out_record_xml;
333 // write(prop_out_record_xml, ".", header);
334 
335  QDPIO::cout << "std::string out header" << std::endl;
336  prop_out_record_xml << xml_header;
337  QDPIO::cout << "std::string out header done" << std::endl;
338 
339  // Write it
340  writeQprop(prop_out_file_xml, prop_out_record_xml, prop,
341  input.prop.prop_out_file, input.prop.prop_out_volfmt,
342  QDPIO_SERIAL);
343  }
344  }
345  break;
346 
347  default:
348  QDPIO::cerr << "unknown output type = " << input.prop.prop_out_type << std::endl;
349  QDP_abort(1);
350  }
351 
352  pop(xml_out); // qproptransf
353 
354  END_CODE();
355 
356  // Time to bolt
358 
359  exit(0);
360 }
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
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
void readSzinQprop(XMLReader &xml, LatticePropagator &q, const std::string &file)
Read a SZIN propagator file. This is a simple memory dump reader.
void writeSzinQprop(const LatticePropagator &q, const std::string &file, const Real kappa)
Write a SZIN propagator file. This is a simple memory dump writer.
PropType
Propagator type.
void readKYUQprop(LatticePropagator &q, const std::string &file)
Read a Kentucky quark propagator.
Definition: kyuqprop_io.cc:22
@ PROP_TYPE_SCIDAC
std::map< std::string, SinkPropContainer_t > prop
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)
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
pop(xml_out)
START_CODE()
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
::std::string string
Definition: gtest.h:1979
int main(int argc, char *argv[])
Definition: qproptransf.cc:143
SciDACPropType
Propagator type.
Definition: qproptransf.cc:14
@ SCIDAC_PROP
Definition: qproptransf.cc:16
@ SCIDAC_SEQSOURCE
Definition: qproptransf.cc:17
@ SCIDAC_SEQPROP
Definition: qproptransf.cc:18
@ SCIDAC_SOURCE
Definition: qproptransf.cc:15
Parameters for running program.
Definition: qpropadd.cc:17
multi1d< int > nrow
Definition: qpropadd.cc:18
Propagators.
std::string prop_out_file
Definition: qpropgfix.cc:27
QDP_volfmt_t prop_out_volfmt
Definition: qpropgfix.cc:28
PropType prop_in_type
Definition: qproptransf.cc:52
std::string prop_in_file
Definition: qpropgfix.cc:24
SciDACPropType scidac_prop_type
Definition: qproptransf.cc:59
PropType prop_out_type
Definition: qproptransf.cc:55