TBTK
Need a break? Support the development by playing Polarity Puzzles
MomentumSpaceContext.h
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 
17 
24 #ifndef COM_DAFER45_TBTK_RPA_MOMENTUM_SPACE_CONTEXT
25 #define COM_DAFER45_TBTK_RPA_MOMENTUM_SPACE_CONTEXT
26 
27 #include "TBTK/BrillouinZone.h"
28 #include "TBTK/Solver/BlockDiagonalizer.h"
29 #include "TBTK/PropertyExtractor/BlockDiagonalizer.h"
30 
31 namespace TBTK{
32 namespace RPA{
33 
34 class MomentumSpaceContext{
35 public:
37  MomentumSpaceContext();
38 
40  ~MomentumSpaceContext();
41 
43  void setModel(Model &model);
44 
46  const Model& getModel() const;
47 
49  void setBrillouinZone(const BrillouinZone &brillouinZone);
50 
52  const BrillouinZone& getBrillouinZone() const;
53 
55  void setNumMeshPoints(const std::vector<unsigned int> &numMeshPoints);
56 
58  const std::vector<unsigned int>& getNumMeshPoints() const;
59 
61  const std::vector<std::vector<double>>& getMesh() const;
62 
64  void setNumOrbitals(unsigned int numOrbitals);
65 
67  unsigned int getNumOrbitals() const;
68 
70  void init();
71 
73  double getEnergy(unsigned int state) const;
74 
76  double getEnergy(unsigned int block, unsigned int state) const;
77 
79  std::complex<double> getAmplitude(
80  unsigned int block,
81  unsigned int state,
82  unsigned int amplitude
83  ) const;
84 
86  Index getKIndex(const std::vector<double> &k) const;
87 
89  const PropertyExtractor::BlockDiagonalizer& getPropertyExtractorBlockDiagonalizer() const;
90 private:
92  Model *model;
93 
95  const BrillouinZone *brillouinZone;
96 
98  std::vector<unsigned int> numMeshPoints;
99 
101  std::vector<std::vector<double>> mesh;
102 
104  unsigned int numOrbitals;
105 
107  Solver::BlockDiagonalizer solver;
108 
110  PropertyExtractor::BlockDiagonalizer *propertyExtractor;
111 
113  double *energies;
114 
116  std::complex<double> *amplitudes;
117 
120  bool isInitialized;
121 
122 };
123 
124 inline void MomentumSpaceContext::setModel(Model &model){
125  this->model = &model;
126 
127  isInitialized = false;
128 }
129 
130 inline const Model& MomentumSpaceContext::getModel() const{
131  return *model;
132 }
133 
134 inline void MomentumSpaceContext::setBrillouinZone(
135  const BrillouinZone &brillouinZone
136 ){
137  this->brillouinZone = &brillouinZone;
138 
139  isInitialized = false;
140 }
141 
142 inline const BrillouinZone& MomentumSpaceContext::getBrillouinZone() const{
143  return *brillouinZone;
144 }
145 
146 inline void MomentumSpaceContext::setNumMeshPoints(
147  const std::vector<unsigned int> &numMeshPoints
148 ){
149  this->numMeshPoints = numMeshPoints;
150  TBTKAssert(
151  brillouinZone != nullptr,
152  "MomentumSpaceContext::setNumMeshPoints()",
153  "BrillouinZone not set.",
154  "First set the BrillouinZone using"
155  << " MomentumSpaceContext::setBrillouinZone()"
156  );
157  mesh = brillouinZone->getMinorMesh(numMeshPoints);
158 
159  isInitialized = false;
160 }
161 
162 inline const std::vector<unsigned int>& MomentumSpaceContext::getNumMeshPoints(
163 ) const{
164  return numMeshPoints;
165 }
166 
167 inline const std::vector<std::vector<double>>& MomentumSpaceContext::getMesh(
168 ) const{
169  return mesh;
170 }
171 
172 inline void MomentumSpaceContext::setNumOrbitals(unsigned int numOrbitals){
173  this->numOrbitals = numOrbitals;
174 
175  isInitialized = false;
176 }
177 
178 inline unsigned int MomentumSpaceContext::getNumOrbitals() const{
179  return numOrbitals;
180 }
181 
182 inline double MomentumSpaceContext::getEnergy(unsigned int state) const{
183  return energies[state];
184 }
185 
186 inline double MomentumSpaceContext::getEnergy(
187  unsigned int block,
188  unsigned int state
189 ) const{
190  return energies[block*numOrbitals + state];
191 }
192 
193 inline std::complex<double> MomentumSpaceContext::getAmplitude(
194  unsigned int block,
195  unsigned int state,
196  unsigned int amplitude
197 ) const{
198  return amplitudes[numOrbitals*(numOrbitals*block + state) + amplitude];
199 }
200 
201 inline Index MomentumSpaceContext::getKIndex(
202  const std::vector<double> &k
203 ) const{
204  return brillouinZone->getMinorCellIndex(
205  k,
206  numMeshPoints
207  );
208 }
209 
210 inline const PropertyExtractor::BlockDiagonalizer& MomentumSpaceContext::getPropertyExtractorBlockDiagonalizer(
211 ) const{
212  return *propertyExtractor;
213 }
214 
215 }; //End of namespace RPA
216 }; //End of namespace TBTK
217 
218 #endif
219 
Definition: Boolean.h:32