TBTK
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/Communicator.h"
27 #include "TBTK/Model.h"
28 #include "TBTK/Solver/Solver.h"
29 
30 #include <complex>
31 
32 namespace TBTK{
33 namespace Solver{
34 
42 class Diagonalizer : public Solver, public Communicator{
43 public:
45  Diagonalizer();
46 
48  virtual ~Diagonalizer();
49 
60  bool (*selfConsistencyCallback)(
61  Diagonalizer &diagonalizer
62  )
63  );
64 
73  void setMaxIterations(int maxIterations);
74 
78  void run();
79 
83  const double* getEigenValues();
84 
89  double* getEigenValuesRW();
90 
98  const std::complex<double>* getEigenVectors();
99 
108  std::complex<double>* getEigenVectorsRW();
109 
115  const double getEigenValue(int state);
116 
124  const std::complex<double> getAmplitude(int state, const Index &index);
125 private:
127  std::complex<double> *hamiltonian;
128 
130  double *eigenValues;
131 
133  std::complex<double> *eigenVectors;
134 
136  int maxIterations;
137 
140  bool (*selfConsistencyCallback)(
141  Diagonalizer &diagonalizer
142  );
143 
145  void init();
146 
148  void update();
149 
151  void solve();
152 };
153 
155  bool (*selfConsistencyCallback)(
156  Diagonalizer &diagonalizer
157  )
158 ){
159  this->selfConsistencyCallback = selfConsistencyCallback;
160 }
161 
162 inline void Diagonalizer::setMaxIterations(int maxIterations){
163  this->maxIterations = maxIterations;
164 }
165 
166 inline const double* Diagonalizer::getEigenValues(){
167  return eigenValues;
168 }
169 
171  return eigenValues;
172 }
173 
174 inline const std::complex<double>* Diagonalizer::getEigenVectors(){
175  return eigenVectors;
176 }
177 
178 inline std::complex<double>* Diagonalizer::getEigenVectorsRW(){
179  return eigenVectors;
180 }
181 
182 inline const std::complex<double> Diagonalizer::getAmplitude(
183  int state,
184  const Index &index
185 ){
186  const Model &model = getModel();
187  return eigenVectors[model.getBasisSize()*state + model.getBasisIndex(index)];
188 }
189 
190 inline const double Diagonalizer::getEigenValue(int state){
191  return eigenValues[state];
192 }
193 
194 }; //End of namespace Solver
195 }; //End of namespace TBTK
196 
197 #endif
Base class for Solvers.
Definition: Solver.h:32
Model & getModel()
Definition: Solver.h:63
void setMaxIterations(int maxIterations)
Definition: Diagonalizer.h:162
double * getEigenValuesRW()
Definition: Diagonalizer.h:170
Container of Model related information.
const std::complex< double > * getEigenVectors()
Definition: Diagonalizer.h:174
const double getEigenValue(int state)
Definition: Diagonalizer.h:190
int getBasisIndex(const Index &index) const
Definition: Model.h:296
Solves a Model using diagonalization.
Definition: Diagonalizer.h:42
int getBasisSize() const
Definition: Model.h:292
const std::complex< double > getAmplitude(int state, const Index &index)
Definition: Diagonalizer.h:182
void setSelfConsistencyCallback(bool(*selfConsistencyCallback)(Diagonalizer &diagonalizer))
Definition: Diagonalizer.h:154
std::complex< double > * getEigenVectorsRW()
Definition: Diagonalizer.h:178
Base class for Solvers.
Flexible physical index.
Definition: Index.h:69
Definition: ModelFactory.h:35
Base class that communicate their current status during execution.
Definition: Communicator.h:28
Container of Model related information.
Definition: Model.h:52
const double * getEigenValues()
Definition: Diagonalizer.h:166