Phoebe developer's documentation  1.1.0
Phonon and Electron Boltzmann Equations
interaction_elph.h
1 #ifndef EL_PH_INTERACTION_H
2 #define EL_PH_INTERACTION_H
3 
4 #include <complex>
5 
6 #include "constants.h"
7 #include "crystal.h"
8 #include "eigen.h"
9 #include "phonon_h0.h"
10 #include "points.h"
11 #include "utilities.h"
12 #include "context.h"
13 #include "common_kokkos.h"
14 #include <Kokkos_Core.hpp>
15 
29 // TODO: add flag to let user decide whether to use or not polar corrections
31 
32  Crystal crystal;
33  PhononH0 phononH0;
34  int numPhBands, numElBands, numWsR1Vectors, numWsR2Vectors;
35  std::vector<Eigen::Tensor<double, 3>> cacheCoupling;
36  bool usePolarCorrection = false;
37  const int phaseConvention;
38 
39  // kokkos objects for GPU accelerated elph coupling
40  ComplexView4D elPhCached;
41  ComplexView5D couplingWannier_k;
42  DoubleView2D wsR2Vectors_k;
43  DoubleView1D wsR2VectorsDegeneracies_k;
44  DoubleView2D wsR1Vectors_k;
45  DoubleView1D wsR1VectorsDegeneracies_k;
46  std::vector<ComplexView4D::HostMirror> elPhCached_hs;
47 
48  // TODO TEMPORARY, for old interpolation method
49  Eigen::MatrixXd wsR1Vectors;
50  Eigen::VectorXd wsR1VectorsDegeneracies;
51  Eigen::MatrixXd wsR2Vectors;
52  Eigen::VectorXd wsR2VectorsDegeneracies;
53  Eigen::Tensor<std::complex<double>, 4> elPhCached_old;
54  Eigen::Vector3d cachedK1;
55  Eigen::Tensor<std::complex<double>, 5> couplingWannier;
56 
57 #ifdef MPI_AVAIL
58  std::vector<MPI_Request> mpi_requests;
59 #endif
60 
61 public:
62 
63  // phase convention options -- TODO switch to ENUM
64  // Giustino uses Re, Rp for R vectors
65  // JDFTx uses Re, Re' R vectors
66  static const int GiustinoPhaseConvention = 0;
67  static const int JdftxPhaseConvention = 1;
68 
69  // spin types -- TODO switch to ENUM
70  static const int spinNonPolarized = 1;
71  static const int spinPolarizedOrSOC = 2;
72 
96  const Crystal& crystal_,
97  const Eigen::Tensor<std::complex<double>, 5> &couplingWannier_,
98  const Eigen::MatrixXd &wsR1Vectors_,
99  const Eigen::VectorXd &wsR1VectorsDegeneracies_,
100  const Eigen::MatrixXd &wsR2Vectors_,
101  const Eigen::VectorXd &wsR2VectorsDegeneracies_,
102  const int& phaseConvention, const PhononH0& phononH0_);
103 
104  void resetK1(); // just resets the first transform for a new cycle
105 
111  //InteractionElPhWan(Crystal &crystal_);
112 
115  //InteractionElPhWan(const InteractionElPhWan &that);
116 
119  //InteractionElPhWan &operator=(const InteractionElPhWan &that);
120 
124 
125  // Core elph interpolation functions --------------------------------
126 
155  void calcCouplingSquared(
156  const Eigen::MatrixXcd &eigvec1,
157  const std::vector<Eigen::MatrixXcd> &eigvecs2,
158  const std::vector<Eigen::MatrixXcd> &eigvecs3,
159  const std::vector<Eigen::Vector3d> &q3Cs,
160  const Eigen::Vector3d &k1C,
161  const std::vector<Eigen::VectorXcd> &polarData);
162 
163  void oldCalcCouplingSquared(
164  const Eigen::MatrixXcd &eigvec1,
165  const std::vector<Eigen::MatrixXcd> &eigvecs2,
166  const std::vector<Eigen::MatrixXcd> &eigvecs3, const Eigen::Vector3d &k1C,
167  const std::vector<Eigen::Vector3d> &k2Cs,
168  const std::vector<Eigen::Vector3d> &q3Cs);
169 
175  void cacheElPh(const Eigen::MatrixXcd &eigvec1, const Eigen::Vector3d &k1C);
176 
188  Eigen::Tensor<double, 3>& getCouplingSquared(const int &ik2);
189 
196  static InteractionElPhWan parse(Context &context, Crystal &crystal,
197  PhononH0& phononH0_);
198 
199  // Helper functions --------------------------------
200 
209  Eigen::Tensor<std::complex<double>, 3>
210  getPolarCorrection(const Eigen::Vector3d &q3, const Eigen::MatrixXcd &ev1,
211  const Eigen::MatrixXcd &ev2, const Eigen::MatrixXcd &ev3);
212 
218  double getDeviceMemoryUsage();
219 
223  Eigen::VectorXi getCouplingDimensions();
224 
231  int estimateNumBatches(const int &nk2, const int &nb1);
232 
233  // Internal polar correction functions --------------------------------
234 
235  // TODO these functions need full documentation
236 
237  // functions to help with the calculation of the polar correction
238  // as described in doi:10.1103/physRevLett.115.176401, Eq. 4
239 
240  // This calculates the long range V_L component of g_L, to be used
241  // in the qe->Wannier transformation
242  static Eigen::Tensor<std::complex<double>, 3> getPolarCorrectionStatic(
243  const Eigen::Vector3d &q3, const Eigen::MatrixXcd &ev1,
244  const Eigen::MatrixXcd &ev2, const Eigen::MatrixXcd &ev3,
245  const double &volume, const Eigen::Matrix3d &reciprocalUnitCell,
246  const Eigen::Matrix3d &epsilon,
247  const Eigen::Tensor<double, 3> &bornCharges,
248  const Eigen::MatrixXd &atomicPositions,
249  const Eigen::Vector3i &qCoarseMesh, const int dimensionality);
250 
251  // this function calculates V_L for the "static" case used in the bloch->Wannier transform
252  static Eigen::VectorXcd polarCorrectionPart1Static(
253  const Eigen::Vector3d &q3, const Eigen::MatrixXcd &ev3,
254  const double &volume, const Eigen::Matrix3d &reciprocalUnitCell,
255  const Eigen::Matrix3d &epsilon, const Eigen::Tensor<double, 3> &bornCharges,
256  const Eigen::MatrixXd &atomicPositions,
257  const Eigen::Vector3i &qCoarseMesh, const int dimensionality);
258 
259  // Sets up a call to polarCorrectionPart1Static for the calculation of V_L
260  // during wannier interpolation of the matrix elements
261  // TODO this function is also public because of elph coupling app.
262  // seems like it should be private
263  Eigen::VectorXcd polarCorrectionPart1(
264  const Eigen::Vector3d &q3, const Eigen::MatrixXcd &ev3);
265 
266  // adds the transformation of V_L to the wannier gauge
267  // regardless of the use case, this calculates <psi|e^{i(G+q).r}|psi> part of polar correction
268  static Eigen::Tensor<std::complex<double>, 3> polarCorrectionPart2(
269  const Eigen::MatrixXcd &ev1, const Eigen::MatrixXcd &ev2, const Eigen::VectorXcd &x);
270 
276  Eigen::MatrixXcd precomputeQDependentPolar(BaseBandStructure &phBandStructure,
277  const bool useMinusQ = false);
278 
279 };
280 
281 #endif
Base class for describing objects containing the band structure, i.e.
Definition: bandstructure.h:15
Class containing the user input variables.
Definition: context.h:15
Object to store the information on the crystal unit cell, such as atomic positions,...
Definition: crystal.h:18
Class to handle the coupling between electron and phonons.
Definition: interaction_elph.h:30
double getDeviceMemoryUsage()
Estimate the memory in bytes, occupied by the kokkos Views containing the coupling tensor to be inter...
Definition: interaction_elph.cpp:895
Eigen::VectorXi getCouplingDimensions()
Auxiliary function to return the shape of the electron-phonon tensor.
Definition: interaction_elph.cpp:617
Eigen::MatrixXcd precomputeQDependentPolar(BaseBandStructure &phBandStructure, const bool useMinusQ=false)
precompute the q-dependent part of the polar correction
Definition: interaction_elph.cpp:113
void cacheElPh(const Eigen::MatrixXcd &eigvec1, const Eigen::Vector3d &k1C)
Computes a partial Fourier transform over the k1/R_el variables.
Definition: interaction_elph.cpp:660
Eigen::Tensor< double, 3 > & getCouplingSquared(const int &ik2)
Get the coupling for the values of the wavevectors triplet (k1,k2,q3), where k1 is the wavevector use...
Definition: interaction_elph.cpp:87
InteractionElPhWan(const Crystal &crystal_, const Eigen::Tensor< std::complex< double >, 5 > &couplingWannier_, const Eigen::MatrixXd &wsR1Vectors_, const Eigen::VectorXd &wsR1VectorsDegeneracies_, const Eigen::MatrixXd &wsR2Vectors_, const Eigen::VectorXd &wsR2VectorsDegeneracies_, const int &phaseConvention, const PhononH0 &phononH0_)
Main constructor.
Definition: interaction_elph.cpp:11
static InteractionElPhWan parse(Context &context, Crystal &crystal, PhononH0 &phononH0_)
Static method to initialize the class by parsing a file.
Definition: interaction_elph_parsing.cpp:747
int estimateNumBatches(const int &nk2, const int &nb1)
Estimate the number of batches that the list of k2 wavevectors must be split into,...
Definition: interaction_elph.cpp:625
~InteractionElPhWan()
Almost empty constructor.
Definition: interaction_elph.cpp:79
void calcCouplingSquared(const Eigen::MatrixXcd &eigvec1, const std::vector< Eigen::MatrixXcd > &eigvecs2, const std::vector< Eigen::MatrixXcd > &eigvecs3, const std::vector< Eigen::Vector3d > &q3Cs, const Eigen::Vector3d &k1C, const std::vector< Eigen::VectorXcd > &polarData)
Computes the values of the el-ph coupling strength for transitions of type k1,q3 -> k2,...
Definition: interaction_elph.cpp:351
Eigen::Tensor< std::complex< double >, 3 > getPolarCorrection(const Eigen::Vector3d &q3, const Eigen::MatrixXcd &ev1, const Eigen::MatrixXcd &ev2, const Eigen::MatrixXcd &ev3)
Add polar correction to the electron-phonon coupling.
Definition: interaction_elph.cpp:94
class that computes phonon energies, velocities and eigenvectors.
Definition: phonon_h0.h:21