20 #ifndef JDFTX_ELECTRONIC_OPERATORS_INTERNAL_H 21 #define JDFTX_ELECTRONIC_OPERATORS_INTERNAL_H 23 #include <core/matrix3.h> 24 #include <electronic/RadialFunction.h> 25 #include <electronic/SphericalHarmonics.h> 31 #define assert(expr) (void)((expr) ? 0 : assertStackTraceExit(#expr, __func__, __FILE__, __LINE__)) 36 template<
typename T,
int N>
39 array(
const std::vector<T>& vec) {
assert(N==
int(vec.size()));
for(
int s=0; s<N; s++) arr[s]=vec[s]; }
40 __hostanddev__
array(T t=0) {
for(
int s=0; s<N; s++) arr[s]=t; }
41 __hostanddev__ T& operator[](
int i) {
return arr[i]; }
42 __hostanddev__
const T& operator[](
int i)
const {
return arr[i]; }
52 { out[i] = in[i] * (-
dot(iG,Ge1) *
dot(iG,Ge2));
56 #define SwitchTemplate_l(l,fTemplate,argList) \ 58 { case 0: fTemplate<0> argList; break; \ 59 case 1: fTemplate<1> argList; break; \ 60 case 2: fTemplate<2> argList; break; \ 61 case 3: fTemplate<3> argList; break; \ 62 case 4: fTemplate<4> argList; break; \ 63 case 5: fTemplate<5> argList; break; \ 64 case 6: fTemplate<6> argList; break; \ 69 { out[lpm][i] = phasedIn * Ylm<l,lpm-l>(g);
76 {
const complex phase = cis(l*0.5*M_PI);
88 {
const complex phase = cis(l*0.5*M_PI);
94 {
return cis(2*M_PI*
dot(k,
vector3<>(iv[0]*invS[0], iv[1]*invS[1], iv[2]*invS[2])));
97 template<
typename scalar> __hostanddev__
99 const scalar* in, scalar* out,
const matrix3<int>& mMesh)
102 for(
int j=0; j<3; j++)
103 { ivRot[j] = ivRot[j] % S[j];
104 if(ivRot[j]<0) ivRot[j] += S[j];
106 int iRot = ivRot[2]+S[2]*(ivRot[1]+S[1]*ivRot[0]);
111 {
return f(
sqrt(GGT.metric_length_squared(iG))) * cis(-2*M_PI*
dot(iG,r0));
114 __hostanddev__
void reducedL_calc(
int j,
int nbasis,
int ncols,
const complex* Y,
complex* LY,
116 {
for (
int i=0; i < ncols; i++)
117 LY[nbasis*i+j] = (-detR * GGT.metric_length_squared(iGarr[j]+k)) * Y[nbasis*i+j];
119 __hostanddev__
void reducedLinv_calc(
int j,
int nbasis,
int ncols,
const complex* Y,
complex* LinvY,
121 {
for (
int i=0; i < ncols; i++)
122 {
double G2 = GGT.metric_length_squared(iGarr[j]+k);
123 LinvY[nbasis*i+j] = (G2 ? -1./(detR*G2) : 0.) * Y[nbasis*i+j];
127 __hostanddev__
void precond_inv_kinetic_calc(
int j,
int nbasis,
int ncols,
complex* Ydata,
130 double x = 0.5*GGT.metric_length_squared(iGarr[j]+k)/KErollover;
131 double precondFactor = 1.+x*(1.+x*(1.+x*(1.+x*(1.+x*(1.+x*(1.+x*(1.+x)))))));
132 precondFactor = precondFactor*invdetR/(1.+x*precondFactor);
133 for(
int i=0; i < ncols; i++)
134 Ydata[nbasis*i+j] *= precondFactor;
137 __hostanddev__
void precond_inv_kinetic_band_calc(
int j,
int nbasis,
int ncols,
complex* Ydata,
const double* KEref,
140 double KE = 0.5*GGT.metric_length_squared(iGarr[j]+k);
141 for(
int i=0; i<ncols; i++)
142 {
double x = KE/KEref[i];
143 Ydata[nbasis*i+j] *= (27.+x*(18.+x*(12.+x*8.))) / (27.+x*(18.+x*(12.+x*(8.+x*16))));
149 {
complex tFactor = cis(-2*M_PI*
dot(iGarr[j]+k,dr));
150 for(
int i=0; i<ncols; i++)
151 Y[nbasis*i+j] *= tFactor;
156 {
for(
int i=0; i<ncols; i++)
157 Y[nbasis*i+j] *= cis(-2*M_PI*
dot(iGarr[j]+k,dr[i]));
160 __hostanddev__
void reducedD_calc(
int j,
int nbasis,
int ncols,
const complex* Ydata,
complex* DYdata,
164 for(
int i=0; i < ncols; i++)
165 DYdata[nbasis*i+j] = Di*Ydata[nbasis*i+j];
168 __hostanddev__
void reducedDD_calc(
int j,
int nbasis,
int ncols,
const complex* Ydata,
complex* DYdata,
173 for(
int i=0; i < ncols; i++)
174 DYdata[nbasis*i+j] = Di*Dj*Ydata[nbasis*i+j];
177 #endif // JDFTX_ELECTRONIC_OPERATORS_INTERNAL_H ScalarField sqrt(const ScalarField &)
Elementwise square root (preserve input)
complex dot(const Tptr &X, const Tptr &Y)
Definition: Operators.h:196
Definition: operators_internal.h:67
int assertStackTraceExit(const char *expr, const char *function, const char *file, long line)
Definition: operators_internal.h:37
G-space radial function stored on a uniform grid (of |G|)
Definition: RadialFunction.h:28
Definition: operators_internal.h:80
Complex number (need to define our own because we need operators for gpu code as well) ...
Definition: scalar.h:49
#define assert(expr)
A custom assertion with stack trace (NOTE: enabled in release modes as well)
Definition: Util.h:100