QMCPACK
CubicBspline.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: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 //
10 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 /** @file CubicBspline.h
15  * @brief declaration of CubicBspline class
16  */
17 #ifndef QMCPLUSPLUS_CUBIC_B_SPLINE_H
18 #define QMCPLUSPLUS_CUBIC_B_SPLINE_H
19 
21 
22 template<class T, unsigned GRIDTYPE, unsigned BC>
23 struct CubicBspline : public CubicBsplineGrid<T, GRIDTYPE, BC>
24 {
28 
32 
33  ///index of current grid point
34  int i0, i1, i2, i3;
35  ///constant shift
37  ///coefficients
38  point_type A[16], dA[12], d2A[8], d3A[4];
39  /// The control points
41 
42  /** default constructor
43  *
44  * Initialize linear coefficients
45  */
46  inline CubicBspline() : OffSet(0.0)
47  {
48  A[0] = -1.0 / 6.0;
49  A[1] = 3.0 / 6.0;
50  A[2] = -3.0 / 6.0;
51  A[3] = 1.0 / 6.0;
52  A[4] = 3.0 / 6.0;
53  A[5] = -6.0 / 6.0;
54  A[6] = 3.0 / 6.0;
55  A[7] = 0.0 / 6.0;
56  A[8] = -3.0 / 6.0;
57  A[9] = 0.0 / 6.0;
58  A[10] = 3.0 / 6.0;
59  A[11] = 0.0 / 6.0;
60  A[12] = 1.0 / 6.0;
61  A[13] = 4.0 / 6.0;
62  A[14] = 1.0 / 6.0;
63  A[15] = 0.0 / 6.0;
64  dA[0] = -0.5;
65  dA[1] = 1.5;
66  dA[2] = -1.5;
67  dA[3] = 0.5;
68  dA[4] = 1.0;
69  dA[5] = -2.0;
70  dA[6] = 1.0;
71  dA[7] = 0.0;
72  dA[8] = -0.5;
73  dA[9] = 0.0;
74  dA[10] = 0.5;
75  dA[11] = 0.0;
76  d2A[0] = -1.0;
77  d2A[1] = 3.0;
78  d2A[2] = -3.0;
79  d2A[3] = 1.0;
80  d2A[4] = 1.0;
81  d2A[5] = -2.0;
82  d2A[6] = 1.0;
83  d2A[7] = 0.0;
84  d3A[0] = -1.0;
85  d3A[1] = 3.0;
86  d3A[2] = -3.0;
87  d3A[3] = 1.0;
88  }
89 
90  void Init(point_type start, point_type end, const container_type& datain, bool closed)
91  {
92  this->spline(start, end, datain, P, closed);
93  }
94 
95  void Init(point_type start, point_type end, const container_type& datain, bool closed, T yp1, T ypn)
96  {
97  this->spline(start, end, yp1, ypn, datain, P);
98  }
99 
101  {
102  if (this->getGridPoint(x, i0))
103  return interpolate0(P[i0], P[i0 + 1], P[i0 + 2], P[i0 + 3]);
104  else
105  return OffSet;
106  }
107 
109  {
110  if (this->getGridPoint(x, i0))
111  return interpolate1(P[i0], P[i0 + 1], P[i0 + 2], P[i0 + 3]);
112  else
113  return OffSet;
114  }
115 
117  {
118  if (this->getGridPoint(x, i0))
119  return interpolate2(P[i0], P[i0 + 1], P[i0 + 2], P[i0 + 3]);
120  else
121  return OffSet;
122  }
123 
125  {
126  if (this->getGridPoint(x, i0))
127  return GridDeltaInv * GridDeltaInv * GridDeltaInv *
128  (tp[3] * (d2A[0] * P[i0] + d2A[1] * P[i1] + d2A[2] * P[i2] + d2A[3] * P[i3]));
129  else
130  return OffSet;
131  }
132 
133  inline value_type operator()(T x) { return getValue(x); }
134 
135  inline value_type splint(T x)
136  {
137  if (this->getGridPoint(x, i0))
138  return interpolate0(P[i0], P[i0 + 1], P[i0 + 2], P[i0 + 3]);
139  else
140  return OffSet;
141  }
142 
144  {
145  if (this->getGridPoint(x, i0))
146  {
147  return interpolate(P[i0], P[i0 + 1], P[i0 + 2], P[i0 + 3], dy, d2y);
148  }
149  else
150  {
151  dy = 0.0;
152  d2y = 0.0;
153  return OffSet;
154  }
155  //Too slow
156  //dy= GridDeltaInv *
157  // (tp[1]*(dA[0]*P[i0]+dA[1]*P[i1]+dA[ 2]*P[i2]+dA[ 3]*P[i3])+
158  // tp[2]*(dA[4]*P[i0]+dA[5]*P[i1]+dA[ 6]*P[i2]+dA[ 7]*P[i3])+
159  // tp[3]*(dA[8]*P[i0]+dA[9]*P[i1]+dA[10]*P[i2]+dA[11]*P[i3]));
160  //d2y=GridDeltaInv2 *
161  // (tp[2]*(d2A[0]*P[i0]+d2A[1]*P[i1]+d2A[2]*P[i2]+d2A[3]*P[i3])+
162  // tp[3]*(d2A[4]*P[i0]+d2A[5]*P[i1]+d2A[6]*P[i2]+d2A[7]*P[i3]));
163  //return
164  // tp[0]*(A[ 0]*P[i0]+A[ 1]*P[i1]+A[ 2]*P[i2]+A[ 3]*P[i3])+
165  // tp[1]*(A[ 4]*P[i0]+A[ 5]*P[i1]+A[ 6]*P[i2]+A[ 7]*P[i3])+
166  // tp[2]*(A[ 8]*P[i0]+A[ 9]*P[i1]+A[10]*P[i2]+A[11]*P[i3])+
167  // tp[3]*(A[12]*P[i0]+A[13]*P[i1]+A[14]*P[i2]+A[15]*P[i3]);
168  }
170  value_type p1,
171  value_type p2,
172  value_type p3,
173  value_type& dy,
174  value_type& d2y)
175  {
176  dy = GridDeltaInv *
177  (tp[1] * (-0.5 * p0 + 1.5 * p1 - 1.5 * p2 + 0.5 * p3) + tp[2] * (p0 - 2.0 * p1 + p2) +
178  tp[3] * (-0.5 * p0 + 0.5 * p2));
179  d2y = GridDeltaInv2 * (tp[2] * (-p0 + 3.0 * p1 - 3.0 * p2 + p3) + tp[3] * (p0 - 2.0 * p1 + p2));
180  const point_type onesixth = 1.0 / 6.0;
181  return onesixth *
182  (tp[0] * (-p0 + 3.0 * p1 - 3.0 * p2 + p3) + tp[1] * (3.0 * p0 - 6.0 * p1 + 3.0 * p2) +
183  tp[2] * (-3.0 * p0 + 3.0 * p2) + tp[3] * (p0 + 4.0 * p1 + p2));
184  }
185 
187  {
188  const point_type onesixth = 1.0 / 6.0;
189  return onesixth *
190  (tp[0] * (-p0 + 3.0 * p1 - 3.0 * p2 + p3) + tp[1] * (3.0 * p0 - 6.0 * p1 + 3.0 * p2) +
191  tp[2] * (-3.0 * p0 + 3.0 * p2) + tp[3] * (p0 + 4.0 * p1 + p2));
192  }
193 
195  {
196  return GridDeltaInv *
197  (tp[1] * (-0.5 * p0 + 1.5 * p1 - 1.5 * p2 + 0.5 * p3) + tp[2] * (p0 - 2.0 * p1 + p2) +
198  tp[3] * (-0.5 * p0 + 0.5 * p2));
199  }
200 
202  {
203  return GridDeltaInv2 * (tp[2] * (-p0 + 3.0 * p1 - 3.0 * p2 + p3) + tp[3] * (p0 - 2.0 * p1 + p2));
204  }
205 };
206 
207 
208 #endif
void Init(point_type start, point_type end, const container_type &datain, bool closed)
Definition: CubicBspline.h:90
value_type getValue(point_type x)
Definition: CubicBspline.h:100
value_type OffSet
constant shift
Definition: CubicBspline.h:36
point_type dA[12]
Definition: CubicBspline.h:38
value_type getDeriv(point_type x)
Definition: CubicBspline.h:108
value_type interpolate0(value_type p0, value_type p1, value_type p2, value_type p3)
Definition: CubicBspline.h:186
container_type P
The control points.
Definition: CubicBspline.h:40
int i0
index of current grid point
Definition: CubicBspline.h:34
typename CubicBsplineGrid< T, GRIDTYPE, BC >::value_type value_type
Definition: CubicBspline.h:26
point_type d3A[4]
Definition: CubicBspline.h:38
value_type splint(point_type x, value_type &dy, value_type &d2y)
Definition: CubicBspline.h:143
value_type interpolate2(value_type p0, value_type p1, value_type p2, value_type p3)
Definition: CubicBspline.h:201
CubicBsplineGrid.
point_type A[16]
coefficients
Definition: CubicBspline.h:38
value_type interpolate1(value_type p0, value_type p1, value_type p2, value_type p3)
Definition: CubicBspline.h:194
value_type splint(T x)
Definition: CubicBspline.h:135
typename CubicBsplineGrid< T, GRIDTYPE, BC >::point_type point_type
Definition: CubicBspline.h:25
CubicBspline()
default constructor
Definition: CubicBspline.h:46
value_type interpolate(value_type p0, value_type p1, value_type p2, value_type p3, value_type &dy, value_type &d2y)
Definition: CubicBspline.h:169
value_type getDeriv3(point_type x)
Definition: CubicBspline.h:124
typename CubicBsplineGrid< T, GRIDTYPE, BC >::container_type container_type
Definition: CubicBspline.h:27
value_type operator()(T x)
Definition: CubicBspline.h:133
point_type d2A[8]
Definition: CubicBspline.h:38
value_type getDeriv2(point_type x)
Definition: CubicBspline.h:116
void Init(point_type start, point_type end, const container_type &datain, bool closed, T yp1, T ypn)
Definition: CubicBspline.h:95