TBTK
Susceptibility.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_SOLVER_SUSCEPTIBILITY
24 #define COM_DAFER45_TBTK_SOLVER_SUSCEPTIBILITY
25 
26 //#include "TBTK/RPA/DualIndex.h"
27 //#include "TBTK/IndexedDataTree.h"
28 //#include "TBTK/InteractionAmplitude.h"
30 //#include "TBTK/Resource.h"
31 //#include "TBTK/SerializableVector.h"
32 //#include "TBTK/UnitHandler.h"
33 
34 #include <complex>
35 #include <vector>
36 
37 //#include <omp.h>
38 
39 namespace TBTK{
40 namespace Solver{
41 
42 class Susceptibility : public Solver{
43 public:
50  enum Algorithm {
51  Lindhard = 0,
52  Matsubara = 1,
53  RPA = 2
54  };
55 
58  Algorithm algorithm,
59  const MomentumSpaceContext &momentumSpaceContext
60  );
61 
63  virtual ~Susceptibility();
64 
68  virtual Susceptibility* createSlave() = 0;
69 
71  virtual std::vector<std::complex<double>> calculateSusceptibility(
72  const Index &index,
73  const std::vector<std::complex<double>> &energies
74  ) = 0;
75 
76  const MomentumSpaceContext& getMomentumSpaceContext() const;
77 
82 
84  Algorithm getAlgorithm() const;
85 
96  bool energiesAreInversionSymmetric
97  );
98 
102 protected:
105  Algorithm algorithm,
106  const MomentumSpaceContext &momentumSpaceContext,
107  int *kPlusQLookupTable
108  );
109 
111  bool getIsMaster() const;
112 
114  int* getKPlusQLookupTable();
115 
117  const int* getKPlusQLookupTable() const;
118 
120  template<bool useKPlusQLookupTable>
122  unsigned int meshIndex,
123  const std::vector<double> &k,
124  int kLinearIndex
125  ) const;
126 private:
128  Algorithm algorithm;
129 
133  bool energiesAreInversionSymmetric;
134 
136  const MomentumSpaceContext *momentumSpaceContext;
137 
139  int *kPlusQLookupTable;
140 
144  bool isMaster;
145 };
146 
147 inline const MomentumSpaceContext& Susceptibility::getMomentumSpaceContext(
148 ) const{
149  return *momentumSpaceContext;
150 }
151 
153  return algorithm;
154 }
155 
157  bool energiesAreInversionSymmetric
158 ){
159  this->energiesAreInversionSymmetric = energiesAreInversionSymmetric;
160 }
161 
163 ) const{
164  return energiesAreInversionSymmetric;
165 }
166 
167 inline bool Susceptibility::getIsMaster() const{
168  return isMaster;
169 }
170 
172  return kPlusQLookupTable;
173 }
174 
175 inline const int* Susceptibility::getKPlusQLookupTable() const{
176  return kPlusQLookupTable;
177 }
178 
179 template<>
180 inline int Susceptibility::getKPlusQLinearIndex<false>(
181  unsigned int meshIndex,
182  const std::vector<double> &k,
183  int kLinearIndex
184 ) const{
185  const std::vector<std::vector<double>> &mesh
186  = momentumSpaceContext->getMesh();
187 
188  Index kPlusQIndex
189  = momentumSpaceContext->getBrillouinZone().getMinorCellIndex(
190  {mesh[meshIndex][0] + k[0], mesh[meshIndex][1] + k[1]},
191  momentumSpaceContext->getNumMeshPoints()
192  );
193  return momentumSpaceContext->getModel().getHoppingAmplitudeSet().getFirstIndexInBlock(
194  kPlusQIndex
195  );
196 }
197 
198 template<>
199 inline int Susceptibility::getKPlusQLinearIndex<true>(
200  unsigned int meshIndex,
201  const std::vector<double> &k,
202  int kLinearIndex
203 ) const{
204  return kPlusQLookupTable[
205  meshIndex*momentumSpaceContext->getMesh().size()
206  + kLinearIndex/momentumSpaceContext->getNumOrbitals()
207  ];
208 }
209 
210 }; //End of namespace Solver
211 }; //End of namespace TBTK
212 
213 #endif
Base class for Solvers.
Definition: Solver.h:32
virtual std::vector< std::complex< double > > calculateSusceptibility(const Index &index, const std::vector< std::complex< double >> &energies)=0
bool getIsMaster() const
Definition: Susceptibility.h:167
Property container for density.
Definition: Susceptibility.h:42
Algorithm
Definition: Susceptibility.h:50
const Model & getModel() const
Definition: MomentumSpaceContext.h:128
bool getEnergiesAreInversionSymmetric() const
Definition: Susceptibility.h:162
Algorithm getAlgorithm() const
Definition: Susceptibility.h:152
Susceptibility(Algorithm algorithm, const MomentumSpaceContext &momentumSpaceContext)
const HoppingAmplitudeSet & getHoppingAmplitudeSet() const
Definition: Model.h:344
int getKPlusQLinearIndex(unsigned int meshIndex, const std::vector< double > &k, int kLinearIndex) const
virtual Susceptibility * createSlave()=0
const std::vector< unsigned int > & getNumMeshPoints() const
Definition: MomentumSpaceContext.h:160
Definition: MomentumSpaceContext.h:32
Flexible physical index.
Definition: Index.h:69
unsigned int getNumOrbitals() const
Definition: MomentumSpaceContext.h:176
const BrillouinZone & getBrillouinZone() const
Definition: MomentumSpaceContext.h:140
Definition: ModelFactory.h:35
virtual Index getMinorCellIndex(const std::vector< double > &coordinates, const std::vector< unsigned int > &numMeshPoints) const
void setEnergiesAreInversionSymmetric(bool energiesAreInversionSymmetric)
Definition: Susceptibility.h:156
int * getKPlusQLookupTable()
Definition: Susceptibility.h:171
const std::vector< std::vector< double > > & getMesh() const
Definition: MomentumSpaceContext.h:165
int getFirstIndexInBlock(const Index &blockIndex) const
Definition: HoppingAmplitudeSet.h:457