24 #ifndef COM_DAFER45_TBTK_SUSCEPTIBILITY_CALCULATOR
25 #define COM_DAFER45_TBTK_SUSCEPTIBILITY_CALCULATOR
27 #include "TBTK/RPA/DualIndex.h"
29 #include "TBTK/InteractionAmplitude.h"
30 #include "TBTK/RPA/MomentumSpaceContext.h"
32 #include "TBTK/SerializableVector.h"
42 class SusceptibilityCalculator{
56 SusceptibilityCalculator(
58 const RPA::MomentumSpaceContext &momentumSpaceContext
62 virtual ~SusceptibilityCalculator();
67 virtual SusceptibilityCalculator* createSlave() = 0;
70 virtual std::complex<double> calculateSusceptibility(
71 const std::vector<double> &k,
72 const std::vector<int> &orbitalIndices,
73 std::complex<double> energy
77 virtual std::vector<std::complex<double>> calculateSusceptibility(
78 const DualIndex &kDual,
79 const std::vector<int> &orbitalIndices
83 std::vector<std::complex<double>> calculateSusceptibility(
84 const std::vector<double> &k,
85 const std::vector<int> &orbitalIndices
93 const RPA::MomentumSpaceContext& getMomentumSpaceContext()
const;
98 void generateKPlusQLookupTable();
102 enum class EnergyType {Real, Imaginary, Complex};
105 Algorithm getAlgorithm()
const;
108 void setEnergyType(EnergyType energyType);
111 EnergyType getEnergyType()
const;
116 const std::vector<std::complex<double>> &energies
121 const std::vector<std::complex<double>>& getEnergies()
const;
132 void setEnergiesAreInversionSymmetric(
133 bool energiesAreInversionSymmetric
138 bool getEnergiesAreInversionSymmetric()
const;
141 void saveSusceptibilities(
const std::string &filename)
const;
144 void loadSusceptibilities(
const std::string &filename);
147 SusceptibilityCalculator(
149 const RPA::MomentumSpaceContext &momentumSpaceContext,
150 int *kPlusQLookupTable
155 bool getIsMaster()
const;
158 int* getKPlusQLookupTable();
161 const int* getKPlusQLookupTable()
const;
164 Index getSusceptibilityResultIndex(
166 const std::vector<int> &orbitalIndices
170 const IndexedDataTree<SerializableVector<std::complex<double>>>& getSusceptibilityTree()
const;
173 template<
bool useKPlusQLookupTable>
174 int getKPlusQLinearIndex(
175 unsigned int meshIndex,
176 const std::vector<double> &k,
181 void cacheSusceptibility(
182 const std::vector<std::complex<double>> &result,
183 const std::vector<double> &k,
184 const std::vector<int> &orbitalIndices,
186 const Index &resultIndex
193 IndexedDataTree<SerializableVector<std::complex<double>>> susceptibilityTree;
199 EnergyType energyType;
202 std::vector<std::complex<double>> energies;
207 bool energiesAreInversionSymmetric;
210 const RPA::MomentumSpaceContext *momentumSpaceContext;
213 int *kPlusQLookupTable;
221 inline const RPA::MomentumSpaceContext& SusceptibilityCalculator::getMomentumSpaceContext(
223 return *momentumSpaceContext;
226 inline SusceptibilityCalculator::Algorithm SusceptibilityCalculator::getAlgorithm()
const{
230 inline Index SusceptibilityCalculator::getSusceptibilityResultIndex(
232 const std::vector<int> &orbitalIndices
237 orbitalIndices.at(0),
238 orbitalIndices.at(1),
239 orbitalIndices.at(2),
245 inline void SusceptibilityCalculator::setEnergyType(
246 EnergyType energyType
248 this->energyType = energyType;
251 inline SusceptibilityCalculator::EnergyType SusceptibilityCalculator::getEnergyType(
256 inline void SusceptibilityCalculator::setEnergies(
257 const std::vector<std::complex<double>> &energies
259 this->energies = energies;
260 susceptibilityTree.clear();
263 inline const std::vector<std::complex<double>>& SusceptibilityCalculator::getEnergies()
const{
267 inline void SusceptibilityCalculator::setEnergiesAreInversionSymmetric(
268 bool energiesAreInversionSymmetric
270 this->energiesAreInversionSymmetric = energiesAreInversionSymmetric;
273 inline bool SusceptibilityCalculator::getEnergiesAreInversionSymmetric(
275 return energiesAreInversionSymmetric;
278 inline void SusceptibilityCalculator::saveSusceptibilities(
279 const std::string &filename
283 susceptibilityTree.serialize(Serializable::Mode::JSON)
285 resource.write(filename);
288 inline void SusceptibilityCalculator::loadSusceptibilities(
289 const std::string &filename
292 resource.read(filename);
293 susceptibilityTree = IndexedDataTree<SerializableVector<std::complex<double>>>(
295 Serializable::Mode::JSON
299 inline std::vector<std::complex<double>> SusceptibilityCalculator::calculateSusceptibility(
300 const std::vector<double> &k,
301 const std::vector<int> &orbitalIndices
303 return calculateSusceptibility(
305 momentumSpaceContext->getKIndex(k),
312 inline void SusceptibilityCalculator::clearCache(){
313 susceptibilityTree.clear();
316 inline bool SusceptibilityCalculator::getIsMaster()
const{
320 inline int* SusceptibilityCalculator::getKPlusQLookupTable(){
321 return kPlusQLookupTable;
324 inline const int* SusceptibilityCalculator::getKPlusQLookupTable()
const{
325 return kPlusQLookupTable;
329 inline int SusceptibilityCalculator::getKPlusQLinearIndex<false>(
330 unsigned int meshIndex,
331 const std::vector<double> &k,
334 const std::vector<std::vector<double>> &mesh
335 = momentumSpaceContext->getMesh();
338 = momentumSpaceContext->getBrillouinZone().getMinorCellIndex(
339 {mesh[meshIndex][0] + k[0], mesh[meshIndex][1] + k[1]},
340 momentumSpaceContext->getNumMeshPoints()
342 return momentumSpaceContext->getModel().getHoppingAmplitudeSet().getFirstIndexInBlock(
348 inline int SusceptibilityCalculator::getKPlusQLinearIndex<true>(
349 unsigned int meshIndex,
350 const std::vector<double> &k,
353 return kPlusQLookupTable[
354 meshIndex*momentumSpaceContext->getMesh().size()
355 + kLinearIndex/momentumSpaceContext->getNumOrbitals()
359 inline const IndexedDataTree<SerializableVector<std::complex<double>>>& SusceptibilityCalculator::getSusceptibilityTree()
const{
360 return susceptibilityTree;