TBTK
Need a break? Support the development by playing Polarity Puzzles
SelfEnergyCalculator.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_SELF_ENERGY_CALCULATOR
25 #define COM_DAFER45_TBTK_SELF_ENERGY_CALCULATOR
26 
27 #include "TBTK/BrillouinZone.h"
28 #include "TBTK/IndexedDataTree.h"
29 #include "TBTK/RPA/ElectronFluctuationVertexCalculator.h"
30 
31 namespace TBTK{
32 
33 class SelfEnergyCalculator{
34 public:
36  SelfEnergyCalculator(
37  const RPA::MomentumSpaceContext &momentumSpaceContext,
38  unsigned int numWorkers
39  );
40 
42  ~SelfEnergyCalculator();
43 
45  const RPA::MomentumSpaceContext& getMomentumSpaceContext() const;
46 
48  void init();
49 
52 // enum class EnergyType {Real, Imaginary, Complex};
53 
55  void setNumSummationEnergies(unsigned int numSummationEnergies);
56 
58 // void setEnergyType(EnergyType energyType);
59 
61 // EnergyType getEnergyType() const;
62 
65  void setSelfEnergyEnergies(
66  const std::vector<std::complex<double>> &selfEnergyEnergies
67  );
68 
70  std::vector<std::complex<double>> calculateSelfEnergy(
71  const std::vector<double> &k,
72  const std::vector<int> &orbitalIndices
73  );
74 
76  std::vector<std::complex<double>> calculateSelfEnergySelfConsistently(
77  unsigned int numMatsubaraFrequencies
78  );
79 
81  void setU(std::complex<double> U);
82 
84  void setUp(std::complex<double> Up);
85 
87  void setJ(std::complex<double> J);
88 
90  void setJp(std::complex<double> Jp);
91 
93 // void precomputeSusceptibilities(unsigned int numWorkers = 128);
94 
96  void saveSusceptibilities(const std::string &filename) const;
97 
99  void loadSusceptibilities(const std::string &filename);
100 private:
102  std::vector<ElectronFluctuationVertexCalculator*> electronFluctuationVertexCalculators;
103 
105  int *kMinusQLookupTable;
106 
109  void generateKMinusQLookupTable();
110 
112  template<bool useKPlusKLookupTable>
113  int getKMinusQLinearIndex(
114  unsigned int meshIndex,
115  const std::vector<double> &k,
116  int kLinearIndex
117  ) const;
118 
120  unsigned int numSummationEnergies;
121 
123  std::vector<std::complex<double>> summationEnergies;
124 
126 // EnergyType energyType;
127 
129  std::vector<std::complex<double>> selfEnergyEnergies;
130 
132  bool isInitialized;
133 
135  IndexedDataTree<SerializableVector<std::complex<double>>> selfEnergyTree;
136 
138  template<bool singleSelfEnergyEnergy>
139  void selfEnergyMainLoop(
140  const std::vector<double> &k,
141  const std::vector<int> &orbitalIndices,
142  std::vector<std::complex<double>> &result
143  );
144 
146  std::complex<double> U, Up, J, Jp;
147 };
148 
149 inline const RPA::MomentumSpaceContext& SelfEnergyCalculator::getMomentumSpaceContext(
150 ) const{
151  return electronFluctuationVertexCalculators[0]->getMomentumSpaceContext();
152 }
153 
154 inline void SelfEnergyCalculator::setNumSummationEnergies(
155  unsigned int numSummationEnergies
156 ){
157  this->numSummationEnergies = numSummationEnergies;
158 }
159 
160 /*inline void SelfEnergyCalculator::setEnergyType(
161  EnergyType energyType
162 ){
163  this->energyType = energyType;
164 }*/
165 
166 /*inline SelfEnergyCalculator::EnergyType SelfEnergyCalculator::getEnergyType(
167 ) const{
168  return energyType;
169 }*/
170 
171 inline void SelfEnergyCalculator::setSelfEnergyEnergies(
172  const std::vector<std::complex<double>> &selfEnergyEnergies
173 ){
174  this->selfEnergyEnergies = selfEnergyEnergies;
175  selfEnergyTree.clear();
176 }
177 
178 inline void SelfEnergyCalculator::setU(std::complex<double> U){
179  this->U = U;
180 
181  for(
182  unsigned int n = 0;
183  n < electronFluctuationVertexCalculators.size();
184  n++
185  ){
186  electronFluctuationVertexCalculators[n]->setU(U);
187  }
188 
189  selfEnergyTree.clear();
190 }
191 
192 inline void SelfEnergyCalculator::setUp(std::complex<double> Up){
193  this->Up = Up;
194 
195  for(
196  unsigned int n = 0;
197  n < electronFluctuationVertexCalculators.size();
198  n++
199  ){
200  electronFluctuationVertexCalculators[n]->setUp(Up);
201  }
202 
203  selfEnergyTree.clear();
204 }
205 
206 inline void SelfEnergyCalculator::setJ(std::complex<double> J){
207  this->J = J;
208 
209  for(
210  unsigned int n = 0;
211  n < electronFluctuationVertexCalculators.size();
212  n++
213  ){
214  electronFluctuationVertexCalculators[n]->setJ(J);
215  }
216 
217  selfEnergyTree.clear();
218 }
219 
220 inline void SelfEnergyCalculator::setJp(std::complex<double> Jp){
221  this->Jp = Jp;
222 
223  for(
224  unsigned int n = 0;
225  n < electronFluctuationVertexCalculators.size();
226  n++
227  ){
228  electronFluctuationVertexCalculators[n]->setJp(Jp);
229  }
230 
231  selfEnergyTree.clear();
232 }
233 
234 /*inline void SelfEnergyCalculator::precomputeSusceptibilities(
235  unsigned int numWorkers
236 ){
237  susceptibilityCalculator.precompute(numWorkers);
238 }*/
239 
240 inline void SelfEnergyCalculator::saveSusceptibilities(
241  const std::string &filename
242 ) const{
243  size_t lastPos = filename.find_last_of('/');
244  std::string path;
245  std::string fname = filename;
246  if(lastPos != std::string::npos){
247  path = filename.substr(0, lastPos+1);
248  fname = filename.substr(lastPos+1, filename.size());
249  }
250 
251  for(
252  unsigned int n = 0;
253  n < electronFluctuationVertexCalculators.size();
254  n++
255  ){
256  electronFluctuationVertexCalculators[n]->saveSusceptibilities(
257  path + "Slice" + std::to_string(n) + "_" + fname
258  );
259  }
260 }
261 
262 inline void SelfEnergyCalculator::loadSusceptibilities(
263  const std::string &filename
264 ){
265  size_t lastPos = filename.find_last_of('/');
266  std::string path;
267  std::string fname = filename;
268  if(lastPos != std::string::npos){
269  path = filename.substr(0, lastPos+1);
270  fname = filename.substr(lastPos+1, filename.size());
271  }
272 
273  for(
274  unsigned int n = 0;
275  n < electronFluctuationVertexCalculators.size();
276  n++
277  ){
278  electronFluctuationVertexCalculators[n]->loadSusceptibilities(
279  path + "Slice" + std::to_string(n) + "_" + fname
280  );
281  }
282 }
283 
284 }; //End of namespace TBTK
285 
286 #endif
287 
Data structure for storing data associated with an index.
Definition: Boolean.h:32