CHROMA
readwupp.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Read in a configuration written by BMW up to configuration
3  version 7 (not the compressed format).
4  */
5 
6 #include "chromabase.h"
7 
8 #include "io/readwupp.h"
9 // #include "io/param_io.h"
10 #include "qdp_util.h" // from QDP
11 #include "util/gauge/unit_check.h"
12 
13 namespace Chroma {
14 
15 
16 //! Read a WUPP configuration file
17 /*!
18  * \ingroup io
19  * Code written by Sara collins
20  * Need to first run a conversion code supplied by Kalman Szabo
21  *
22  * \param header structure holding config info ( Modify )
23  * \param u gauge configuration ( Modify )
24  * \param cfg_file path ( Read )
25  */
26 
27  void readWupp(multi1d<LatticeColorMatrix>& u, const std::string& cfg_file)
28 {
29  START_CODE();
30 
31  int NT = Layout::lattSize()[3];
32  int NZ = Layout::lattSize()[2];
33  int NY = Layout::lattSize()[1];
34  int NX = Layout::lattSize()[0];
35 
36  BinaryFileReader cfg_in(cfg_file) ;
37 
38  int nxw,nyw,nzw,ntw;
39 
40  read(cfg_in, nxw);
41  read(cfg_in, nyw);
42  read(cfg_in, nzw);
43  read(cfg_in, ntw);
44 
45  bool byterev = false;
46  if( nxw != NX ) {
47  QDPIO::cout << "nxw " << nxw <<std::endl;
48  QDPIO::cout << "readWupp: lattice dimension invalid" << std::endl;
49  QDPIO::cout << "Trying byte reversal" << std::endl;
50  QDPUtil::byte_swap((void *)&nxw, sizeof(int), 1 );
51  byterev = true;
52  }
53  QDPIO::cout << "NX: " << nxw << std::endl;
54 
55 
56  if( nxw != NX){
57  QDP_error_exit("readWupp: unexpected lattice dimension");
58  }
59 
60  if(byterev)
61  {
62  QDPIO::cout<<"Doing bytereversal on the links...\n" ;
63  QDPUtil::byte_swap((void *)&nyw, sizeof(int), 1 );
64  QDPUtil::byte_swap((void *)&nzw, sizeof(int), 1 );
65  QDPUtil::byte_swap((void *)&ntw, sizeof(int), 1 );
66  QDPIO::cout << " Ny Nz Nt " << nyw << " " << nzw << " " <<ntw <<std::endl;
67  }
68 
69  if( ntw != NT ) {
70  fprintf(stderr,"readWupp: NT mismatch %d %d\n",NT,ntw) ;
71  exit(1) ; }
72  if( nyw != NY ) {
73  fprintf(stderr,"readWupp: NY mismatch %d %d\n",NY,nyw) ;
74  exit(1) ; }
75  if( nzw != NX ) {
76  fprintf(stderr,"readWupp: NZ mismatch %d %d\n",NZ,nzw) ;
77  exit(1) ; }
78 
79 // Read in SU(3) matrices.
80 // the running of the lexicographic index and the su3_matrix layout in WUPP
81 // gauge configs is the same as in QDP
82 // (the fastest running direction is the 0th direction, corresponding to the
83 // x-direction)
84 
85  u = zero ;
86 
87  ColorMatrix uu ;
88  ColorMatrixF uuF ;
89 
90  QDPIO::cout<<"Reading the gauge fields...\n" ;
91  for(int site=0; site < Layout::vol(); ++site)
92  {
93  multi1d<int> coord = crtesn(site, Layout::lattSize()); // The coordinate
94  // read in a single site
95  for(int mu=0; mu < Nd; ++mu)
96  {
97  read(cfg_in, uuF );
98  if(byterev){
99  QDPUtil::byte_swap((void *)&uuF.elem(),sizeof(float),2*Nc*Nc);
100  }
101  uu = uuF;
102  /*
103  if(site < 10 && mu == 0){
104  QDPIO::cout << "site "<<site<<std::endl;
105  for(int ic = 0; ic < Nc; ic++){
106  for(int jc = 0; jc < Nc; jc++){
107  QDPIO::cout << "ic "<<ic<<" "<< jc<<" "<< peekColor(uuF,ic,jc)<<std::endl;
108  QDPIO::cout << "ic "<<ic<<" "<< jc<<" "<< peekColor(uu,ic,jc)<<std::endl;
109  }
110  }
111  }
112  */
113  pokeSite(u[mu],uu,coord);
114  }
115 
116  }
117 
118  cfg_in.close();
119 
120  END_CODE();
121 }
122 
123 
124 
125 //! Read a Wupp configuration file
126 /*!
127  * \ingroup io
128  *
129  *
130  * \param xml xml reader holding config info ( Modify )
131  * \param u gauge configuration ( Modify )
132  * \param cfg_file path ( Read )
133  */
134 
135 void readWupp(XMLReader& xml, multi1d<LatticeColorMatrix>& u, const std::string& cfg_file)
136 {
137  START_CODE();
138 
139  // Read the config and its binary header
140  readWupp(u, cfg_file);
141 
142 #if 0
143  // Now, set up the XML header. Do this by first making a buffer
144  // writer that is then used to make the reader
145  XMLBufferWriter xml_buf;
146  const std::string ss("wupper_config_read") ;
147  write(xml, ss );
148 
149 
150  write(xml_buf, ss );
151 
152  try
153  {
154  xml.open(xml_buf);
155  }
156  catch(const std::string& e)
157  {
158  QDPIO::cerr << __func__ << ": Error in readwupp: " << e.c_str() << std::endl;
159  QDP_abort(1);
160  }
161 
162 #endif
163 
164  END_CODE();
165 }
166 
167 } // end namespace Chroma
Primary include file for CHROMA library code.
int mu
Definition: cool.cc:24
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 readWupp(multi1d< LatticeColorMatrix > &u, const std::string &cfg_file)
Read a WUPP configuration file.
Definition: readwupp.cc:27
multi1d< int > coord(Nd)
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)
static multi1d< LatticeColorMatrix > u
START_CODE()
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
Read in a configuration written by Wupp up to configuration version 7.