24 #ifndef COM_DAFER45_TBTK_SELF_ENERGY_CALCULATOR
25 #define COM_DAFER45_TBTK_SELF_ENERGY_CALCULATOR
27 #include "BrillouinZone.h"
28 #include "BlockDiagonalizationSolver.h"
29 #include "BPropertyExtractor.h"
31 #include "SusceptibilityCalculator.h"
35 class SelfEnergyCalculator{
39 const MomentumSpaceContext &momentumSpaceContext,
40 unsigned int numWorkers
44 ~SelfEnergyCalculator();
47 const MomentumSpaceContext& getMomentumSpaceContext()
const;
54 enum class EnergyType {Real, Imaginary, Complex};
57 void setNumSummationEnergies(
unsigned int numSummationEnergies);
60 void setSelfEnergyEnergyType(EnergyType energyType);
63 EnergyType getSelfEnergyEnergyType()
const;
67 void setSelfEnergyEnergies(
68 const std::vector<std::complex<double>> &selfEnergyEnergies
72 std::vector<std::complex<double>> calculateSelfEnergy(
73 const std::vector<double> &k,
74 const std::vector<int> &orbitalIndices
78 std::vector<std::complex<double>> calculateSelfEnergySelfConsistently(
79 unsigned int numMatsubaraFrequencies
83 std::vector<std::complex<double>> calculateSelfEnergyVertex(
84 const std::vector<double> &k,
85 const std::vector<int> &orbitalIndices,
90 void setU(std::complex<double> U);
93 void setUp(std::complex<double> Up);
96 void setJ(std::complex<double> J);
99 void setJp(std::complex<double> Jp);
105 void saveSusceptibilities(
const std::string &filename)
const;
108 void loadSusceptibilities(
const std::string &filename);
111 std::vector<SusceptibilityCalculator*> susceptibilityCalculators;
114 int *kMinusQLookupTable;
118 void generateKMinusQLookupTable();
121 template<
bool useKPlusKLookupTable>
122 int getKMinusQLinearIndex(
123 unsigned int meshIndex,
124 const std::vector<double> &k,
129 unsigned int numSummationEnergies;
132 std::vector<std::complex<double>> summationEnergies;
135 EnergyType selfEnergyEnergyType;
138 std::vector<std::complex<double>> selfEnergyEnergies;
144 IndexedDataTree<SerializeableVector<std::complex<double>>> selfEnergyTree;
147 SerializeableVector<IndexedDataTree<SerializeableVector<std::complex<double>>>> selfEnergyVertexTrees;
151 std::complex<double> *matrix,
152 unsigned int dimensions
156 void multiplyMatrices(
157 std::complex<double> *matrix1,
158 std::complex<double> *matrix2,
159 std::complex<double> *result,
160 unsigned int dimensions
165 std::complex<double> *matrix,
166 unsigned int dimensions
170 template<
bool singleSelfEnergyEnergy>
171 void selfEnergyMainLoop(
172 const std::vector<double> &k,
173 const std::vector<int> &orbitalIndices,
174 std::vector<std::complex<double>> &result
178 std::complex<double> U, Up, J, Jp;
181 std::vector<InteractionAmplitude> u1;
182 std::vector<InteractionAmplitude> u2;
183 std::vector<InteractionAmplitude> u3;
187 bool interactionAmplitudesAreGenerated;
191 void generateInteractionAmplitudes();
194 inline const MomentumSpaceContext& SelfEnergyCalculator::getMomentumSpaceContext(
196 return susceptibilityCalculators[0]->getMomentumSpaceContext();
199 inline void SelfEnergyCalculator::setNumSummationEnergies(
200 unsigned int numSummationEnergies
202 this->numSummationEnergies = numSummationEnergies;
205 inline void SelfEnergyCalculator::setSelfEnergyEnergyType(
206 EnergyType energyType
208 selfEnergyEnergyType = energyType;
211 inline SelfEnergyCalculator::EnergyType SelfEnergyCalculator::getSelfEnergyEnergyType(
213 return selfEnergyEnergyType;
216 inline void SelfEnergyCalculator::setSelfEnergyEnergies(
217 const std::vector<std::complex<double>> &selfEnergyEnergies
219 this->selfEnergyEnergies = selfEnergyEnergies;
220 selfEnergyTree.clear();
222 for(
unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
223 selfEnergyVertexTrees[n].clear();
226 inline void SelfEnergyCalculator::setU(std::complex<double> U){
229 for(
unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
230 susceptibilityCalculators[n]->setU(U);
232 selfEnergyTree.clear();
234 for(
unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
235 selfEnergyVertexTrees[n].clear();
237 interactionAmplitudesAreGenerated =
false;
240 inline void SelfEnergyCalculator::setUp(std::complex<double> Up){
243 for(
unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
244 susceptibilityCalculators[n]->setUp(Up);
246 selfEnergyTree.clear();
248 for(
unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
249 selfEnergyVertexTrees[n].clear();
251 interactionAmplitudesAreGenerated =
false;
254 inline void SelfEnergyCalculator::setJ(std::complex<double> J){
257 for(
unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
258 susceptibilityCalculators[n]->setJ(J);
260 selfEnergyTree.clear();
262 for(
unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
263 selfEnergyVertexTrees[n].clear();
265 interactionAmplitudesAreGenerated =
false;
268 inline void SelfEnergyCalculator::setJp(std::complex<double> Jp){
271 for(
unsigned int n = 0; n < susceptibilityCalculators.size(); n++)
272 susceptibilityCalculators[n]->setJp(Jp);
274 selfEnergyTree.clear();
276 for(
unsigned int n = 0; n < selfEnergyVertexTrees.size(); n++)
277 selfEnergyVertexTrees[n].clear();
279 interactionAmplitudesAreGenerated =
false;
288 inline void SelfEnergyCalculator::saveSusceptibilities(
289 const std::string &filename
291 unsigned int lastPos = filename.find_last_of(
'/');
293 std::string fname = filename;
294 if(lastPos != std::string::npos){
295 path = filename.substr(0, lastPos+1);
296 fname = filename.substr(lastPos+1, filename.size());
299 for(
unsigned int n = 0; n < susceptibilityCalculators.size(); n++){
300 susceptibilityCalculators[n]->saveSusceptibilities(
301 path +
"Slice" + std::to_string(n) +
"_" + fname
306 inline void SelfEnergyCalculator::loadSusceptibilities(
307 const std::string &filename
309 unsigned int lastPos = filename.find_last_of(
'/');
311 std::string fname = filename;
312 if(lastPos != std::string::npos){
313 path = filename.substr(0, lastPos+1);
314 fname = filename.substr(lastPos+1, filename.size());
317 for(
unsigned int n = 0; n < susceptibilityCalculators.size(); n++){
318 susceptibilityCalculators[n]->loadSusceptibilities(
319 path +
"Slice" + std::to_string(n) +
"_" + fname