CHROMA
overlap_state.cc
Go to the documentation of this file.
1 /*! @file
2  * @brief Connection state holding eigenvectors
3  *
4  * Holds gauge fields and eigenvectors for overlap-ish thingies
5  */
6 
7 #include "chromabase.h"
10 
11 
12 namespace Chroma
13 {
14 
15  // Save some typing
16  typedef FermBC<LatticeFermion, multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> > FBC;
17 
18  //! Constructor with no eigenvalues
20  const multi1d<LatticeColorMatrix>& u_, // gauge field
21  const WordBase_t& approxMin_, // epsilon
22  const WordBase_t& approxMax_) // approx max
23  {
24  init(fbc_, u_, approxMin_, approxMax_);
25  }
26 
27  //! Constructor with e-values and e-vectors
29  const multi1d<LatticeColorMatrix>& u_,
30  const multi1d<WordBase_t>& val_,
31  const multi1d<LatticeFermion>& vec_,
32  const WordBase_t& val_max_,
33  const WordBase_t& approxMin_,
34  const WordBase_t& approxMax_)
35  {
36  init(fbc_, u_, val_, vec_, val_max_, approxMin_, approxMax_);
37  }
38 
39 
40  //! Constructor with no eigenvalues
42  const multi1d<LatticeColorMatrix>& u_, // gauge field
43  const WordBase_t& approxMin_, // epsilon
44  const WordBase_t& approxMax_) // approx max
45  {
46  std::ostringstream error_str;
47 
48  if ( toBool(approxMin_ < 0 )) {
49  error_str << "OverlapConnectState::createState: approxMin_ has to be positive" << std::endl;
50  throw error_str.str();
51  }
52 
53  if ( toBool(approxMax_ < approxMin_) ) {
54  error_str << "OverlapConnectState::createState: approxMax_ has to be larger than approxMin_" << std::endl;
55  throw error_str.str();
56  }
57 
58  // hhmm, for now make a copy
59  fbc = fbc_;
60  u = u_;
61  fbc->modify(u); // apply BC
62 
63  eigVal.resize(0);
64  eigVec.resize(0);
65  eigValMax = 0;
66  approxMin = approxMin_;
67  approxMax = approxMax_;
68  }
69 
70  //! Constructor with e-values and e-vectors
72  const multi1d<LatticeColorMatrix>& u_,
73  const multi1d<WordBase_t>& val_,
74  const multi1d<LatticeFermion>& vec_,
75  const WordBase_t& val_max_,
76  const WordBase_t& approxMin_,
77  const WordBase_t& approxMax_)
78  {
79  std::ostringstream error_str;
80 
81  if ( val_.size() == 0 ) {
82  error_str << "Attempt to createState with 0 e-values and no approxMin" << std::endl;
83  throw error_str.str();
84  }
85 
86  if ( val_.size() != vec_.size() ) {
87  error_str << "Attempt to createState with no of low eigenvalues != no of low eigenvectors" << std::endl;
88  throw error_str.str();
89  }
90 
91  // hhmm, for now make a copy
92  fbc = fbc_;
93  u = u_;
94  fbc->modify(u); // apply BC
95 
96  eigVal = val_;
97  eigVec = vec_;
98  eigValMax = val_max_;
99  approxMin = approxMin_;
100  approxMax = approxMax_;
101  }
102 
103 
104  //! Create a ConnectState with just the gauge fields
105  /*! Assumes that approximation bounds are those of the free field
106  WilsonOp - ie. ApproxMin=0, ApproxMax=2Nd
107  */
109  const multi1d<LatticeColorMatrix>& u_)
110  {
111  Real approxMin_ = 0.0;
112  Real approxMax_ = Real(2)*Real(Nd);
113  init(fbc_, u_, approxMin_, approxMax_);
114  }
115 
116  //! Create a ConnectState with just the gauge fields, and a lower
117  // approximation bound
118  /*! Assumes that maximum approximation bounds are those of the free field
119  WilsonOp - ie. ApproxMax=2Nd
120  */
122  const multi1d<LatticeColorMatrix>& u_,
123  const Real& approxMin_)
124  {
125  // Set Approx Max
126  Real approxMax_ = Real(2)*Real(Nd);
127  init(fbc_, u_, approxMin_, approxMax_);
128  }
129 
130 
131  //! Create OverlapConnectState with eigenvalues/vectors
133  const multi1d<LatticeColorMatrix>& u_,
134  const multi1d<Real>& lambda_lo_,
135  const multi1d<LatticeFermion>& evecs_lo_,
136  const Real& lambda_hi_)
137  {
138  Real approxMax_ = lambda_hi_;
139  Real approxMin_ = fabs(lambda_lo_[ lambda_lo_.size() - 1 ]);
140 
141  init(fbc, u_, lambda_lo_, evecs_lo_, lambda_hi_, approxMin_, approxMax_);
142  }
143 
144 
145 
146 #if 1
147  //! Create a ConnectState out of XML
148  /*! Needs the auxiliary fermion action linear operator
149  passed just in case it needs to check eigenvalues/vectors.
150  The caller should be a fermact so it should be able to
151  generate the linop easy enough */
153  const multi1d<LatticeColorMatrix> u_,
154  XMLReader& state_info_xml,
155  const std::string& state_info_path,
157  {
158  OverlapStateInfo tmp_info;
159  read(state_info_xml, state_info_path, tmp_info);
160  init(fbc_, u_, tmp_info, H);
161  }
162 #endif
163 
164 
165  //! Create from OverlapStateInfo Structure
166  /*! Needs the auxiliary fermion action linear operator
167  passed just in case it needs to check eigenvalues/vectors.
168  The caller should be a fermact so it should be able to
169  generate the linop easy enough */
171  const multi1d<LatticeColorMatrix>& u_,
172  const OverlapStateInfo& state_info,
174  {
175  init(fbc_, u_, state_info, H);
176  }
177 
178 
179  //! Create from OverlapStateInfo Structure
180  /*! Needs the auxiliary fermion action linear operator
181  passed just in case it needs to check eigenvalues/vectors.
182  The caller should be a fermact so it should be able to
183  generate the linop easy enough */
185  const multi1d<LatticeColorMatrix>& u_,
186  const OverlapStateInfo& state_info,
188  {
189  // If No eigen values specified use min and max
190  if ( state_info.getNWilsVec() == 0 )
191  {
192  init(fbc_, u_, state_info.getApproxMin(), state_info.getApproxMax());
193  }
194  else
195  {
196  // If there are eigen values, either load them,
197  if( state_info.loadEigVec() ) {
198  ChromaWilsonRitz_t ritz_header;
199  multi1d<Real> lambda_lo;
200  multi1d<LatticeFermion> eigv_lo;
201  Real lambda_hi;
202  const EigenIO_t& eigen_io = state_info.getEigenIO();
203 
204  if( eigen_io.eigen_filefmt == EVEC_TYPE_SCIDAC ) {
205  readEigen(ritz_header, lambda_lo, eigv_lo, lambda_hi,
206  eigen_io.eigen_file,
207  state_info.getNWilsVec(),
208  QDPIO_SERIAL);
209  }
210  else {
211  QDPIO::cerr << "Unsupported Eigenstd::vector format for reading " << std::endl;
212  QDP_abort(1);
213  }
214 
215  QDPIO::cout << "createOverlapState: " << std::endl;
216  for(int i=0; i < lambda_lo.size(); i++) {
217  QDPIO::cout << "lambda_lo["<<i<<"]= " << lambda_lo[i] << std::endl;
218  }
219 
220  QDPIO::cout << "|lambda_high|= " << lambda_hi << std::endl;
221 
222  // Test the e-values
223  // BEASTLY HACKERY!!!!
224  // In order to test the evecs I need to create a ConnectState
225  // for the fermions. I am assuming here, that the AuxiliaryFermAct
226  // needs only a SimpleFermState and I manufacture it by
227  // hand after applying the BC's of the calling Operator.
228  // This goes hand in hand with the problem of turning
229  // a potentially 5D FermBC into a 4D one. If I could do that
230  // then I wouldn't need to hack trivial
231  //
232  // RGE: maybe this problem is solved. There is really no difference in 4D and 5D
233  // fermbcs anymore. Anyway, the fbc is passed into the SimpleFermState now.
234 
235  Handle< FermState<T,P,Q> > wils_connect_state(new SimpleFermState<T,P,Q>(fbc_, u_));
236 
237  multi1d<Double> check_norm(state_info.getNWilsVec());
238  multi1d<Double> check_norm_rel(state_info.getNWilsVec());
239  for(int i=0; i < state_info.getNWilsVec() ; i++)
240  {
241  LatticeFermion Me;
242  H(Me, eigv_lo[i], PLUS);
243 
244  LatticeFermion lambda_e;
245 
246  lambda_e = lambda_lo[i]*eigv_lo[i];
247  LatticeFermion r_norm = Me - lambda_e;
248  check_norm[i] = sqrt(norm2(r_norm));
249  check_norm_rel[i] = check_norm[i]/fabs(Double(lambda_lo[i]));
250 
251  QDPIO::cout << "Eigenpair " << i << " Resid Norm = "
252  << check_norm[i] << " Resid Rel Norm = " << check_norm_rel[i] << std::endl;
253  }
254 
255  Real approxMax_ = lambda_hi;
256  Real approxMin_ = fabs(lambda_lo[ lambda_lo.size() - 1 ]);
257 
258  init(fbc_, u_, lambda_lo, eigv_lo, lambda_hi, approxMin_, approxMax_);
259  }
260  else if( state_info.computeEigVec() )
261  {
262  QDPIO::cerr << "Recomputation of eigensystem not yet implemented" << std::endl;
263  QDP_abort(1);
264  }
265  else
266  {
267  QDPIO::cerr << "I have to create a state without min/max, loading/computing eigenvectors/values. How do I do that? "<< std::endl;
268  QDP_abort(1);
269  }
270  }
271  }
272 
273 
274 } // namespace Chroma
275 
Primary include file for CHROMA library code.
Base class for all fermion action boundary conditions.
Definition: fermbc.h:20
Class for counted reference semantics.
Definition: handle.h:33
multi1d< WordBase_t > eigVal
multi1d< LatticeFermion > eigVec
Handle< FermBC< T, P, Q > > fbc
void init(Handle< FermBC< T, P, Q > > fbc_, const multi1d< LatticeColorMatrix > &u_, const WordBase_t &approxMin_, const WordBase_t &approxMax_)
for now inherit the deriv operation
multi1d< LatticeColorMatrix > u
const EigenIO_t & getEigenIO(void) const
const Real & getApproxMax(void) const
bool computeEigVec(void) const
const Real & getApproxMin(void) const
Simple version of FermState.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void readEigen(ChromaWilsonRitz_t &header, multi1d< Real > &lambda_lo, multi1d< LatticeFermion > &eigv_lo, Real &lambda_hi, const std::string &filename_stem, int Neig, QDP_serialparallel_t serpar)
Definition: eigen_io.cc:276
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
int i
Definition: pbg5p_w.cc:55
@ PLUS
Definition: chromabase.h:45
FermBC< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > FBC
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Connection state holding eigenvectors.
Double r_norm
Definition: pade_trln_w.cc:86
Simple ferm state and a creator.
Struct for the overall application.
Definition: eigen_io.h:50
Struct for dumping the eigenvalues/vectors.
Definition: eigen_io.h:40
EigenVecType eigen_filefmt
Definition: eigen_io.h:41
std::string eigen_file
Definition: eigen_io.h:42