TBTK
Need a break? Support the development by playing Polarity Puzzles
Diagonalizer.h
Go to the documentation of this file.
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 
82  SelfConsistencyCallback &selfConsistencyCallback
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 
164  SelfConsistencyCallback *selfConsistencyCallback;
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 
186  SelfConsistencyCallback &selfConsistencyCallback
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
TBTK::Model
Container of Model related information.
Definition: Model.h:57
Model.h
Container of Model related information.
TBTK::Solver::Diagonalizer
Solves a Model using diagonalization.
Definition: Diagonalizer.h:52
TBTK::Model::getBasisSize
int getBasisSize() const
Definition: Model.h:311
TBTK::CArray< double >
TBTK::Solver::Diagonalizer::SelfConsistencyCallback
Definition: Diagonalizer.h:55
TBTK::Model::getBasisIndex
int getBasisIndex(const Index &index) const
Definition: Model.h:331
TBTK::Solver::Diagonalizer::getAmplitude
const std::complex< double > getAmplitude(int state, const Index &index)
Definition: Diagonalizer.h:211
Solver.h
Base class for Solvers.
TBTK::Solver::Diagonalizer::run
void run()
TBTK::Solver::Diagonalizer::getEigenValue
const double getEigenValue(int state)
Definition: Diagonalizer.h:219
TBTK::Solver::Diagonalizer::getEigenVectors
const CArray< std::complex< double > > & getEigenVectors()
Definition: Diagonalizer.h:203
TBTK::Solver::Diagonalizer::getEigenValuesRW
CArray< double > & getEigenValuesRW()
Definition: Diagonalizer.h:199
TBTK::Solver::Diagonalizer::Diagonalizer
Diagonalizer()
TBTK::Solver::Diagonalizer::SelfConsistencyCallback::selfConsistencyCallback
virtual bool selfConsistencyCallback(Diagonalizer &diagonalizer)=0
TBTK::Solver::Diagonalizer::getEigenVectorsRW
CArray< std::complex< double > > & getEigenVectorsRW()
Definition: Diagonalizer.h:207
TBTK::Communicator
Base class for classes that can communicate their status during execution.
Definition: Communicator.h:56
Communicator.h
Base class for classes that can communicate their status during execution.
TBTK::Solver::Solver::getModel
Model & getModel()
Definition: Solver.h:73
TBTK::Solver::Diagonalizer::getEigenValues
const CArray< double > & getEigenValues()
Definition: Diagonalizer.h:195
TBTK::Solver::Solver
Base class for Solvers.
Definition: Solver.h:42
TBTK::Solver::Diagonalizer::setMaxIterations
void setMaxIterations(int maxIterations)
Definition: Diagonalizer.h:191
CArray.h
Container for a C style array.
TBTK::Index
Physical index.
Definition: Index.h:44
TBTK::Solver::Diagonalizer::setSelfConsistencyCallback
void setSelfConsistencyCallback(SelfConsistencyCallback &selfConsistencyCallback)
Definition: Diagonalizer.h:185