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