QMCPACK
SplineFunctors.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 // Ken Esler, kpesler@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 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
12 //
13 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
14 //////////////////////////////////////////////////////////////////////////////////////
15 
16 
17 #ifndef QMCPLUSPLUS_CUBICFUNCTORSFORJASTROW_H
18 #define QMCPLUSPLUS_CUBICFUNCTORSFORJASTROW_H
20 #include "Numerics/CubicBspline.h"
21 #include "OptimizableFunctorBase.h"
22 #include "Message/Communicate.h"
24 
25 namespace qmcplusplus
26 {
27 /** A numerical functor
28  *
29  * implements interfaces to be used for Jastrow functions and replaces CubicBsplineSingle.
30  * Template parameters
31  * - RT real data type
32  * - FNOUT final numerical functor
33  * An example is in CBSOBuilder.h which uses CubicBspline
34  * using SplineEngineType = CubicBspline<RealType,LINEAR_1DGRID,FIRSTDERIV_CONSTRAINTS>;
35  * using RadialOrbitalType = CubicSplineSingle<RealType,SplineEngineType>;
36  */
37 template<typename RT, typename FNOUT>
39 {
40  ///typedef for the value_type
41  using value_type = RT;
42  ///typedef of the source functor
44  ///typedef for the grid
46 
47  // mmorales: until I figure out how to go around this
48  int NumParams;
50  FNOUT OutFunc;
57  ///constructor
59 
62  {
63  NumParams = 0;
64  if (old.InFunc)
65  {
66  initialize(old.InFunc->makeClone(), old.Rmax, old.NumGridPoints);
67  }
68  }
69 
70  OptimizableFunctorBase* makeClone() const override { return new CubicSplineSingle<RT, FNOUT>(*this); }
71 
72  ///constructor with arguments
73  CubicSplineSingle(FNIN* in_, grid_type* agrid) : InFunc(in_) { initialize(in_, agrid); }
74  ///constructor with arguments
75  CubicSplineSingle(FNIN* in_, real_type rc, int npts) : InFunc(in_) { initialize(in_, rc, npts); }
76  ///set the input, analytic function
77  void setInFunc(FNIN* in_) { InFunc = in_; }
78 
79  void reportStatus(std::ostream& os) override
80  {
81  //myVars.print(os);
82  }
83 
84  bool isOptimizable() { return false; }
85 
86  /** evaluate everything: value, first, second and third derivatives
87  */
88  inline real_type evaluate(real_type r, real_type& dudr, real_type& d2udr2, real_type& d3udr3)
89  {
90  std::cerr << "Third derivative not implemented for CubicSplineSingle.\n";
91  return OutFunc.splint(r, dudr, d2udr2);
92  }
93 
94 
95  /** evaluate everything: value, first and second derivatives
96  */
97  inline real_type evaluate(real_type r, real_type& dudr, real_type& d2udr2) { return OutFunc.splint(r, dudr, d2udr2); }
98 
99  /** evaluate value only
100  */
101  inline real_type evaluate(real_type r) { return OutFunc.splint(r); }
102 
103  /** evaluate value only
104  *
105  * Function required for SphericalBasisSet
106  */
107  inline real_type evaluate(real_type r, real_type rinv) { return Y = OutFunc.splint(r); }
108 
109  /** evaluate everything: value, first and second derivatives
110  *
111  * Function required for SphericalBasisSet
112  */
113  inline real_type evaluateAll(real_type r, real_type rinv) { return Y = OutFunc.splint(r, dY, d2Y); }
114 
115  /** implement the virtual function of OptimizableFunctorBase */
116  inline real_type f(real_type r) override { return OutFunc.splint(r); }
117 
118  /** implement the virtual function of OptimizableFunctorBase */
119  inline real_type df(real_type r) override
120  {
121  real_type dudr, d2udr2;
122  OutFunc.splint(r, dudr, d2udr2);
123  return dudr;
124  }
125 
126  inline real_type evaluateV(const int iat,
127  const int iStart,
128  const int iEnd,
129  const real_type* restrict _distArray,
130  real_type* restrict distArrayCompressed) const
131  {
132  // need to actually implement this!
133  return real_type(0);
134  }
135 
136  /** evaluate sum of the pair potentials FIXME
137  * @return \f$\sum u(r_j)\f$ for r_j < cutoff_radius
138  */
139  static void mw_evaluateV(const int num_groups,
140  const CubicSplineSingle* const functors[],
141  const int n_src,
142  const int* grp_ids,
143  const int num_pairs,
144  const int* ref_at,
145  const RT* mw_dist,
146  const int dist_stride,
147  RT* mw_vals,
148  Vector<char, OffloadPinnedAllocator<char>>& transfer_buffer)
149  {
150  throw std::runtime_error("mw_evaluateV not implemented!");
151  }
152 
153  inline void evaluateVGL(const int iat,
154  const int iStart,
155  const int iEnd,
156  const real_type* distArray,
157  real_type* restrict valArray,
158  real_type* restrict gradArray,
159  real_type* restrict laplArray,
160  real_type* restrict distArrayCompressed,
161  int* restrict distIndices) const
162  {
163  // need to actually implement this!
164  }
165 
166  bool put(xmlNodePtr cur) override
167  {
168  bool s = false;
169  if (InFunc)
170  s = InFunc->put(cur);
171  return s;
172  }
173 
175  {
176  if (InFunc)
178  }
179 
180  void checkOutVariables(const opt_variables_type& active) override
181  {
182  if (InFunc)
183  InFunc->checkOutVariables(active);
184  }
185 
186  ///reset the input/output function
187  void resetParametersExclusive(const opt_variables_type& active) override
188  {
189  if (InFunc)
190  {
192  reset();
193  }
194  }
195 
196  void print(std::ostream& os)
197  {
198  real_type r = 0;
199  for (int i = 0; i < NumGridPoints; i++, r += GridDelta)
200  os << r << " " << OutFunc.splint(r) << std::endl;
201  }
202 
203  ///set the input, analytic function
204  void initialize(FNIN* in_, grid_type* agrid) { initialize(in_, agrid->rmax(), agrid->size()); }
205 
206  void initialize(FNIN* in_, real_type rmax, int npts)
207  {
208  InFunc = in_;
209  Rmax = rmax;
210  NumGridPoints = npts;
211  GridDelta = Rmax / static_cast<real_type>(NumGridPoints - 1);
212  reset();
213  }
214 
215  void reset() override
216  {
217  if (InFunc)
218  {
219  typename FNOUT::container_type datain(NumGridPoints);
220  real_type r = 0;
221  for (int i = 0; i < NumGridPoints; i++, r += GridDelta)
222  {
223  datain[i] = InFunc->f(r);
224  }
225  OutFunc.Init(0.0, Rmax, datain, true, InFunc->df(0.0), 0.0);
226  }
227  else
228  {
229  APP_ABORT("CubicSplineSingle::reset has no input functor");
230  }
231  }
232 };
233 
234 
235 template<typename RT>
237 {
238  ///typedef of the source functor
240  ///typedef for the argument
242  ///typedef for the grid
244 
250 
251  ///constructor
253  ///constructor with arguments
254  CubicSplineBasisSet(FNIN* in_, grid_type* agrid) { initialize(in_, agrid); }
255  ///set the input, analytic function
256  void setInFunc(FNIN* in_) { InFunc = in_; }
257  ///set the output numerical function
258  void setOutFunc(FNOUT* out_) { OutFunc = out_; }
259  ///reset the input/output function
260  void resetParametersExclusive(const opt_variables_type& active) override
261  {
262  if (!InFunc)
263  APP_ABORT("CubicSplineBasisSet::resetParameters failed due to null input function ");
265  reset();
266  }
267 
268  void reset() override
269  {
270  if (!OutFunc)
271  OutFunc = new FNOUT;
272  typename FNOUT::container_type datain(NumGridPoints);
273  real_type r = 0;
274  for (int i = 0; i < NumGridPoints; i++, r += GridDelta)
275  datain[i] = InFunc->f(r);
276  OutFunc->Init(0.0, Rmax, datain, true, InFunc->df(0.0), 0.0);
277  }
278 
279  /** evaluate everything: value, first and second derivatives
280  */
281  inline real_type evaluate(real_type r, real_type& dudr, real_type& d2udr2)
282  {
283  return OutFunc->splint(r, dudr, d2udr2);
284  }
285 
286  /** evaluate value only
287  */
288  inline real_type evaluate(real_type r) { return OutFunc->splint(r); }
289 
290  /** implement the virtual function of OptimizableFunctorBase */
291  real_type f(real_type r) override { return OutFunc->splint(r); }
292 
293  /** implement the virtual function of OptimizableFunctorBase */
294  real_type df(real_type r) override
295  {
296  real_type dudr, d2udr2;
297  OutFunc->splint(r, dudr, d2udr2);
298  return dudr;
299  }
300 
301  bool put(xmlNodePtr cur) override { return InFunc->put(cur); }
302 
303  void print(std::ostream& os)
304  {
305  real_type r = 0;
306  for (int i = 0; i < NumGridPoints; i++, r += GridDelta)
307  os << r << " " << OutFunc->splint(r) << std::endl;
308  }
309 
310  ///set the input, analytic function
311  void initialize(FNIN* in_, grid_type* agrid)
312  {
313  Rmax = agrid->rmax();
314  NumGridPoints = agrid->size();
315  GridDelta = Rmax / static_cast<real_type>(NumGridPoints - 1);
316  InFunc = in_;
317  reset();
318  }
319 };
320 
321 } // namespace qmcplusplus
322 #endif
void Init(point_type start, point_type end, const container_type &datain, bool closed)
Definition: CubicBspline.h:90
virtual void resetParametersExclusive(const opt_variables_type &active)=0
reset the parameters during optimizations
void reset() override
reset function
void checkInVariablesExclusive(opt_variables_type &active) override
check in variational parameters to the global list of parameters used by the optimizer.
void setOutFunc(FNOUT *out_)
set the output numerical function
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
real_type df(real_type r) override
implement the virtual function of OptimizableFunctorBase
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
void initialize(FNIN *in_, real_type rmax, int npts)
A numerical functor.
real_type evaluate(real_type r, real_type &dudr, real_type &d2udr2)
evaluate everything: value, first and second derivatives
real_type evaluate(real_type r)
evaluate value only
OptimizableFunctorBase(const std::string &name="")
default constructor
virtual real_type f(real_type r)=0
evaluate the value at r
CubicSplineSingle(FNIN *in_, real_type rc, int npts)
constructor with arguments
real_type evaluate(real_type r)
evaluate value only
real_type df(real_type r) override
implement the virtual function of OptimizableFunctorBase
OptimizableFunctorBase * makeClone() const override
create a clone of this object
Define a base class for one-dimensional functions with optimizable variables.
void setInFunc(FNIN *in_)
set the input, analytic function
RT value_type
typedef for the value_type
void print(std::ostream &os)
An abstract base class to implement a One-Dimensional grid.
void reset() override
reset function
Decalaration of One-Dimesional grids.
void resetParametersExclusive(const opt_variables_type &active) override
reset the input/output function
void initialize(FNIN *in_, grid_type *agrid)
set the input, analytic function
bool put(xmlNodePtr cur) override
process xmlnode and registers variables to optimize
void initialize(FNIN *in_, grid_type *agrid)
set the input, analytic function
real_type f(real_type r) override
implement the virtual function of OptimizableFunctorBase
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
real_type evaluate(real_type r, real_type &dudr, real_type &d2udr2, real_type &d3udr3)
evaluate everything: value, first, second and third derivatives
virtual void checkInVariablesExclusive(opt_variables_type &active)=0
check in variational parameters to the global list of parameters used by the optimizer.
value_type splint(T x)
Definition: CubicBspline.h:135
void reportStatus(std::ostream &os) override
print the state, e.g., optimizables
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
real_type evaluate(real_type r, real_type &dudr, real_type &d2udr2)
evaluate everything: value, first and second derivatives
virtual bool put(xmlNodePtr cur)=0
process xmlnode and registers variables to optimize
bool put(xmlNodePtr cur) override
process xmlnode and registers variables to optimize
OMPallocator is an allocator with fused device and dualspace allocator functionality.
void resetParametersExclusive(const opt_variables_type &active) override
reset the input/output function
static void mw_evaluateV(const int num_groups, const CubicSplineSingle *const functors[], const int n_src, const int *grp_ids, const int num_pairs, const int *ref_at, const RT *mw_dist, const int dist_stride, RT *mw_vals, Vector< char, OffloadPinnedAllocator< char >> &transfer_buffer)
evaluate sum of the pair potentials FIXME
Base class for any functor with optimizable parameters.
real_type evaluateV(const int iat, const int iStart, const int iEnd, const real_type *restrict _distArray, real_type *restrict distArrayCompressed) const
void setInFunc(FNIN *in_)
set the input, analytic function
virtual OptimizableFunctorBase * makeClone() const =0
create a clone of this object
virtual void checkOutVariables(const opt_variables_type &active)=0
check out variational optimizable variables
CubicSplineBasisSet(FNIN *in_, grid_type *agrid)
constructor with arguments
real_type evaluate(real_type r, real_type rinv)
evaluate value only
int size() const
returns the size of the grid
void evaluateVGL(const int iat, const int iStart, const int iEnd, const real_type *distArray, real_type *restrict valArray, real_type *restrict gradArray, real_type *restrict laplArray, real_type *restrict distArrayCompressed, int *restrict distIndices) const
T rmax() const
return the last grid point
declaration of CubicBspline class
real_type evaluateAll(real_type r, real_type rinv)
evaluate everything: value, first and second derivatives
CubicSplineSingle(FNIN *in_, grid_type *agrid)
constructor with arguments
CubicBspline< RT, LINEAR_1DGRID, FIRSTDERIV_CONSTRAINTS > FNOUT
typedef for the argument
virtual real_type df(real_type r)=0
evaluate the first derivative
typename CubicBsplineGrid< T, GRIDTYPE, BC >::container_type container_type
Definition: CubicBspline.h:27
real_type f(real_type r) override
implement the virtual function of OptimizableFunctorBase
optimize::VariableSet::real_type real_type
typedef for real values
CubicSplineSingle(const CubicSplineSingle &old)
void print(std::ostream &os)