CHROMA
multi_propagator_comp.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 // define MRES_CALCULATION in order to run the code computing the residual mass
14 // and the pseudoscalar to conserved axial current correlator
15 #define MRES_CALCULATION
16 
17 /*
18  * Input
19  */
20 struct Prop_t
21 {
22  std::string source_file;
23  std::string prop_file;
24  QDP_volfmt_t prop_volfmt;
25 };
26 
27 
28 struct Component_t {
29  int color;
30  int spin;
31 };
32 
34 {
35  ChromaMultiProp_t param;
36  Cfg_t cfg;
37  Prop_t prop;
38  multi1d<Component_t> components;
39 };
40 
41 
42 void read(XMLReader& xml, const std::string& path, Component_t &comp)
43 {
44  XMLReader top(xml,path);
45  try {
46  read(top, "color", comp.color);
47  read(top, "spin", comp.spin);
48  }
49  catch( const std::string& e ) {
50  QDPIO::cerr << "Caught Exception : " << e << std::endl;
51  QDP_abort(1);
52  }
53  if( comp.color < 0 || comp.color >= Nc ) {
54  QDPIO::cerr << "Component color >= Nc. color = " << comp.color << std::endl;
55  QDP_abort(1);
56  }
57 
58  if( comp.spin < 0 || comp.spin >= Ns ) {
59  QDPIO::cerr << "Component spin >= Ns. spin = " << comp.spin << std::endl;
60  QDP_abort(1);
61  }
62 }
63 
64 void write(XMLWriter& xml, const std::string& path, const Component_t &comp)
65 {
66 
67  push( xml, path );
68 
69  write(xml, "color", comp.color);
70  write(xml, "spin", comp.spin);
71 
72  pop( xml );
73 }
74 
75 
76 // Propagator parameters
77 void read(XMLReader& xml, const std::string& path, Prop_t& input)
78 {
79  XMLReader inputtop(xml, path);
80 
81  read(inputtop, "source_file", input.source_file);
82  read(inputtop, "prop_file", input.prop_file);
83  read(inputtop, "prop_volfmt", input.prop_volfmt); // singlefile or multifile
84 }
85 
86 
87 // Reader for input parameters
88 void read(XMLReader& xml, const std::string& path, PropagatorComponent_input_t& input)
89 {
90  XMLReader inputtop(xml, path);
91 
92  // Read the input
93  try
94  {
95  // The parameters holds the version number
96  read(inputtop, "Param", input.param);
97 
98  // Read in the gauge configuration info
99  read(inputtop, "Cfg", input.cfg);
100 
101  // Read in the source/propagator info
102  read(inputtop, "Prop", input.prop);
103 
104  read(inputtop, "Components", input.components);
105  }
106  catch (const std::string& e)
107  {
108  QDPIO::cerr << "Error reading data: " << e << std::endl;
109  throw;
110  }
111 }
112 
113 // Forward declaration
114 void saveComponents(const ChromaMultiProp_t& param,
115  const Prop_t& prop,
116  XMLReader& source_record_xml,
117  const Component_t& component,
118  XMLReader& gauge_xml,
119  XMLWriter& xml_out,
120  const multi1d<LatticeFermion>& psi);
121 
122 //! Propagator generation
123 /*! \defgroup multi_propagator_comp Propagator generation
124  * \ingroup main
125  *
126  * Main program for propagator generation.
127  */
128 
129 int main(int argc, char **argv)
130 {
131  // Put the machine into a known state
132  Chroma::initialize(&argc, &argv);
133 
134  START_CODE();
135 
136  // Input parameter structure
138 
139  // Instantiate xml reader for DATA
140  XMLReader xml_in(Chroma::getXMLInputFileName());
141 
142  // Read data
143  read(xml_in, "/multiPropagatorComp", input);
144 
145  // Specify lattice size, shape, etc.
146  Layout::setLattSize(input.param.nrow);
147  Layout::create();
148 
149  QDPIO::cout << "multiPropagatorComp" << std::endl;
150 
151  // Read in the configuration along with relevant information.
152  multi1d<LatticeColorMatrix> u(Nd);
153  XMLReader gauge_file_xml, gauge_xml;
154 
155  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
156 
157  // Read in the source along with relevant information.
158  LatticePropagator quark_prop_source;
159  XMLReader source_file_xml, source_record_xml;
160 
161  // ONLY SciDAC mode is supported for propagators!!
162  readQprop(source_file_xml,
163  source_record_xml, quark_prop_source,
164  input.prop.source_file, QDPIO_SERIAL);
165 
166  // Try to invert this record XML into a source struct
167  // Also pull out the id of this source
168  PropSourceConst_t source_header;
169 
170  try
171  {
172  read(source_record_xml, "/MakeSource/PropSource", source_header);
173  }
174  catch (const std::string& e)
175  {
176  QDPIO::cerr << "Error extracting source_header: " << e << std::endl;
177  throw;
178  }
179 
180 
181  // Instantiate XML writer for XMLDAT
182  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
183  push(xml_out, "multiPropagatorComp");
184 
185  proginfo(xml_out); // Print out basic program info
186 
187  // Write out the input
188  write(xml_out, "Input", xml_in);
189 
190  // Write out the config header
191  write(xml_out, "Config_info", gauge_xml);
192 
193  // Write out the source header
194  write(xml_out, "Source_file_info", source_file_xml);
195  write(xml_out, "Source_record_info", source_record_xml);
196 
197  push(xml_out, "Output_version");
198  write(xml_out, "out_version", 1);
199  pop(xml_out);
200 
201  xml_out.flush();
202 
203 
204  // Check if the gauge field configuration is unitarized
205  unitarityCheck(u);
206 
207  // Calculate some gauge invariant observables just for info.
208  MesPlq(xml_out, "Observables", u);
209  xml_out.flush();
210 
211  // Sanity check - write out the norm2 of the source in the Nd-1 direction
212  // Use this for any possible verification
213  {
214  // Initialize the slow Fourier transform phases
215  SftMom phases(0, true, Nd-1);
216 
217  multi1d<Double> source_corr = sumMulti(localNorm2(quark_prop_source),
218  phases.getSet());
219 
220  push(xml_out, "Source_correlator");
221  write(xml_out, "source_corr", source_corr);
222  pop(xml_out);
223  }
224 
225  xml_out.flush();
226 
227  //
228  // Initialize fermion action
229  //
230  FermionAction<LatticeFermion>* S_f_ptr = 0;
232 
233  //
234  // Loop over the source color and spin, creating the source
235  // and calling the relevant propagator routines. The QDP
236  // terminology is that a propagator is a matrix in color
237  // and spin space
238  //
239  int num_mass = input.param.MultiMasses.size();
240 
241  multi1d<LatticeFermion> psi(num_mass);
242  int ncg_had = 0;
243 
244  //
245  // Initialize fermion action
246  //
247  switch (input.param.FermActHandle->getFermActType()) {
248 
249 
250  /***********************************************************************/
251  /* 4D ZOlotarev */
252  /***********************************************************************/
253  case FERM_ACT_ZOLOTAREV_4D:
254  {
255  QDPIO::cout << "FERM_ACT_ZOLOTAREV_4D" << std::endl;
256  const Zolotarev4DFermActParams& zolo4d = dynamic_cast<const Zolotarev4DFermActParams& > (*(input.param.FermActHandle));
257 
258  // Construct Fermact -- now uses constructor from the zolo4d params
259  // struct
260  S_f_ptr = new Zolotarev4DFermAct(zolo4d, xml_out);
261  }
262  break;
263  default:
264  QDPIO::cerr << "Unsupported fermion action" << std::endl;
265  QDP_abort(1);
266  }
267 
268  // Create a useable handle on the action
269  // The handle now owns the pointer
272 
273  // FIrst we have to set up the state -- this is fermact dependent
274  const ConnectState *state_ptr;
275 
276  switch(input.param.FermActHandle->getFermActType()) {
277  case FERM_ACT_ZOLOTAREV_4D:
278  {
279  const Zolotarev4DFermActParams& zolo4d = dynamic_cast<const Zolotarev4DFermActParams& > (*(input.param.FermActHandle));
280  const Zolotarev4DFermAct& S_zolo4 = dynamic_cast<const Zolotarev4DFermAct&>(*S_f);
281 
282  state_ptr = S_zolo4.createState(u, zolo4d.StateInfo, xml_out,zolo4d.AuxFermActHandle->getMass());
283 
284  }
285  break;
286  default:
287  QDPIO::cerr << "Unsupported fermion action (state creation)" << std::endl;
288  QDP_abort(1);
289  }
290 
291  // Now do the quarkprop here again depending on which of the
292  // action pointers is not null
293  Handle<const ConnectState> state(state_ptr); // inserts any BC
294 
295 
296  for(int comp = 0; comp < input.components.size(); comp++) {
297 
298  LatticeFermion chi;
299  PropToFerm(quark_prop_source, chi, input.components[comp].color,
300  input.components[comp].spin);
301 
302 
303  // Zero out initial guess
304  for(int i=0; i < num_mass; i++) {
305  psi[i] = zero;
306  }
307 
308  // Normalise source
309  Real fact = Real(1) / sqrt(norm2(chi));
310  chi *= fact;
311 
312  int n_count = 0;
313 
314  // Do the appropriate inversion.
315  // Unfortunately Fermion action does not have multiQprop
316  // In it so its switch and Dynamic Cast again
317  switch(input.param.FermActHandle->getFermActType()) {
318  case FERM_ACT_ZOLOTAREV_4D:
319  {
320  const Zolotarev4DFermAct& S=dynamic_cast<const Zolotarev4DFermAct&>(*S_f);
321  S.multiQprop(psi,
322  input.param.MultiMasses, state, chi,
323  input.param.invParam.invType,
324  input.param.invParam.RsdCG,
325  1,
326  input.param.invParam.MaxCG,
327  n_count);
328  }
329  break;
330  default:
331  QDPIO::cerr << "Fermion action unsupported " << std::endl;
332  break;
333  }
334 
335  // Remove source normalisation
336  fact = Real(1) / fact;
337  for(int i=0; i < num_mass; i++) {
338  psi[i] *= fact;
339 
340  }
341 
342  push(xml_out,"Relaxation_Iterations");
343  write(xml_out, "ncg_had", n_count);
344  pop(xml_out);
345 
346  saveComponents( input.param,
347  input.prop,
348  source_record_xml,
349  input.components[comp],
350  gauge_xml,
351  xml_out,
352  psi );
353 
354  }
355 
356  pop(xml_out); // propagator
357 
358  xml_out.close();
359  xml_in.close();
360 
361  END_CODE();
362 
363  // Time to bolt
364  QDP_finalize();
365 
366  exit(0);
367 }
368 
370  const Prop_t& prop,
371  XMLReader& source_record_xml,
372  const Component_t& component,
373  XMLReader& gauge_xml,
374  XMLWriter& xml_out,
375  const multi1d<LatticeFermion>& psi)
376 {
377  START_CODE();
378 
379  // Initialize the slow Fourier transform phases
380  int num_mass = param.MultiMasses.size();
381 
382  SftMom phases(0, true, Nd-1);
383  for(int m=0; m < num_mass; m++) {
384 
385  multi1d<Double> prop_corr = sumMulti(localNorm2(psi[m]),
386  phases.getSet());
387 
388  push(xml_out, "PropComp_correlator");
389  write(xml_out, "Number", m);
390  write(xml_out, "Mass", param.MultiMasses[m]);
391  write(xml_out, "prop_corr", prop_corr);
392  pop(xml_out);
393 
394  XMLBufferWriter file_xml;
395  push(file_xml, "propagatorComponent");
396  int id = 0; // NEED TO FIX THIS - SOMETHING NON-TRIVIAL NEEDED
397  write(file_xml, "id", id);
398  pop(file_xml);
399 
400 
401 
402  XMLBufferWriter record_xml;
403  push(record_xml, "PropagatorComponent");
404 
405  // Jiggery pokery. Substitute the ChromaMultiProp_t with a
406  // ChromaProp. This is a pisser because of the FermActParams
407  // THIS IS NOT TOTALLY KOSHER AS IT CHANGES THE MASS IN INPUT
408  // PARAM as well. However, at this stage we have no further need
409  // for input param.
410  // I Will eventually write Copy Constructors.
411 
412  ChromaProp_t out_param(param, m);
413 
414  write(record_xml, "ForwardProp", out_param);
415  XMLReader xml_tmp(source_record_xml, "/MakeSource");
416  record_xml << xml_tmp;
417  write(record_xml, "Component", component);
418 
419  pop(record_xml);
420 
421  std::ostringstream outfile;
422  outfile << prop.prop_file << "_component_s" << component.spin
423  << "_c" << component.color << "_"
424  << std::setw(3) << std::setfill('0') << m;
425 
426  QDPIO::cout << "Attempting to write " << outfile.str() << std::endl;
427 
428  // Write the source
429  writeFermion(file_xml, record_xml, psi[m],
430  outfile.str(), prop.prop_volfmt, QDPIO_SERIAL);
431  }
432 
434 
435  END_CODE();
436 }
Primary include file for CHROMA in application codes.
Support class for fermion actions and linear operators.
Definition: state.h:28
Base class for quadratic matter actions (e.g., fermions)
Definition: fermact.h:53
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
void PropToFerm(const LatticePropagatorF &b, LatticeFermionF &a, int color_index, int spin_index)
Extract a LatticeFermion from a LatticePropagator.
Definition: transf.cc:226
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
static int m[4]
Definition: make_seeds.cc:16
Nd
Definition: meslate.cc:74
void saveComponents(const ChromaMultiProp_t &param, const Prop_t &prop, XMLReader &source_record_xml, const Component_t &component, XMLReader &gauge_xml, XMLWriter &xml_out, const multi1d< LatticeFermion > &psi)
int main(int argc, char **argv)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
int n_count
Definition: invbicg.cc:78
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
multi1d< LatticeFermion > chi(Ncb)
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 writeFermion(XMLBufferWriter &file_xml, XMLBufferWriter &record_xml, const LatticeFermion &fermion, const std::string &file, QDP_volfmt_t volfmt, QDP_serialparallel_t serpar)
Definition: qprop_io.cc:1613
START_CODE()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
const WilsonTypeFermAct< multi1d< LatticeFermion > > & S_f
Definition: pbg5p_w.cc:27
Double zero
Definition: invbicg.cc:106
::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
Propagators.
std::string source_file
QDP_volfmt_t prop_volfmt
std::string prop_file
multi1d< Component_t > components