QMCPACK
OneDimLinearSpline< Td, Tg, CTd, CTg > Class Template Reference

Perform One-Dimensional linear spline Interpolation. More...

+ Inheritance diagram for OneDimLinearSpline< Td, Tg, CTd, CTg >:
+ Collaboration diagram for OneDimLinearSpline< 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

 OneDimLinearSpline (const grid_type *gt=0)
 
 OneDimLinearSpline (point_type ri, point_type rf)
 
template<class VV >
 OneDimLinearSpline (grid_type *gt, const VV &nv, bool pbc=false)
 
OneDimLinearSpline< Td, Tg, CTd, CTg > * makeClone () const
 
template<class IT >
void assign (IT d_first, IT d_last)
 
point_type rmax () const
 
value_type splint (point_type r) const override
 evaluate the value at r More...
 
void locate (point_type r, int &k, point_type &rfrac)
 evaluate the value at r using a binary search on a grid More...
 
value_type f (int k, point_type rfrac)
 evaluate the value at r=(k + rfrac)*delta More...
 
value_type splint (point_type r, value_type &du, value_type &d2u) const override
 evaluate the value at r More...
 
void spline (int imin, value_type yp1, int imax, value_type ypn)
 evaluate the spline coefficients More...
 
void spline ()
 
- 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...
 
value_type evaluate (point_type r, point_type rinv, value_type &du, value_type &d2u)
 Evaluate the function and its derivatives. More...
 

Public Attributes

int First
 
int Last
 
value_type ConstValue
 
point_type r_min
 
point_type r_max
 
point_type delta
 
point_type delta_inv
 
data_type m_Y1
 
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...
 
- 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::OneDimLinearSpline< Td, Tg, CTd, CTg >

Perform One-Dimensional linear spline Interpolation.

Only valid with linear grid.

Todo:
Have to prevent OneDimLinearSpline<T> being used with other than linear grid!!

Definition at line 30 of file OneDimLinearSpline.h.

Member Typedef Documentation

◆ base_type

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

Definition at line 33 of file OneDimLinearSpline.h.

◆ data_type

using data_type = typename base_type::data_type

Definition at line 36 of file OneDimLinearSpline.h.

◆ grid_type

using grid_type = typename base_type::grid_type

Definition at line 37 of file OneDimLinearSpline.h.

◆ point_type

Definition at line 35 of file OneDimLinearSpline.h.

◆ value_type

Definition at line 34 of file OneDimLinearSpline.h.

Constructor & Destructor Documentation

◆ OneDimLinearSpline() [1/3]

OneDimLinearSpline ( const grid_type gt = 0)
inline

Definition at line 56 of file OneDimLinearSpline.h.

References OneDimLinearSpline< Td, Tg, CTd, CTg >::r_max, and OneDimLinearSpline< Td, Tg, CTd, CTg >::r_min.

56  : base_type(gt), r_min(0), r_max(0)
57  {
58  if (gt)
59  {
60  r_min = gt->rmin();
61  r_max = gt->rmax();
62  }
63  }
OneDimGridFunctor< Td, Tg, CTd, CTg > base_type

◆ OneDimLinearSpline() [2/3]

OneDimLinearSpline ( point_type  ri,
point_type  rf 
)
inline

Definition at line 65 of file OneDimLinearSpline.h.

65 : base_type(0), r_min(ri), r_max(rf) {}
OneDimGridFunctor< Td, Tg, CTd, CTg > base_type

◆ OneDimLinearSpline() [3/3]

OneDimLinearSpline ( grid_type gt,
const VV &  nv,
bool  pbc = false 
)
inline

Definition at line 68 of file OneDimLinearSpline.h.

References OneDimLinearSpline< Td, Tg, CTd, CTg >::assign(), OneDimLinearSpline< Td, Tg, CTd, CTg >::r_max, OneDimLinearSpline< Td, Tg, CTd, CTg >::r_min, OneDimGridBase< T, CT >::rmax(), and OneDimGridBase< T, CT >::rmin().

68  : base_type(gt)
69  {
70  if (gt)
71  {
72  r_min = gt->rmin();
73  r_max = gt->rmax();
74  }
75  assign(nv.begin(), nv.end());
76  }
OneDimGridFunctor< Td, Tg, CTd, CTg > base_type
void assign(IT d_first, IT d_last)

Member Function Documentation

◆ assign()

void assign ( IT  d_first,
IT  d_last 
)
inline

Definition at line 81 of file OneDimLinearSpline.h.

References copy(), OneDimLinearSpline< Td, Tg, CTd, CTg >::delta, OneDimLinearSpline< Td, Tg, CTd, CTg >::delta_inv, OneDimGridFunctor< Td, Tg, CTd, CTg >::m_Y, OneDimLinearSpline< Td, Tg, CTd, CTg >::r_max, and OneDimLinearSpline< Td, Tg, CTd, CTg >::r_min.

Referenced by OneDimLinearSpline< Td, Tg, CTd, CTg >::OneDimLinearSpline().

82  {
83  m_Y.resize(d_last - d_first);
84  copy(d_first, d_last, m_Y.data());
85  delta = (r_max - r_min) / static_cast<point_type>(m_Y.size() - 1);
86  //r_min=m_grid->rmin();
87  //r_max=m_grid->rmax();
88  //delta=m_grid->dh();
89  delta_inv = 1.0 / delta;
90  }
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
data_type m_Y
data for the function on the grid

◆ f()

value_type f ( int  k,
point_type  rfrac 
)
inline

evaluate the value at r=(k + rfrac)*delta

Definition at line 155 of file OneDimLinearSpline.h.

References OneDimGridFunctor< Td, Tg, CTd, CTg >::m_Y.

155 { return m_Y[k] * (1.0 - rfrac) + m_Y[k + 1] * rfrac; }
data_type m_Y
data for the function on the grid

◆ locate()

void locate ( point_type  r,
int &  k,
point_type rfrac 
)
inline

evaluate the value at r using a binary search on a grid

Parameters
rdistance evaluate the index and the linear coefficient
rdistance
kreturn index
rfrac(r-floor(r/delta))/delta

Definition at line 147 of file OneDimLinearSpline.h.

References OneDimLinearSpline< Td, Tg, CTd, CTg >::delta_inv, OneDimGridFunctor< Td, Tg, CTd, CTg >::r(), and OneDimLinearSpline< Td, Tg, CTd, CTg >::r_min.

148  {
149  k = static_cast<int>((r - r_min) * delta_inv);
150  rfrac = r * delta_inv - k;
151  }
point_type r(int i) const
return the grid point at index i

◆ makeClone()

OneDimLinearSpline<Td, Tg, CTd, CTg>* makeClone ( ) const
inline

Definition at line 78 of file OneDimLinearSpline.h.

78 { return new OneDimLinearSpline<Td, Tg, CTd, CTg>(*this); }

◆ rmax()

point_type rmax ( ) const
inline

Definition at line 93 of file OneDimLinearSpline.h.

References OneDimLinearSpline< Td, Tg, CTd, CTg >::r_max.

93 { return r_max; }

◆ spline() [1/2]

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

evaluate the spline coefficients

Parameters
iminindex of the first valid grid
yp1first derivative at imin grid point
imaxindex of the last valid grid
ypnfirst derivative at imax grid point

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

Definition at line 176 of file OneDimLinearSpline.h.

References OneDimLinearSpline< Td, Tg, CTd, CTg >::ConstValue, OneDimLinearSpline< Td, Tg, CTd, CTg >::First, OneDimLinearSpline< Td, Tg, CTd, CTg >::Last, OneDimGridFunctor< Td, Tg, CTd, CTg >::m_grid, OneDimGridFunctor< Td, Tg, CTd, CTg >::m_Y, and OneDimLinearSpline< Td, Tg, CTd, CTg >::m_Y1.

177  {
178  int npts(imax - imin + 1);
179  First = imin;
180  Last = imax;
181  m_Y1.resize(npts);
182  //r_min=m_grid->r(imin);
183  //r_max=m_grid->r(imax);
184  for (int i = imin; i < imax - 1; i++)
185  {
186  m_Y1[i] = (m_Y[i + 1] - m_Y[i]) / ((*m_grid)[i + 1] - (*m_grid)[i]);
187  //m_Y1[i]= (m_Y[i+1]-m_Y[i])*delta_inv;
188  }
189  m_Y1[imax] = 0.0;
190  ConstValue = m_Y[imax];
191  }
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 ( )
inlinevirtual

◆ splint() [1/2]

value_type splint ( point_type  r) const
inlineoverridevirtual

evaluate the value at r

Parameters
rvalue on a grid
Returns
value obtained by cubic-spline

Performance may be tunned: define USE_MEMORYSAVEMODE to evaluate the coefficients instead of using aux. arrays

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

Definition at line 102 of file OneDimLinearSpline.h.

References OneDimLinearSpline< Td, Tg, CTd, CTg >::ConstValue, OneDimLinearSpline< Td, Tg, CTd, CTg >::delta_inv, OneDimGridFunctor< Td, Tg, CTd, CTg >::m_Y, OneDimLinearSpline< Td, Tg, CTd, CTg >::m_Y1, OneDimGridFunctor< Td, Tg, CTd, CTg >::r(), OneDimLinearSpline< Td, Tg, CTd, CTg >::r_max, and OneDimLinearSpline< Td, Tg, CTd, CTg >::r_min.

103  {
104  if (r >= r_max)
105  return ConstValue;
106  int k = static_cast<int>((r - r_min) * delta_inv);
107 #if defined(USE_MEMORYSAVEMODE)
108  return m_Y[k] + (m_Y[k + 1] - m_Y[k]) * (r * delta_inv - k);
109 #else
110  return m_Y[k] + m_Y1[k] * (r - (*m_grid)[k]);
111 #endif
112  }
point_type r(int i) const
return the grid point at index i
data_type m_Y
data for the function on the grid

◆ splint() [2/2]

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

evaluate the value at r

Parameters
rvalue on a grid
dufirst derivative (assigned)
d2usecond derivative (assigned)
Returns
value obtained by cubic-spline

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

Definition at line 163 of file OneDimLinearSpline.h.

164  {
165  std::cerr << " OneDimLinearSpline cannot be used for derivates." << std::endl;
166  return 0.0;
167  }

Member Data Documentation

◆ ConstValue

◆ d2Y

store the second derivative of the function

Definition at line 191 of file OneDimGridFunctor.h.

◆ delta

point_type delta

Definition at line 52 of file OneDimLinearSpline.h.

Referenced by OneDimLinearSpline< Td, Tg, CTd, CTg >::assign().

◆ delta_inv

◆ dY

store the derivative of the function

Definition at line 189 of file OneDimGridFunctor.h.

◆ First

int First

Definition at line 47 of file OneDimLinearSpline.h.

Referenced by OneDimLinearSpline< Td, Tg, CTd, CTg >::spline().

◆ Last

int Last

Definition at line 48 of file OneDimLinearSpline.h.

Referenced by OneDimLinearSpline< Td, Tg, CTd, CTg >::spline().

◆ m_grid

std::unique_ptr<grid_type> m_grid

pointer to the radial grid

Definition at line 184 of file OneDimGridFunctor.h.

◆ m_Y

data_type m_Y

data for the function on the grid

Definition at line 194 of file OneDimGridFunctor.h.

◆ m_Y1

◆ 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: