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 
53  bool (*selfConsistencyCallback)(
54  Diagonalizer &diagonalizer
55  )
56  );
57 
59  void setMaxIterations(int maxIterations);
60 
64  void run();
65 
67  const double* getEigenValues();
68 
71  double* getEigenValuesRW();
72 
74  const std::complex<double>* getEigenVectors();
75 
78  std::complex<double>* getEigenVectorsRW();
79 
81  const double getEigenValue(int state);
82 
88  const std::complex<double> getAmplitude(int state, const Index &index);
89 private:
91  std::complex<double> *hamiltonian;
92 
94  double *eigenValues;
95 
97  std::complex<double> *eigenVectors;
98 
100  int maxIterations;
101 
104  bool (*selfConsistencyCallback)(
105  Diagonalizer &diagonalizer
106  );
107 
109  void init();
110 
112  void update();
113 
115  void solve();
116 };
117 
119  bool (*selfConsistencyCallback)(
120  Diagonalizer &diagonalizer
121  )
122 ){
123  this->selfConsistencyCallback = selfConsistencyCallback;
124 }
125 
126 inline void Diagonalizer::setMaxIterations(int maxIterations){
127  this->maxIterations = maxIterations;
128 }
129 
130 inline const double* Diagonalizer::getEigenValues(){
131  return eigenValues;
132 }
133 
135  return eigenValues;
136 }
137 
138 inline const std::complex<double>* Diagonalizer::getEigenVectors(){
139  return eigenVectors;
140 }
141 
142 inline std::complex<double>* Diagonalizer::getEigenVectorsRW(){
143  return eigenVectors;
144 }
145 
146 inline const std::complex<double> Diagonalizer::getAmplitude(
147  int state,
148  const Index &index
149 ){
150  const Model &model = getModel();
151  return eigenVectors[model.getBasisSize()*state + model.getBasisIndex(index)];
152 }
153 
154 inline const double Diagonalizer::getEigenValue(int state){
155  return eigenValues[state];
156 }
157 
158 }; //End of namespace Solver
159 }; //End of namespace TBTK
160 
161 #endif
Base class for Solvers.
Definition: Solver.h:32
Model & getModel()
Definition: Solver.h:57
void setMaxIterations(int maxIterations)
Definition: Diagonalizer.h:126
double * getEigenValuesRW()
Definition: Diagonalizer.h:134
Container of Model related information.
const std::complex< double > * getEigenVectors()
Definition: Diagonalizer.h:138
const double getEigenValue(int state)
Definition: Diagonalizer.h:154
int getBasisIndex(const Index &index) const
Definition: Model.h:214
Solves a Model using diagonalization.
Definition: Diagonalizer.h:42
int getBasisSize() const
Definition: Model.h:210
const std::complex< double > getAmplitude(int state, const Index &index)
Definition: Diagonalizer.h:146
void setSelfConsistencyCallback(bool(*selfConsistencyCallback)(Diagonalizer &diagonalizer))
Definition: Diagonalizer.h:118
std::complex< double > * getEigenVectorsRW()
Definition: Diagonalizer.h:142
Base class for Solvers.
Flexible physical index.
Definition: Index.h:70
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:130