TBTK
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 
23 #ifndef COM_DAFER45_TBTK_SELF_ENERGY_CALCULATOR
24 #define COM_DAFER45_TBTK_SELF_ENERGY_CALCULATOR
25 
26 #include "BrillouinZone.h"
27 #include "BlockDiagonalizationSolver.h"
28 #include "BPropertyExtractor.h"
29 #include "IndexedDataTree.h"
30 #include "SusceptibilityCalculator.h"
31 
32 namespace TBTK{
33 
34 class SelfEnergyCalculator{
35 public:
38  const MomentumSpaceContext &momentumSpaceContext,
39  unsigned int numWorkers
40  );
41 
44 
46  const MomentumSpaceContext& getMomentumSpaceContext() const;
47 
49  void init();
50 
53  enum class EnergyType {Real, Imaginary, Complex};
54 
56  void setNumSummationEnergies(unsigned int numSummationEnergies);
57 
59  void setSelfEnergyEnergyType(EnergyType energyType);
60 
63 
67  const std::vector<std::complex<double>> &selfEnergyEnergies
68  );
69 
71  std::vector<std::complex<double>> calculateSelfEnergy(
72  const std::vector<double> &k,
73  const std::vector<int> &orbitalIndices
74  );
75 
77  std::vector<std::complex<double>> calculateSelfEnergySelfConsistently(
78  unsigned int numMatsubaraFrequencies
79  );
80 
82  std::vector<std::complex<double>> calculateSelfEnergyVertex(
83  const std::vector<double> &k,
84  const std::vector<int> &orbitalIndices,
85  unsigned int worker
86  );
87 
89  void setU(std::complex<double> U);
90 
92  void setUp(std::complex<double> Up);
93 
95  void setJ(std::complex<double> J);
96 
98  void setJp(std::complex<double> Jp);
99 
101 // void precomputeSusceptibilities(unsigned int numWorkers = 128);
102 
104  void saveSusceptibilities(const std::string &filename) const;
105 
107  void loadSusceptibilities(const std::string &filename);
108 private:
110  std::vector<SusceptibilityCalculator*> susceptibilityCalculators;
111 
113  int *kMinusQLookupTable;
114 
117  void generateKMinusQLookupTable();
118 
120  template<bool useKPlusKLookupTable>
121  int getKMinusQLinearIndex(
122  unsigned int meshIndex,
123  const std::vector<double> &k,
124  int kLinearIndex
125  ) const;
126 
128  unsigned int numSummationEnergies;
129 
131  std::vector<std::complex<double>> summationEnergies;
132 
134  EnergyType selfEnergyEnergyType;
135 
137  std::vector<std::complex<double>> selfEnergyEnergies;
138 
140  bool isInitialized;
141 
144 
146  SerializeableVector<IndexedDataTree<SerializeableVector<std::complex<double>>>> selfEnergyVertexTrees;
147 
149  void invertMatrix(
150  std::complex<double> *matrix,
151  unsigned int dimensions
152  );
153 
155  void multiplyMatrices(
156  std::complex<double> *matrix1,
157  std::complex<double> *matrix2,
158  std::complex<double> *result,
159  unsigned int dimensions
160  );
161 
163  void printMatrix(
164  std::complex<double> *matrix,
165  unsigned int dimensions
166  );
167 
169  template<bool singleSelfEnergyEnergy>
170  void selfEnergyMainLoop(
171  const std::vector<double> &k,
172  const std::vector<int> &orbitalIndices,
173  std::vector<std::complex<double>> &result
174  );
175 
177  std::complex<double> U, Up, J, Jp;
178 
180  std::vector<InteractionAmplitude> u1;
181  std::vector<InteractionAmplitude> u2;
182  std::vector<InteractionAmplitude> u3;
183 
186  bool interactionAmplitudesAreGenerated;
187 
190  void generateInteractionAmplitudes();
191 };
192 
194 ) const{
195  return susceptibilityCalculators[0]->getMomentumSpaceContext();
196 }
197 
199  unsigned int numSummationEnergies
200 ){
201  this->numSummationEnergies = numSummationEnergies;
202 }
203 
205  EnergyType energyType
206 ){
207  selfEnergyEnergyType = energyType;
208 }
209 
211 ) const{
212  return selfEnergyEnergyType;
213 }
214 
216  const std::vector<std::complex<double>> &selfEnergyEnergies
217 ){
218  this->selfEnergyEnergies = selfEnergyEnergies;
219  selfEnergyTree.clear();
220 
221  for(unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
222  selfEnergyVertexTrees[n].clear();
223 }
224 
225 inline void SelfEnergyCalculator::setU(std::complex<double> U){
226  this->U = U;
227 
228  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
229  susceptibilityCalculators[n]->setU(U);
230 
231  selfEnergyTree.clear();
232 
233  for(unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
234  selfEnergyVertexTrees[n].clear();
235 
236  interactionAmplitudesAreGenerated = false;
237 }
238 
239 inline void SelfEnergyCalculator::setUp(std::complex<double> Up){
240  this->Up = Up;
241 
242  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
243  susceptibilityCalculators[n]->setUp(Up);
244 
245  selfEnergyTree.clear();
246 
247  for(unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
248  selfEnergyVertexTrees[n].clear();
249 
250  interactionAmplitudesAreGenerated = false;
251 }
252 
253 inline void SelfEnergyCalculator::setJ(std::complex<double> J){
254  this->J = J;
255 
256  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
257  susceptibilityCalculators[n]->setJ(J);
258 
259  selfEnergyTree.clear();
260 
261  for(unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
262  selfEnergyVertexTrees[n].clear();
263 
264  interactionAmplitudesAreGenerated = false;
265 }
266 
267 inline void SelfEnergyCalculator::setJp(std::complex<double> Jp){
268  this->Jp = Jp;
269 
270  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
271  susceptibilityCalculators[n]->setJp(Jp);
272 
273  selfEnergyTree.clear();
274 
275  for(unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
276  selfEnergyVertexTrees[n].clear();
277 
278  interactionAmplitudesAreGenerated = false;
279 }
280 
281 /*inline void SelfEnergyCalculator::precomputeSusceptibilities(
282  unsigned int numWorkers
283 ){
284  susceptibilityCalculator.precompute(numWorkers);
285 }*/
286 
288  const std::string &filename
289 ) const{
290  unsigned int lastPos = filename.find_last_of('/');
291  std::string path;
292  std::string fname = filename;
293  if(lastPos != std::string::npos){
294  path = filename.substr(0, lastPos+1);
295  fname = filename.substr(lastPos+1, filename.size());
296  }
297 
298  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++){
299  susceptibilityCalculators[n]->saveSusceptibilities(
300  path + "Slice" + std::to_string(n) + "_" + fname
301  );
302  }
303 }
304 
306  const std::string &filename
307 ){
308  unsigned int lastPos = filename.find_last_of('/');
309  std::string path;
310  std::string fname = filename;
311  if(lastPos != std::string::npos){
312  path = filename.substr(0, lastPos+1);
313  fname = filename.substr(lastPos+1, filename.size());
314  }
315 
316  for(unsigned int n = 0; n < susceptibilityCalculators.size(); n++){
317  susceptibilityCalculators[n]->loadSusceptibilities(
318  path + "Slice" + std::to_string(n) + "_" + fname
319  );
320  }
321 }
322 
323 }; //End of namespace TBTK
324 
325 #endif
std::vector< std::complex< double > > calculateSelfEnergyVertex(const std::vector< double > &k, const std::vector< int > &orbitalIndices, unsigned int worker)
void saveSusceptibilities(const std::string &filename) const
Definition: SelfEnergyCalculator.h:239
EnergyType
Definition: SelfEnergyCalculator_old.h:53
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 setSelfEnergyEnergyType(EnergyType energyType)
Definition: SelfEnergyCalculator_old.h:204
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)
EnergyType getSelfEnergyEnergyType() const
Definition: SelfEnergyCalculator_old.h:210
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