20 #ifndef JDFTX_CORE_COULOMB_INTERNAL_H 21 #define JDFTX_CORE_COULOMB_INTERNAL_H 25 #include <core/matrix3.h> 27 #include <gsl/gsl_integration.h> 30 #define wsTruncationPaper "R. Sundararaman and T.A. Arias, Phys. Rev. B 87, 165122 (2013)" 31 #define invariantTruncationPaper "S. Ismail-Beigi, Phys. Rev. B 73, 233103 (2006)" 32 #define expandedTruncationPaper "C.A. Rozzi et al., Phys. Rev. B 73, 205119 (2006)" 35 #define ionMarginMessage "Expand unit cell, or if absolutely sure, reduce coulomb-truncation-ion-margin.\n" 40 {
double Gsq = GGT.metric_length_squared(iG);
41 return Gsq ? (4*M_PI)/Gsq : 0.;
47 {
int iDir;
double hlfL;
50 {
double Gsq = GGT.metric_length_squared(iG);
51 double Gplane = Gsq - GGT(iDir,iDir) * iG[iDir]*iG[iDir];
52 Gplane = Gplane>0. ?
sqrt(Gplane) : 0.;
53 return (4*M_PI) * (Gsq ? (1. -
exp(-Gplane*hlfL) * cos(M_PI*iG[iDir]))/Gsq : -0.5*hlfL*hlfL);
62 {
double Gsq = GGT.metric_length_squared(iG);
63 return Gsq ? (4*M_PI) * (1. - cos(Rc*
sqrt(Gsq)))/Gsq : (2*M_PI)*Rc*Rc;
79 if(xSq<1e-6)
return (1./
sqrt(M_PI))*(2. - xSq*(2./3 + 0.2*xSq));
92 double operator()(
double k,
double sigma,
double rho,
double rho0=1.);
94 static const size_t maxIntervals = 1000;
95 gsl_integration_workspace* iWS;
96 static double integrandSmallRho(
double t,
void* params);
97 static double integrandLargeRho(
double t,
void* params);
102 {
Cbar_k_sigma(
double k,
double sigma,
double rhoMax,
double rho0=1.);
104 inline double value(
double rho)
const 106 return isLog ?
exp(f) : f;
109 inline double deriv(
double rho)
const 111 return isLog ? fp *
value(rho) : fp;
114 double drhoInv;
bool isLog;
115 std::vector<double> coeff;
126 __hostanddev__
double erfcTilde(
double Gsq,
double omegaSq)
127 {
return (4*M_PI) * (omegaSq ? (1.-
exp(-0.25*Gsq/omegaSq)) : 1.) / Gsq;
133 { __hostanddev__
double operator()(
double kSq)
const 134 {
return (4*M_PI) / kSq;
143 __hostanddev__
double operator()(
double kSq)
const 144 {
return (4*M_PI) * (1.-
exp(-inv4omegaSq*kSq)) / kSq;
153 __hostanddev__
double operator()(
double kSq)
const 154 {
return (4*M_PI) * (1. - cos(Rc *
sqrt(kSq))) / kSq;
165 __hostanddev__
double operator()(
double kSq)
const 166 {
double t = dGinv *
sqrt(kSq);
167 if(t >= nSamples)
return 0.;
174 {
int iDir;
double hlfL;
175 double* coeff;
double dGinv;
size_t nSamples, nCoeff;
179 double Gsq = GGT.metric_length_squared(g);
180 if(Gsq < thresholdSq)
182 double Gplane = Gsq - GGT(iDir,iDir) * iG[iDir]*iG[iDir];
183 Gplane = Gplane>0. ?
sqrt(Gplane) : 0.;
184 double Vc = (4*M_PI) * (1. -
exp(-Gplane*hlfL) * cos(M_PI*iG[iDir]))/Gsq;
187 const double* coeffPlane = coeff + abs(iG[iDir]) * nCoeff;
188 double t = dGinv * Gplane;
189 double prefac = iG[iDir] ? 1. : 1./Gplane;
211 __hostanddev__
void multRealKernel_calc(
size_t i,
const vector3<int>& iG,
215 if(iGreal[2]<0) iGreal = -iGreal;
216 if(iGreal[1]<0) iGreal[1] += S[1];
217 if(iGreal[0]<0) iGreal[0] += S[0];
218 size_t iReal = iGreal[2] + size_t(1+S[2]/2) * (iGreal[1] + S[1]*iGreal[0]);
220 data[i] *= kernel[iReal];
228 __hostanddev__
void multTransformedKernel_calc(
size_t i,
const vector3<int>& iG,
231 for(
int k=0; k<3; k++)
if(iGkernel[k]<0) iGkernel[k] += S[k];
232 size_t iReal = iGkernel[2] + S[2]*size_t(iGkernel[1] + S[1]*iGkernel[0]);
233 data[i] *= kernel[iReal];
240 #endif // JDFTX_CORE_COULOMB_INTERNAL_H double inv4omegaSq
1/(4 omega^2)
Definition: Coulomb_internal.h:140
double dGinv
inverse of coefficient spacing
Definition: Coulomb_internal.h:161
ScalarField sqrt(const ScalarField &)
Elementwise square root (preserve input)
Erfc-screened Spherical-truncated exchange.
Definition: Coulomb_internal.h:159
Compute Cbar_k^sigma - the gaussian convolved cylindrical coulomb kernel - by numerical quadrature...
Definition: Coulomb_internal.h:89
Sphere-truncated coulomb interaction.
Definition: Coulomb_internal.h:58
__hostanddev__ double value(const double *coeff, double x)
Compute value of quintic spline. Warning: x is not range-checked.
__hostanddev__ double erfcTilde(double Gsq, double omegaSq)
Radial fourier transform of erfc(omega r)/r (not valid at G=0)
Definition: Coulomb_internal.h:126
double deriv(double rho) const
Get derivative:
Definition: Coulomb_internal.h:109
double value(double rho) const
Get value:
Definition: Coulomb_internal.h:104
Periodic exchange.
Definition: Coulomb_internal.h:132
Look-up table for Cbar_k^sigma(rho) for specific values of k and sigma.
Definition: Coulomb_internal.h:101
Slab-truncated exchange.
Definition: Coulomb_internal.h:173
__hostanddev__ double erf_by_x(double x)
Compute erf(x)/x (with x~0 handled properly)
Definition: Coulomb_internal.h:77
Periodic coulomb interaction (4 pi/G^2)
Definition: Coulomb_internal.h:38
ScalarField exp(const ScalarField &)
Elementwise exponential (preserve input)
double * coeff
quintic spline coefficients
Definition: Coulomb_internal.h:160
Erfc-screened Periodic exchange.
Definition: Coulomb_internal.h:139
Spherical-truncated exchange.
Definition: Coulomb_internal.h:149
__hostanddev__ double deriv(const double *coeff, double x)
Compute derivative (w.r.t x) of quintic spline. Warning: x is not range-checked.
Spline interpolation routines.
Complex number (need to define our own because we need operators for gpu code as well) ...
Definition: scalar.h:49
size_t nSamples
number of coefficients
Definition: Coulomb_internal.h:162
Slab-truncated coulomb interaction.
Definition: Coulomb_internal.h:46