JDFTx  1.2.0
RadialFunction.h
1 /*-------------------------------------------------------------------
2 Copyright 2012 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_ELECTRONIC_RADIALFUNCTION_H
21 #define JDFTX_ELECTRONIC_RADIALFUNCTION_H
22 
23 #include <core/Spline.h>
24 
25 struct RadialFunctionR;
26 
29 {
30  double dGinv;
31  int nCoeff;
32  std::vector<double> coeff;
33  #ifdef GPU_ENABLED
34  double* coeffGpu;
35  const double* coeffPref() const { return coeffGpu; }
36  #else
37  const double* coeffPref() const { return coeff.data(); }
38  #endif
39 
40  //Access appropriate coefficients depending on whether called from CPU/GPU
41  __hostanddev__ const double* getCoeff() const
42  {
43  #ifdef __CUDA_ARCH__
44  return coeffGpu;
45  #else
46  return coeff.data();
47  #endif
48  }
49 
51  void init(int l, int nSamples, double dG, const char* filename, double scale=1.0);
52  void init(int l, const std::vector<double>& samples, double dG);
53  void set(const std::vector<double>& coeff, double dGInv);
54  void updateGmax(int l, int nSamples);
55  void free(bool rFuncDelete=true);
56 
58  __hostanddev__ double operator()(double G) const
59  { double Gindex = G * dGinv;
60  if(Gindex >= nCoeff-5) return 0.;
61  else return QuinticSpline::value(getCoeff(), Gindex);
62  }
63 
65 
66  #ifndef __in_a_cu_file__
67  template<typename Func, typename... Args> void init(int l, double dG, double Gmax, const Func& func, Args... args)
69  { std::vector<double> samples(unsigned(ceil(Gmax/dG))+5);
70  for(unsigned i=0; i<samples.size(); i++) samples[i] = func(i*dG, args...);
71  init(l, samples, dG);
72  }
73 
74  //Fourier transform of cuspless exponential (for use with init)
75  static inline double cusplessExpTilde(double G, double norm, double a)
76  { double aG = a*G;
77  double den = 1./(1.+aG*aG);
78  return norm * den*den*den;
79  }
80 
81  //Fourier transform of exponential (for use with init)
82  static inline double exponentialTilde(double G, double norm, double a)
83  {
84  double aG = a*G;
85  double den = 1./(1.+aG*aG);
86  return norm * den*den;
87  }
88 
89  //Fourier transform of gaussian (for use with init)
90  static inline double gaussTilde(double G, double norm, double sigma)
91  { double sigmaG = sigma*G;
92  return norm * exp(-0.5*sigmaG*sigmaG);
93  }
94 
95  explicit operator bool() const { return nCoeff; }
96  #endif
97 };
98 
99 
102 { std::vector<double> r;
103  std::vector<double> dr;
104  std::vector<double> f;
105 
106  RadialFunctionR(int nSamples=0);
107  RadialFunctionR(const std::vector<double>& r, double dlogr);
108  void set(std::vector<double> r, std::vector<double> dr);
109 
113  void initWeights();
114 
117  double transform(int l, double G) const;
118 
121  void transform(int l, double dG, int nGrid, RadialFunctionG& func) const;
122 };
123 
124 #endif // JDFTX_ELECTRONIC_RADIALFUNCTION_H
int nCoeff
number of coefficients
Definition: RadialFunction.h:31
std::vector< double > f
sample value
Definition: RadialFunction.h:104
void init(int l, int nSamples, double dG, const char *filename, double scale=1.0)
read and initialize from an ascii file (DFT PSP format)
__hostanddev__ double value(const double *coeff, double x)
Compute value of quintic spline. Warning: x is not range-checked.
A function on a non-uniform real-space radial grid.
Definition: RadialFunction.h:101
double * coeffGpu
coefficients on gpu
Definition: RadialFunction.h:34
G-space radial function stored on a uniform grid (of |G|)
Definition: RadialFunction.h:28
ScalarField exp(const ScalarField &)
Elementwise exponential (preserve input)
std::vector< double > dr
radial weight
Definition: RadialFunction.h:103
std::vector< double > coeff
coefficients on cpu
Definition: RadialFunction.h:32
__hostanddev__ double operator()(double G) const
Blip (quintic spline evaluation)
Definition: RadialFunction.h:58
void updateGmax(int l, int nSamples)
if created from a RadialFunctionR, increase nCoeff if necessary (call when lattice is modified) ...
Spline interpolation routines.
RadialFunctionR * rFunc
copy of the real-space radial version (if created from one)
Definition: RadialFunction.h:64
double dGinv
inverse sample spacing
Definition: RadialFunction.h:30
std::vector< double > r
radial location
Definition: RadialFunction.h:102