CHROMA
collect_propcomp.cc
Go to the documentation of this file.
1 // $Log: collect_propcomp.cc,v $
2 // Revision 3.0 2006-04-03 04:59:13 edwards
3 // Major overhaul of fermion and gauge action interface. Basically,
4 // all fermacts and gaugeacts now carry out <T,P,Q> template parameters. These are
5 // the fermion type, the "P" - conjugate momenta, and "Q" - generalized coordinates
6 // in the sense of Hamilton's equations. The fermbc's have been rationalized to never
7 // be over multi1d<T>. The "createState" within the FermionAction is now fixed meaning
8 // the "u" fields are now from the coordinate type. There are now "ConnectState" that
9 // derive into FermState<T,P,Q> and GaugeState<P,Q>.
10 //
11 // Revision 2.4 2005/12/15 04:04:22 edwards
12 // New QuarkSpinType to replace the "bool nonRelProp". Now choices
13 // of how to compute quark prop - FULL,UPPER,LOWER.
14 //
15 // Revision 2.3 2005/11/30 04:47:27 edwards
16 // Changed PropSource_t to PropSourceConst_t and added a new PropSourceSmear_t.
17 // Renamed PropSink_t to PropSinkSmear_t .
18 //
19 // Revision 2.2 2005/11/08 06:30:59 edwards
20 // Moved nrow to outer structure.
21 //
22 // Revision 2.1 2005/11/08 05:40:49 edwards
23 // Update to use new source mechanism.
24 //
25 // Revision 2.0 2005/09/25 21:04:45 edwards
26 // Moved to version 2.0
27 //
28 // Revision 1.13 2005/03/02 00:44:18 edwards
29 // Changed to new Chroma initialize/finalize format. Changed
30 // all XMLReader("DATA") to use a command-line param arg.
31 // Changed all XMLFileWriter(XMLDAT) to use the singleton instance.
32 //
33 // Revision 1.12 2005/02/28 03:34:46 edwards
34 // Collapsed code surrounding MesPlq call to a single sub call.
35 //
36 // Revision 1.11 2005/01/14 20:13:08 edwards
37 // Removed all using namespace QDP/Chroma from lib files. The library
38 // should now be 100% in the Chroma namespace. All mainprogs need a
39 // using namespace Chroma.
40 //
41 // Revision 1.10 2005/01/12 15:23:26 bjoo
42 // Moved the mainprogs to use ChromaInitialize and ChromaFinalize. Howver this doesnt buy us much since the linkage hack cannot be properly hidden at the moment (causes segfaults in propagator) and I need closure about how to deal with default input streams. You do get a TheXMLOutputWriter tho
43 //
44 // Revision 1.9 2004/12/24 04:19:22 edwards
45 // Removed explict FermBC args to FermAct factory functions.
46 //
47 // Revision 1.8 2004/11/17 15:23:00 bjoo
48 // t_su3 removed from make check. Throws std::stringified
49 //
50 // Revision 1.7 2004/09/08 14:41:36 edwards
51 // Ifdef'ed out old FermActHandle code to get to compile.
52 //
53 // Revision 1.6 2004/07/28 03:08:04 edwards
54 // Added START/END_CODE to all routines. Changed some to not pass an
55 // argument.
56 //
57 // Revision 1.5 2004/04/28 14:56:11 bjoo
58 // Tested propagator_comp and collect_propcomp
59 //
60 // Revision 1.3 2004/04/23 11:23:38 bjoo
61 // Added component based propagator (non multishift) and added Zolotarev5D operator to propagator and propagator_comp. Reworked propagator collection scripts
62 //
63 // Revision 1.2 2004/04/22 16:25:25 bjoo
64 // Added overlap_state_info Param struct and gauge startup convenience function. Tidyed up propagator zolo4d case
65 //
66 // Revision 1.1 2004/04/20 13:08:12 bjoo
67 // Added multi mass component based solves and propagator collection program
68 //
69 // Revision 1.3 2004/04/16 22:03:59 bjoo
70 // Added Zolo 4D test files and tidyed up
71 //
72 // Revision 1.2 2004/04/16 20:18:03 bjoo
73 // Zolo seems to work now
74 //
75 // Revision 1.1 2004/04/16 17:04:49 bjoo
76 // Added multi_propagator for Zolo4D multi massery. Seems to work even
77 //
78 // Revision 1.49 2004/04/15 14:43:25 bjoo
79 // Added generalised qprop_io FermAct reading
80 //
81 // Revision 1.48 2004/04/06 04:20:33 edwards
82 // Added SZINQIO support.
83 //
84 // Revision 1.47 2004/04/01 18:10:22 edwards
85 // Added support for non-relativistic quark props.
86 //
87 // Revision 1.46 2004/02/23 03:13:58 edwards
88 // Major overhaul of input/output model! Now using EXCLUSIVELY
89 // SciDAC propagator format for propagators. Now, Param part of input
90 // files directly matches source/sink/propagator/seqprop headers
91 // of propagators. All ``known'' input of a propagator is derived
92 // from its header(s) and used for subsequent calculations.
93 //
94 // Revision 1.45 2004/02/11 12:51:35 bjoo
95 // Stripped out Read() and Write()
96 //
97 // Revision 1.44 2004/02/07 04:51:58 edwards
98 // Removed SSE hack - pushed it down into the SSE code where it belongs.
99 //
100 // Revision 1.43 2004/02/06 22:31:00 edwards
101 // Put in sse hack for the short term.
102 //
103 // Revision 1.42 2004/02/06 17:39:05 edwards
104 // Added a std::flush to xml_out.
105 //
106 // Revision 1.41 2004/02/05 04:18:56 edwards
107 // Changed call of quarkProp4 to write to xml_out instead of xml buffer.
108 //
109 // Revision 1.40 2004/02/04 17:01:55 edwards
110 // Changed getSubset() to the now correct getSet().
111 //
112 // Revision 1.39 2004/01/31 23:22:01 edwards
113 // Added proginfo call.
114 //
115 // Revision 1.38 2004/01/30 21:35:22 kostas
116 // added calls to calculate mres for dwf
117 //
118 /*! \file
119  * \brief Main code for propagator generation
120  */
121 
122 #include <iostream>
123 #include <cstdio>
124 #include <iomanip>
125 #include "chroma.h"
126 
127 using namespace Chroma;
128 
129 /*
130  * Input
131  */
132 struct Prop_t
133 {
134  std::string source_file;
135  std::string prop_file;
136  QDP_volfmt_t prop_volfmt;
137 };
138 
139 
140 struct Component_t {
141  int color;
142  int spin;
143 };
144 
146 {
148  Cfg_t cfg;
149  Prop_t prop;
150  multi1d<Component_t> components;
151  multi1d<int> nrow;
152 };
153 
154 
155 void read(XMLReader& xml, const std::string& path, Component_t &comp)
156 {
157  XMLReader top(xml,path);
158  try {
159  read(top, "color", comp.color);
160  read(top, "spin", comp.spin);
161  }
162  catch( const std::string& e ) {
163  QDPIO::cerr << "Caught Exception : " << e << std::endl;
164  QDP_abort(1);
165  }
166  if( comp.color < 0 || comp.color >= Nc ) {
167  QDPIO::cerr << "Component color >= Nc. color = " << comp.color << std::endl;
168  QDP_abort(1);
169  }
170 
171  if( comp.spin < 0 || comp.spin >= Ns ) {
172  QDPIO::cerr << "Component spin >= Ns. spin = " << comp.spin << std::endl;
173  QDP_abort(1);
174  }
175 }
176 
177 void write(XMLWriter& xml, const std::string& path, const Component_t &comp)
178 {
179 
180  push( xml, path );
181 
182  write(xml, "color", comp.color);
183  write(xml, "spin", comp.spin);
184 
185  pop( xml );
186 }
187 
188 
189 // Propagator parameters
190 void read(XMLReader& xml, const std::string& path, Prop_t& input)
191 {
192  XMLReader inputtop(xml, path);
193 
194  read(inputtop, "source_file", input.source_file);
195  read(inputtop, "prop_file", input.prop_file);
196  read(inputtop, "prop_volfmt", input.prop_volfmt); // singlefile or multifile
197 }
198 
199 
200 // Reader for input parameters
201 void read(XMLReader& xml, const std::string& path, PropagatorComponent_input_t& input)
202 {
203  XMLReader inputtop(xml, path);
204 
205  // Read the input
206  try
207  {
208  // The parameters holds the version number
209  read(inputtop, "Param", input.param);
210 
211  // Read in the gauge configuration info
212  read(inputtop, "Cfg", input.cfg);
213 
214  // Read in the source/propagator info
215  read(inputtop, "Prop", input.prop);
216 
217  read(inputtop, "Components", input.components);
218  }
219  catch (const std::string& e)
220  {
221  QDPIO::cerr << "Error reading data: " << e << std::endl;
222  throw;
223  }
224 }
225 
226 /*!
227  * Main program for propagator generation.
228  */
229 
230 int main(int argc, char **argv)
231 {
232  Chroma::initialize(&argc, &argv);
233 
234  START_CODE();
235 
236  // Input parameter structure
238 
239  // Instantiate xml reader for DATA
240  XMLReader xml_in(Chroma::getXMLInputFileName());
241 
242  // Read data
243  try {
244  read(xml_in, "/propagatorComp", input);
245  }
246  catch ( const std::string& e ) {
247  QDPIO::cerr << "Caught exception " << e << std::endl;
248  QDP_abort(1);
249  }
250 
251  // Specify lattice size, shape, etc.
252  Layout::setLattSize(input.nrow);
253  Layout::create();
254 
255  QDPIO::cout << "propagatorComp" << std::endl;
256 
257  // Read in the configuration along with relevant information.
258  multi1d<LatticeColorMatrix> u(Nd);
259  XMLReader gauge_file_xml, gauge_xml;
260 
261 
262  // Start up the gauge field
263  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
264 
265  // Read in the source along with relevant information.
266  LatticePropagator quark_prop_source;
267  XMLReader source_file_xml, source_record_xml;
268 
269  bool make_sourceP = false;;
270  bool seqsourceP = false;
271  {
272  // ONLY SciDAC mode is supported for propagators!!
273  QDPIO::cout << "Attempt to read source" << std::endl;
274  readQprop(source_file_xml,
275  source_record_xml, quark_prop_source,
276  input.prop.source_file, QDPIO_SERIAL);
277  QDPIO::cout << "Forward propagator successfully read" << std::endl;
278 
279  // Try to invert this record XML into a source struct
280  try
281  {
282  // First identify what kind of source might be here
283  if (source_record_xml.count("/MakeSource") != 0)
284  {
285  PropSourceConst_t source_header;
286 
287  read(source_record_xml, "/MakeSource/PropSource", source_header);
288  make_sourceP = true;
289  }
290  else if (source_record_xml.count("/SequentialSource") != 0)
291  {
292  SeqSource_t seqsource_header;
293 
294  read(source_record_xml, "/SequentialSource/SeqSource", seqsource_header);
295  seqsourceP = true;
296  }
297  else
298  throw std::string("No appropriate header found");
299  }
300  catch (const std::string& e)
301  {
302  QDPIO::cerr << "Error extracting source_header: " << e << std::endl;
303  QDP_abort(1);
304  }
305  }
306 
307 
308 
309  // Instantiate XML writer for XMLDAT
310 // XMLFileWriter xml_out(Chroma::getXMLOutputFileName());
311  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
312 
313  push(xml_out, "collectPropcomp");
314 
315  proginfo(xml_out); // Print out basic program info
316 
317  // Write out the input
318  write(xml_out, "Input", xml_in);
319 
320  // Write out the config header
321  write(xml_out, "Config_info", gauge_xml);
322 
323  // Write out the source header
324  write(xml_out, "Source_file_info", source_file_xml);
325  write(xml_out, "Source_record_info", source_record_xml);
326 
327  push(xml_out, "Output_version");
328  write(xml_out, "out_version", 1);
329  pop(xml_out);
330 
331  xml_out.flush();
332 
333 
334  // Check if the gauge field configuration is unitarized
335  unitarityCheck(u);
336 
337  // Calculate some gauge invariant observables just for info.
338  MesPlq(xml_out, "Observables", u);
339  xml_out.flush();
340 
341  // Sanity check - write out the norm2 of the source in the Nd-1 direction
342  // Use this for any possible verification
343  {
344  // Initialize the slow Fourier transform phases
345  SftMom phases(0, true, Nd-1);
346 
347  multi1d<Double> source_corr = sumMulti(localNorm2(quark_prop_source),
348  phases.getSet());
349 
350  push(xml_out, "Source_correlator");
351  write(xml_out, "source_corr", source_corr);
352  pop(xml_out);
353  }
354 
355  xml_out.flush();
356 
357  // Loop over the source color and spin, creating the source
358  // and calling the relevant propagator routines. The QDP
359  // terminology is that a propagator is a matrix in color
360  // and spin space
361  //
362  LatticeFermion psi;
363  LatticePropagator quark_prop;
364 
365  XMLReader file_xml_in;
366  XMLReader record_xml_in;
367 
368  int start_spin;
369  int end_spin;
370  if( make_sourceP ) {
371  start_spin = 0;
372  end_spin = Ns;
373  }
374  else if (seqsourceP ) {
375  switch (input.param.quarkSpinType)
376  {
378  start_spin = 0;
379  end_spin = Ns;
380  break;
381 
383  start_spin = 0;
384  end_spin = Ns/2;
385  break;
386 
388  start_spin = Ns/2;
389  end_spin = Ns;
390  break;
391  }
392  }
393 
394  for(int spin=start_spin; spin < end_spin; spin++) {
395  for(int color=0; color < Nc; color++) {
396  std::ostringstream filename ;
397  filename << input.prop.prop_file << "_component_s" << spin
398  << "_c" << color ;
399 
400  QDPIO::cout << "Attempting to read " << filename.str() << std::endl;
401 
402  // Write the source
403  readFermion(file_xml_in, record_xml_in, psi,
404  filename.str(), QDPIO_SERIAL);
405 
406  FermToProp(psi, quark_prop, color, spin);
407  }
408  }
409 
410  if( seqsourceP )
411  {
412  switch (input.param.quarkSpinType)
413  {
415  // Do nothing here
416  break;
417 
419  {
420  for(int color_source = 0; color_source < Nc ; ++color_source)
421  {
422  for(int spin_source = Ns/2; spin_source < Ns; ++spin_source)
423  {
424  PropToFerm(quark_prop,psi, color_source, spin_source-Ns/2);
425  FermToProp((-psi), quark_prop, color_source, spin_source);
426  }
427  }
428  }
429  break;
430 
432  {
433  // NOT SURE THIS IS CORRECT
434  for(int color_source = 0; color_source < Nc ; ++color_source)
435  {
436  for(int spin_source = 0; spin_source < Ns/2; ++spin_source)
437  {
438  PropToFerm(quark_prop,psi, color_source, spin_source+Ns/2);
439  FermToProp((-psi), quark_prop, color_source, spin_source);
440  }
441  }
442  }
443  break;
444  } // end switch(quarkSpinType)
445  }
446 
447  SftMom phases(0, true, Nd-1);
448 
449  multi1d<Double> prop_corr = sumMulti(localNorm2(quark_prop),
450  phases.getSet());
451 
452 #if 0
453  // Need to fix FermActHandle here
454  push(xml_out, "Prop_correlator");
455  write(xml_out, "Mass", input.param.FermActHandle->getMass());
456  write(xml_out, "prop_corr", prop_corr);
457  pop(xml_out);
458 #endif
459 
460 
461  xml_out.flush();
462 
463  XMLBufferWriter file_xml;
464  push(file_xml, "propagator");
465  int id = 0; // NEED TO FIX THIS - SOMETHING NON-TRIVIAL NEEDED
466  write(file_xml, "id", id);
467  pop(file_xml);
468 
469 
470 
471  XMLBufferWriter record_xml;
472  if( make_sourceP) {
473 
474  // Jiggery pokery. Substitute the ChromaMultiProp_t with a
475  // ChromaProp. This is a pisser because of the FermActParams
476  // THIS IS NOT TOTALLY KOSHER AS IT CHANGES THE MASS IN INPUT
477  // PARAM as well. However, at this stage we have no further need
478  // for input param.
479  // I Will eventually write Copy Constructors.
480  XMLReader xml_tmp(source_record_xml, "/MakeSource");
481 
482  push(record_xml, "Propagator");
483  write(record_xml, "ForwardProp", input.param);
484  record_xml << xml_tmp;
485  pop(record_xml);
486  }
487  else if (seqsourceP) {
488  XMLReader xml_tmp(source_record_xml, "/SequentialSource");
489 
490  push(record_xml, "SequentialProp");
491  write(record_xml, "SeqProp", input.param);
492  record_xml << xml_tmp; // write out all the stuff under SequentialSource
493  pop(record_xml);
494  }
495 
496 
497  QDPIO::cout << "Attempting to write " << input.prop.prop_file << std::endl;
498 
499  // Write the source
500  writeQprop(file_xml, record_xml, quark_prop,
501  input.prop.prop_file, input.prop.prop_volfmt, QDPIO_SERIAL);
502 
503 
504 
505  pop(xml_out); // propagator
506 
507  END_CODE();
508 
509  // Time to bolt
511 
512  exit(0);
513 }
514 
515 
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 PropToFerm(const LatticePropagatorF &b, LatticeFermionF &a, int color_index, int spin_index)
Extract a LatticeFermion from a LatticePropagator.
Definition: transf.cc:226
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
std::map< std::string, SinkPropContainer_t > prop
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
QuarkSpinType quarkSpinType
Definition: qprop_io.h:63
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