TBTK
Need a break? Support the development by playing Polarity Puzzles
SelfEnergyCalculator_old.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 "BrillouinZone.h"
28 #include "BlockDiagonalizationSolver.h"
29 #include "BPropertyExtractor.h"
30 #include "IndexedDataTree.h"
31 #include "SusceptibilityCalculator.h"
32 
33 namespace TBTK{
34 
35 class SelfEnergyCalculator{
36 public:
38  SelfEnergyCalculator(
39  const MomentumSpaceContext &momentumSpaceContext,
40  unsigned int numWorkers
41  );
42 
44  ~SelfEnergyCalculator();
45 
47  const MomentumSpaceContext& getMomentumSpaceContext() const;
48 
50  void init();
51 
54  enum class EnergyType {Real, Imaginary, Complex};
55 
57  void setNumSummationEnergies(unsigned int numSummationEnergies);
58 
60  void setSelfEnergyEnergyType(EnergyType energyType);
61 
63  EnergyType getSelfEnergyEnergyType() const;
64 
67  void setSelfEnergyEnergies(
68  const std::vector<std::complex<double>> &selfEnergyEnergies
69  );
70 
72  std::vector<std::complex<double>> calculateSelfEnergy(
73  const std::vector<double> &k,
74  const std::vector<int> &orbitalIndices
75  );
76 
78  std::vector<std::complex<double>> calculateSelfEnergySelfConsistently(
79  unsigned int numMatsubaraFrequencies
80  );
81 
83  std::vector<std::complex<double>> calculateSelfEnergyVertex(
84  const std::vector<double> &k,
85  const std::vector<int> &orbitalIndices,
86  unsigned int worker
87  );
88 
90  void setU(std::complex<double> U);
91 
93  void setUp(std::complex<double> Up);
94 
96  void setJ(std::complex<double> J);
97 
99  void setJp(std::complex<double> Jp);
100 
102 // void precomputeSusceptibilities(unsigned int numWorkers = 128);
103 
105  void saveSusceptibilities(const std::string &filename) const;
106 
108  void loadSusceptibilities(const std::string &filename);
109 private:
111  std::vector<SusceptibilityCalculator*> susceptibilityCalculators;
112 
114  int *kMinusQLookupTable;
115 
118  void generateKMinusQLookupTable();
119 
121  template<bool useKPlusKLookupTable>
122  int getKMinusQLinearIndex(
123  unsigned int meshIndex,
124  const std::vector<double> &k,
125  int kLinearIndex
126  ) const;
127 
129  unsigned int numSummationEnergies;
130 
132  std::vector<std::complex<double>> summationEnergies;
133 
135  EnergyType selfEnergyEnergyType;
136 
138  std::vector<std::complex<double>> selfEnergyEnergies;
139 
141  bool isInitialized;
142 
144  IndexedDataTree<SerializeableVector<std::complex<double>>> selfEnergyTree;
145 
147  SerializeableVector<IndexedDataTree<SerializeableVector<std::complex<double>>>> selfEnergyVertexTrees;
148 
150  void invertMatrix(
151  std::complex<double> *matrix,
152  unsigned int dimensions
153  );
154 
156  void multiplyMatrices(
157  std::complex<double> *matrix1,
158  std::complex<double> *matrix2,
159  std::complex<double> *result,
160  unsigned int dimensions
161  );
162 
164  void printMatrix(
165  std::complex<double> *matrix,
166  unsigned int dimensions
167  );
168 
170  template<bool singleSelfEnergyEnergy>
171  void selfEnergyMainLoop(
172  const std::vector<double> &k,
173  const std::vector<int> &orbitalIndices,
174  std::vector<std::complex<double>> &result
175  );
176 
178  std::complex<double> U, Up, J, Jp;
179 
181  std::vector<InteractionAmplitude> u1;
182  std::vector<InteractionAmplitude> u2;
183  std::vector<InteractionAmplitude> u3;
184 
187  bool interactionAmplitudesAreGenerated;
188 
191  void generateInteractionAmplitudes();
192 };
193 
194 inline const MomentumSpaceContext& SelfEnergyCalculator::getMomentumSpaceContext(
195 ) const{
196  return susceptibilityCalculators[0]->getMomentumSpaceContext();
197 }
198 
199 inline void SelfEnergyCalculator::setNumSummationEnergies(
200  unsigned int numSummationEnergies
201 ){
202  this->numSummationEnergies = numSummationEnergies;
203 }
204 
205 inline void SelfEnergyCalculator::setSelfEnergyEnergyType(
206  EnergyType energyType
207 ){
208  selfEnergyEnergyType = energyType;
209 }
210 
211 inline SelfEnergyCalculator::EnergyType SelfEnergyCalculator::getSelfEnergyEnergyType(
212 ) const{
213  return selfEnergyEnergyType;
214 }
215 
216 inline void SelfEnergyCalculator::setSelfEnergyEnergies(
217  const std::vector<std::complex<double>> &selfEnergyEnergies
218 ){
219  this->selfEnergyEnergies = selfEnergyEnergies;
220  selfEnergyTree.clear();
221 
222  for(unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
223  selfEnergyVertexTrees[n].clear();
224 }
225 
226 inline void SelfEnergyCalculator::setU(std::complex<double> U){
227  this->U = U;
228 
229  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
230  susceptibilityCalculators[n]->setU(U);
231 
232  selfEnergyTree.clear();
233 
234  for(unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
235  selfEnergyVertexTrees[n].clear();
236 
237  interactionAmplitudesAreGenerated = false;
238 }
239 
240 inline void SelfEnergyCalculator::setUp(std::complex<double> Up){
241  this->Up = Up;
242 
243  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
244  susceptibilityCalculators[n]->setUp(Up);
245 
246  selfEnergyTree.clear();
247 
248  for(unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
249  selfEnergyVertexTrees[n].clear();
250 
251  interactionAmplitudesAreGenerated = false;
252 }
253 
254 inline void SelfEnergyCalculator::setJ(std::complex<double> J){
255  this->J = J;
256 
257  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
258  susceptibilityCalculators[n]->setJ(J);
259 
260  selfEnergyTree.clear();
261 
262  for(unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
263  selfEnergyVertexTrees[n].clear();
264 
265  interactionAmplitudesAreGenerated = false;
266 }
267 
268 inline void SelfEnergyCalculator::setJp(std::complex<double> Jp){
269  this->Jp = Jp;
270 
271  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
272  susceptibilityCalculators[n]->setJp(Jp);
273 
274  selfEnergyTree.clear();
275 
276  for(unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
277  selfEnergyVertexTrees[n].clear();
278 
279  interactionAmplitudesAreGenerated = false;
280 }
281 
282 /*inline void SelfEnergyCalculator::precomputeSusceptibilities(
283  unsigned int numWorkers
284 ){
285  susceptibilityCalculator.precompute(numWorkers);
286 }*/
287 
288 inline void SelfEnergyCalculator::saveSusceptibilities(
289  const std::string &filename
290 ) const{
291  unsigned int lastPos = filename.find_last_of('/');
292  std::string path;
293  std::string fname = filename;
294  if(lastPos != std::string::npos){
295  path = filename.substr(0, lastPos+1);
296  fname = filename.substr(lastPos+1, filename.size());
297  }
298 
299  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++){
300  susceptibilityCalculators[n]->saveSusceptibilities(
301  path + "Slice" + std::to_string(n) + "_" + fname
302  );
303  }
304 }
305 
306 inline void SelfEnergyCalculator::loadSusceptibilities(
307  const std::string &filename
308 ){
309  unsigned int lastPos = filename.find_last_of('/');
310  std::string path;
311  std::string fname = filename;
312  if(lastPos != std::string::npos){
313  path = filename.substr(0, lastPos+1);
314  fname = filename.substr(lastPos+1, filename.size());
315  }
316 
317  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++){
318  susceptibilityCalculators[n]->loadSusceptibilities(
319  path + "Slice" + std::to_string(n) + "_" + fname
320  );
321  }
322 }
323 
324 }; //End of namespace TBTK
325 
326 #endif
327 
Data structure for storing data associated with an index.
Definition: Boolean.h:32