24 #ifndef COM_DAFER45_TBTK_SOLVER_FLEX
25 #define COM_DAFER45_TBTK_SOLVER_FLEX
27 #include "TBTK/MomentumSpaceContext.h"
29 #include "TBTK/Property/Susceptibility.h"
30 #include "TBTK/Property/InteractionVertex.h"
31 #include "TBTK/Property/SelfEnergy.h"
37 class FLEX :
public Solver{
42 GreensFunctionCalculated,
43 BareSusceptibilityCalculated,
44 RPASusceptibilitiesCalculated,
45 InteractionVertexCalculated,
51 enum class Norm{Max, L2};
54 FLEX(
const MomentumSpaceContext &momentumSpaceContext);
57 const MomentumSpaceContext& getMomentumSpaceContext()
const;
62 const Property::GreensFunction& getGreensFunction()
const;
67 const Property::Susceptibility& getBareSusceptibility()
const;
72 const Property::Susceptibility& getRPASpinSusceptibility()
const;
77 const Property::Susceptibility& getRPAChargeSusceptibility()
const;
82 const Property::InteractionVertex& getInteractionVertex()
const;
87 void setSelfEnergy(
const Property::SelfEnergy &selfEnergy);
92 const Property::SelfEnergy& getSelfEnergy()
const;
99 void setSelfEnergyMixingParameter(
double selfEnergyMixingParameter);
116 void setEnergyWindow(
117 int lowerFermionicMatsubaraEnergyIndex,
118 int upperFermionicMatsubaraEnergyIndex,
119 int lowerBosonicMatsubaraEnergyIndex,
120 int upperBosonicMatsubaraEnergyIndex
136 void setUp(
double Up);
141 void setJp(
double Jp);
146 void setNumOrbitals(
unsigned int numOrbitals);
151 double getDensity()
const;
161 void setTargetDensity(
double targetDensity);
167 void setDensityTolerance(
double densityTolerance);
173 void setChemicalPotentialStepSize(
double chemicalPotentialStepSize);
178 State getState()
const;
184 void setMaxIterations(
unsigned int maxIterations);
190 void setNorm(Norm norm);
196 void setTolerance(
double tolerance);
202 void setCallback(
void (*callback)(FLEX &solver));
212 void setNumSlices(
unsigned int numSlices);
218 const MomentumSpaceContext momentumSpaceContext;
221 Property::GreensFunction greensFunction0;
224 Property::GreensFunction greensFunction;
227 Property::GreensFunction oldGreensFunction;
230 Property::Susceptibility bareSusceptibility;
233 Property::Susceptibility rpaSpinSusceptibility;
236 Property::Susceptibility rpaChargeSusceptibility;
239 Property::InteractionVertex interactionVertex;
242 Property::SelfEnergy selfEnergy;
245 Property::SelfEnergy previousSelfEnergy;
249 double selfEnergyMixingParameter;
255 double targetDensity;
258 double densityTolerance;
261 double chemicalPotentialStepSize;
264 int lowerFermionicMatsubaraEnergyIndex;
267 int upperFermionicMatsubaraEnergyIndex;
270 int lowerBosonicMatsubaraEnergyIndex;
273 int upperBosonicMatsubaraEnergyIndex;
288 unsigned int numOrbitals;
294 unsigned int maxIterations;
305 unsigned int numSlices;
309 double convergenceParameter;
312 void (*callback)(FLEX &solver);
315 void calculateBareGreensFunction();
318 void calculateBareSusceptibility(
unsigned int slice);
321 void calculateRPASusceptibilities();
324 void calculateInteractionVertex();
327 void calculateSelfEnergy(
unsigned int slice);
330 void calculateGreensFunction();
335 void convertSelfEnergyIndexStructure();
340 void calculateConvergenceParameter();
344 std::vector<InteractionAmplitude>
345 generateRPAChargeSusceptibilityInteractionAmplitudes();
348 std::vector<InteractionAmplitude>
349 generateRPASpinSusceptibilityInteractionAmplitudes();
352 std::vector<InteractionAmplitude> generateU1();
355 std::vector<InteractionAmplitude> generateU2();
358 std::vector<InteractionAmplitude> generateU3();
361 std::vector<InteractionAmplitude> generateU4();
364 Property::InteractionVertex generateHartreeFockTerm();
367 void calculateDensity();
371 int getLowerBosonicMatsubaraEnergyIndex(
unsigned int slice);
375 int getUpperBosonicMatsubaraEnergyIndex(
unsigned int slice);
378 inline const MomentumSpaceContext& FLEX::getMomentumSpaceContext()
const{
379 return momentumSpaceContext;
382 inline const Property::GreensFunction& FLEX::getGreensFunction()
const{
383 return greensFunction;
386 inline const Property::Susceptibility& FLEX::getBareSusceptibility()
const{
387 return bareSusceptibility;
390 inline const Property::Susceptibility& FLEX::getRPASpinSusceptibility()
const{
391 return rpaSpinSusceptibility;
394 inline const Property::Susceptibility& FLEX::getRPAChargeSusceptibility(
396 return rpaChargeSusceptibility;
399 inline const Property::InteractionVertex& FLEX::getInteractionVertex()
const{
400 return interactionVertex;
403 inline void FLEX::setSelfEnergy(
const Property::SelfEnergy &selfEnergy){
404 this->selfEnergy = selfEnergy;
407 inline const Property::SelfEnergy& FLEX::getSelfEnergy()
const{
411 inline void FLEX::setSelfEnergyMixingParameter(
412 double selfEnergyMixingParameter
414 this->selfEnergyMixingParameter = selfEnergyMixingParameter;
417 inline double FLEX::getDensity()
const{
420 "Solver::FLEX::getDensity()",
421 "This function is only available for non-negative target"
423 "Use Solver::FLEX::setTargetDensity() to set the target"
430 inline void FLEX::setTargetDensity(
double targetDensity){
431 this->targetDensity = targetDensity;
434 inline void FLEX::setDensityTolerance(
double densityTolerance){
435 this->densityTolerance = densityTolerance;
438 inline void FLEX::setChemicalPotentialStepSize(
439 double chemicalPotentialStepSize
441 this->chemicalPotentialStepSize = chemicalPotentialStepSize;
444 inline void FLEX::setEnergyWindow(
445 int lowerFermionicMatsubaraEnergyIndex,
446 int upperFermionicMatsubaraEnergyIndex,
447 int lowerBosonicMatsubaraEnergyIndex,
448 int upperBosonicMatsubaraEnergyIndex
451 lowerFermionicMatsubaraEnergyIndex
452 <= upperFermionicMatsubaraEnergyIndex,
453 "Solver::FLEX::setEnergyWindow()",
454 "The 'lowerFermionicMatsubaraEnergyIndex="
455 << lowerFermionicMatsubaraEnergyIndex <<
"' must be less or"
456 <<
" equal to the 'upperFermionicMatsubaraEnergyIndex="
457 << upperFermionicMatsubaraEnergyIndex <<
"'.",
461 lowerBosonicMatsubaraEnergyIndex
462 <= upperBosonicMatsubaraEnergyIndex,
463 "Solver::FLEX::setEnergyWindow()",
464 "The 'lowerBosonicMatsubaraEnergyIndex="
465 << lowerBosonicMatsubaraEnergyIndex <<
"' must be less or"
466 <<
" equal to the 'upperBosonicMatsubaraEnergyIndex="
467 << upperBosonicMatsubaraEnergyIndex <<
"'.",
471 this->lowerFermionicMatsubaraEnergyIndex
472 = lowerFermionicMatsubaraEnergyIndex;
473 this->upperFermionicMatsubaraEnergyIndex
474 = upperFermionicMatsubaraEnergyIndex;
475 this->lowerBosonicMatsubaraEnergyIndex
476 = lowerBosonicMatsubaraEnergyIndex;
477 this->upperBosonicMatsubaraEnergyIndex
478 = upperBosonicMatsubaraEnergyIndex;
481 inline void FLEX::setU(
double U){
485 inline void FLEX::setJ(
double J){
489 inline void FLEX::setUp(
double Up){
493 inline void FLEX::setJp(
double Jp){
497 inline void FLEX::setNumOrbitals(
unsigned int numOrbitals){
498 this->numOrbitals = numOrbitals;
501 inline FLEX::State FLEX::getState()
const{
505 inline void FLEX::setMaxIterations(
unsigned int maxIterations){
508 "Solver::FLEX::setMaxIterations()",
509 "'maxIterations=" << maxIterations <<
"' must be larger than"
514 this->maxIterations = maxIterations;
517 inline void FLEX::setNorm(Norm norm){
521 inline void FLEX::setTolerance(
double tolerance){
522 this->tolerance = tolerance;
525 inline void FLEX::setCallback(
void (*callback)(FLEX &solver)){
526 this->callback = callback;
529 inline void FLEX::setNumSlices(
unsigned int numSlices){
532 "Solver::FLEX::setNumSlices()",
533 "'numSlices' must be non-zero.",
537 this->numSlices = numSlices;