QMCPACK
LPQHISRCoulombBasis.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 //
10 // File created by: Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #ifndef QMCPLUSPLUS_LPQHISRCOULOMBBASIS_H
15 #define QMCPLUSPLUS_LPQHISRCOULOMBBASIS_H
16 
17 #include "LongRange/LRBasis.h"
18 #include <complex>
19 
20 namespace qmcplusplus
21 {
22 /** @ingroup longrange
23  *\brief A derivative of LRBasis class to provide the functionality
24  * of the LPQHI basis. A 1/r factor is incorporated into the basis functions
25  * to facilitate real space representation of the short-ranged coulomb potential,
26  * following Natoli & Ceperley's 1995 paper on Optimized Breakup. http://dx.doi.org/10.1006/jcph.1995.1054.
27  */
28 
30 {
31 private:
32  int NumKnots; //Number of knots for basis.
34  Matrix<mRealType> S; //Coefficients for LPQHI
35  Matrix<mRealType> S1; //First derivatives
36  Matrix<mRealType> S2; //Second derivatives
38  std::vector<mRealType> tvec; //Coefficients
39 
40  //Helper functions for computing FT of basis functions (used in c(n,k))
41  inline std::complex<mRealType> Eplus(int i, mRealType k, int n) const;
42  inline std::complex<mRealType> Eminus(int i, mRealType k, int n) const;
43  inline std::complex<mRealType> Eplus_dG(int i, mRealType k, int n) const;
44  inline std::complex<mRealType> Eminus_dG(int i, mRealType k, int n) const;
45  inline mRealType Dplus(int i, mRealType k, int n) const;
46  inline mRealType Dminus(int i, mRealType k, int n) const;
47  inline mRealType Dplus_dG(int i, mRealType k, int n) const;
48  inline mRealType Dminus_dG(int i, mRealType k, int n) const;
49 
50 
51 public:
53  : LRBasis(ref),
54  NumKnots(b.NumKnots),
55  delta(b.delta),
56  deltainv(b.deltainv),
57  S(b.S),
58  S1(b.S1),
59  S2(b.S2),
60  tvec(b.tvec)
61  {
62  Mfactor[0] = 1.0;
63  Mfactor[1] = -1.0;
64  Mfactor[2] = 1.0;
65  BasisSize = b.BasisSize;
66  m_rc = b.m_rc;
67  }
68 
69  inline mRealType get_delta() const { return delta; }
70  //inline int NumBasisElem() const {return 3*NumKnots;}
71  void set_NumKnots(int n); // n >= 2 required
72  void set_rc(mRealType rc) override;
73  inline mRealType h(int n, mRealType r) const override
74  {
75  int i = n / 3;
76  int alpha = n - 3 * i;
77  mRealType ra = delta * (i - 1);
78  mRealType rb = delta * i;
79  mRealType rc = delta * (i + 1);
80  mRealType rinv = 1.0 / r;
81  rc = std::min(m_rc, rc);
82  const mRealType* restrict Sa(S[alpha]);
83  if (r < ra || r > rc)
84  return 0.0;
85  if (r <= rb)
86  {
87  mRealType x = (rb - r) * deltainv;
88  return std::pow(delta, alpha) * Mfactor[alpha] * rinv *
89  (Sa[0] + x * (Sa[1] + x * (Sa[2] + x * (Sa[3] + x * (Sa[4] + x * Sa[5])))));
90  }
91  else
92  {
93  mRealType x = (r - rb) * deltainv;
94  return std::pow(delta, alpha) * rinv *
95  (Sa[0] + x * (Sa[1] + x * (Sa[2] + x * (Sa[3] + x * (Sa[4] + x * Sa[5])))));
96  }
97  }
98 
99  inline mRealType rh(int n, mRealType r) const
100  {
101  int i = n / 3;
102  int alpha = n - 3 * i;
103  mRealType ra = delta * (i - 1);
104  mRealType rb = delta * i;
105  mRealType rc = delta * (i + 1);
106  rc = std::min(m_rc, rc);
107  const mRealType* restrict Sa(S[alpha]);
108  if (r < ra || r > rc)
109  return 0.0;
110  if (r <= rb)
111  {
112  mRealType x = (rb - r) * deltainv;
113  return std::pow(delta, alpha) * Mfactor[alpha] *
114  (Sa[0] + x * (Sa[1] + x * (Sa[2] + x * (Sa[3] + x * (Sa[4] + x * Sa[5])))));
115  }
116  else
117  {
118  mRealType x = (r - rb) * deltainv;
119  return std::pow(delta, alpha) * (Sa[0] + x * (Sa[1] + x * (Sa[2] + x * (Sa[3] + x * (Sa[4] + x * Sa[5])))));
120  }
121  }
122 
123  inline mRealType dh_dr(int n, mRealType r) const override
124  {
125  int i = n / 3;
126  int alpha = n - 3 * i;
127  mRealType ra = delta * (i - 1);
128  mRealType rb = delta * i;
129  mRealType rc = delta * (i + 1);
130  rc = std::min(m_rc, rc);
131 
132  mRealType polyderiv = 0.0;
133  mRealType rinv = 1.0 / r;
134  mRealType hval = h(n, r);
135 
136  const mRealType* restrict Sa(S1[alpha]);
137  if (r < ra || r > rc)
138  return 0.0;
139  if (r <= rb)
140  {
141  mRealType x = (rb - r) * deltainv;
142  polyderiv =
143  -std::pow(delta, alpha - 1) * Mfactor[alpha] * (Sa[0] + x * (Sa[1] + x * (Sa[2] + x * (Sa[3] + x * Sa[4]))));
144  }
145  else
146  {
147  mRealType x = (r - rb) * deltainv;
148  polyderiv = std::pow(delta, alpha - 1) * (Sa[0] + x * (Sa[1] + x * (Sa[2] + x * (Sa[3] + x * Sa[4]))));
149  }
150 
151  return rinv * (polyderiv - hval);
152  }
153 
154  inline mRealType dh_ddelta(int n, mRealType r) const
155  {
156  int i = n / 3;
157  int alpha = n - 3 * i;
158 
159  return h(n, r) * alpha / double(delta) - dh_dr(n, r) * r / double(delta);
160  }
161 
162 
163  // inline TinyVector<mRealType,3> getTriplet(int n, mRealType r) const {
164  // using Return_t = TinyVector<mRealType,3>;
165  // int i=n/3;
166  // int alpha = n-3*i;
167  // mRealType ra = delta*(i-1);
168  // mRealType rb = delta*i;
169  // mRealType rc = delta*(i+1);
170  // rc = std::min(m_rc, rc);
171  // if(r<ra || r>rc) return Return_t;
172  // const mRealType* restrict Sa(S[alpha]);
173  // const mRealType* restrict S1a(S1[alpha]);
174  // const mRealType* restrict S2a(S2[alpha]);
175  // if (r <= rb) {
176  // mRealType x=(rb-r)*deltainv;
177  // return Return_t(
178  // Mfactor[alpha]*(Sa[0] +x*(Sa[1] +x*(Sa[2] +x*(Sa[3] +x*(Sa[4]+x*Sa[5]))))),
179  // Mfactor[alpha]*(S1a[0]+x*(S1a[1]+x*(S1a[2]+x*(S1a[3]+x*S1a[4])))),
180  // Mfactor[alpha]*(S2a[0]+x*(S2a[1]+x*(S2a[2]+x*S2a[3]))));
181  // } else {
182  // mRealType x=(r-rb)*deltainv;
183  // return Return_t(
184  // Sa[0] +x*(Sa[1] +x*(Sa[2] +x*(Sa[3] +x*(Sa[4]+x*Sa[5])))),
185  // S1a[0]+x*(S1a[1]+x*(S1a[2]+x*(S1a[3]+x*S1a[4]))),
186  // S2a[0]+x*(S2a[1]+x*(S2a[2]+x*S2a[3])));
187  // }
188  // }
189 
190  mRealType hintr2(int n) const override;
191  mRealType c(int n, mRealType k) const override;
192  mRealType dc_dk(int n, mRealType k) const override;
193 
194  //Constructor...fill S matrix...call correct base-class constructor
196  {
197  S.resize(3, 6);
198  S(0, 0) = 1.0;
199  S(0, 1) = 0.0;
200  S(0, 2) = 0.0;
201  S(0, 3) = -10.0;
202  S(0, 4) = 15.0;
203  S(0, 5) = -6.0;
204  S(1, 0) = 0.0;
205  S(1, 1) = 1.0;
206  S(1, 2) = 0.0;
207  S(1, 3) = -6.0;
208  S(1, 4) = 8.0;
209  S(1, 5) = -3.0;
210  S(2, 0) = 0.0;
211  S(2, 1) = 0.0;
212  S(2, 2) = 0.5;
213  S(2, 3) = -1.5;
214  S(2, 4) = 1.5;
215  S(2, 5) = -0.5;
216  S1.resize(3, 5);
217  for (int i = 0; i < 5; i++)
218  {
219  for (int j = 0; j < 3; j++)
220  {
221  S1(j, i) = static_cast<double>(i + 1.0) * S(j, i + 1);
222  }
223  }
224  Mfactor[0] = 1.0;
225  Mfactor[1] = -1.0;
226  Mfactor[2] = 1.0;
227  }
228 };
229 
230 } // namespace qmcplusplus
231 
232 #endif
a class that defines a supercell in D-dimensional Euclean space.
mRealType Dminus(int i, mRealType k, int n) const
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::complex< mRealType > Eminus(int i, mRealType k, int n) const
A derivative of LRBasis class to provide the functionality of the LPQHI basis.
mRealType c(int n, mRealType k) const override
EwaldHandler3D::mRealType mRealType
LPQHISRCoulombBasis(const LPQHISRCoulombBasis &b, const ParticleLayout &ref)
mRealType Dplus_dG(int i, mRealType k, int n) const
mRealType dc_dk(int n, mRealType k) const override
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
T min(T a, T b)
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
mRealType rh(int n, mRealType r) const
std::complex< mRealType > Eplus(int i, mRealType k, int n) const
Base-class for long-range breakups.
Definition: LRBasis.h:33
void set_rc(mRealType rc) override
mRealType Dminus_dG(int i, mRealType k, int n) const
std::complex< mRealType > Eminus_dG(int i, mRealType k, int n) const
mRealType Dplus(int i, mRealType k, int n) const
mRealType m_rc
Real-space cutoff for short-range part.
Definition: LRBasis.h:40
mRealType h(int n, mRealType r) const override
mRealType dh_dr(int n, mRealType r) const override
LPQHISRCoulombBasis(const ParticleLayout &ref)
DECLARE_COULOMB_TYPES int BasisSize
size of the basis elements
Definition: LRBasis.h:38
std::complex< mRealType > Eplus_dG(int i, mRealType k, int n) const
mRealType hintr2(int n) const override
mRealType dh_ddelta(int n, mRealType r) const