CHROMA
t_propagator_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Main code for propagator generation
3  *
4  * This version is for Wilson fermions.
5  * This code should work for su3 or su4.
6  *
7  *
8  *
9  */
10 
11 #include <iostream>
12 #include <cstdio>
13 
14 #define MAIN
15 
16 // Include everything...
17 #include "chroma.h"
18 
19 
20 using namespace Chroma;
21 
22 
23 /*
24  * Input
25  */
26 
27 
28 // Parameters which must be determined from the XML input
29 // and written to the XML output
30 struct Param_t
31 {
33  Real Mass; // Staggered mass
34  Real u0; // Tadpole Factor
35 
36  // GaugeStartType cfg_type; // storage order for stored gauge configuration
37  PropType prop_type; // storage order for stored propagator
38 
39  SysSolverCGParams invParam;
40 
41  Real GFAccu, OrPara; // Gauge fixing tolerance and over-relaxation param
42  int GFMax; // Maximum gauge fixing iterations
43 
44  multi1d<int> nrow;
45  multi1d<int> boundary;
46  multi1d<int> t_srce;
47 };
48 
49 
50 struct Prop_t
51 {
52  std::string source_file;
53  std::string prop_file;
54 };
55 
56 struct Propagator_input_t
57 {
58  IO_version_t io_version;
59  Param_t param;
60  Cfg_t cfg;
61  Prop_t prop;
62 };
63 
64 
65 //
66 void read(XMLReader& xml, const std::string& path, Prop_t& input)
67 {
68  XMLReader inputtop(xml, path);
69 
70 // read(inputtop, "source_file", input.source_file);
71  read(inputtop, "prop_file", input.prop_file);
72 }
73 
74 
75 
76 // Reader for input parameters
77 // first called
78 //
79 
80 void read(XMLReader& xml, const std::string& path, Propagator_input_t& input)
81 {
82  XMLReader inputtop(xml, path);
83 
84 
85  // First, read the input parameter version. Then, if this version
86  // includes 'Nc' and 'Nd', verify they agree with values compiled
87  // into QDP++
88 
89  // Read in the IO_version
90  try
91  {
92  read(inputtop, "IO_version/version", input.io_version.version);
93  }
94  catch (const std::string& e)
95  {
96  QDPIO::cerr << "Error reading data: " << e << std::endl;
97  throw;
98  }
99 
100 
101  // Currently, in the supported IO versions, there is only a small difference
102  // in the inputs. So, to make code simpler, extract the common bits
103 
104  // Read the uncommon bits first
105  try
106  {
107  XMLReader paramtop(inputtop, "param"); // push into 'param' group
108 
109  switch (input.io_version.version)
110  {
111  /**************************************************************************/
112  case 1 :
113  /**************************************************************************/
114  break;
115 
116  default :
117  /**************************************************************************/
118 
119  QDPIO::cerr << "Input parameter version " << input.io_version.version << " unsupported." << std::endl;
120  QDP_abort(1);
121  }
122  }
123  catch (const std::string& e)
124  {
125  QDPIO::cerr << "Error reading data: " << e << std::endl;
126  throw;
127  }
128 
129 
130  // Read the common bits
131  try
132  {
133  XMLReader paramtop(inputtop, "param"); // push into 'param' group
134 
135  {
136  std::string ferm_type_str;
137  read(paramtop, "FermTypeP", ferm_type_str);
138  if (ferm_type_str == "WILSON") {
140  }
141  }
142 
143  // GTF NOTE: I'm going to switch on FermTypeP here because I want
144  // to leave open the option of treating masses differently.
145  switch (input.param.FermTypeP) {
146  case FERM_TYPE_WILSON :
147 
148  QDPIO::cout << " PROPAGATOR: Propagator for Wilson fermions" << std::endl;
149 
150  // read(paramtop, "Mass", input.param.Mass);
151  read(paramtop, "u0" , input.param.u0);
152  // Read the stuff for the action
153  if (paramtop.count("Mass") != 0)
154  {
155  read(paramtop, "Mass", input.param.Mass);
156  if (paramtop.count("Kappa") != 0)
157  {
158  QDPIO::cerr << "Error: found both a Kappa and a Mass tag" << std::endl;
159  QDP_abort(1);
160  }
161  }
162  else if (paramtop.count("Kappa") != 0)
163  {
164  Real Kappa;
165  read(paramtop, "Kappa", Kappa);
166  input.param.Mass = kappaToMass(Kappa); // Convert Kappa to Mass
167  }
168  else
169  {
170  QDPIO::cerr << "Error: neither Mass or Kappa found" << std::endl;
171  QDP_abort(1);
172  }
173 
174 
175 
176 
177  break;
178 
179  default :
180  QDP_error_exit("Fermion type not supported\n.");
181  }
182 
183 
184 
185 // read(paramtop, "invType", input.param.invType);
186  read(paramtop, "RsdCG", input.param.invParam.RsdCG);
187  read(paramtop, "MaxCG", input.param.invParam.MaxCG);
188  // read(paramtop, "GFAccu", input.param.GFAccu);
189  // read(paramtop, "OrPara", input.param.OrPara);
190  // read(paramtop, "GFMax", input.param.GFMax);
191 
192  read(paramtop, "nrow", input.param.nrow);
193  read(paramtop, "boundary", input.param.boundary);
194  read(paramtop, "t_srce", input.param.t_srce);
195 
196  }
197  catch (const std::string& e)
198  {
199  QDPIO::cerr << "Error reading data: " << e << std::endl;
200  throw;
201  }
202 
203  //
204  // outside <param> </param>
205  //
206 
207 
208  // Read in the gauge configuration file name
209  try
210  {
211  read(inputtop, "Cfg", input.cfg);
212  read(inputtop, "Prop", input.prop);
213  }
214  catch (const std::string& e)
215  {
216  QDPIO::cerr << "Error reading data: " << e << std::endl;
217  throw;
218  }
219 }
220 
221 //! Propagator generation
222 /*! \defgroup t_propagator_w Propagator generation
223  * \ingroup testsmain
224  *
225  * Main program for propagator generation.
226  */
227 
228 int main(int argc, char **argv)
229 {
230  // Put the machine into a known state
231  Chroma::initialize(&argc, &argv);
232 
233  // Input parameter structure
234  Propagator_input_t input;
235 
236  // Instantiate xml reader for DATA
237  XMLReader xml_in ;
239  try
240  {
241  xml_in.open(in_name);
242  }
243  catch (...)
244  {
245  QDPIO::cerr << "Error reading input file " << in_name << std::endl;
246  QDPIO::cerr << "The input file name can be passed via the -i flag " << std::endl;
247  QDPIO::cerr << "The default name is ./DATA" << std::endl;
248  throw;
249  }
250 
251 
252 
253  // Read data
254  read(xml_in, "/propagator", input);
255 
256  // Specify lattice size, shape, etc.
257  Layout::setLattSize(input.param.nrow);
258  Layout::create();
259 
260  // Read in the configuration along with relevant information.
261  multi1d<LatticeColorMatrix> u(Nd);
262  QDPIO::cout << "Calculation for SU(" << Nc << ")" << std::endl;
263 
264 
265  XMLReader gauge_file_xml, gauge_xml;
266  // Start up the gauge field
267  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
268 
269 
270  // Check if the gauge field configuration is unitarized
271  unitarityCheck(u);
272 
273  // Instantiate XML writer for XMLDAT
274  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
275  push(xml_out, "propagator");
276 
277  // Write out the input
278  write(xml_out, "Input", xml_in);
279 
280  // Write out the source header
281  // write(xml_out, "Source_info", source_xml);
282 
283  push(xml_out, "Output_version");
284  write(xml_out, "out_version", 1);
285  pop(xml_out);
286 
287  xml_out.flush();
288 
289 
290  // Calculate some gauge invariant observables just for info.
291  MesPlq(xml_out, "Observables", u);
292  xml_out.flush();
293 
294  //
295  // gauge invariance test
296  //
297 
298  // this parameter will be read from the input file
299  bool do_gauge_transform ;
300  do_gauge_transform = false ;
301  // do_gauge_transform = true ;
302 
303 
304  if( do_gauge_transform )
305  {
306  // gauge transform the gauge fields
307  multi1d<LatticeColorMatrix> u_trans(Nd);
308 
309  // create a random gauge transform
310  LatticeColorMatrix v ;
311 
312  gaussian(v);
313  reunit(v) ;
314 
315  for(int dir = 0 ; dir < Nd ; ++dir)
316  {
317  u_trans[dir] = v*u[dir]*adj(shift(v,FORWARD,dir)) ;
318  u[dir] = u_trans[dir] ;
319  }
320 
321  QDPIO::cout << "Random gauge transform done" << std::endl;
322 
323  } // end of gauge transform
324 
325 
326  int j_decay = Nd-1;
327 
328 
329  // set up the calculation of quark propagators
330 
331  // Create a fermion BC. Note, the handle is on an ABSTRACT type.
333 
334  //
335  // Initialize fermion action
336  //
337  UnprecWilsonFermAct S_f(fbc,input.param.Mass);
338 
339  GroupXML_t inv_param;
340  {
341  XMLBufferWriter xml_buf;
342  write(xml_buf, "InvertParam", input.param.invParam);
343  XMLReader xml_in(xml_buf);
344  inv_param = readXMLGroup(xml_in, "/InvertParam", "invType");
345  }
346 
347  // Set up a state for the current u,
348  Handle<const ConnectState > state(S_f.createState(u));
349  Handle<const SystemSolver<LatticeFermion> > qprop(S_f.qprop(state,inv_param));
350 
351 
352  //
353  // Loop over the source color and spin , creating the source
354  // and calling the relevant propagator routines.
355  //
356  //
357  LatticePropagator quark_propagator;
358  XMLBufferWriter xml_buf;
359  int ncg_had = 0;
360 
361  LatticeFermion q_source, psi;
362 
363  int t_source = 0;
364 
365  QDPIO::cout << "Source time slice = " << t_source << std::endl;
366 
367  for(int color_source = 0; color_source < Nc; ++color_source)
368  for(int spin_source = 0 ; spin_source < Ns ; ++spin_source)
369  {
370  QDPIO::cout << "Inversion for Color = " << color_source << std::endl;
371  QDPIO::cout << "Inversion for Spin = " << spin_source << std::endl;
372 
373 
374  q_source = zero ;
375  multi1d<int> coord(Nd);
376  coord[0]=0; coord[1] = 0; coord[2] = 0; coord[3] = 0;
377  srcfil(q_source, coord, color_source, spin_source);
378 
379  // initial guess is zero
380  psi = zero; // note this is ``zero'' and not 0
381 
382 
383  // Compute the propagator for given source color/spin
384  // int n_count;
385  SystemSolverResults_t res = (*qprop)(psi, q_source);
386  ncg_had += res.n_count;
387 
388  push(xml_out,"Qprop");
389  write(xml_out, "Mass" , input.param.Mass);
390  write(xml_out, "RsdCG", input.param.invParam.RsdCG);
391  write(xml_out, "n_count", res.n_count);
392  pop(xml_out);
393 
394  /*
395  * Move the solution to the appropriate components
396  * of quark propagator.
397  */
398  FermToProp(psi, quark_propagator, color_source, spin_source);
399  } //spin / color_source
400 
401  // compute the meson spectrum
402 
403  // source timeslice
404  int t0 = 0 ;
405 
406  // create averaged Fourier phases with (mom)^2 <= 10
407  SftMom phases(10, true, j_decay) ;
408 
409  mesons(quark_propagator,quark_propagator,
410  phases, t0, xml_out,
411  "Point_Point_Wilson_Mesons") ;
412 
413 
414  pop(xml_out);
415 
416  xml_out.close();
417  xml_in.close();
418 
419  // Time to bolt
421 
422  exit(0);
423 }
Primary include file for CHROMA in application codes.
Class for counted reference semantics.
Definition: handle.h:33
Fourier transform phase factor support.
Definition: sftmom.h:35
Concrete class for all gauge actions with simple boundary conditions.
Definition: simple_fermbc.h:42
Unpreconditioned Wilson fermion action.
Real u0
EXTERN int FermTypeP
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 mesons(const LatticePropagator &quark_prop_1, const LatticePropagator &quark_prop_2, const SftMom &phases, int t0, XMLWriter &xml, const std::string &xml_group)
Meson 2-pt functions.
Definition: mesons_w.cc:111
FermType
Fermion type.
PropType
Propagator type.
Real kappaToMass(const Real &Kappa)
Convert a Kappa to a mass.
Definition: param_io.cc:12
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
@ FERM_TYPE_WILSON
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
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
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)
static multi1d< LatticeColorMatrix > u
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > & Mass
Definition: pbg5p_w.cc:29
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 reunit(LatticeColorMatrixF3 &xa)
Definition: reunit.cc:467
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
#define FORWARD
Definition: primitives.h:82
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
SysSolverCGParams invParam
FermType FermTypeP
multi1d< int > t_srce
multi1d< int > nrow
Definition: qpropadd.cc:18
multi1d< int > boundary
Propagators.
std::string prop_file
IO_version_t io_version
int main(int argc, char **argv)