CHROMA
t_propagator_s.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Main code for propagator generation
3  *
4  * I using this code to DEBUG the HISQ inverter.
5  *
6  */
7 
8 #include <iostream>
9 #include <cstdio>
10 
11 #define MAIN
12 
13 // Include everything...
14 #include "chroma.h"
15 
18 
19 #include "io/xml_group_reader.h"
20 
21 /*
22  * Here we have various temporary definitions
23  */
24 
25 using namespace Chroma;
26 
27 
28 /*
29  * Input
30  */
31 
32 
33 // Parameters which must be determined from the XML input
34 // and written to the XML output
35 struct Param_t
36 {
37  Real Mass; // Staggered mass
38  Real u0; // Tadpole Factor
39 
40  CfgType cfg_type; // storage order for stored gauge configuration
41 
42  SysSolverCGParams invParam;
43 
45 
46  Real GFAccu, OrPara; // Gauge fixing tolerance and over-relaxation param
47  int GFMax; // Maximum gauge fixing iterations
48 
49  multi1d<int> nrow;
50  multi1d<int> boundary;
51  multi1d<int> t_srce;
52 };
53 
54 
55 struct Prop_t
56 {
57  std::string source_file;
58  std::string prop_file;
59 };
60 
61 struct Propagator_input_t
62 {
63  Param_t param;
64  Cfg_t cfg;
65  Prop_t prop;
66 };
67 
68 
69 
70 
71 // Reader for input parameters
72 void read(XMLReader& xml, const std::string& path, Propagator_input_t& input)
73 {
74  XMLReader inputtop(xml, path);
75 
76 
77  // First, read the input parameter version. Then, if this version
78  // includes 'Nc' and 'Nd', verify they agree with values compiled
79  // into QDP++
80 
81  // Read in the IO_version
82  int version;
83  try
84  {
85  read(inputtop, "IO_version/version", version);
86  }
87  catch (const std::string& e)
88  {
89  QDPIO::cerr << "Error reading data: " << e << std::endl;
90  throw;
91  }
92 
93 
94  // Currently, in the supported IO versions, there is only a small difference
95  // in the inputs. So, to make code simpler, extract the common bits
96 
97  // Read the uncommon bits first
98  try
99  {
100  XMLReader paramtop(inputtop, "param"); // push into 'param' group
101 
102  switch (version)
103  {
104  /**************************************************************************/
105  case 2 :
106  /**************************************************************************/
107  break;
108 
109  default :
110  /**************************************************************************/
111 
112  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
113  QDP_abort(1);
114  }
115  }
116  catch (const std::string& e)
117  {
118  QDPIO::cerr << "Error reading data: " << e << std::endl;
119  throw;
120  }
121 
122  QDPIO::cout << "Propagator for Staggered fermions" << std::endl;
123  // Read the common bits
124  try
125  {
126  XMLReader paramtop(inputtop, "param"); // push into 'param' group
127 
128  // This is a Group XML structure which has 2 members
129  // One is the 'id' which will be found in the "FermAct" sub-tag
130  // One is the root tag of the Group in this case "FermionAction"
131  input.param.fermact = readXMLGroup(paramtop, "FermionAction", "FermAct");
132 
133  read(paramtop, "RsdCG", input.param.invParam.RsdCG);
134  read(paramtop, "MaxCG", input.param.invParam.MaxCG);
135  read(paramtop, "GFAccu", input.param.GFAccu);
136  read(paramtop, "OrPara", input.param.OrPara);
137  read(paramtop, "GFMax", input.param.GFMax);
138 
139  read(paramtop, "nrow", input.param.nrow);
140  read(paramtop, "t_srce", input.param.t_srce);
141  }
142  catch (const std::string& e)
143  {
144  QDPIO::cerr << "Error reading data: " << e << std::endl;
145  throw;
146  }
147 
148 
149  // Read in the gauge configuration file name
150  try
151  {
152  read(inputtop, "Cfg", input.cfg);
153  }
154  catch (const std::string& e)
155  {
156  QDPIO::cerr << "Error reading data: " << e << std::endl;
157  throw;
158  }
159  }
160 
161 
162  bool linkageHack(void)
163 {
164  bool foo = true;
165 
166  // Inline Measurements
169  foo &= GaugeInitEnv::registerAll();
170 
171  return foo;
172 }
173 // ! Propagator generation
174  /*! \defgroup t_propagator_s Propagator generation
175  * \ingroup testsmain
176  *
177  * Main program for propagator generation.
178  */
179 
180  int main(int argc, char **argv)
181  {
182  // Put the machine into a known state
183  Chroma::initialize(&argc, &argv);
184 
185  linkageHack();
186  // Input parameter structure
187  Propagator_input_t input;
188 
189  // Instantiate xml reader for DATA
190  XMLReader xml_in ;
192  try
193  {
194  xml_in.open(in_name);
195  }
196  catch (...)
197  {
198  QDPIO::cerr << "Error reading input file " << in_name << std::endl;
199  QDPIO::cerr << "The input file name can be passed via the -i flag " << std::endl;
200  QDPIO::cerr << "The default name is ./DATA" << std::endl;
201  throw;
202  }
203 
204 
205  // Read the input file
206  try
207  {
208  read(xml_in, "/propagator", input);
209  }
210  catch (...)
211  {
212  QDPIO::cerr << "Error parsing the input file " << in_name << std::endl;
213  throw;
214  }
215  // Specify lattice size, shape, etc.
216  Layout::setLattSize(input.param.nrow);
217  Layout::create();
218 
219  // Read in the configuration along with relevant information.
220  multi1d<LatticeColorMatrix> u(Nd);
221 
222  XMLReader gauge_file_xml, gauge_xml;
223  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
224 
225  // Instantiate XML writer for the output file
226  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
227  push(xml_out, "hadron_corr");
228 
229  // Write out the input
230  write(xml_out, "Input", xml_in);
231 
232  // Write out the config header
233  write(xml_out, "Config_info", gauge_xml);
234 
235  // Write out the source header
236 
237  push(xml_out, "Output_version");
238  write(xml_out, "out_version", 1);
239  pop(xml_out);
240 
241  xml_out.flush();
242 
243  // Check if the gauge field configuration is unitarized
244  unitarityCheck(u);
245 
246  // Calculate some gauge invariant observables just for info.
247  MesPlq(xml_out, "Observables", u);
248  xml_out.flush();
249 
250  // Fix to the coulomb gauge
251  int n_gf;
252  int j_decay = Nd-1;
253 
254  // Calcluate plaq on the gauge fixed field
255  MesPlq(xml_out, "Is_this_gauge_invariant", u);
256  xml_out.flush();
257 
258  // Typedefs to save typing
259  typedef LatticeStaggeredFermion T;
260  typedef multi1d<LatticeColorMatrix> P;
261  typedef multi1d<LatticeColorMatrix> Q;
262 
263  //
264  // Initialize fermion action
265  //
266 
267  XMLReader fermact_reader ;
268  // Make a memory 'input stream' out of the XML, so we can open an
269  // XML Reader on it.
270  try{
271  std::istringstream is(input.param.fermact.xml);
272 
273  // Open a reader on the memory stream.
274  // XMLReader fermact_reader(is);
275  fermact_reader.open(is);
276  }
277  catch (...)
278  {
279  QDPIO::cerr << "Error reading action name " << std::endl;
280  throw;
281  }
282 
283 
284  Handle< StaggeredTypeFermAct< T,P,Q> > fermact(TheStagTypeFermActFactory::Instance().createObject(input.param.fermact.id, fermact_reader, input.param.fermact.path));
285  // Cast of a pointer to a reference?
286  StaggeredTypeFermAct<T,P,Q>& S_f= *(fermact);
287 
288 
289  // Set up a state for the current u,
290  // (compute fat & triple links)
291  // Use S_f.createState so that S_f can pass in u0
292 
293  Handle< FermState<T,P,Q> > state(S_f.createState(u));
294 
295  //
296  // Loop over the source color, creating the source
297  // and calling the relevant propagator routines.
298  //
299  //
300 
301  LatticeStaggeredPropagator quark_propagator;
302  XMLBufferWriter xml_buf;
303  int ncg_had = 0;
304  int n_count;
305  int t_length = input.param.nrow[3];
306 
307  LatticeStaggeredFermion q_source, psi;
308 
309  push(xml_out, "point_source");
310  push(xml_out,"Inverter_properties");
311  write(xml_out, "Mass" , input.param.Mass);
312  write(xml_out, "RsdCG", input.param.invParam.RsdCG);
313  pop(xml_out);
314 
315  GroupXML_t inv_param;
316  {
317  XMLBufferWriter xml_buf;
318  write(xml_buf, "InvertParam", input.param.invParam);
319  XMLReader xml_in(xml_buf);
320  inv_param = readXMLGroup(xml_in, "/InvertParam", "invType");
321  }
322  Handle< SystemSolver<LatticeStaggeredFermion> > qprop(S_f.qprop(state,inv_param));
323 
324  /** do inversions **************************/
325 
326  for(int t_source = 0; t_source < 1; t_source += 2) {
327  QDPIO::cout << "Source time slice = " << t_source << std::endl;
328 
329  psi = zero; // note this is ``zero'' and not 0
330  multi1d<int> coord(4) ;
331  coord[0] = 0 ;
332  coord[1] = 0 ;
333  coord[2] = 0 ;
334  coord[3] = t_source ;
335 
336  for(int color_source = 0; color_source < Nc; ++color_source) {
337  QDPIO::cout << "Inversion for Color = " << color_source << std::endl;
338 
339  q_source = zero ;
340 
341  // Use a point source
342  srcfil(q_source, coord, color_source);
343 
344  // Use the last initial guess as the current guess
345 
346  // Compute the propagator for given source color/spin
347  SystemSolverResults_t res = (*qprop)(psi, q_source);
348  ncg_had += res.n_count;
349 
350  push(xml_out,"Inverter_performance");
351  write(xml_out, "color", color_source);
352  write(xml_out, "iterations", res.n_count);
353  pop(xml_out);
354 
355  /*
356  * Move the solution to the appropriate components
357  * of quark propagator.
358  */
359  FermToProp(psi, quark_propagator, color_source);
360  } //color_source
361 
362  int t_eff;
363 
364  push(xml_out, "Hadrons_from_time_source");
365  write(xml_out, "source_time", t_source);
366 
367  staggered_local_pion pion(t_length,u) ;
368  pion.compute(quark_propagator,quark_propagator,j_decay) ;
369  pion.dump(t_source,xml_out) ;
370 
371  pop(xml_out);
372 
373  } //t_source;
374  pop(xml_out);
375 
376  pop(xml_out);
377  xml_out.close();
378  xml_in.close();
379 
380 
381  // Time to bolt
383 
384  exit(0);
385 }
Primary include file for CHROMA in application codes.
Class for counted reference semantics.
Definition: handle.h:33
static T & Instance()
Definition: singleton.h:432
Staggered-like fermion actions.
Definition: fermact.orig.h:644
void dump(int t_source, XMLWriter &xml_out)
Definition: hadron_corr_s.h:33
void compute(LatticeStaggeredPropagator &quark_prop_A, LatticeStaggeredPropagator &quark_prop_B, int j_decay)
Definition: pion_local_s.cc:56
Real u0
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.
CfgType
Configuration type.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
void srcfil(LatticeFermion &a, const multi1d< int > &coord, int color_index, int spin_index)
Fill a specific color and spin index with 1.0.
Definition: srcfil.cc:23
std::map< std::string, SinkPropContainer_t > prop
multi1d< int > t_srce
multi1d< int > coord(Nd)
int j_decay
Definition: meslate.cc:22
Nd
Definition: meslate.cc:74
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
multi1d< LatticeColorMatrix > P
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
int n_count
Definition: invbicg.cc:78
LinOpSysSolverMGProtoClover::Q Q
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > & Mass
Definition: pbg5p_w.cc:29
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
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
bool linkageHack(void)
Definition: const_hmc.cc:660
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
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
Hold group xml and type id.
Params for CG inverter.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Parameters for running program.
Definition: qpropadd.cc:17
Real OrPara
SysSolverCGParams invParam
multi1d< int > t_srce
multi1d< int > nrow
Definition: qpropadd.cc:18
Real GFAccu
GroupXML_t fermact
Propagators.
int main(int argc, char **argv)
Read an XML group as a std::string.