TBTK
Need a break? Support the development by playing Polarity Puzzles
LindhardSusceptibility.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_SOLVER_LINDHARD_SUSCEPTIBILITY
25 #define COM_DAFER45_TBTK_SOLVER_LINDHARD_SUSCEPTIBILITY
26 
27 #include "TBTK/RPA/MomentumSpaceContext.h"
28 #include "TBTK/Solver/Susceptibility.h"
29 
30 #include <complex>
31 
32 namespace TBTK{
33 namespace Solver{
34 
35 class LindhardSusceptibility : public Susceptibility{
36 public:
38  LindhardSusceptibility(
39  const RPA::MomentumSpaceContext &momentumSpaceContext
40  );
41 
43  virtual ~LindhardSusceptibility();
44 
48  virtual LindhardSusceptibility* createSlave();
49 
51  virtual std::vector<std::complex<double>> calculateSusceptibility(
52  const Index &index,
53  const std::vector<std::complex<double>> &energies
54  );
55 private:
57  double *fermiDiracLookupTable;
58 
60  LindhardSusceptibility(
61  const RPA::MomentumSpaceContext &momentumSpaceContext,
62  int *kPlusQLookupTable,
63  double *fermiDiracLookupTable
64  );
65 
67  template<bool useKPlusQLookupTable/*, bool isSafeFromPoles*/>
68  std::vector<std::complex<double>> calculateSusceptibilityLindhard(
69  const Index &index,
70  const std::vector<std::complex<double>> &energies
71  );
72 
75  std::complex<double> getPoleTimesTwoFermi(
76  std::complex<double> energy,
77  double e2,
78  double e1,
79  double chemicalPotential,
80  double temperature,
81  int kPlusQLinearIndex,
82  unsigned int meshPoint,
83  unsigned int state2,
84  unsigned int state1,
85  unsigned int numOrbitals
86  ) const;
87 
91  void generateKPlusQLookupTable();
92 
94  int* getKPlusQLookupTable();
95 
97  const int* getKPlusQLookupTable() const;
98 
100  template<bool useKPlusQLookupTable>
101  int getKPlusQLinearIndex(
102  unsigned int meshIndex,
103  const std::vector<double> &k,
104  int kLinearIndex
105  ) const;
106 
108  int *kPlusQLookupTable;
109 
113  bool isMaster;
114 };
115 
116 inline int* LindhardSusceptibility::getKPlusQLookupTable(){
117  return kPlusQLookupTable;
118 }
119 
120 inline const int* LindhardSusceptibility::getKPlusQLookupTable() const{
121  return kPlusQLookupTable;
122 }
123 
124 template<>
125 inline int LindhardSusceptibility::getKPlusQLinearIndex<false>(
126  unsigned int meshIndex,
127  const std::vector<double> &k,
128  int kLinearIndex
129 ) const{
130  const RPA::MomentumSpaceContext &momentumSpaceContext
131  = getMomentumSpaceContext();
132 
133  const std::vector<std::vector<double>> &mesh
134  = momentumSpaceContext.getMesh();
135 
136  Index kPlusQIndex
137  = momentumSpaceContext.getBrillouinZone().getMinorCellIndex(
138  {mesh[meshIndex][0] + k[0], mesh[meshIndex][1] + k[1]},
139  momentumSpaceContext.getNumMeshPoints()
140  );
141  return momentumSpaceContext.getModel().getHoppingAmplitudeSet().getFirstIndexInBlock(
142  kPlusQIndex
143  );
144 }
145 
146 template<>
147 inline int LindhardSusceptibility::getKPlusQLinearIndex<true>(
148  unsigned int meshIndex,
149  const std::vector<double> &k,
150  int kLinearIndex
151 ) const{
152  const RPA::MomentumSpaceContext &momentumSpaceContext
153  = getMomentumSpaceContext();
154 
155  return kPlusQLookupTable[
156  meshIndex*momentumSpaceContext.getMesh().size()
157  + kLinearIndex/momentumSpaceContext.getNumOrbitals()
158  ];
159 }
160 
161 }; //End of namespace Solver
162 }; //End of namespace TBTK
163 
164 #endif
165 
Definition: Boolean.h:32