TBTK
Need a break? Support the development by playing Polarity Puzzles
FLEX.h
1 /* Copyright 2018 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_FLEX
25 #define COM_DAFER45_TBTK_SOLVER_FLEX
26 
27 #include "TBTK/MomentumSpaceContext.h"
29 #include "TBTK/Property/Susceptibility.h"
30 #include "TBTK/Property/InteractionVertex.h"
31 #include "TBTK/Property/SelfEnergy.h"
32 #include "TBTK/Solver/Solver.h"
33 
34 namespace TBTK{
35 namespace Solver{
36 
37 class FLEX : public Solver{
38 public:
40  enum class State {
41  NotYetStarted,
42  GreensFunctionCalculated,
43  BareSusceptibilityCalculated,
44  RPASusceptibilitiesCalculated,
45  InteractionVertexCalculated,
46  SelfEnergyCalculated
47  };
48 
51  enum class Norm{Max, L2};
52 
54  FLEX(const MomentumSpaceContext &momentumSpaceContext);
55 
57  const MomentumSpaceContext& getMomentumSpaceContext() const;
58 
62  const Property::GreensFunction& getGreensFunction() const;
63 
67  const Property::Susceptibility& getBareSusceptibility() const;
68 
72  const Property::Susceptibility& getRPASpinSusceptibility() const;
73 
77  const Property::Susceptibility& getRPAChargeSusceptibility() const;
78 
82  const Property::InteractionVertex& getInteractionVertex() const;
83 
87  void setSelfEnergy(const Property::SelfEnergy &selfEnergy);
88 
92  const Property::SelfEnergy& getSelfEnergy() const;
93 
99  void setSelfEnergyMixingParameter(double selfEnergyMixingParameter);
100 
116  void setEnergyWindow(
117  int lowerFermionicMatsubaraEnergyIndex,
118  int upperFermionicMatsubaraEnergyIndex,
119  int lowerBosonicMatsubaraEnergyIndex,
120  int upperBosonicMatsubaraEnergyIndex
121  );
122 
126  void setU(double U);
127 
131  void setJ(double J);
132 
136  void setUp(double Up);
137 
141  void setJp(double Jp);
142 
146  void setNumOrbitals(unsigned int numOrbitals);
147 
151  double getDensity() const;
152 
161  void setTargetDensity(double targetDensity);
162 
167  void setDensityTolerance(double densityTolerance);
168 
173  void setChemicalPotentialStepSize(double chemicalPotentialStepSize);
174 
178  State getState() const;
179 
184  void setMaxIterations(unsigned int maxIterations);
185 
190  void setNorm(Norm norm);
191 
196  void setTolerance(double tolerance);
197 
202  void setCallback(void (*callback)(FLEX &solver));
203 
212  void setNumSlices(unsigned int numSlices);
213 
215  void run();
216 private:
218  const MomentumSpaceContext momentumSpaceContext;
219 
221  Property::GreensFunction greensFunction0;
222 
224  Property::GreensFunction greensFunction;
225 
227  Property::GreensFunction oldGreensFunction;
228 
230  Property::Susceptibility bareSusceptibility;
231 
233  Property::Susceptibility rpaSpinSusceptibility;
234 
236  Property::Susceptibility rpaChargeSusceptibility;
237 
239  Property::InteractionVertex interactionVertex;
240 
242  Property::SelfEnergy selfEnergy;
243 
245  Property::SelfEnergy previousSelfEnergy;
246 
249  double selfEnergyMixingParameter;
250 
252  double density;
253 
255  double targetDensity;
256 
258  double densityTolerance;
259 
261  double chemicalPotentialStepSize;
262 
264  int lowerFermionicMatsubaraEnergyIndex;
265 
267  int upperFermionicMatsubaraEnergyIndex;
268 
270  int lowerBosonicMatsubaraEnergyIndex;
271 
273  int upperBosonicMatsubaraEnergyIndex;
274 
276  double U;
277 
279  double J;
280 
282  double Up;
283 
285  double Jp;
286 
288  unsigned int numOrbitals;
289 
291  State state;
292 
294  unsigned int maxIterations;
295 
297  Norm norm;
298 
301  double tolerance;
302 
305  unsigned int numSlices;
306 
309  double convergenceParameter;
310 
312  void (*callback)(FLEX &solver);
313 
315  void calculateBareGreensFunction();
316 
318  void calculateBareSusceptibility(unsigned int slice);
319 
321  void calculateRPASusceptibilities();
322 
324  void calculateInteractionVertex();
325 
327  void calculateSelfEnergy(unsigned int slice);
328 
330  void calculateGreensFunction();
331 
335  void convertSelfEnergyIndexStructure();
336 
340  void calculateConvergenceParameter();
341 
344  std::vector<InteractionAmplitude>
345  generateRPAChargeSusceptibilityInteractionAmplitudes();
346 
348  std::vector<InteractionAmplitude>
349  generateRPASpinSusceptibilityInteractionAmplitudes();
350 
352  std::vector<InteractionAmplitude> generateU1();
353 
355  std::vector<InteractionAmplitude> generateU2();
356 
358  std::vector<InteractionAmplitude> generateU3();
359 
361  std::vector<InteractionAmplitude> generateU4();
362 
364  Property::InteractionVertex generateHartreeFockTerm();
365 
367  void calculateDensity();
368 
371  int getLowerBosonicMatsubaraEnergyIndex(unsigned int slice);
372 
375  int getUpperBosonicMatsubaraEnergyIndex(unsigned int slice);
376 };
377 
378 inline const MomentumSpaceContext& FLEX::getMomentumSpaceContext() const{
379  return momentumSpaceContext;
380 }
381 
382 inline const Property::GreensFunction& FLEX::getGreensFunction() const{
383  return greensFunction;
384 }
385 
386 inline const Property::Susceptibility& FLEX::getBareSusceptibility() const{
387  return bareSusceptibility;
388 }
389 
390 inline const Property::Susceptibility& FLEX::getRPASpinSusceptibility() const{
391  return rpaSpinSusceptibility;
392 }
393 
394 inline const Property::Susceptibility& FLEX::getRPAChargeSusceptibility(
395 ) const{
396  return rpaChargeSusceptibility;
397 }
398 
399 inline const Property::InteractionVertex& FLEX::getInteractionVertex() const{
400  return interactionVertex;
401 }
402 
403 inline void FLEX::setSelfEnergy(const Property::SelfEnergy &selfEnergy){
404  this->selfEnergy = selfEnergy;
405 }
406 
407 inline const Property::SelfEnergy& FLEX::getSelfEnergy() const{
408  return selfEnergy;
409 }
410 
411 inline void FLEX::setSelfEnergyMixingParameter(
412  double selfEnergyMixingParameter
413 ){
414  this->selfEnergyMixingParameter = selfEnergyMixingParameter;
415 }
416 
417 inline double FLEX::getDensity() const{
418  TBTKAssert(
419  targetDensity >= 0,
420  "Solver::FLEX::getDensity()",
421  "This function is only available for non-negative target"
422  << " densities.",
423  "Use Solver::FLEX::setTargetDensity() to set the target"
424  << " density."
425  );
426 
427  return density;
428 }
429 
430 inline void FLEX::setTargetDensity(double targetDensity){
431  this->targetDensity = targetDensity;
432 }
433 
434 inline void FLEX::setDensityTolerance(double densityTolerance){
435  this->densityTolerance = densityTolerance;
436 }
437 
438 inline void FLEX::setChemicalPotentialStepSize(
439  double chemicalPotentialStepSize
440 ){
441  this->chemicalPotentialStepSize = chemicalPotentialStepSize;
442 }
443 
444 inline void FLEX::setEnergyWindow(
445  int lowerFermionicMatsubaraEnergyIndex,
446  int upperFermionicMatsubaraEnergyIndex,
447  int lowerBosonicMatsubaraEnergyIndex,
448  int upperBosonicMatsubaraEnergyIndex
449 ){
450  TBTKAssert(
451  lowerFermionicMatsubaraEnergyIndex
452  <= upperFermionicMatsubaraEnergyIndex,
453  "Solver::FLEX::setEnergyWindow()",
454  "The 'lowerFermionicMatsubaraEnergyIndex="
455  << lowerFermionicMatsubaraEnergyIndex << "' must be less or"
456  << " equal to the 'upperFermionicMatsubaraEnergyIndex="
457  << upperFermionicMatsubaraEnergyIndex << "'.",
458  ""
459  );
460  TBTKAssert(
461  lowerBosonicMatsubaraEnergyIndex
462  <= upperBosonicMatsubaraEnergyIndex,
463  "Solver::FLEX::setEnergyWindow()",
464  "The 'lowerBosonicMatsubaraEnergyIndex="
465  << lowerBosonicMatsubaraEnergyIndex << "' must be less or"
466  << " equal to the 'upperBosonicMatsubaraEnergyIndex="
467  << upperBosonicMatsubaraEnergyIndex << "'.",
468  ""
469  );
470 
471  this->lowerFermionicMatsubaraEnergyIndex
472  = lowerFermionicMatsubaraEnergyIndex;
473  this->upperFermionicMatsubaraEnergyIndex
474  = upperFermionicMatsubaraEnergyIndex;
475  this->lowerBosonicMatsubaraEnergyIndex
476  = lowerBosonicMatsubaraEnergyIndex;
477  this->upperBosonicMatsubaraEnergyIndex
478  = upperBosonicMatsubaraEnergyIndex;
479 }
480 
481 inline void FLEX::setU(double U){
482  this->U = U;
483 }
484 
485 inline void FLEX::setJ(double J){
486  this->J = J;
487 }
488 
489 inline void FLEX::setUp(double Up){
490  this->Up = Up;
491 }
492 
493 inline void FLEX::setJp(double Jp){
494  this->Jp = Jp;
495 }
496 
497 inline void FLEX::setNumOrbitals(unsigned int numOrbitals){
498  this->numOrbitals = numOrbitals;
499 }
500 
501 inline FLEX::State FLEX::getState() const{
502  return state;
503 }
504 
505 inline void FLEX::setMaxIterations(unsigned int maxIterations){
506  TBTKAssert(
507  maxIterations > 0,
508  "Solver::FLEX::setMaxIterations()",
509  "'maxIterations=" << maxIterations << "' must be larger than"
510  << " zero.",
511  ""
512  );
513 
514  this->maxIterations = maxIterations;
515 }
516 
517 inline void FLEX::setNorm(Norm norm){
518  this->norm = norm;
519 }
520 
521 inline void FLEX::setTolerance(double tolerance){
522  this->tolerance = tolerance;
523 }
524 
525 inline void FLEX::setCallback(void (*callback)(FLEX &solver)){
526  this->callback = callback;
527 }
528 
529 inline void FLEX::setNumSlices(unsigned int numSlices){
530  TBTKAssert(
531  numSlices != 0,
532  "Solver::FLEX::setNumSlices()",
533  "'numSlices' must be non-zero.",
534  ""
535  );
536 
537  this->numSlices = numSlices;
538 }
539 
540 }; //End of namespace Solver
541 }; //End of namespace TBTK
542 
543 #endif
544 
Property container for the Green&#39;s function.
Base class for Solvers.
Definition: Boolean.h:32