TBTK
MomentumSpaceContext.h
Go to the documentation of this file.
1 /* Copyright 2017 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_MOMENTUM_SPACE_CONTEXT
24 #define COM_DAFER45_TBTK_MOMENTUM_SPACE_CONTEXT
25 
26 #include "TBTK/BrillouinZone.h"
27 #include "TBTK/Solver/BlockDiagonalizer.h"
28 #include "TBTK/PropertyExtractor/BlockDiagonalizer.h"
29 
30 namespace TBTK{
31 
33 public:
36 
39 
41  void setModel(Model &model);
42 
44  const Model& getModel() const;
45 
47  void setBrillouinZone(const BrillouinZone &brillouinZone);
48 
50  const BrillouinZone& getBrillouinZone() const;
51 
53  void setNumMeshPoints(const std::vector<unsigned int> &numMeshPoints);
54 
56  const std::vector<unsigned int>& getNumMeshPoints() const;
57 
59  const std::vector<std::vector<double>>& getMesh() const;
60 
62  void setNumOrbitals(unsigned int numOrbitals);
63 
65  unsigned int getNumOrbitals() const;
66 
68  void init();
69 
71  double getEnergy(unsigned int state) const;
72 
74  double getEnergy(unsigned int block, unsigned int state) const;
75 
77  std::complex<double> getAmplitude(
78  unsigned int block,
79  unsigned int state,
80  unsigned int amplitude
81  ) const;
82 
84  Index getKIndex(const std::vector<double> &k) const;
85 
88 private:
90  Model *model;
91 
93  const BrillouinZone *brillouinZone;
94 
96  std::vector<unsigned int> numMeshPoints;
97 
99  std::vector<std::vector<double>> mesh;
100 
102  unsigned int numOrbitals;
103 
106 
108  PropertyExtractor::BlockDiagonalizer *propertyExtractor;
109 
111  double *energies;
112 
114  std::complex<double> *amplitudes;
115 
118  bool isInitialized;
119 
120 };
121 
123  this->model = &model;
124 
125  isInitialized = false;
126 }
127 
128 inline const Model& MomentumSpaceContext::getModel() const{
129  return *model;
130 }
131 
133  const BrillouinZone &brillouinZone
134 ){
135  this->brillouinZone = &brillouinZone;
136 
137  isInitialized = false;
138 }
139 
141  return *brillouinZone;
142 }
143 
145  const std::vector<unsigned int> &numMeshPoints
146 ){
147  this->numMeshPoints = numMeshPoints;
148  TBTKAssert(
149  brillouinZone != nullptr,
150  "MomentumSpaceContext::setNumMeshPoints()",
151  "BrillouinZone not set.",
152  "First set the BrillouinZone using"
153  << " MomentumSpaceContext::setBrillouinZone()"
154  );
155  mesh = brillouinZone->getMinorMesh(numMeshPoints);
156 
157  isInitialized = false;
158 }
159 
160 inline const std::vector<unsigned int>& MomentumSpaceContext::getNumMeshPoints(
161 ) const{
162  return numMeshPoints;
163 }
164 
165 inline const std::vector<std::vector<double>>& MomentumSpaceContext::getMesh(
166 ) const{
167  return mesh;
168 }
169 
170 inline void MomentumSpaceContext::setNumOrbitals(unsigned int numOrbitals){
171  this->numOrbitals = numOrbitals;
172 
173  isInitialized = false;
174 }
175 
176 inline unsigned int MomentumSpaceContext::getNumOrbitals() const{
177  return numOrbitals;
178 }
179 
180 inline double MomentumSpaceContext::getEnergy(unsigned int state) const{
181  return energies[state];
182 }
183 
185  unsigned int block,
186  unsigned int state
187 ) const{
188  return energies[block*numOrbitals + state];
189 }
190 
191 inline std::complex<double> MomentumSpaceContext::getAmplitude(
192  unsigned int block,
193  unsigned int state,
194  unsigned int amplitude
195 ) const{
196  return amplitudes[numOrbitals*(numOrbitals*block + state) + amplitude];
197 }
198 
200  const std::vector<double> &k
201 ) const{
202  return brillouinZone->getMinorCellIndex(
203  k,
204  numMeshPoints
205  );
206 }
207 
209 ) const{
210  return *propertyExtractor;
211 }
212 
213 }; //End of namespace TBTK
214 
215 #endif
std::complex< double > getAmplitude(unsigned int block, unsigned int state, unsigned int amplitude) const
Definition: MomentumSpaceContext.h:191
Index getKIndex(const std::vector< double > &k) const
Definition: MomentumSpaceContext.h:199
Definition: BlockDiagonalizer.h:46
Brillouin zone.
const Model & getModel() const
Definition: MomentumSpaceContext.h:128
virtual std::vector< std::vector< double > > getMinorMesh(const std::vector< unsigned int > &numMeshPoints) const
const std::vector< unsigned int > & getNumMeshPoints() const
Definition: MomentumSpaceContext.h:160
Definition: BrillouinZone.h:34
const PropertyExtractor::BlockDiagonalizer & getPropertyExtractorBlockDiagonalizer() const
Definition: MomentumSpaceContext.h:208
Definition: MomentumSpaceContext.h:32
void setNumOrbitals(unsigned int numOrbitals)
Definition: MomentumSpaceContext.h:170
Flexible physical index.
Definition: Index.h:69
unsigned int getNumOrbitals() const
Definition: MomentumSpaceContext.h:176
const BrillouinZone & getBrillouinZone() const
Definition: MomentumSpaceContext.h:140
Definition: ModelFactory.h:35
void setNumMeshPoints(const std::vector< unsigned int > &numMeshPoints)
Definition: MomentumSpaceContext.h:144
void setModel(Model &model)
Definition: MomentumSpaceContext.h:122
Solves a block diagonal Model using diagonalization.
Definition: BlockDiagonalizer.h:43
virtual Index getMinorCellIndex(const std::vector< double > &coordinates, const std::vector< unsigned int > &numMeshPoints) const
const std::vector< std::vector< double > > & getMesh() const
Definition: MomentumSpaceContext.h:165
Container of Model related information.
Definition: Model.h:52
double getEnergy(unsigned int state) const
Definition: MomentumSpaceContext.h:180
void setBrillouinZone(const BrillouinZone &brillouinZone)
Definition: MomentumSpaceContext.h:132