24 #ifndef COM_DAFER45_TBTK_RPA_SUSCEPTIBILITY_CALCULATOR
25 #define COM_DAFER45_TBTK_RPA_SUSCEPTIBILITY_CALCULATOR
27 #include "TBTK/InteractionAmplitude.h"
28 #include "TBTK/RPA/MomentumSpaceContext.h"
29 #include "TBTK/SerializableVector.h"
30 #include "TBTK/RPA/SusceptibilityCalculator.h"
31 #include "TBTK/RPA/LindhardSusceptibilityCalculator.h"
39 class RPASusceptibilityCalculator{
42 RPASusceptibilityCalculator(
43 const RPA::MomentumSpaceContext &momentumSpaceContext,
44 SusceptibilityCalculator::Algorithm algorithm
45 = SusceptibilityCalculator::Algorithm::Lindhard
49 ~RPASusceptibilityCalculator();
54 RPASusceptibilityCalculator* createSlave();
59 void precompute(
unsigned int numWorkers = 129);
61 const RPA::MomentumSpaceContext& getMomentumSpaceContext()
const;
64 void setInteractionAmplitudes(
65 const std::vector<InteractionAmplitude> &interactionAmplitudes
70 enum class EnergyType {Real, Imaginary, Complex};
79 void setEnergyType(EnergyType energyType);
82 EnergyType getEnergyType()
const;
87 const std::vector<std::complex<double>> &energies
99 void setEnergiesAreInversionSymmetric(
100 bool energiesAreInversionSymmetric
105 bool getEnergiesAreInversionSymmetric()
const;
109 void setSusceptibilityIsSafeFromPoles(
110 bool susceptibilityIsSafeFromPoles
115 bool getSusceptibilityIsSafeFromPoles()
const;
121 void saveSusceptibilities(
const std::string &filename)
const;
124 void loadSusceptibilities(
const std::string &filename);
127 IndexedDataTree<SerializableVector<std::complex<double>>> rpaSusceptibilityTree;
130 IndexedDataTree<SerializableVector<std::complex<double>>> rpaChargeSusceptibilityTree;
133 IndexedDataTree<SerializableVector<std::complex<double>>> rpaSpinSusceptibilityTree;
136 EnergyType energyType;
139 std::vector<std::complex<double>> energies;
142 std::vector<std::complex<double>> calculateRPASusceptibility(
143 const DualIndex &kDual,
144 const std::vector<int> &orbitalIndices
148 std::vector<std::complex<double>> calculateRPASusceptibility(
149 const std::vector<double> &k,
150 const std::vector<int> &orbitalIndices
154 std::vector<std::complex<double>> calculateChargeRPASusceptibility(
155 const DualIndex &kDual,
156 const std::vector<int> &orbitalIndices
160 std::vector<std::complex<double>> calculateChargeRPASusceptibility(
161 const std::vector<double> &k,
162 const std::vector<int> &orbitalIndices
166 std::vector<std::complex<double>> calculateSpinRPASusceptibility(
167 const DualIndex &kDual,
168 const std::vector<int> &orbitalIndices
172 std::vector<std::complex<double>> calculateSpinRPASusceptibility(
173 const std::vector<double> &k,
174 const std::vector<int> &orbitalIndices
178 void setU(std::complex<double> U);
181 void setUp(std::complex<double> Up);
184 void setJ(std::complex<double> J);
187 void setJp(std::complex<double> Jp);
190 SusceptibilityCalculator *susceptibilityCalculator;
193 std::vector<InteractionAmplitude> interactionAmplitudes;
196 std::vector<InteractionAmplitude> interactionAmplitudesCharge;
199 std::vector<InteractionAmplitude> interactionAmplitudesSpin;
203 bool interactionAmplitudesAreGenerated;
206 RPASusceptibilityCalculator(
207 SusceptibilityCalculator &susceptibilityCalculator
211 Index getSusceptibilityResultIndex(
213 const std::vector<int> &orbitalIndices
217 void invertMatrix(std::complex<double> *matrix,
unsigned int dimensions);
220 void multiplyMatrices(
221 std::complex<double> *matrix1,
222 std::complex<double> *matrix2,
223 std::complex<double> *result,
224 unsigned int dimensions
228 std::vector<std::vector<std::vector<std::complex<double>>>> rpaSusceptibilityMainAlgorithm(
229 const DualIndex &kDual,
230 const std::vector<int> &orbitalIndices,
231 const std::vector<InteractionAmplitude> &interactionAmpltiudes
235 std::complex<double> U, Up, J, Jp;
240 void generateInteractionAmplitudes();
243 inline const RPA::MomentumSpaceContext& RPASusceptibilityCalculator::getMomentumSpaceContext(
245 return susceptibilityCalculator->getMomentumSpaceContext();
248 inline void RPASusceptibilityCalculator::setInteractionAmplitudes(
249 const std::vector<InteractionAmplitude> &interactionAmplitudes
251 this->interactionAmplitudes = interactionAmplitudes;
254 inline Index RPASusceptibilityCalculator::getSusceptibilityResultIndex(
256 const std::vector<int> &orbitalIndices
261 orbitalIndices.at(0),
262 orbitalIndices.at(1),
263 orbitalIndices.at(2),
280 inline void RPASusceptibilityCalculator::setEnergyType(
281 EnergyType energyType
283 this->energyType = energyType;
285 case EnergyType::Real:
286 susceptibilityCalculator->setEnergyType(
287 SusceptibilityCalculator::EnergyType::Real
290 case EnergyType::Imaginary:
291 susceptibilityCalculator->setEnergyType(
292 SusceptibilityCalculator::EnergyType::Imaginary
295 case EnergyType::Complex:
296 susceptibilityCalculator->setEnergyType(
297 SusceptibilityCalculator::EnergyType::Complex
302 "RPASusceptibilityCalculator::setEnergyType()",
303 "Unknown energy type.",
304 "This should never happen, contact the developer."
309 inline RPASusceptibilityCalculator::EnergyType RPASusceptibilityCalculator::getEnergyType(
314 inline void RPASusceptibilityCalculator::setEnergies(
315 const std::vector<std::complex<double>> &energies
317 susceptibilityCalculator->setEnergies(
321 this->energies = energies;
323 rpaSusceptibilityTree.clear();
324 rpaChargeSusceptibilityTree.clear();
325 rpaSpinSusceptibilityTree.clear();
328 inline void RPASusceptibilityCalculator::setEnergiesAreInversionSymmetric(
329 bool energiesAreInversionSymmetric
331 susceptibilityCalculator->setEnergiesAreInversionSymmetric(
332 energiesAreInversionSymmetric
336 inline bool RPASusceptibilityCalculator::getEnergiesAreInversionSymmetric(
338 return susceptibilityCalculator->getEnergiesAreInversionSymmetric();
341 inline void RPASusceptibilityCalculator::setSusceptibilityIsSafeFromPoles(
342 bool susceptibilityIsSafeFromPoles
345 susceptibilityCalculator->getAlgorithm()
346 == SusceptibilityCalculator::Algorithm::Lindhard,
347 "RPASusceptibilityCalculator::setSusceptibilityIsSafeFromPoles()",
348 "Only valid function call if the underlying algorithm is"
349 <<
" SusceptibilityCalculator::Algorithm::Lindhard.",
353 ((LindhardSusceptibilityCalculator*)susceptibilityCalculator)->setSusceptibilityIsSafeFromPoles(
354 susceptibilityIsSafeFromPoles
358 inline bool RPASusceptibilityCalculator::getSusceptibilityIsSafeFromPoles()
const{
360 susceptibilityCalculator->getAlgorithm()
361 == SusceptibilityCalculator::Algorithm::Lindhard,
362 "RPASusceptibilityCalculator::getSusceptibilityIsSafeFromPoles()",
363 "Only valid function call if the underlying algorithm is"
364 <<
" SusceptibilityCalculator::Algorithm::Lindhard.",
368 return ((LindhardSusceptibilityCalculator*)susceptibilityCalculator)->getSusceptibilityIsSafeFromPoles();
379 inline void RPASusceptibilityCalculator::saveSusceptibilities(
380 const std::string &filename
382 susceptibilityCalculator->saveSusceptibilities(filename);
385 inline void RPASusceptibilityCalculator::loadSusceptibilities(
386 const std::string &filename
388 susceptibilityCalculator->loadSusceptibilities(filename);
391 inline std::vector<std::complex<double>> RPASusceptibilityCalculator::calculateRPASusceptibility(
392 const std::vector<double> &k,
393 const std::vector<int> &orbitalIndices
395 return calculateRPASusceptibility(
397 susceptibilityCalculator->getMomentumSpaceContext().getKIndex(k),
404 inline std::vector<std::complex<double>> RPASusceptibilityCalculator::calculateChargeRPASusceptibility(
405 const std::vector<double> &k,
406 const std::vector<int> &orbitalIndices
408 return calculateChargeRPASusceptibility(
410 susceptibilityCalculator->getMomentumSpaceContext().getKIndex(k),
417 inline std::vector<std::complex<double>> RPASusceptibilityCalculator::calculateSpinRPASusceptibility(
418 const std::vector<double> &k,
419 const std::vector<int> &orbitalIndices
421 return calculateSpinRPASusceptibility(
423 susceptibilityCalculator->getMomentumSpaceContext().getKIndex(k),
430 inline void RPASusceptibilityCalculator::setU(std::complex<double> U){
432 rpaSusceptibilityTree.clear();
433 rpaChargeSusceptibilityTree.clear();
434 rpaSpinSusceptibilityTree.clear();
435 interactionAmplitudesAreGenerated =
false;
438 inline void RPASusceptibilityCalculator::setUp(std::complex<double> Up){
440 rpaSusceptibilityTree.clear();
441 rpaChargeSusceptibilityTree.clear();
442 rpaSpinSusceptibilityTree.clear();
443 interactionAmplitudesAreGenerated =
false;
446 inline void RPASusceptibilityCalculator::setJ(std::complex<double> J){
448 rpaSusceptibilityTree.clear();
449 rpaChargeSusceptibilityTree.clear();
450 rpaSpinSusceptibilityTree.clear();
451 interactionAmplitudesAreGenerated =
false;
454 inline void RPASusceptibilityCalculator::setJp(std::complex<double> Jp){
456 rpaSusceptibilityTree.clear();
457 rpaChargeSusceptibilityTree.clear();
458 rpaSpinSusceptibilityTree.clear();
459 interactionAmplitudesAreGenerated =
false;