JDFTx  1.2.0
TranslationOperator_internal.h
1 /*-------------------------------------------------------------------
2 Copyright 2011 Ravishankar Sundararaman
3 
4 This file is part of JDFTx.
5 
6 JDFTx is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 JDFTx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with JDFTx. If not, see <http://www.gnu.org/licenses/>.
18 -------------------------------------------------------------------*/
19 
20 #ifndef JDFTX_FLUID_TRANSLATIONOPERATORINTERNAL_H
21 #define JDFTX_FLUID_TRANSLATIONOPERATORINTERNAL_H
22 
23 #include <core/vector3.h>
24 
26 __hostanddev__ int wrappedIndex(const vector3<int> i, const vector3<int> S)
27 {
28  vector3<int> iWrapped = i;
29  for(int k=0; k<3; k++) if(iWrapped[k]>=S[k]) iWrapped[k]-=S[k];
30  return iWrapped[2] + S[2]*(iWrapped[1] + S[1]*iWrapped[0]);
31 }
32 
33 __hostanddev__
34 void constantSplineTaxpy_calc(int yIndex, const vector3<int> iy, const vector3<int> S,
35  double alpha, const double* x, double* y, const vector3<int> Tint)
36 {
37  y[yIndex] += alpha * x[wrappedIndex(iy+Tint,S)];
38 }
39 
40 __hostanddev__
41 void linearSplineTaxpy_calc(int yIndex, const vector3<int> iy, const vector3<int> S,
42  double alpha, const double* x, double* y, const vector3<int> Tint, const vector3<> Tfrac)
43 {
44  //Weights for linear interpolation:
45  double w0[] = {1-Tfrac[0], Tfrac[0]};
46  double w1[] = {1-Tfrac[1], Tfrac[1]};
47  double w2[] = {1-Tfrac[2], Tfrac[2]};
48  vector3<int> ix = iy + Tint;
49  //Interpolate:
50  double temp0 = 0.0;
51  for(int i0=0; i0<2; i0++) //loop unrolled by default
52  { double temp1 = 0.0;
53  for(int i1=0; i1<2; i1++) //loop unrolled by default
54  { double temp2 = 0.0;
55  for(int i2=0; i2<2; i2++) //loop unrolled by default
56  { temp2 += w2[i2] * x[wrappedIndex(ix+vector3<int>(i0,i1,i2),S)];
57  }
58  temp1 += w1[i1] * temp2;
59  }
60  temp0 += w0[i0] * temp1;
61  }
62  y[yIndex] += alpha * temp0;
63 }
64 
65 __hostanddev__
66 void fourierTranslate_calc(int i, const vector3<int> iG, const vector3<int> S, const vector3<> Gt, complex* xTilde)
67 { xTilde[i] *= cis(-dot(iG,Gt));
68 }
69 
70 
71 #endif // JDFTX_FLUID_TRANSLATIONOPERATORINTERNAL_H
complex dot(const Tptr &X, const Tptr &Y)
Definition: Operators.h:196
Complex number (need to define our own because we need operators for gpu code as well) ...
Definition: scalar.h:49