QMCPACK
OneDimCubicSpline< Td, Tg, CTd, CTg > Class Template Reference
+ Inheritance diagram for OneDimCubicSpline< Td, Tg, CTd, CTg >:
+ Collaboration diagram for OneDimCubicSpline< Td, Tg, CTd, CTg >:

Public Types

using base_type = OneDimGridFunctor< Td, Tg, CTd, CTg >
 
using value_type = typename base_type::value_type
 
using point_type = typename base_type::point_type
 
using data_type = typename base_type::data_type
 
using grid_type = typename base_type::grid_type
 
- Public Types inherited from OneDimGridFunctor< Td, Tg, CTd, CTg >
using value_type = Td
 the type of the value on a grid More...
 
using point_type = Tg
 the type of the grid value More...
 
using data_type = CTd
 the type of the containers Y, dY and d2Y More...
 
using grid_type = OneDimGridBase< Tg, CTg >
 the grid type More...
 
using this_type = OneDimGridFunctor< Td, Tg, CTd, CTg >
 the type of this class More...
 

Public Member Functions

 OneDimCubicSpline (std::unique_ptr< grid_type > gt=std::unique_ptr< grid_type >())
 
template<class VV >
 OneDimCubicSpline (std::unique_ptr< grid_type > gt, const VV &nv)
 
OneDimCubicSplinemakeClone () const
 
 OneDimCubicSpline (const OneDimCubicSpline &a)
 
value_type splint (point_type r) const override
 
value_type splint (point_type r, value_type &du, value_type &d2u) const override
 Interpolation to evaluate the function and itsderivatives. More...
 
value_type splint (point_type r, value_type &du, value_type &d2u, value_type &d3u) const
 Interpolation to evaluate the function and itsderivatives. More...
 
void spline (int imin, value_type yp1, int imax, value_type ypn) override
 Evaluate the 2nd derivative on the grid points. More...
 
void spline () override
 
- Public Member Functions inherited from OneDimGridFunctor< Td, Tg, CTd, CTg >
 OneDimGridFunctor (std::unique_ptr< grid_type > gt=std::unique_ptr< grid_type >())
 constructor More...
 
 OneDimGridFunctor (const OneDimGridFunctor &a)
 
virtual ~OneDimGridFunctor ()=default
 
template<typename TT >
void resetParameters (const TT &active)
 
void setNumOfNodes (int n)
 set the number of nodes More...
 
int getNumOfNodes () const
 return the number of nodes More...
 
value_typedata ()
 return the grid data More...
 
const value_typedata () const
 assign the grid data More...
 
int size () const
 return the number of data points More...
 
void resize (int n)
 resize the number of data points More...
 
const grid_typegrid () const
 return the radial grid More...
 
grid_typegrid ()
 assign a radial grid More...
 
value_type operator() (int i) const
 returns a value More...
 
value_typeoperator() (int i)
 asign a value at i More...
 
point_type dh () const
 return the address of the values More...
 
point_type r (int i) const
 return $r(i)$ the grid point at index i More...
 
point_type dr (int i) const
 return $r(i+1)-r(i)$ More...
 
value_type f (point_type r)
 Evaluate the function and its derivatives, store the derivatives. More...
 
value_type df (point_type r)
 Evaluate the function and its derivatives, store the derivatives. More...
 
value_type evaluate (point_type r, point_type rinv)
 Evaluate the function value only. More...
 
value_type evaluateAll (point_type r, point_type rinv)
 Evaluate the function and its derivatives. More...
 
virtual value_type splint (point_type r, value_type &du, value_type &d2u) const
 
virtual value_type splint (point_type r) const
 
virtual void spline (int imin, value_type yp1, int imax, value_type ypn)
 
value_type evaluate (point_type r, point_type rinv, value_type &du, value_type &d2u)
 Evaluate the function and its derivatives. More...
 

Public Attributes

data_type m_Y2
 
point_type r_min
 
point_type r_max
 
value_type first_deriv
 
value_type last_deriv
 
value_type ConstValue
 
value_type d2Y
 store the second derivative of the function More...
 
value_type dY
 store the derivative of the function More...
 
std::unique_ptr< grid_typem_grid
 pointer to the radial grid More...
 
data_type m_Y
 data for the function on the grid More...
 
value_type Y
 store the value of the function More...
 
int NumNodes
 the number of nodes More...
 
- Public Attributes inherited from OneDimGridFunctor< Td, Tg, CTd, CTg >
std::unique_ptr< grid_typem_grid
 pointer to the radial grid More...
 
value_type Y
 store the value of the function More...
 
value_type dY
 store the derivative of the function More...
 
value_type d2Y
 store the second derivative of the function More...
 
data_type m_Y
 data for the function on the grid More...
 
int NumNodes
 the number of nodes More...
 

Detailed Description

template<class Td, class Tg = Td, class CTd = Vector<Td>, class CTg = Vector<Tg>>
class qmcplusplus::OneDimCubicSpline< Td, Tg, CTd, CTg >

Definition at line 153 of file OneDimCubicSpline.h.

Member Typedef Documentation

◆ base_type

using base_type = OneDimGridFunctor<Td, Tg, CTd, CTg>

Definition at line 156 of file OneDimCubicSpline.h.

◆ data_type

using data_type = typename base_type::data_type

Definition at line 159 of file OneDimCubicSpline.h.

◆ grid_type

using grid_type = typename base_type::grid_type

Definition at line 160 of file OneDimCubicSpline.h.

◆ point_type

Definition at line 158 of file OneDimCubicSpline.h.

◆ value_type

Definition at line 157 of file OneDimCubicSpline.h.

Constructor & Destructor Documentation

◆ OneDimCubicSpline() [1/3]

OneDimCubicSpline ( std::unique_ptr< grid_type gt = std::unique_ptr<grid_type>())
inline

Definition at line 183 of file OneDimCubicSpline.h.

Referenced by OneDimCubicSpline< T >::makeClone().

183 : base_type(std::move(gt)) {}
OneDimGridFunctor< Td, Tg, CTd, CTg > base_type

◆ OneDimCubicSpline() [2/3]

OneDimCubicSpline ( std::unique_ptr< grid_type gt,
const VV &  nv 
)
inline

Definition at line 186 of file OneDimCubicSpline.h.

187  : base_type(std::move(gt)), first_deriv(0.0), last_deriv(0.0)
188  {
189  m_Y.resize(nv.size());
190  m_Y2.resize(nv.size());
191  copy(nv.begin(), nv.end(), m_Y.data());
192  }
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
OneDimGridFunctor< Td, Tg, CTd, CTg > base_type
data_type m_Y
data for the function on the grid

◆ OneDimCubicSpline() [3/3]

OneDimCubicSpline ( const OneDimCubicSpline< Td, Tg, CTd, CTg > &  a)
inline

Definition at line 196 of file OneDimCubicSpline.h.

196  : base_type(a)
197  {
198  m_Y2.resize(a.m_Y2.size());
199  m_Y2 = a.m_Y2;
200  ConstValue = a.ConstValue;
201  r_min = a.r_min;
202  r_max = a.r_max;
203  first_deriv = a.first_deriv;
204  last_deriv = a.last_deriv;
205  }
OneDimGridFunctor< Td, Tg, CTd, CTg > base_type

Member Function Documentation

◆ makeClone()

OneDimCubicSpline* makeClone ( ) const
inline

Definition at line 194 of file OneDimCubicSpline.h.

194 { return new OneDimCubicSpline(*this); }
OneDimCubicSpline(std::unique_ptr< grid_type > gt=std::unique_ptr< grid_type >())

◆ spline() [1/2]

void spline ( int  imin,
value_type  yp1,
int  imax,
value_type  ypn 
)
inlineoverride

Evaluate the 2nd derivative on the grid points.

Parameters
iminthe index of the first valid data point
yp1the derivative at the imin-th grid point
imaxthe index of the last valid data point
ypnthe derivative at the imax-th grid point

In general, a grid is shared by several OneDimCubicSpline objects and each object can have its own range of valid grid points. r_min and r_max are used to specify the range.

Definition at line 294 of file OneDimCubicSpline.h.

Referenced by ECPComponentBuilder::buildL2(), ECPComponentBuilder::buildSO(), ECPComponentBuilder::createVrWithBasisGroup(), ECPComponentBuilder::doBreakUp(), OneDimNumGridFunctor< T >::put(), and qmcplusplus::TEST_CASE().

295  {
296  first_deriv = yp1;
297  last_deriv = ypn;
298  r_min = m_grid->r(imin);
299  r_max = m_grid->r(imax);
300  int npts(this->size());
301  m_Y2.resize(npts);
302  m_Y2 = 0.0;
303  CubicSplineSolve(m_grid->data() + imin, m_Y.data() + imin, npts - imin, yp1, ypn, m_Y2.data() + imin);
304  ConstValue = m_Y[imax];
305  //FirstAddress[0]=m_Y.data()+imin;
306  //FirstAddress[2]=m_Y2.data()+imin;
307  }
void CubicSplineSolve(T const *x, T const *y, int n, T yp0, T ypn, T *y2)
Solve for second derivatives for cubic splines.
Definition: SplineSolvers.h:33
int size() const
return the number of data points
std::unique_ptr< grid_type > m_grid
pointer to the radial grid
data_type m_Y
data for the function on the grid

◆ spline() [2/2]

void spline ( )
inlineoverridevirtual

Reimplemented from OneDimGridFunctor< Td, Tg, CTd, CTg >.

Definition at line 309 of file OneDimCubicSpline.h.

Referenced by OneDimCubicSpline< T >::spline().

309 { spline(0, 0.0, m_grid->size() - 1, 0.0); }
std::unique_ptr< grid_type > m_grid
pointer to the radial grid

◆ splint() [1/3]

value_type splint ( point_type  r) const
inlineoverride

Definition at line 207 of file OneDimCubicSpline.h.

Referenced by OneDimNumGridFunctor< T >::splint(), and qmcplusplus::TEST_CASE().

208  {
209  if (r < r_min)
210  {
211  return m_Y[0] + first_deriv * (r - r_min);
212  }
213  else if (r >= r_max)
214  {
215  return ConstValue;
216  }
217 
218  value_type dist;
219  int Loc = m_grid->getIndexAndDistanceFromGridPoint(r, dist);
220  value_type dL = m_grid->dr(Loc);
221  CubicSplineEvaluator<value_type> eval(dist, dL);
222  return eval.cubicInterpolate(m_Y[Loc], m_Y[Loc + 1], m_Y2[Loc], m_Y2[Loc + 1]);
223  }
typename base_type::value_type value_type
point_type r(int i) const
return the grid point at index i
std::unique_ptr< grid_type > m_grid
pointer to the radial grid
data_type m_Y
data for the function on the grid

◆ splint() [2/3]

value_type splint ( point_type  r,
value_type du,
value_type d2u 
) const
inlineoverride

Interpolation to evaluate the function and itsderivatives.

Parameters
rthe radial distance
dureturn the derivative
d2ureturn the 2nd derivative
Returns
the value of the function

Definition at line 231 of file OneDimCubicSpline.h.

232  {
233  if (r < r_min)
234  //linear-extrapolation returns y[0]+y'*(r-r[0])
235  {
236  du = first_deriv;
237  d2u = 0.0;
238  return m_Y[0] + first_deriv * (r - r_min);
239  }
240  else if (r >= r_max)
241  {
242  du = 0.0;
243  d2u = 0.0;
244  return ConstValue;
245  }
246  value_type dist;
247  int Loc = m_grid->getIndexAndDistanceFromGridPoint(r, dist);
248  value_type dL = m_grid->dr(Loc);
249  CubicSplineEvaluator<value_type> eval(dist, dL);
250  return eval.cubicInterpolateSecondDeriv(m_Y[Loc], m_Y[Loc + 1], m_Y2[Loc], m_Y2[Loc + 1], du, d2u);
251  }
typename base_type::value_type value_type
point_type r(int i) const
return the grid point at index i
std::unique_ptr< grid_type > m_grid
pointer to the radial grid
data_type m_Y
data for the function on the grid

◆ splint() [3/3]

value_type splint ( point_type  r,
value_type du,
value_type d2u,
value_type d3u 
) const
inline

Interpolation to evaluate the function and itsderivatives.

Parameters
rthe radial distance
dureturn the derivative
d2ureturn the 2nd derivative
d3ureturn the 3nd derivative
Returns
the value of the function

Definition at line 260 of file OneDimCubicSpline.h.

261  {
262  if (r < r_min)
263  //linear-extrapolation returns y[0]+y'*(r-r[0])
264  {
265  du = first_deriv;
266  d2u = 0.0;
267  return m_Y[0] + first_deriv * (r - r_min);
268  }
269  else if (r >= r_max)
270  {
271  du = 0.0;
272  d2u = 0.0;
273  return ConstValue;
274  }
275  // no third derivatives yet, only for templating purposes
276  d3u = 0.0;
277 
278  value_type dist;
279  int Loc = m_grid->getIndexAndDistanceFromGridPoint(r, dist);
280  value_type dL = m_grid->dr(Loc);
281  CubicSplineEvaluator<value_type> eval(dist, dL);
282  return eval.cubicInterpolateSecondDeriv(m_Y[Loc], m_Y[Loc + 1], m_Y2[Loc], m_Y2[Loc + 1], du, d2u);
283  }
typename base_type::value_type value_type
point_type r(int i) const
return the grid point at index i
std::unique_ptr< grid_type > m_grid
pointer to the radial grid
data_type m_Y
data for the function on the grid

Member Data Documentation

◆ ConstValue

◆ d2Y

store the second derivative of the function

Definition at line 191 of file OneDimGridFunctor.h.

◆ dY

store the derivative of the function

Definition at line 189 of file OneDimGridFunctor.h.

◆ first_deriv

◆ last_deriv

◆ m_grid

◆ m_Y

data_type m_Y

data for the function on the grid

Definition at line 194 of file OneDimGridFunctor.h.

Referenced by OneDimCubicSplineLinearGrid< T >::OneDimCubicSplineLinearGrid().

◆ m_Y2

◆ NumNodes

int NumNodes

the number of nodes

Definition at line 197 of file OneDimGridFunctor.h.

◆ r_max

◆ r_min

◆ Y

store the value of the function

Definition at line 187 of file OneDimGridFunctor.h.


The documentation for this class was generated from the following file: