TBTK
Need a break? Support the development by playing Polarity Puzzles
Diagonalizer.h
1 /* Copyright 2016 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_SOLVER_DIAGONALIZATION
24 #define COM_DAFER45_TBTK_SOLVER_DIAGONALIZATION
25 
26 #include "TBTK/CArray.h"
27 #include "TBTK/Communicator.h"
28 #include "TBTK/Model.h"
29 #include "TBTK/Solver/Solver.h"
30 
31 #include <complex>
32 
33 namespace TBTK{
34 namespace Solver{
35 
52 class Diagonalizer : public Solver, public Communicator{
53 public:
56  public:
66  virtual bool selfConsistencyCallback(Diagonalizer &diagonalizer) = 0;
67  };
68 
70  Diagonalizer();
71 
83  );
84 
93  void setMaxIterations(int maxIterations);
94 
98  void run();
99 
104 
110 
119 
129 
135  const double getEigenValue(int state);
136 
144  const std::complex<double> getAmplitude(int state, const Index &index);
145 private:
147  CArray<std::complex<double>> hamiltonian;
148 
150  CArray<double> eigenValues;
151 
153  CArray<std::complex<double>> eigenVectors;
154 
157  CArray<std::complex<double>> basisTransformation;
158 
160  int maxIterations;
161 
165 
167  void init();
168 
170  void update();
171 
173  void solve();
174 
176  void setupBasisTransformation();
177 
179  void transformToOrthonormalBasis();
180 
182  void transformToOriginalBasis();
183 };
184 
187 ){
188  this->selfConsistencyCallback = &selfConsistencyCallback;
189 }
190 
191 inline void Diagonalizer::setMaxIterations(int maxIterations){
192  this->maxIterations = maxIterations;
193 }
194 
196  return eigenValues;
197 }
198 
200  return eigenValues;
201 }
202 
204  return eigenVectors;
205 }
206 
208  return eigenVectors;
209 }
210 
211 inline const std::complex<double> Diagonalizer::getAmplitude(
212  int state,
213  const Index &index
214 ){
215  const Model &model = getModel();
216  return eigenVectors[model.getBasisSize()*state + model.getBasisIndex(index)];
217 }
218 
219 inline const double Diagonalizer::getEigenValue(int state){
220  return eigenValues[state];
221 }
222 
223 }; //End of namespace Solver
224 }; //End of namespace TBTK
225 
226 #endif
Base class for Solvers.
Definition: Solver.h:42
Model & getModel()
Definition: Solver.h:73
void setMaxIterations(int maxIterations)
Definition: Diagonalizer.h:191
int getBasisIndex(const Index &index) const
Definition: Model.h:331
virtual bool selfConsistencyCallback(Diagonalizer &diagonalizer)=0
Container of Model related information.
Container for a C style array.
const double getEigenValue(int state)
Definition: Diagonalizer.h:219
Solves a Model using diagonalization.
Definition: Diagonalizer.h:52
const std::complex< double > getAmplitude(int state, const Index &index)
Definition: Diagonalizer.h:211
Base class for Solvers.
Physical index.
Definition: Index.h:44
CArray< std::complex< double > > & getEigenVectorsRW()
Definition: Diagonalizer.h:207
const CArray< double > & getEigenValues()
Definition: Diagonalizer.h:195
Definition: Boolean.h:32
Base class for classes that can communicate their status during execution.
void setSelfConsistencyCallback(SelfConsistencyCallback &selfConsistencyCallback)
Definition: Diagonalizer.h:185
CArray< double > & getEigenValuesRW()
Definition: Diagonalizer.h:199
int getBasisSize() const
Definition: Model.h:311
const CArray< std::complex< double > > & getEigenVectors()
Definition: Diagonalizer.h:203
Base class for classes that can communicate their status during execution.
Definition: Communicator.h:56
Container of Model related information.
Definition: Model.h:57