QMCPACK
OneDimGridFunctor.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: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
10 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 #ifndef QMCPLUSPLUS_GRID_FUNCTOR_H
17 #define QMCPLUSPLUS_GRID_FUNCTOR_H
18 
19 #include <memory>
21 
22 namespace qmcplusplus
23 {
24 /** Implement One-Dimensional function on a radial grid.
25  *
26  * template parameters
27  * - Td return type
28  * - Tg grid value type
29  * - CTd container type associated with the values and derivatives
30  * - CTg container type associated with the grid data
31  *
32  * Store the values of the function for the
33  * corresponding grid points, \f$ y_i = y(x_i) \f$.
34  */
35 template<class Td, class Tg = Td, class CTd = Vector<Td>, class CTg = Vector<Tg>>
37 {
38  /// the type of the value on a grid
39  using value_type = Td;
40  /// the type of the grid value
41  using point_type = Tg;
42  /// the type of the containers Y, dY and d2Y
43  using data_type = CTd;
44  /// the grid type
46  /// the type of this class
48 
49  /** constructor
50  *@param gt a radial grid. The pointer is treated as a reference
51  */
52  OneDimGridFunctor(std::unique_ptr<grid_type> gt = std::unique_ptr<grid_type>()) : m_grid(std::move(gt))
53  {
54  if (m_grid)
55  resize(m_grid->size());
56  }
57 
59  {
60  if (a.m_grid)
61  m_grid = a.m_grid->makeClone();
62  Y = a.Y;
63  dY = a.dY;
64  d2Y = a.d2Y;
65  m_Y.resize(a.m_Y.size());
66  m_Y = a.m_Y;
67  NumNodes = a.NumNodes;
68  }
69 
70  virtual ~OneDimGridFunctor() = default;
71 
72  template<typename TT>
73  inline void resetParameters(const TT& active)
74  {}
75 
76  ///set the number of nodes
77  inline void setNumOfNodes(int n) { NumNodes = n; }
78 
79  ///return the number of nodes
80  inline int getNumOfNodes() const { return NumNodes; }
81 
82  ///return the grid data
83  inline value_type* data() { return &(m_Y[0]); }
84  ///assign the grid data
85  inline const value_type* data() const { return &(m_Y[0]); }
86  ///return the number of data points
87  inline int size() const { return m_Y.size(); }
88  ///resize the number of data points
89  inline void resize(int n) { m_Y.resize(n); }
90  ///return the radial grid
91  inline const grid_type& grid() const { return *m_grid; }
92  ///assign a radial grid
93  inline grid_type& grid() { return *m_grid; }
94 
95  /**returns a value
96  * @param i grid index
97  * @return the value at i
98  */
99  inline value_type operator()(int i) const { return m_Y[i]; }
100 
101  /**asign a value at i
102  * @param i grid index
103  * @return the value at i
104  */
105  inline value_type& operator()(int i) { return m_Y[i]; }
106 
107  ///** return the address of the values
108  // * @param i index, i=0 value, i=1 first derivative, i=2 second
109  // */
110  //inline value_type* data(int i) {
111  // return 0;
112  // //return FirstAddress[i];
113  //}
114 
115  /**return the differntial spacing for the grid
116  *@warning only for LinearGrid and LogGrid
117  */
118  inline point_type dh() const { return m_grid->dh(); }
119 
120  ///return \f$r(i)\f$ the grid point at index i
121  inline point_type r(int i) const { return m_grid->r(i); }
122  ///return \f$r(i+1)-r(i)\f$
123  inline point_type dr(int i) const { return m_grid->dr(i); }
124 
125  /** Evaluate the function and its derivatives, store the derivatives.
126  *@param r radial distance
127  *@return the value of the function
128  */
130  {
131  //setgrid(r);
132  return Y = splint(r);
133  }
134 
135  /** Evaluate the function and its derivatives, store the derivatives.
136  *@param r radial distance
137  *@return the derivative of the function
138  */
140  {
141  //setgrid(r);
142  Y = splint(r, dY, d2Y);
143  return dY;
144  }
145 
146  /** Evaluate the function value only
147  * @param r value on a grid
148  * @param rinv inverse of r
149  * @return value at r
150  */
151  inline value_type evaluate(point_type r, point_type rinv) { return Y = splint(r); }
152 
153  /** Evaluate the function and its derivatives.
154  * @param r value on a grid
155  * @param rinv inverse of r
156  * @return value at r
157  *
158  * Derivatives are storged.
159  */
160  inline value_type evaluateAll(point_type r, point_type rinv) { return Y = splint(r, dY, d2Y); }
161 
162  virtual value_type splint(point_type r, value_type& du, value_type& d2u) const { return 0.0; }
163 
164  virtual value_type splint(point_type r) const { return 0.0; }
165 
166  virtual void spline(int imin, value_type yp1, int imax, value_type ypn) {}
167 
168  virtual void spline() {}
169 
170  /**
171  *@param r radial distance
172  *@param rinv inverse of radial distance
173  *@param du return derivative
174  *@param d2u return 2nd derivative
175  *@return the value of the function
176  *@brief Evaluate the function and its derivatives.
177  */
179  {
180  return splint(r, du, d2u);
181  }
182 
183  ///pointer to the radial grid
184  std::unique_ptr<grid_type> m_grid;
185 
186  ///store the value of the function
188  ///store the derivative of the function
190  ///store the second derivative of the function
192 
193  ///data for the function on the grid
195 
196  ///the number of nodes
197  int NumNodes;
198 
199  ///address of coefficients Y and dY or d2Y
200  //std::vector<value_type*> FirstAddress;
201 };
202 
203 /** One-dimensional grid functor that returns a constant
204  */
205 template<class Td, class Tg = Td, class CTd = Vector<Td>, class CTg = Vector<Tg>>
206 class OneDimConstFunctor : public OneDimGridFunctor<Td, Tg, CTd, CTg>
207 {
208 public:
213  using data_type = typename base_type::data_type;
214  using grid_type = typename base_type::grid_type;
215 
216 
218 
219  inline value_type splint(point_type r) const override { return ConstValue; }
220 
221  inline value_type splint(point_type r, value_type& du, value_type& d2u) const override
222  {
223  du = 0.0;
224  d2u = 0.0;
225  return ConstValue;
226  }
227 
228  inline void spline(int imin, value_type yp1, int imax, value_type ypn) {}
229 
230  inline void spline() {}
231 };
232 
233 } // namespace qmcplusplus
234 #endif
value_type f(point_type r)
Evaluate the function and its derivatives, store the derivatives.
CTd data_type
the type of the containers Y, dY and d2Y
OneDimGridFunctor(const OneDimGridFunctor &a)
value_type evaluate(point_type r, point_type rinv)
Evaluate the function value only.
value_type splint(point_type r, value_type &du, value_type &d2u) const override
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void resetParameters(const TT &active)
int getNumOfNodes() const
return the number of nodes
virtual void spline(int imin, value_type yp1, int imax, value_type ypn)
value_type * data()
return the grid data
Implement One-Dimensional function on a radial grid.
int NumNodes
the number of nodes
void spline(int imin, value_type yp1, int imax, value_type ypn)
value_type & operator()(int i)
asign a value at i
An abstract base class to implement a One-Dimensional grid.
Decalaration of One-Dimesional grids.
value_type Y
store the value of the function
One-dimensional grid functor that returns a constant.
value_type d2Y
store the second derivative of the function
value_type df(point_type r)
Evaluate the function and its derivatives, store the derivatives.
OneDimGridBase< Tg, CTg > grid_type
the grid type
value_type splint(point_type r) const override
point_type dr(int i) const
return
OneDimGridFunctor(std::unique_ptr< grid_type > gt=std::unique_ptr< grid_type >())
constructor
virtual ~OneDimGridFunctor()=default
virtual value_type splint(point_type r, value_type &du, value_type &d2u) const
int size() const
return the number of data points
value_type dY
store the derivative of the function
void setNumOfNodes(int n)
set the number of nodes
value_type evaluate(point_type r, point_type rinv, value_type &du, value_type &d2u)
Evaluate the function and its derivatives.
const value_type * data() const
assign the grid data
void resize(int n)
resize the number of data points
grid_type & grid()
assign a radial grid
value_type operator()(int i) const
returns a value
const grid_type & grid() const
return the radial grid
point_type dh() const
return the address of the values
point_type r(int i) const
return the grid point at index i
value_type evaluateAll(point_type r, point_type rinv)
Evaluate the function and its derivatives.
std::unique_ptr< grid_type > m_grid
pointer to the radial grid
virtual value_type splint(point_type r) const
data_type m_Y
data for the function on the grid