TBTK
MatsubaraSusceptibilityCalculator.h
1 /* Copyright 2018 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_MATSUBARA_SUSCEPTIBILITY_CALCULATOR
24 #define COM_DAFER45_TBTK_MATSUBARA_SUSCEPTIBILITY_CALCULATOR
25 
26 #include "TBTK/RPA/SusceptibilityCalculator.h"
27 
28 #include <complex>
29 
30 //#include <omp.h>
31 
32 namespace TBTK{
33 
35 public:
38  const MomentumSpaceContext &momentumSpaceContext
39  );
40 
43 
48 
50  std::complex<double> calculateSusceptibility(
51  const std::vector<double> &k,
52  const std::vector<int> &orbitalIndices,
53  std::complex<double> energy
54  );
55 
57  std::vector<std::complex<double>> calculateSusceptibility(
58  const DualIndex &kDual,
59  const std::vector<int> &orbitalIndices
60  );
61 
63  void setNumSummationEnergies(unsigned int numSummationEnergies);
64 private:
66  std::complex<double> *greensFunction;
67 
69  std::vector<std::complex<double>> summationEnergies;
70 
73  const MomentumSpaceContext &momentumSpaceContext,
74  int *kPlusQLookupTable
75  );
76 
78  std::complex<double> calculateSusceptibilityMatsubara(
79  const std::vector<double> &k,
80  const std::vector<int> &orbitalIndices,
81  std::complex<double> energy
82  );
83 
85  template<bool useKPlusQLookupTable>
86  std::vector<std::complex<double>> calculateSusceptibilityMatsubara(
87  const DualIndex &kDual,
88  const std::vector<int> &orbitalIndices
89  );
90 
92  void calculateGreensFunction();
93 
95  std::complex<double>& getGreensFunctionValue(
96  unsigned int meshPoint,
97  unsigned int orbital0,
98  unsigned int orbital1,
99  unsigned int energy,
100  unsigned int numEnergies,
101  unsigned int numOrbitals
102  );
103 };
104 
106  unsigned int numSummationEnergies
107 ){
108  TBTKAssert(
109  numSummationEnergies%2 == 1,
110  "MatsubaraSusceptibilityCalculator::setNumSummationEnergies()",
111  "The number of summation energies must be an odd number.",
112  ""
113  );
114 
115  double temperature = UnitHandler::convertTemperatureNtB(
116  getMomentumSpaceContext().getModel().getTemperature()
117  );
118  double kT = UnitHandler::getK_BB()*temperature;
119  double hbar = UnitHandler::getHbarB();
120 
121  summationEnergies.clear();
122  for(unsigned int n = 0; n < numSummationEnergies; n++){
123  summationEnergies.push_back(
124  M_PI*(2*(n - numSummationEnergies/2))*kT/hbar
125  );
126  }
127 
128  clearCache();
129  if(greensFunction != nullptr){
130  delete [] greensFunction;
131  greensFunction = nullptr;
132  }
133 }
134 
135 /*inline std::vector<std::complex<double>> SusceptibilityCalculator::calculateSusceptibility(
136  const std::vector<double> &k,
137  const std::vector<int> &orbitalIndices
138 ){
139  return calculateSusceptibility(
140  DualIndex(
141  momentumSpaceContext->getKIndex(k),
142  k
143  ),
144  orbitalIndices
145  );
146 }*/
147 
148 inline std::complex<double>& MatsubaraSusceptibilityCalculator::getGreensFunctionValue(
149  unsigned int meshPoint,
150  unsigned int orbital0,
151  unsigned int orbital1,
152  unsigned int energy,
153  unsigned int numEnergies,
154  unsigned int numOrbitals
155 ){
156  return greensFunction[
157  numEnergies*(
158  numOrbitals*(numOrbitals*meshPoint + orbital0)
159  + orbital1
160  ) + energy
161  ];
162 }
163 
164 }; //End of namespace TBTK
165 
166 #endif
void setNumSummationEnergies(unsigned int numSummationEnergies)
Definition: MatsubaraSusceptibilityCalculator.h:105
static double getK_BB()
Definition: UnitHandler.h:746
Definition: DualIndex.h:33
const MomentumSpaceContext & getMomentumSpaceContext() const
Definition: SusceptibilityCalculator.h:220
static double convertTemperatureNtB(double temperature)
Definition: UnitHandler.h:872
Definition: SusceptibilityCalculator.h:41
Definition: MomentumSpaceContext.h:32
MatsubaraSusceptibilityCalculator * createSlave()
void clearCache()
Definition: SusceptibilityCalculator.h:311
MatsubaraSusceptibilityCalculator(const MomentumSpaceContext &momentumSpaceContext)
Definition: ModelFactory.h:35
Definition: MatsubaraSusceptibilityCalculator.h:34
std::complex< double > calculateSusceptibility(const std::vector< double > &k, const std::vector< int > &orbitalIndices, std::complex< double > energy)
static double getHbarB()
Definition: UnitHandler.h:738