QMCPACK
BsplineFunctor< REAL > Struct Template Reference

BsplineFunctor class for the Jastrows REAL is the real type used by offload target, it is the correct type for the mw data pointers and is also used to coerce/implicitly convert the Real type inherited OptimizableFunctorBase into that buffer if offload is off this happens too but is just an implementation quirk. More...

+ Inheritance diagram for BsplineFunctor< REAL >:
+ Collaboration diagram for BsplineFunctor< REAL >:

Public Types

using Real = OptimizableFunctorBase::real_type
 
- Public Types inherited from OptimizableFunctorBase
using real_type = optimize::VariableSet::real_type
 typedef for real values More...
 
using opt_variables_type = optimize::VariableSet
 typedef for variableset: this is going to be replaced More...
 

Public Member Functions

 BsplineFunctor (const std::string &my_name, Real cusp=0.0)
 constructor More...
 
OptimizableFunctorBasemakeClone () const override
 create a clone of this object More...
 
void setCusp (Real c) override
 empty virtual function to help builder classes More...
 
void setPeriodic (bool p) override
 empty virtual function to help builder classes More...
 
int getMaxIndex () const
 return the max allowed beginning index to access spline coefficients More...
 
void resize (int n)
 
void reset () override
 reset coefs from Parameters More...
 
void evaluateVGL (const int iat, const int iStart, const int iEnd, const REAL *_distArray, REAL *restrict _valArray, REAL *restrict _gradArray, REAL *restrict _laplArray, REAL *restrict distArrayCompressed, int *restrict distIndices) const
 compute value, first and second derivatives for [iStart, iEnd) pairs More...
 
REAL evaluateV (const int iat, const int iStart, const int iEnd, const REAL *restrict _distArray, REAL *restrict distArrayCompressed) const
 evaluate sum of the pair potentials for [iStart,iEnd) More...
 
Real evaluate (Real r) const
 
Real evaluate (Real r, Real rinv)
 
void evaluateAll (Real r, Real rinv)
 
Real evaluate (Real r, Real &dudr, Real &d2udr2)
 
Real evaluate (Real r, Real &dudr, Real &d2udr2, Real &d3udr3)
 
bool evaluateDerivatives (Real r, std::vector< TinyVector< Real, 3 >> &derivs) override
 
bool evaluateDerivatives (Real r, std::vector< Real > &derivs) override
 
Real f (Real r) override
 evaluate the value at r More...
 
Real df (Real r) override
 evaluate the first derivative More...
 
bool put (xmlNodePtr cur) override
 process xmlnode and registers variables to optimize More...
 
void initialize (int numPoints, std::vector< Real > &x, std::vector< Real > &y, REAL cusp, REAL rcut, std::string &id, std::string &optimize)
 
void reportStatus (std::ostream &os) override
 print the state, e.g., optimizables More...
 
void checkOutVariables (const opt_variables_type &active) override
 check out variational optimizable variables More...
 
void checkInVariablesExclusive (opt_variables_type &active) override
 check in variational parameters to the global list of parameters used by the optimizer. More...
 
void resetParametersExclusive (const opt_variables_type &active) override
 reset the parameters during optimizations. More...
 
bool isOptimizable ()
 
- Public Member Functions inherited from OptimizableFunctorBase
 OptimizableFunctorBase (const std::string &name="")
 default constructor More...
 
virtual ~OptimizableFunctorBase ()=default
 virtual destrutor More...
 
void getIndex (const opt_variables_type &active)
 
virtual void setDensity (real_type n)
 empty virtual function to help builder classes More...
 
virtual void setGridManager (bool willmanage)
 
virtual void checkInVariablesExclusive (opt_variables_type &active)=0
 check in variational parameters to the global list of parameters used by the optimizer. More...
 
virtual void resetParametersExclusive (const opt_variables_type &active)=0
 reset the parameters during optimizations More...
 
- Public Member Functions inherited from OptimizableObject
 OptimizableObject (const std::string &name)
 
const std::string & getName () const
 
bool isOptimized () const
 
void setOptimization (bool state)
 
virtual void writeVariationalParameters (hdf_archive &hout)
 Write the variational parameters for this object to the VP HDF file. More...
 
virtual void readVariationalParameters (hdf_archive &hin)
 Read the variational parameters for this object from the VP HDF file. More...
 

Static Public Member Functions

static void mw_evaluateVGL (const int iat, const int num_groups, const BsplineFunctor *const functors[], const int n_src, const int *grp_ids, const int nw, REAL *mw_vgl, const int n_padded, const REAL *mw_dist, REAL *mw_cur_allu, Vector< char, OffloadPinnedAllocator< char >> &transfer_buffer)
 compute value, gradient and laplacian for target particles This more than just a batched call of evaluateVGL More...
 
static void mw_evaluateV (const int num_groups, const BsplineFunctor *const functors[], const int n_src, const int *grp_ids, const int num_pairs, const int *ref_at, const REAL *mw_dist, const int dist_stride, REAL *mw_vals, Vector< char, OffloadPinnedAllocator< char >> &transfer_buffer)
 compute value for target-source particle pair potentials This more than just a batched call of evaluateV More...
 
static Real evaluate_impl (Real r, const Real *coefs, const Real DeltaRInv, const int max_index)
 
static Real evaluate_impl (Real r, const Real *coefs, const Real DeltaRInv, const int max_index, Real &dudr, Real &d2udr2)
 
static void mw_updateVGL (const int iat, const std::vector< bool > &isAccepted, const int num_groups, const BsplineFunctor *const functors[], const int n_src, const int *grp_ids, const int nw, REAL *mw_vgl, const int n_padded, const REAL *mw_dist, REAL *mw_allUat, REAL *mw_cur_allu, Vector< char, OffloadPinnedAllocator< char >> &transfer_buffer)
 update value, gradient and laplacian for target particles It serves multile walkers and handles update in a batched fashion More...
 

Public Attributes

std::shared_ptr< Vector< Real, OffloadAllocator< Real > > > spline_coefs_
 
int NumParams
 
Real DeltaR
 
Real DeltaRInv
 
Real CuspValue
 
Real Y
 
Real dY
 
Real d2Y
 
std::vector< TinyVector< Real, 3 > > SplineDerivs
 
std::vector< RealParameters
 
std::vector< std::string > ParameterNames
 
std::string elementType
 
std::string pairType
 
std::string fileName
 
bool notOpt
 
bool periodic
 
- Public Attributes inherited from OptimizableFunctorBase
real_type cutoff_radius = 0.0
 maximum cutoff More...
 
opt_variables_type myVars
 set of variables to be optimized More...
 

Static Public Attributes

static constexpr Real A0 = -1.0 / 6.0
 
static constexpr Real A1 = 3.0 / 6.0
 
static constexpr Real A2 = -3.0 / 6.0
 
static constexpr Real A3 = 1.0 / 6.0
 
static constexpr Real A4 = 3.0 / 6.0
 
static constexpr Real A5 = -6.0 / 6.0
 
static constexpr Real A6 = 0.0 / 6.0
 
static constexpr Real A7 = 4.0 / 6.0
 
static constexpr Real A8 = -3.0 / 6.0
 
static constexpr Real A9 = 3.0 / 6.0
 
static constexpr Real A10 = 3.0 / 6.0
 
static constexpr Real A11 = 1.0 / 6.0
 
static constexpr Real A12 = 1.0 / 6.0
 
static constexpr Real A13 = 0.0 / 6.0
 
static constexpr Real A14 = 0.0 / 6.0
 
static constexpr Real A15 = 0.0 / 6.0
 
static constexpr Real dA0 = 0.0
 
static constexpr Real dA1 = -0.5
 
static constexpr Real dA2 = 1.0
 
static constexpr Real dA3 = -0.5
 
static constexpr Real dA4 = 0.0
 
static constexpr Real dA5 = 1.5
 
static constexpr Real dA6 = -2.0
 
static constexpr Real dA7 = 0.0
 
static constexpr Real dA8 = 0.0
 
static constexpr Real dA9 = -1.5
 
static constexpr Real dA10 = 1.0
 
static constexpr Real dA11 = 0.5
 
static constexpr Real dA12 = 0.0
 
static constexpr Real dA13 = 0.5
 
static constexpr Real dA14 = 0.0
 
static constexpr Real dA15 = 0.0
 
static constexpr Real d2A0 = 0.0
 
static constexpr Real d2A1 = 0.0
 
static constexpr Real d2A2 = -1.0
 
static constexpr Real d2A3 = 1.0
 
static constexpr Real d2A4 = 0.0
 
static constexpr Real d2A5 = 0.0
 
static constexpr Real d2A6 = 3.0
 
static constexpr Real d2A7 = -2.0
 
static constexpr Real d2A8 = 0.0
 
static constexpr Real d2A9 = 0.0
 
static constexpr Real d2A10 = -3.0
 
static constexpr Real d2A11 = 1.0
 
static constexpr Real d2A12 = 0.0
 
static constexpr Real d2A13 = 0.0
 
static constexpr Real d2A14 = 1.0
 
static constexpr Real d2A15 = 0.0
 
static constexpr Real d3A0 = 0.0
 
static constexpr Real d3A1 = 0.0
 
static constexpr Real d3A2 = 0.0
 
static constexpr Real d3A3 = -1.0
 
static constexpr Real d3A4 = 0.0
 
static constexpr Real d3A5 = 0.0
 
static constexpr Real d3A6 = 0.0
 
static constexpr Real d3A7 = 3.0
 
static constexpr Real d3A8 = 0.0
 
static constexpr Real d3A9 = 0.0
 
static constexpr Real d3A10 = 0.0
 
static constexpr Real d3A11 = -3.0
 
static constexpr Real d3A12 = 0.0
 
static constexpr Real d3A13 = 0.0
 
static constexpr Real d3A14 = 0.0
 
static constexpr Real d3A15 = 1.0
 

Detailed Description

template<typename REAL>
struct qmcplusplus::BsplineFunctor< REAL >

BsplineFunctor class for the Jastrows REAL is the real type used by offload target, it is the correct type for the mw data pointers and is also used to coerce/implicitly convert the Real type inherited OptimizableFunctorBase into that buffer if offload is off this happens too but is just an implementation quirk.

Definition at line 30 of file BackflowBuilder.h.

Member Typedef Documentation

◆ Real

Definition at line 46 of file BsplineFunctor.h.

Constructor & Destructor Documentation

◆ BsplineFunctor()

BsplineFunctor ( const std::string &  my_name,
Real  cusp = 0.0 
)
inline

constructor

Definition at line 86 of file BsplineFunctor.h.

References OptimizableFunctorBase::cutoff_radius.

Referenced by BsplineFunctor< REAL >::makeClone().

87  : OptimizableFunctorBase(my_name), NumParams(0), CuspValue(cusp), notOpt(false), periodic(true)
88  {
89  cutoff_radius = 0.0;
90  }
OptimizableFunctorBase(const std::string &name="")
default constructor

Member Function Documentation

◆ checkInVariablesExclusive()

void checkInVariablesExclusive ( opt_variables_type active)
inlineoverridevirtual

check in variational parameters to the global list of parameters used by the optimizer.

Parameters
activea super set of optimizable variables

The existing checkInVariables implementation in WFC/SPO/.. are inclusive and it calls checkInVariables of its members class A: public SPOSet {} class B: public WFC { A objA; checkInVariables() { objA.checkInVariables(); } };

With OptimizableObject, class A: public OptimizableObject {} class B: public OptimizableObject { A objA; checkInVariablesExclusive() { // should not call objA.checkInVariablesExclusive() if objA has been extracted; } }; A vector of OptimizableObject, will be created by calling extractOptimizableObjects(). All the checkInVariablesExclusive() will be called through this vector and thus checkInVariablesExclusive implementation should only handle non-OptimizableObject members.

Implements OptimizableObject.

Definition at line 686 of file BsplineFunctor.h.

References VariableSet::insertFrom(), OptimizableFunctorBase::myVars, BsplineFunctor< REAL >::notOpt, and VariableSet::setIndexDefault().

687  {
688  if (notOpt)
689  return;
691  active.insertFrom(myVars);
692  }
void setIndexDefault()
set default Indices, namely all the variables are active
opt_variables_type myVars
set of variables to be optimized

◆ checkOutVariables()

void checkOutVariables ( const opt_variables_type active)
inlineoverridevirtual

check out variational optimizable variables

Parameters
activea super set of optimizable variables

Implements OptimizableFunctorBase.

Definition at line 679 of file BsplineFunctor.h.

References VariableSet::getIndex(), OptimizableFunctorBase::myVars, and BsplineFunctor< REAL >::notOpt.

680  {
681  if (notOpt)
682  return;
683  myVars.getIndex(active);
684  }
int getIndex(const std::string &vname) const
return the Index vaule for the named parameter
opt_variables_type myVars
set of variables to be optimized

◆ df()

Real df ( Real  r)
inlineoverridevirtual

evaluate the first derivative

Parameters
rdistance

virtual function necessary for a transformation to a numerical functor

Implements OptimizableFunctorBase.

Definition at line 479 of file BsplineFunctor.h.

References OptimizableFunctorBase::cutoff_radius, and BsplineFunctor< REAL >::evaluate().

480  {
481  if (r >= cutoff_radius)
482  return 0.0;
483  Real du, d2u;
484  evaluate(r, du, d2u);
485  return du;
486  }
OptimizableFunctorBase::real_type Real
Real evaluate(Real r) const

◆ evaluate() [1/4]

Real evaluate ( Real  r) const
inline

Definition at line 240 of file BsplineFunctor.h.

References OptimizableFunctorBase::cutoff_radius, BsplineFunctor< REAL >::DeltaRInv, BsplineFunctor< REAL >::evaluate_impl(), BsplineFunctor< REAL >::getMaxIndex(), and BsplineFunctor< REAL >::spline_coefs_.

Referenced by BsplineFunctor< REAL >::df(), BsplineFunctor< REAL >::evaluateAll(), BsplineFunctor< REAL >::f(), qmcplusplus::TEST_CASE(), and qmcplusplus::test_J1_spline().

241  {
242  Real u(0);
243  if (r < cutoff_radius)
244  u = evaluate_impl(r, spline_coefs_->data(), DeltaRInv, getMaxIndex());
245  return u;
246  }
int getMaxIndex() const
return the max allowed beginning index to access spline coefficients
OptimizableFunctorBase::real_type Real
static Real evaluate_impl(Real r, const Real *coefs, const Real DeltaRInv, const int max_index)
std::shared_ptr< Vector< Real, OffloadAllocator< Real > > > spline_coefs_

◆ evaluate() [2/4]

◆ evaluate() [3/4]

Real evaluate ( Real  r,
Real dudr,
Real d2udr2 
)
inline

Definition at line 277 of file BsplineFunctor.h.

References OptimizableFunctorBase::cutoff_radius, BsplineFunctor< REAL >::DeltaRInv, BsplineFunctor< REAL >::evaluate_impl(), BsplineFunctor< REAL >::getMaxIndex(), and BsplineFunctor< REAL >::spline_coefs_.

278  {
279  Real u(0);
280  dudr = Real(0);
281  d2udr2 = Real(0);
282 
283  if (r < cutoff_radius)
284  u = evaluate_impl(r, spline_coefs_->data(), DeltaRInv, getMaxIndex(), dudr, d2udr2);
285  return u;
286  }
int getMaxIndex() const
return the max allowed beginning index to access spline coefficients
OptimizableFunctorBase::real_type Real
static Real evaluate_impl(Real r, const Real *coefs, const Real DeltaRInv, const int max_index)
std::shared_ptr< Vector< Real, OffloadAllocator< Real > > > spline_coefs_

◆ evaluate() [4/4]

Real evaluate ( Real  r,
Real dudr,
Real d2udr2,
Real d3udr3 
)
inline

Definition at line 289 of file BsplineFunctor.h.

References BsplineFunctor< REAL >::A0, BsplineFunctor< REAL >::A1, BsplineFunctor< REAL >::A10, BsplineFunctor< REAL >::A11, BsplineFunctor< REAL >::A12, BsplineFunctor< REAL >::A13, BsplineFunctor< REAL >::A14, BsplineFunctor< REAL >::A15, BsplineFunctor< REAL >::A2, BsplineFunctor< REAL >::A3, BsplineFunctor< REAL >::A4, BsplineFunctor< REAL >::A5, BsplineFunctor< REAL >::A6, BsplineFunctor< REAL >::A7, BsplineFunctor< REAL >::A8, BsplineFunctor< REAL >::A9, OptimizableFunctorBase::cutoff_radius, BsplineFunctor< REAL >::d2A0, BsplineFunctor< REAL >::d2A1, BsplineFunctor< REAL >::d2A10, BsplineFunctor< REAL >::d2A11, BsplineFunctor< REAL >::d2A12, BsplineFunctor< REAL >::d2A13, BsplineFunctor< REAL >::d2A14, BsplineFunctor< REAL >::d2A15, BsplineFunctor< REAL >::d2A2, BsplineFunctor< REAL >::d2A3, BsplineFunctor< REAL >::d2A4, BsplineFunctor< REAL >::d2A5, BsplineFunctor< REAL >::d2A6, BsplineFunctor< REAL >::d2A7, BsplineFunctor< REAL >::d2A8, BsplineFunctor< REAL >::d2A9, BsplineFunctor< REAL >::d3A0, BsplineFunctor< REAL >::d3A1, BsplineFunctor< REAL >::d3A10, BsplineFunctor< REAL >::d3A11, BsplineFunctor< REAL >::d3A12, BsplineFunctor< REAL >::d3A13, BsplineFunctor< REAL >::d3A14, BsplineFunctor< REAL >::d3A15, BsplineFunctor< REAL >::d3A2, BsplineFunctor< REAL >::d3A3, BsplineFunctor< REAL >::d3A4, BsplineFunctor< REAL >::d3A5, BsplineFunctor< REAL >::d3A6, BsplineFunctor< REAL >::d3A7, BsplineFunctor< REAL >::d3A8, BsplineFunctor< REAL >::d3A9, BsplineFunctor< REAL >::dA0, BsplineFunctor< REAL >::dA1, BsplineFunctor< REAL >::dA10, BsplineFunctor< REAL >::dA11, BsplineFunctor< REAL >::dA12, BsplineFunctor< REAL >::dA13, BsplineFunctor< REAL >::dA14, BsplineFunctor< REAL >::dA15, BsplineFunctor< REAL >::dA2, BsplineFunctor< REAL >::dA3, BsplineFunctor< REAL >::dA4, BsplineFunctor< REAL >::dA5, BsplineFunctor< REAL >::dA6, BsplineFunctor< REAL >::dA7, BsplineFunctor< REAL >::dA8, BsplineFunctor< REAL >::dA9, BsplineFunctor< REAL >::DeltaRInv, BsplineFunctor< REAL >::getMaxIndex(), qmcplusplus::getSplineBound(), and BsplineFunctor< REAL >::spline_coefs_.

290  {
291  if (r >= cutoff_radius)
292  {
293  dudr = d2udr2 = d3udr3 = 0.0;
294  return 0.0;
295  }
296  // Real eps = 1.0e-5;
297  // Real dudr_FD = (evaluate(r+eps)-evaluate(r-eps))/(2.0*eps);
298  // Real d2udr2_FD = (evaluate(r+eps)+evaluate(r-eps)-2.0*evaluate(r))/(eps*eps);
299  // Real d3udr3_FD = (-1.0*evaluate(r+1.0*eps)
300  // +2.0*evaluate(r+0.5*eps)
301  // -2.0*evaluate(r-0.5*eps)
302  // +1.0*evaluate(r-1.0*eps))/(eps*eps*eps);
303  r *= DeltaRInv;
304  int i;
305  Real t;
306  getSplineBound(r, getMaxIndex(), i, t);
307  Real tp[4];
308  tp[0] = t * t * t;
309  tp[1] = t * t;
310  tp[2] = t;
311  tp[3] = 1.0;
312  auto& coefs = *spline_coefs_;
313  d3udr3 = DeltaRInv * DeltaRInv * DeltaRInv *
314  (coefs[i + 0] * (d3A0 * tp[0] + d3A1 * tp[1] + d3A2 * tp[2] + d3A3 * tp[3]) +
315  coefs[i + 1] * (d3A4 * tp[0] + d3A5 * tp[1] + d3A6 * tp[2] + d3A7 * tp[3]) +
316  coefs[i + 2] * (d3A8 * tp[0] + d3A9 * tp[1] + d3A10 * tp[2] + d3A11 * tp[3]) +
317  coefs[i + 3] * (d3A12 * tp[0] + d3A13 * tp[1] + d3A14 * tp[2] + d3A15 * tp[3]));
318  d2udr2 = DeltaRInv * DeltaRInv *
319  (coefs[i + 0] * (d2A0 * tp[0] + d2A1 * tp[1] + d2A2 * tp[2] + d2A3 * tp[3]) +
320  coefs[i + 1] * (d2A4 * tp[0] + d2A5 * tp[1] + d2A6 * tp[2] + d2A7 * tp[3]) +
321  coefs[i + 2] * (d2A8 * tp[0] + d2A9 * tp[1] + d2A10 * tp[2] + d2A11 * tp[3]) +
322  coefs[i + 3] * (d2A12 * tp[0] + d2A13 * tp[1] + d2A14 * tp[2] + d2A15 * tp[3]));
323  dudr = DeltaRInv *
324  (coefs[i + 0] * (dA0 * tp[0] + dA1 * tp[1] + dA2 * tp[2] + dA3 * tp[3]) +
325  coefs[i + 1] * (dA4 * tp[0] + dA5 * tp[1] + dA6 * tp[2] + dA7 * tp[3]) +
326  coefs[i + 2] * (dA8 * tp[0] + dA9 * tp[1] + dA10 * tp[2] + dA11 * tp[3]) +
327  coefs[i + 3] * (dA12 * tp[0] + dA13 * tp[1] + dA14 * tp[2] + dA15 * tp[3]));
328  // if (std::abs(dudr_FD-dudr) > 1.0e-8)
329  // std::cerr << "Error in BsplineFunction: dudr = " << dudr
330  // << " dudr_FD = " << dudr_FD << std::endl;
331  // if (std::abs(d2udr2_FD-d2udr2) > 1.0e-4)
332  // std::cerr << "Error in BsplineFunction: r = " << r << " d2udr2 = " << dudr
333  // << " d2udr2_FD = " << d2udr2_FD << " rcut = " << cutoff_radius << std::endl;
334  // if (std::abs(d3udr3_FD-d3udr3) > 1.0e-4)
335  // std::cerr << "Error in BsplineFunction: r = " << r << " d3udr3 = " << dudr
336  // << " d3udr3_FD = " << d3udr3_FD << " rcut = " << cutoff_radius << std::endl;
337  return (coefs[i + 0] * (A0 * tp[0] + A1 * tp[1] + A2 * tp[2] + A3 * tp[3]) +
338  coefs[i + 1] * (A4 * tp[0] + A5 * tp[1] + A6 * tp[2] + A7 * tp[3]) +
339  coefs[i + 2] * (A8 * tp[0] + A9 * tp[1] + A10 * tp[2] + A11 * tp[3]) +
340  coefs[i + 3] * (A12 * tp[0] + A13 * tp[1] + A14 * tp[2] + A15 * tp[3]));
341  }
static constexpr Real A1
static constexpr Real d2A8
static constexpr Real dA6
static constexpr Real d2A7
static constexpr Real d2A9
static constexpr Real dA3
static constexpr Real d2A13
static constexpr Real dA12
static constexpr Real d2A10
static constexpr Real d2A14
static constexpr Real A5
static constexpr Real A10
static constexpr Real dA9
static constexpr Real d2A5
static constexpr Real d3A9
static constexpr Real A6
static constexpr Real A12
static constexpr Real A0
static constexpr Real d3A10
int getMaxIndex() const
return the max allowed beginning index to access spline coefficients
static constexpr Real A7
static constexpr Real d3A6
static constexpr Real d3A5
static constexpr Real d3A14
static constexpr Real d3A7
static constexpr Real d2A2
static constexpr Real dA7
static constexpr Real dA10
static constexpr Real d3A0
OptimizableFunctorBase::real_type Real
static constexpr Real d3A8
static constexpr Real d3A4
static constexpr Real d2A3
static constexpr Real d2A15
static constexpr Real d3A15
static constexpr Real dA8
static constexpr Real d2A1
static constexpr Real d3A3
static constexpr Real dA11
static constexpr Real dA0
static constexpr Real A3
static constexpr Real dA1
static constexpr Real d3A1
static constexpr Real dA5
static constexpr Real dA4
static constexpr Real d3A13
static constexpr Real A11
static constexpr Real dA2
static constexpr Real d2A0
static constexpr Real A2
static constexpr Real d2A6
static constexpr Real A4
static constexpr Real d2A11
void getSplineBound(const T x, const int nmax, int &ind, TRESIDUAL &dx)
break x into the integer part and residual part and apply bounds
Definition: SplineBound.hpp:37
static constexpr Real d3A11
static constexpr Real dA14
static constexpr Real A13
static constexpr Real d2A12
static constexpr Real d3A2
static constexpr Real A8
std::shared_ptr< Vector< Real, OffloadAllocator< Real > > > spline_coefs_
static constexpr Real d2A4
static constexpr Real dA13
static constexpr Real A15
static constexpr Real A9
static constexpr Real d3A12
static constexpr Real dA15
static constexpr Real A14

◆ evaluate_impl() [1/2]

static Real evaluate_impl ( Real  r,
const Real coefs,
const Real  DeltaRInv,
const int  max_index 
)
inlinestatic

Definition at line 224 of file BsplineFunctor.h.

References BsplineFunctor< REAL >::A0, BsplineFunctor< REAL >::A1, BsplineFunctor< REAL >::A10, BsplineFunctor< REAL >::A11, BsplineFunctor< REAL >::A12, BsplineFunctor< REAL >::A13, BsplineFunctor< REAL >::A14, BsplineFunctor< REAL >::A15, BsplineFunctor< REAL >::A2, BsplineFunctor< REAL >::A3, BsplineFunctor< REAL >::A4, BsplineFunctor< REAL >::A5, BsplineFunctor< REAL >::A6, BsplineFunctor< REAL >::A7, BsplineFunctor< REAL >::A8, BsplineFunctor< REAL >::A9, BsplineFunctor< REAL >::DeltaRInv, and qmcplusplus::getSplineBound().

Referenced by BsplineFunctor< REAL >::evaluate().

225  {
226  r *= DeltaRInv;
227  int i;
228  Real t;
229  getSplineBound(r, max_index, i, t);
230 
231  Real sCoef0 = coefs[i + 0];
232  Real sCoef1 = coefs[i + 1];
233  Real sCoef2 = coefs[i + 2];
234  Real sCoef3 = coefs[i + 3];
235 
236  return (sCoef0 * (((A0 * t + A1) * t + A2) * t + A3) + sCoef1 * (((A4 * t + A5) * t + A6) * t + A7) +
237  sCoef2 * (((A8 * t + A9) * t + A10) * t + A11) + sCoef3 * (((A12 * t + A13) * t + A14) * t + A15));
238  }
static constexpr Real A1
static constexpr Real A5
static constexpr Real A10
static constexpr Real A6
static constexpr Real A12
static constexpr Real A0
static constexpr Real A7
OptimizableFunctorBase::real_type Real
static constexpr Real A3
static constexpr Real A11
static constexpr Real A2
static constexpr Real A4
void getSplineBound(const T x, const int nmax, int &ind, TRESIDUAL &dx)
break x into the integer part and residual part and apply bounds
Definition: SplineBound.hpp:37
static constexpr Real A13
static constexpr Real A8
static constexpr Real A15
static constexpr Real A9
static constexpr Real A14

◆ evaluate_impl() [2/2]

static Real evaluate_impl ( Real  r,
const Real coefs,
const Real  DeltaRInv,
const int  max_index,
Real dudr,
Real d2udr2 
)
inlinestatic

Definition at line 252 of file BsplineFunctor.h.

References BsplineFunctor< REAL >::A0, BsplineFunctor< REAL >::A1, BsplineFunctor< REAL >::A10, BsplineFunctor< REAL >::A11, BsplineFunctor< REAL >::A12, BsplineFunctor< REAL >::A13, BsplineFunctor< REAL >::A14, BsplineFunctor< REAL >::A15, BsplineFunctor< REAL >::A2, BsplineFunctor< REAL >::A3, BsplineFunctor< REAL >::A4, BsplineFunctor< REAL >::A5, BsplineFunctor< REAL >::A6, BsplineFunctor< REAL >::A7, BsplineFunctor< REAL >::A8, BsplineFunctor< REAL >::A9, BsplineFunctor< REAL >::d2A10, BsplineFunctor< REAL >::d2A11, BsplineFunctor< REAL >::d2A14, BsplineFunctor< REAL >::d2A15, BsplineFunctor< REAL >::d2A2, BsplineFunctor< REAL >::d2A3, BsplineFunctor< REAL >::d2A6, BsplineFunctor< REAL >::d2A7, BsplineFunctor< REAL >::dA1, BsplineFunctor< REAL >::dA10, BsplineFunctor< REAL >::dA11, BsplineFunctor< REAL >::dA13, BsplineFunctor< REAL >::dA14, BsplineFunctor< REAL >::dA15, BsplineFunctor< REAL >::dA2, BsplineFunctor< REAL >::dA3, BsplineFunctor< REAL >::dA5, BsplineFunctor< REAL >::dA6, BsplineFunctor< REAL >::dA7, BsplineFunctor< REAL >::dA9, BsplineFunctor< REAL >::DeltaRInv, and qmcplusplus::getSplineBound().

253  {
254  r *= DeltaRInv;
255  int i;
256  Real t;
257  getSplineBound(r, max_index, i, t);
258 
259  Real sCoef0 = coefs[i + 0];
260  Real sCoef1 = coefs[i + 1];
261  Real sCoef2 = coefs[i + 2];
262  Real sCoef3 = coefs[i + 3];
263 
264  d2udr2 = DeltaRInv * DeltaRInv *
265  (sCoef0 * (d2A2 * t + d2A3) + sCoef1 * (d2A6 * t + d2A7) + sCoef2 * (d2A10 * t + d2A11) +
266  sCoef3 * (d2A14 * t + d2A15));
267 
268  dudr = DeltaRInv *
269  (sCoef0 * ((dA1 * t + dA2) * t + dA3) + sCoef1 * ((dA5 * t + dA6) * t + dA7) +
270  sCoef2 * ((dA9 * t + dA10) * t + dA11) + sCoef3 * ((dA13 * t + dA14) * t + dA15));
271 
272  Real u = (sCoef0 * (((A0 * t + A1) * t + A2) * t + A3) + sCoef1 * (((A4 * t + A5) * t + A6) * t + A7) +
273  sCoef2 * (((A8 * t + A9) * t + A10) * t + A11) + sCoef3 * (((A12 * t + A13) * t + A14) * t + A15));
274  return u;
275  }
static constexpr Real A1
static constexpr Real dA6
static constexpr Real d2A7
static constexpr Real dA3
static constexpr Real d2A10
static constexpr Real d2A14
static constexpr Real A5
static constexpr Real A10
static constexpr Real dA9
static constexpr Real A6
static constexpr Real A12
static constexpr Real A0
static constexpr Real A7
static constexpr Real d2A2
static constexpr Real dA7
static constexpr Real dA10
OptimizableFunctorBase::real_type Real
static constexpr Real d2A3
static constexpr Real d2A15
static constexpr Real dA11
static constexpr Real A3
static constexpr Real dA1
static constexpr Real dA5
static constexpr Real A11
static constexpr Real dA2
static constexpr Real A2
static constexpr Real d2A6
static constexpr Real A4
static constexpr Real d2A11
void getSplineBound(const T x, const int nmax, int &ind, TRESIDUAL &dx)
break x into the integer part and residual part and apply bounds
Definition: SplineBound.hpp:37
static constexpr Real dA14
static constexpr Real A13
static constexpr Real A8
static constexpr Real dA13
static constexpr Real A15
static constexpr Real A9
static constexpr Real dA15
static constexpr Real A14

◆ evaluateAll()

◆ evaluateDerivatives() [1/2]

bool evaluateDerivatives ( Real  r,
std::vector< TinyVector< Real, 3 >> &  derivs 
)
inlineoverridevirtual

Reimplemented from OptimizableFunctorBase.

Definition at line 376 of file BsplineFunctor.h.

References BsplineFunctor< REAL >::A0, BsplineFunctor< REAL >::A1, BsplineFunctor< REAL >::A10, BsplineFunctor< REAL >::A11, BsplineFunctor< REAL >::A12, BsplineFunctor< REAL >::A13, BsplineFunctor< REAL >::A14, BsplineFunctor< REAL >::A15, BsplineFunctor< REAL >::A2, BsplineFunctor< REAL >::A3, BsplineFunctor< REAL >::A4, BsplineFunctor< REAL >::A5, BsplineFunctor< REAL >::A6, BsplineFunctor< REAL >::A7, BsplineFunctor< REAL >::A8, BsplineFunctor< REAL >::A9, OptimizableFunctorBase::cutoff_radius, BsplineFunctor< REAL >::d2A10, BsplineFunctor< REAL >::d2A11, BsplineFunctor< REAL >::d2A14, BsplineFunctor< REAL >::d2A15, BsplineFunctor< REAL >::d2A2, BsplineFunctor< REAL >::d2A3, BsplineFunctor< REAL >::d2A6, BsplineFunctor< REAL >::d2A7, BsplineFunctor< REAL >::dA1, BsplineFunctor< REAL >::dA10, BsplineFunctor< REAL >::dA11, BsplineFunctor< REAL >::dA13, BsplineFunctor< REAL >::dA14, BsplineFunctor< REAL >::dA15, BsplineFunctor< REAL >::dA2, BsplineFunctor< REAL >::dA3, BsplineFunctor< REAL >::dA5, BsplineFunctor< REAL >::dA6, BsplineFunctor< REAL >::dA7, BsplineFunctor< REAL >::dA9, BsplineFunctor< REAL >::DeltaRInv, BsplineFunctor< REAL >::getMaxIndex(), qmcplusplus::getSplineBound(), omptarget::min(), qmcplusplus::n, BsplineFunctor< REAL >::NumParams, and BsplineFunctor< REAL >::SplineDerivs.

Referenced by BsplineFunctor< REAL >::initialize(), and BsplineFunctor< REAL >::put().

377  {
378  if (r >= cutoff_radius)
379  return false;
380  r *= DeltaRInv;
381  int i;
382  Real t;
383  getSplineBound(r, getMaxIndex(), i, t);
384  Real tp[4];
385  tp[0] = t * t * t;
386  tp[1] = t * t;
387  tp[2] = t;
388  tp[3] = 1.0;
389 
391  // d/dp_i u(r)
392  SplineDerivs[i + 0][0] = A0 * tp[0] + A1 * tp[1] + A2 * tp[2] + A3 * tp[3];
393  SplineDerivs[i + 1][0] = A4 * tp[0] + A5 * tp[1] + A6 * tp[2] + A7 * tp[3];
394  SplineDerivs[i + 2][0] = A8 * tp[0] + A9 * tp[1] + A10 * tp[2] + A11 * tp[3];
395  SplineDerivs[i + 3][0] = A12 * tp[0] + A13 * tp[1] + A14 * tp[2] + A15 * tp[3];
396  // d/dp_i du/dr
397  SplineDerivs[i + 0][1] = DeltaRInv * (dA1 * tp[1] + dA2 * tp[2] + dA3 * tp[3]);
398  SplineDerivs[i + 1][1] = DeltaRInv * (dA5 * tp[1] + dA6 * tp[2] + dA7 * tp[3]);
399  SplineDerivs[i + 2][1] = DeltaRInv * (dA9 * tp[1] + dA10 * tp[2] + dA11 * tp[3]);
400  SplineDerivs[i + 3][1] = DeltaRInv * (dA13 * tp[1] + dA14 * tp[2] + dA15 * tp[3]);
401  // d/dp_i d2u/dr2
402  SplineDerivs[i + 0][2] = DeltaRInv * DeltaRInv * (d2A2 * tp[2] + d2A3 * tp[3]);
403  SplineDerivs[i + 1][2] = DeltaRInv * DeltaRInv * (d2A6 * tp[2] + d2A7 * tp[3]);
404  SplineDerivs[i + 2][2] = DeltaRInv * DeltaRInv * (d2A10 * tp[2] + d2A11 * tp[3]);
405  SplineDerivs[i + 3][2] = DeltaRInv * DeltaRInv * (d2A14 * tp[2] + d2A15 * tp[3]);
406 
407  int imin = std::max(i, 1);
408  int imax = std::min(i + 4, NumParams + 1);
409  for (int n = imin; n < imax; ++n)
410  derivs[n - 1] = SplineDerivs[n];
411  derivs[1] += SplineDerivs[0];
412 
413  //Real v[4],dv[4],d2v[4];
414  //v[0] = A[ 0]*tp[0] + A[ 1]*tp[1] + A[ 2]*tp[2] + A[ 3]*tp[3];
415  //v[1] = A[ 4]*tp[0] + A[ 5]*tp[1] + A[ 6]*tp[2] + A[ 7]*tp[3];
416  //v[2] = A[ 8]*tp[0] + A[ 9]*tp[1] + A10*tp[2] + A11*tp[3];
417  //v[3] = A12*tp[0] + A13*tp[1] + A14*tp[2] + A15*tp[3];
418  //// d/dp_i du/dr
419  //dv[0] = DeltaRInv * (dA[ 1]*tp[1] + dA[ 2]*tp[2] + dA[ 3]*tp[3]);
420  //dv[1] = DeltaRInv * (dA[ 5]*tp[1] + dA[ 6]*tp[2] + dA[ 7]*tp[3]);
421  //dv[2] = DeltaRInv * (dA[ 9]*tp[1] + dA10*tp[2] + dA11*tp[3]);
422  //dv[3] = DeltaRInv * (dA13*tp[1] + dA14*tp[2] + dA15*tp[3]);
423  //// d/dp_i d2u/dr2
424  //d2v[0] = DeltaRInv * DeltaRInv * (d2A[ 2]*tp[2] + d2A[ 3]*tp[3]);
425  //d2v[1] = DeltaRInv * DeltaRInv * (d2A[ 6]*tp[2] + d2A[ 7]*tp[3]);
426  //d2v[2] = DeltaRInv * DeltaRInv * (d2A10*tp[2] + d2A11*tp[3]);
427  //d2v[3] = DeltaRInv * DeltaRInv * (d2A14*tp[2] + d2A15*tp[3]);
428 
429  //int imin=std::max(i,1);
430  //int imax=std::min(i+4,NumParams+1)-1;
431  //int n=imin-1, j=imin-i;
432  //while(n<imax && j<4)
433  //{
434  // derivs[n] = TinyVector<Real,3>(v[j],dv[j],d2v[j]);
435  // n++; j++;
436  //}
437  //if(i==0) derivs[1]+= TinyVector<Real,3>(v[0],dv[0],d2v[0]);
438 
439  return true;
440  }
static constexpr Real A1
static constexpr Real dA6
static constexpr Real d2A7
static constexpr Real dA3
static constexpr Real d2A10
static constexpr Real d2A14
static constexpr Real A5
static constexpr Real A10
static constexpr Real dA9
static constexpr Real A6
static constexpr Real A12
static constexpr Real A0
int getMaxIndex() const
return the max allowed beginning index to access spline coefficients
static constexpr Real A7
T min(T a, T b)
static constexpr Real d2A2
static constexpr Real dA7
static constexpr Real dA10
OptimizableFunctorBase::real_type Real
static constexpr Real d2A3
static constexpr Real d2A15
std::vector< TinyVector< Real, 3 > > SplineDerivs
static constexpr Real dA11
static constexpr Real A3
static constexpr Real dA1
static constexpr Real dA5
static constexpr Real A11
static constexpr Real dA2
static constexpr Real A2
static constexpr Real d2A6
static constexpr Real A4
static constexpr Real d2A11
void getSplineBound(const T x, const int nmax, int &ind, TRESIDUAL &dx)
break x into the integer part and residual part and apply bounds
Definition: SplineBound.hpp:37
static constexpr Real dA14
static constexpr Real A13
static constexpr Real A8
static constexpr Real dA13
static constexpr Real A15
static constexpr Real A9
static constexpr Real dA15
static constexpr Real A14

◆ evaluateDerivatives() [2/2]

bool evaluateDerivatives ( Real  r,
std::vector< Real > &  derivs 
)
inlineoverridevirtual

Reimplemented from OptimizableFunctorBase.

Definition at line 442 of file BsplineFunctor.h.

References BsplineFunctor< REAL >::A0, BsplineFunctor< REAL >::A1, BsplineFunctor< REAL >::A10, BsplineFunctor< REAL >::A11, BsplineFunctor< REAL >::A12, BsplineFunctor< REAL >::A13, BsplineFunctor< REAL >::A14, BsplineFunctor< REAL >::A15, BsplineFunctor< REAL >::A2, BsplineFunctor< REAL >::A3, BsplineFunctor< REAL >::A4, BsplineFunctor< REAL >::A5, BsplineFunctor< REAL >::A6, BsplineFunctor< REAL >::A7, BsplineFunctor< REAL >::A8, BsplineFunctor< REAL >::A9, OptimizableFunctorBase::cutoff_radius, BsplineFunctor< REAL >::DeltaRInv, BsplineFunctor< REAL >::getMaxIndex(), qmcplusplus::getSplineBound(), omptarget::min(), qmcplusplus::n, and BsplineFunctor< REAL >::NumParams.

443  {
444  if (r >= cutoff_radius)
445  return false;
446  r *= DeltaRInv;
447  int i;
448  Real t;
449  getSplineBound(r, getMaxIndex(), i, t);
450  Real tp[4], v[4];
451  tp[0] = t * t * t;
452  tp[1] = t * t;
453  tp[2] = t;
454  tp[3] = 1.0;
455  v[0] = A0 * tp[0] + A1 * tp[1] + A2 * tp[2] + A3 * tp[3];
456  v[1] = A4 * tp[0] + A5 * tp[1] + A6 * tp[2] + A7 * tp[3];
457  v[2] = A8 * tp[0] + A9 * tp[1] + A10 * tp[2] + A11 * tp[3];
458  v[3] = A12 * tp[0] + A13 * tp[1] + A14 * tp[2] + A15 * tp[3];
459  int imin = std::max(i, 1);
460  int imax = std::min(i + 4, NumParams + 1) - 1;
461  int n = imin - 1, j = imin - i;
462  while (n < imax && j < 4)
463  {
464  derivs[n] = v[j];
465  n++;
466  j++;
467  }
468  if (i == 0)
469  derivs[1] += v[0];
470  return true;
471  }
static constexpr Real A1
static constexpr Real A5
static constexpr Real A10
static constexpr Real A6
static constexpr Real A12
static constexpr Real A0
int getMaxIndex() const
return the max allowed beginning index to access spline coefficients
static constexpr Real A7
T min(T a, T b)
OptimizableFunctorBase::real_type Real
static constexpr Real A3
static constexpr Real A11
static constexpr Real A2
static constexpr Real A4
void getSplineBound(const T x, const int nmax, int &ind, TRESIDUAL &dx)
break x into the integer part and residual part and apply bounds
Definition: SplineBound.hpp:37
static constexpr Real A13
static constexpr Real A8
static constexpr Real A15
static constexpr Real A9
static constexpr Real A14

◆ evaluateV()

REAL evaluateV ( const int  iat,
const int  iStart,
const int  iEnd,
const REAL *restrict  _distArray,
REAL *restrict  distArrayCompressed 
) const
inline

evaluate sum of the pair potentials for [iStart,iEnd)

Parameters
iatdummy
iStartstarting particle index
iEndending particle index
_distArraydistance arrUay
distArrayCompressedtemp storage to filter r_j < cutoff_radius
Returns
$\sum u(r_j)$ for r_j < cutoff_radius

Definition at line 723 of file BsplineFunctor.h.

References ASSUME_ALIGNED, and qmcplusplus::getSplineBound().

728 {
729  const Real* restrict distArray = _distArray + iStart;
730 
731  ASSUME_ALIGNED(distArrayCompressed);
732  int iCount = 0;
733  const int iLimit = iEnd - iStart;
734 
735 #pragma vector always
736  for (int jat = 0; jat < iLimit; jat++)
737  {
738  Real r = distArray[jat];
739  // pick the distances smaller than the cutoff and avoid the reference atom
740  if (r < cutoff_radius && iStart + jat != iat)
741  distArrayCompressed[iCount++] = distArray[jat];
742  }
743 
744  Real d = 0.0;
745  auto& coefs = *spline_coefs_;
746  const int max_index = getMaxIndex();
747 #pragma omp simd reduction(+ : d)
748  for (int jat = 0; jat < iCount; jat++)
749  {
750  Real r = distArrayCompressed[jat];
751  r *= DeltaRInv;
752  int i;
753  Real t;
754  getSplineBound(r, max_index, i, t);
755  Real d1 = coefs[i + 0] * (((A0 * t + A1) * t + A2) * t + A3);
756  Real d2 = coefs[i + 1] * (((A4 * t + A5) * t + A6) * t + A7);
757  Real d3 = coefs[i + 2] * (((A8 * t + A9) * t + A10) * t + A11);
758  Real d4 = coefs[i + 3] * (((A12 * t + A13) * t + A14) * t + A15);
759  d += (d1 + d2 + d3 + d4);
760  }
761  return d;
762 }
static constexpr Real A1
static constexpr Real A5
static constexpr Real A10
static constexpr Real A6
static constexpr Real A12
static constexpr Real A0
int getMaxIndex() const
return the max allowed beginning index to access spline coefficients
static constexpr Real A7
OptimizableFunctorBase::real_type Real
static constexpr Real A3
static constexpr Real A11
static constexpr Real A2
static constexpr Real A4
#define ASSUME_ALIGNED(x)
void getSplineBound(const T x, const int nmax, int &ind, TRESIDUAL &dx)
break x into the integer part and residual part and apply bounds
Definition: SplineBound.hpp:37
static constexpr Real A13
static constexpr Real A8
std::shared_ptr< Vector< Real, OffloadAllocator< Real > > > spline_coefs_
static constexpr Real A15
static constexpr Real A9
static constexpr Real A14

◆ evaluateVGL()

void evaluateVGL ( const int  iat,
const int  iStart,
const int  iEnd,
const REAL *  _distArray,
REAL *restrict  _valArray,
REAL *restrict  _gradArray,
REAL *restrict  _laplArray,
REAL *restrict  distArrayCompressed,
int *restrict  distIndices 
) const
inline

compute value, first and second derivatives for [iStart, iEnd) pairs

Parameters
iatthe source particle that should be avoided (self pairs)
iStartstarting particle index
iEndending particle index
_distArraydistance arrUay
_valArrayu(r_j) for j=[iStart,iEnd)
_gradArraydu(r_j)/dr /r_j for j=[iStart,iEnd)
_lapArrayd2u(r_j)/dr2 for j=[iStart,iEnd)
distArrayCompressedtemp storage to filter r_j < cutoff_radius
distIndicestemp storage for the compressed index

Definition at line 765 of file BsplineFunctor.h.

References ASSUME_ALIGNED, and qmcplusplus::getSplineBound().

774 {
775  Real dSquareDeltaRinv = DeltaRInv * DeltaRInv;
776  constexpr Real cOne(1);
777 
778  // START_MARK_FIRST();
779 
780  ASSUME_ALIGNED(distIndices);
781  ASSUME_ALIGNED(distArrayCompressed);
782  int iCount = 0;
783  int iLimit = iEnd - iStart;
784  const REAL* distArray = _distArray + iStart;
785  REAL* valArray = _valArray + iStart;
786  REAL* gradArray = _gradArray + iStart;
787  REAL* laplArray = _laplArray + iStart;
788 
789 #pragma vector always
790  for (int jat = 0; jat < iLimit; jat++)
791  {
792  Real r = distArray[jat];
793  if (r < cutoff_radius && iStart + jat != iat)
794  {
795  distIndices[iCount] = jat;
796  distArrayCompressed[iCount] = r;
797  iCount++;
798  }
799  }
800 
801  auto& coefs = *spline_coefs_;
802  const int max_index = getMaxIndex();
803 #pragma omp simd
804  for (int j = 0; j < iCount; j++)
805  {
806  Real r = distArrayCompressed[j];
807  int iScatter = distIndices[j];
808  Real rinv = cOne / r;
809  r *= DeltaRInv;
810  int iGather;
811  Real t;
812  getSplineBound(r, max_index, iGather, t);
813 
814  Real sCoef0 = coefs[iGather + 0];
815  Real sCoef1 = coefs[iGather + 1];
816  Real sCoef2 = coefs[iGather + 2];
817  Real sCoef3 = coefs[iGather + 3];
818 
819  laplArray[iScatter] = dSquareDeltaRinv *
820  (sCoef0 * (d2A2 * t + d2A3) + sCoef1 * (d2A6 * t + d2A7) + sCoef2 * (d2A10 * t + d2A11) +
821  sCoef3 * (d2A14 * t + d2A15));
822 
823  gradArray[iScatter] = DeltaRInv * rinv *
824  (sCoef0 * ((dA1 * t + dA2) * t + dA3) + sCoef1 * ((dA5 * t + dA6) * t + dA7) +
825  sCoef2 * ((dA9 * t + dA10) * t + dA11) + sCoef3 * ((dA13 * t + dA14) * t + dA15));
826 
827  valArray[iScatter] =
828  (sCoef0 * (((A0 * t + A1) * t + A2) * t + A3) + sCoef1 * (((A4 * t + A5) * t + A6) * t + A7) +
829  sCoef2 * (((A8 * t + A9) * t + A10) * t + A11) + sCoef3 * (((A12 * t + A13) * t + A14) * t + A15));
830  }
831 }
static constexpr Real A1
static constexpr Real dA6
static constexpr Real d2A7
static constexpr Real dA3
static constexpr Real d2A10
static constexpr Real d2A14
static constexpr Real A5
static constexpr Real A10
static constexpr Real dA9
static constexpr Real A6
static constexpr Real A12
static constexpr Real A0
int getMaxIndex() const
return the max allowed beginning index to access spline coefficients
static constexpr Real A7
static constexpr Real d2A2
static constexpr Real dA7
static constexpr Real dA10
OptimizableFunctorBase::real_type Real
static constexpr Real d2A3
static constexpr Real d2A15
static constexpr Real dA11
static constexpr Real A3
static constexpr Real dA1
static constexpr Real dA5
static constexpr Real A11
static constexpr Real dA2
static constexpr Real A2
static constexpr Real d2A6
static constexpr Real A4
static constexpr Real d2A11
#define ASSUME_ALIGNED(x)
void getSplineBound(const T x, const int nmax, int &ind, TRESIDUAL &dx)
break x into the integer part and residual part and apply bounds
Definition: SplineBound.hpp:37
static constexpr Real dA14
static constexpr Real A13
static constexpr Real A8
std::shared_ptr< Vector< Real, OffloadAllocator< Real > > > spline_coefs_
static constexpr Real dA13
static constexpr Real A15
static constexpr Real A9
static constexpr Real dA15
static constexpr Real A14

◆ f()

Real f ( Real  r)
inlineoverridevirtual

evaluate the value at r

Parameters
rdistance

virtual function necessary for a transformation to a numerical functor

Implements OptimizableFunctorBase.

Definition at line 473 of file BsplineFunctor.h.

References OptimizableFunctorBase::cutoff_radius, and BsplineFunctor< REAL >::evaluate().

474  {
475  if (r >= cutoff_radius)
476  return 0.0;
477  return evaluate(r);
478  }
Real evaluate(Real r) const

◆ getMaxIndex()

int getMaxIndex ( ) const
inline

return the max allowed beginning index to access spline coefficients

Definition at line 99 of file BsplineFunctor.h.

References BsplineFunctor< REAL >::spline_coefs_.

Referenced by BsplineFunctor< REAL >::evaluate(), BsplineFunctor< REAL >::evaluateDerivatives(), BsplineFunctor< REAL >::mw_evaluateV(), BsplineFunctor< REAL >::mw_evaluateVGL(), and BsplineFunctor< REAL >::mw_updateVGL().

99 { return spline_coefs_->size() - 4; }
std::shared_ptr< Vector< Real, OffloadAllocator< Real > > > spline_coefs_

◆ initialize()

void initialize ( int  numPoints,
std::vector< Real > &  x,
std::vector< Real > &  y,
REAL  cusp,
REAL  rcut,
std::string &  id,
std::string &  optimize 
)
inline

Definition at line 611 of file BsplineFunctor.h.

References qmcplusplus::app_log(), BsplineFunctor< REAL >::CuspValue, OptimizableFunctorBase::cutoff_radius, ReportEngine::error(), BsplineFunctor< REAL >::evaluateDerivatives(), VariableSet::insert(), qmcplusplus::LinearFit(), optimize::LOGLINEAR_P, OptimizableFunctorBase::myVars, BsplineFunctor< REAL >::notOpt, BsplineFunctor< REAL >::NumParams, BsplineFunctor< REAL >::Parameters, VariableSet::print(), BsplineFunctor< REAL >::reset(), and BsplineFunctor< REAL >::resize().

Referenced by RPAJastrow::makeShortRange().

618  {
619  ReportEngine PRE("BsplineFunctor", "initialize");
620  NumParams = numPoints;
621  cutoff_radius = rcut;
622  CuspValue = cusp;
623  if (NumParams == 0)
624  {
625  PRE.error("You must specify a positive number of parameters for the Bspline jastrow function.", true);
626  }
627  app_log() << "Initializing BsplineFunctor from array. \n";
628  app_log() << " size = " << NumParams << " parameters " << std::endl;
629  app_log() << " cusp = " << CuspValue << std::endl;
630  app_log() << " rcut = " << cutoff_radius << std::endl;
631  resize(NumParams);
632  int npts = x.size();
633  Matrix<Real> basis(npts, NumParams);
634  std::vector<TinyVector<Real, 3>> derivs(NumParams);
635  for (int i = 0; i < npts; i++)
636  {
637  Real r = x[i];
638  if (r > cutoff_radius)
639  {
640  PRE.error("Error in BsplineFunctor::initialize: r > cutoff_radius.", true);
641  }
642  evaluateDerivatives(r, derivs);
643  for (int j = 0; j < NumParams; j++)
644  basis(i, j) = derivs[j][0];
645  }
646  resize(NumParams);
647  LinearFit(y, basis, Parameters);
648  app_log() << "New parameters are:\n";
649  for (int i = 0; i < Parameters.size(); i++)
650  app_log() << " " << Parameters[i] << std::endl;
651 #if !defined(QMC_BUILD_SANDBOX_ONLY)
652  if (optimize == "yes")
653  {
654  // Setup parameter names
655  for (int i = 0; i < NumParams; i++)
656  {
657  std::stringstream sstr;
658  sstr << id << "_" << i;
659  myVars.insert(sstr.str(), (Real)Parameters[i], true, optimize::LOGLINEAR_P);
660  }
661  myVars.print(app_log());
662  }
663  else
664 #endif
665  {
666  notOpt = true;
667  app_log() << "Parameters of BsplineFunctor id:" << id << " are not being optimized.\n";
668  }
669  reset();
670  }
std::ostream & app_log()
Definition: OutputManager.h:65
std::vector< Real > Parameters
void insert(const std::string &vname, real_type v, bool enable=true, int type=OTHER_P)
Definition: VariableSet.h:133
OptimizableFunctorBase::real_type Real
bool evaluateDerivatives(Real r, std::vector< TinyVector< Real, 3 >> &derivs) override
void print(std::ostream &os, int leftPadSpaces=0, bool printHeader=false) const
void LinearFit(std::vector< T > &y, Matrix< T > &A, std::vector< T > &coefs)
Definition: LinearFit.h:28
void reset() override
reset coefs from Parameters
opt_variables_type myVars
set of variables to be optimized

◆ isOptimizable()

bool isOptimizable ( )
inline

Definition at line 708 of file BsplineFunctor.h.

References OptimizableFunctorBase::myVars, BsplineFunctor< REAL >::notOpt, BsplineFunctor< REAL >::Parameters, and VariableSet::where().

709  {
710  if (notOpt)
711  return false;
712  for (int i = 0; i < Parameters.size(); ++i)
713  {
714  int loc = myVars.where(i);
715  if (loc >= 0)
716  return true;
717  }
718  return false;
719  }
std::vector< Real > Parameters
int where(int i) const
return the locator of the i-th Index
Definition: VariableSet.h:90
opt_variables_type myVars
set of variables to be optimized

◆ makeClone()

OptimizableFunctorBase* makeClone ( ) const
inlineoverridevirtual

create a clone of this object

Implements OptimizableFunctorBase.

Definition at line 92 of file BsplineFunctor.h.

References BsplineFunctor< REAL >::BsplineFunctor().

92 { return new BsplineFunctor(*this); }
BsplineFunctor(const std::string &my_name, Real cusp=0.0)
constructor

◆ mw_evaluateV()

void mw_evaluateV ( const int  num_groups,
const BsplineFunctor< REAL > *const  functors[],
const int  n_src,
const int *  grp_ids,
const int  num_pairs,
const int *  ref_at,
const REAL *  mw_dist,
const int  dist_stride,
REAL *  mw_vals,
Vector< char, OffloadPinnedAllocator< char >> &  transfer_buffer 
)
static

compute value for target-source particle pair potentials This more than just a batched call of evaluateV

Parameters
num_groupsthe number of source particle groups
functorsfor the num_groups of source particles
n_srcthe number of source particles
grp_idsthe group ids of the n_src source particles
nnum_pairsthe number of particle pairs
ref_atthe source particles that should be avoided (self pairs)
mw_vglreturn resutls. Multi walker value, gradient and laplacian [nw][1(v)+DIM(g)+1(l)]
dist_stridethe offset of distance pointers between to consecutive walkers
mw_distMulti walker distance table [nw][1(distance)+DIM(displacements)][n_padded]
transfer_buffertemporary transfer buffer.

If mw_dist is dual space, up-to-date data is assumed on device.

Definition at line 135 of file BsplineFunctor.cpp.

References OptimizableFunctorBase::cutoff_radius, BsplineFunctor< REAL >::DeltaRInv, BsplineFunctor< REAL >::getMaxIndex(), and BsplineFunctor< REAL >::spline_coefs_.

145 {
146  /* transfer buffer used for
147  * Bspline coefs device pointer sizeof(REAL*), DeltaRInv sizeof(REAL), cutoff_radius sizeof(REAL)
148  * these contents change based on the group of the target particle, so it is prepared per call.
149  */
150  transfer_buffer.resize((sizeof(REAL*) + sizeof(REAL) * 2 + sizeof(int)) * num_groups);
151  REAL** mw_coefs_ptr = reinterpret_cast<REAL**>(transfer_buffer.data());
152  REAL* mw_DeltaRInv_ptr = reinterpret_cast<REAL*>(transfer_buffer.data() + sizeof(REAL*) * num_groups);
153  REAL* mw_cutoff_radius_ptr = mw_DeltaRInv_ptr + num_groups;
154  int* mw_max_index_ptr = reinterpret_cast<int*>(transfer_buffer.data() + (sizeof(REAL*) + sizeof(REAL) * 2) * num_groups);
155  for (int ig = 0; ig < num_groups; ig++)
156  if (functors[ig])
157  {
158  mw_coefs_ptr[ig] = functors[ig]->spline_coefs_->device_data();
159  mw_DeltaRInv_ptr[ig] = functors[ig]->DeltaRInv;
160  mw_cutoff_radius_ptr[ig] = functors[ig]->cutoff_radius;
161  mw_max_index_ptr[ig] = functors[ig]->getMaxIndex();
162  }
163  else
164  {
165  mw_coefs_ptr[ig] = nullptr;
166  mw_DeltaRInv_ptr[ig] = 0.0;
167  mw_cutoff_radius_ptr[ig] = 0.0; // important! Prevent spline evaluation to access nullptr.
168  mw_max_index_ptr[ig] = 0;
169  }
170 
171  auto* transfer_buffer_ptr = transfer_buffer.data();
172 
173  PRAGMA_OFFLOAD("omp target teams distribute map(always, to:transfer_buffer_ptr[:transfer_buffer.size()]) \
174  map(to: grp_ids[:n_src]) \
175  map(to:ref_at[:num_pairs], mw_dist[:dist_stride*num_pairs]) \
176  map(always, from:mw_vals[:num_pairs])")
177  for (int ip = 0; ip < num_pairs; ip++)
178  {
179  REAL sum = 0;
180  const REAL* dist = mw_dist + ip * dist_stride;
181  REAL** mw_coefs = reinterpret_cast<REAL**>(transfer_buffer_ptr);
182  REAL* mw_DeltaRInv = reinterpret_cast<REAL*>(transfer_buffer_ptr + sizeof(REAL*) * num_groups);
183  REAL* mw_cutoff_radius = mw_DeltaRInv + num_groups;
184  int* mw_max_index = reinterpret_cast<int*>(transfer_buffer_ptr + (sizeof(REAL*) + sizeof(REAL) * 2) * num_groups);
185  PRAGMA_OFFLOAD("omp parallel for reduction(+: sum)")
186  for (int j = 0; j < n_src; j++)
187  {
188  const int ig = grp_ids[j];
189  const REAL* coefs = mw_coefs[ig];
190  REAL DeltaRInv = mw_DeltaRInv[ig];
191  REAL cutoff_radius = mw_cutoff_radius[ig];
192  const int max_index = mw_max_index[ig];
193 
194  REAL r = dist[j];
195  if (j != ref_at[ip] && r < cutoff_radius)
196  sum += evaluate_impl(r, coefs, DeltaRInv, max_index);
197  }
198  mw_vals[ip] = sum;
199  }
200 }
for(int i=0;i< size_test;++i) CHECK(Approx(gauss_random_vals[offset_for_rs+i])
static Real evaluate_impl(Real r, const Real *coefs, const Real DeltaRInv, const int max_index)

◆ mw_evaluateVGL()

void mw_evaluateVGL ( const int  iat,
const int  num_groups,
const BsplineFunctor< REAL > *const  functors[],
const int  n_src,
const int *  grp_ids,
const int  nw,
REAL *  mw_vgl,
const int  n_padded,
const REAL *  mw_dist,
REAL *  mw_cur_allu,
Vector< char, OffloadPinnedAllocator< char >> &  transfer_buffer 
)
static

compute value, gradient and laplacian for target particles This more than just a batched call of evaluateVGL

Parameters
iatthe source particle that should be avoided (self pairs)
num_groupsthe number of source particle groups
functorsfor the num_groups of source particles
n_srcthe number of source particles
grp_idsthe group ids of the n_src source particles
nwbatch size (number of walkers)
mw_vglreturn resutls. Multi walker value, gradient and laplacian [nw][1(v)+DIM(g)+1(l)]
n_paddedthe padded size of source particles
mw_distMulti walker distance table [nw][1(distance)+DIM(displacements)][n_padded]
mw_cur_alluMulti walker value, first and second derivatives of pair potentials [nw][DIM][n_padded]. if mw_cur_allu is dual space, only update device side.
transfer_buffertemporary transfer buffer.

If mw_dist is dual space, up-to-date data is assumed on device. If mw_cur_allu is dual space, data is created on the device and there is no transfer to the host because it will be consumed by mw_updateVGL on the device.

Definition at line 26 of file BsplineFunctor.cpp.

References OptimizableFunctorBase::cutoff_radius, BsplineFunctor< REAL >::DeltaRInv, qmcplusplus::ewaldref::DIM, BsplineFunctor< REAL >::getMaxIndex(), OHMMS_DIM, and BsplineFunctor< REAL >::spline_coefs_.

37 {
38  constexpr unsigned DIM = OHMMS_DIM;
39  static_assert(DIM == 3, "only support 3D due to explicit x,y,z coded.");
40  const size_t dist_stride = n_padded * (DIM + 1);
41 
42  /* transfer buffer used for
43  * Bspline coefs device pointer sizeof(T*), DeltaRInv sizeof(T) and cutoff_radius sizeof(T)
44  * these contents change based on the group of the target particle, so it is prepared per call.
45  */
46  transfer_buffer.resize((sizeof(REAL*) + sizeof(REAL) * 2 + sizeof(int)) * num_groups);
47  REAL** mw_coefs_ptr = reinterpret_cast<REAL**>(transfer_buffer.data());
48  REAL* mw_DeltaRInv_ptr = reinterpret_cast<REAL*>(transfer_buffer.data() + sizeof(REAL*) * num_groups);
49  REAL* mw_cutoff_radius_ptr = mw_DeltaRInv_ptr + num_groups;
50  int* mw_max_index_ptr = reinterpret_cast<int*>(transfer_buffer.data() + (sizeof(REAL*) + sizeof(REAL) * 2) * num_groups);
51  for (int ig = 0; ig < num_groups; ig++)
52  if (functors[ig])
53  {
54  mw_coefs_ptr[ig] = functors[ig]->spline_coefs_->device_data();
55  mw_DeltaRInv_ptr[ig] = functors[ig]->DeltaRInv;
56  mw_cutoff_radius_ptr[ig] = functors[ig]->cutoff_radius;
57  mw_max_index_ptr[ig] = functors[ig]->getMaxIndex();
58  }
59  else
60  {
61  mw_coefs_ptr[ig] = nullptr;
62  mw_DeltaRInv_ptr[ig] = 0.0;
63  mw_cutoff_radius_ptr[ig] = 0.0; // important! Prevent spline evaluation to access nullptr.
64  mw_max_index_ptr[ig] = 0;
65  }
66 
67  auto* transfer_buffer_ptr = transfer_buffer.data();
68 
69  PRAGMA_OFFLOAD("omp target teams distribute map(always, to: transfer_buffer_ptr[:transfer_buffer.size()]) \
70  map(to: grp_ids[:n_src]) \
71  map(to: mw_dist[:dist_stride*nw]) \
72  map(from: mw_cur_allu[:n_padded*3*nw]) \
73  map(always, from: mw_vgl[:(DIM+2)*nw])")
74  for (int ip = 0; ip < nw; ip++)
75  {
76  REAL val_sum(0);
77  REAL grad_x(0);
78  REAL grad_y(0);
79  REAL grad_z(0);
80  REAL lapl(0);
81 
82  const REAL* dist = mw_dist + ip * dist_stride;
83  const REAL* dipl_x = dist + n_padded;
84  const REAL* dipl_y = dist + n_padded * 2;
85  const REAL* dipl_z = dist + n_padded * 3;
86 
87  REAL** mw_coefs = reinterpret_cast<REAL**>(transfer_buffer_ptr);
88  REAL* mw_DeltaRInv = reinterpret_cast<REAL*>(transfer_buffer_ptr + sizeof(REAL*) * num_groups);
89  REAL* mw_cutoff_radius = mw_DeltaRInv + num_groups;
90  int* mw_max_index = reinterpret_cast<int*>(transfer_buffer_ptr + (sizeof(REAL*) + sizeof(REAL) * 2) * num_groups);
91 
92  REAL* cur_allu = mw_cur_allu + ip * n_padded * 3;
93 
94  PRAGMA_OFFLOAD("omp parallel for reduction(+: val_sum, grad_x, grad_y, grad_z, lapl)")
95  for (int j = 0; j < n_src; j++)
96  {
97  if (j == iat)
98  continue;
99  const int ig = grp_ids[j];
100  const REAL* coefs = mw_coefs[ig];
101  REAL DeltaRInv = mw_DeltaRInv[ig];
102  REAL cutoff_radius = mw_cutoff_radius[ig];
103  const int max_index = mw_max_index[ig];
104 
105  REAL r = dist[j];
106  REAL u(0);
107  REAL dudr(0);
108  REAL d2udr2(0);
109  if (r < cutoff_radius)
110  {
111  u = evaluate_impl(r, coefs, DeltaRInv, max_index, dudr, d2udr2);
112  dudr *= REAL(1) / r;
113  }
114  // save u, dudr/r and d2udr2 to cur_allu
115  cur_allu[j] = u;
116  cur_allu[j + n_padded] = dudr;
117  cur_allu[j + n_padded * 2] = d2udr2;
118  val_sum += u;
119  lapl += d2udr2 + (DIM - 1) * dudr;
120  grad_x += dudr * dipl_x[j];
121  grad_y += dudr * dipl_y[j];
122  grad_z += dudr * dipl_z[j];
123  }
124 
125  REAL* vgl = mw_vgl + ip * (DIM + 2);
126  vgl[0] = val_sum;
127  vgl[1] = grad_x;
128  vgl[2] = grad_y;
129  vgl[3] = grad_z;
130  vgl[4] = -lapl;
131  }
132 }
#define OHMMS_DIM
Definition: config.h:64
for(int i=0;i< size_test;++i) CHECK(Approx(gauss_random_vals[offset_for_rs+i])
static Real evaluate_impl(Real r, const Real *coefs, const Real DeltaRInv, const int max_index)

◆ mw_updateVGL()

void mw_updateVGL ( const int  iat,
const std::vector< bool > &  isAccepted,
const int  num_groups,
const BsplineFunctor< REAL > *const  functors[],
const int  n_src,
const int *  grp_ids,
const int  nw,
REAL *  mw_vgl,
const int  n_padded,
const REAL *  mw_dist,
REAL *  mw_allUat,
REAL *  mw_cur_allu,
Vector< char, OffloadPinnedAllocator< char >> &  transfer_buffer 
)
static

update value, gradient and laplacian for target particles It serves multile walkers and handles update in a batched fashion

Parameters
iatthe source particle that should be avoided (self pairs)
isAcceptedaccept/reject status
num_groupsthe number of source particle groups
functorsfor the num_groups of source particles
n_srcthe number of source particles
grp_idsthe group ids of the n_src source particles
nwbatch size (number of walkers)
mw_vglMulti walker value, gradient and laplacian [nw][1(v)+DIM(g)+1(l)]
n_paddedthe padded size of source particles
mw_distMulti walker distance table [new + old][nw][1(distance)+DIM(displacements)][n_padded]
mw_allUat,returnedresults. Multi walker value, gradient and laplacian of pair potentials [nw][1(v)+DIM(g)+1(l)][n_padded]
mw_cur_alluMulti walker value, first and second derivatives of pair potentials [nw][DIM][n_padded]
transfer_buffertemporary transfer buffer

If mw_dist is dual space, up-to-date data is assumed on device. If mw_cur_allu is dual space, data on the device is consumed and no transfer is needed.

Definition at line 203 of file BsplineFunctor.cpp.

References OptimizableFunctorBase::cutoff_radius, BsplineFunctor< REAL >::DeltaRInv, qmcplusplus::ewaldref::DIM, BsplineFunctor< REAL >::getMaxIndex(), OHMMS_DIM, and BsplineFunctor< REAL >::spline_coefs_.

216 {
217  constexpr unsigned DIM = OHMMS_DIM;
218  static_assert(DIM == 3, "only support 3D due to explicit x,y,z coded.");
219  const size_t dist_stride = n_padded * (DIM + 1);
220 
221  /* transfer buffer used for
222  * Bspline coefs device pointer sizeof(REAL*), DeltaRInv sizeof(REAL), cutoff_radius sizeof(REAL)
223  * and packed accept list at most nw * sizeof(int)
224  * these contents change based on the group of the target particle, so it is prepared per call.
225  */
226  transfer_buffer.resize((sizeof(REAL*) + sizeof(REAL) * 2 + sizeof(int)) * num_groups + nw * sizeof(int));
227  REAL** mw_coefs_ptr = reinterpret_cast<REAL**>(transfer_buffer.data());
228  REAL* mw_DeltaRInv_ptr = reinterpret_cast<REAL*>(transfer_buffer.data() + sizeof(REAL*) * num_groups);
229  REAL* mw_cutoff_radius_ptr = mw_DeltaRInv_ptr + num_groups;
230  int* mw_max_index_ptr = reinterpret_cast<int*>(transfer_buffer.data() + (sizeof(REAL*) + sizeof(REAL) * 2) * num_groups);
231  int* accepted_indices = mw_max_index_ptr + num_groups;
232 
233  for (int ig = 0; ig < num_groups; ig++)
234  if (functors[ig])
235  {
236  mw_coefs_ptr[ig] = functors[ig]->spline_coefs_->device_data();
237  mw_DeltaRInv_ptr[ig] = functors[ig]->DeltaRInv;
238  mw_cutoff_radius_ptr[ig] = functors[ig]->cutoff_radius;
239  mw_max_index_ptr[ig] = functors[ig]->getMaxIndex();
240  }
241  else
242  {
243  mw_coefs_ptr[ig] = nullptr;
244  mw_DeltaRInv_ptr[ig] = 0.0;
245  mw_cutoff_radius_ptr[ig] = 0.0; // important! Prevent spline evaluation to access nullptr.
246  mw_max_index_ptr[ig] = 0;
247  }
248 
249  int nw_accepted = 0;
250  for (int iw = 0; iw < nw; iw++)
251  if (isAccepted[iw])
252  accepted_indices[nw_accepted++] = iw;
253 
254  auto* transfer_buffer_ptr = transfer_buffer.data();
255 
256  PRAGMA_OFFLOAD("omp target teams distribute map(always, to: transfer_buffer_ptr[:transfer_buffer.size()]) \
257  map(to: grp_ids[:n_src]) \
258  map(to: mw_dist[:dist_stride*nw]) \
259  map(to: mw_vgl[:(DIM+2)*nw]) \
260  map(always, from: mw_allUat[:nw * n_padded * (DIM + 2)])")
261  for (int iw = 0; iw < nw_accepted; iw++)
262  {
263  REAL** mw_coefs = reinterpret_cast<REAL**>(transfer_buffer_ptr);
264  REAL* mw_DeltaRInv = reinterpret_cast<REAL*>(transfer_buffer_ptr + sizeof(REAL*) * num_groups);
265  REAL* mw_cutoff_radius = mw_DeltaRInv + num_groups;
266  int* mw_max_index = reinterpret_cast<int*>(transfer_buffer_ptr + (sizeof(REAL*) + sizeof(REAL) * 2) * num_groups);
267  int* accepted_indices = mw_max_index + num_groups;
268  const int ip = accepted_indices[iw];
269 
270  const REAL* dist_new = mw_dist + ip * dist_stride;
271  const REAL* dipl_x_new = dist_new + n_padded;
272  const REAL* dipl_y_new = dist_new + n_padded * 2;
273  const REAL* dipl_z_new = dist_new + n_padded * 3;
274 
275  const REAL* dist_old = mw_dist + ip * dist_stride + dist_stride * nw;
276  const REAL* dipl_x_old = dist_old + n_padded;
277  const REAL* dipl_y_old = dist_old + n_padded * 2;
278  const REAL* dipl_z_old = dist_old + n_padded * 3;
279 
280  REAL* Uat = mw_allUat + ip * n_padded;
281  REAL* dUat_x = mw_allUat + n_padded * nw + ip * n_padded * DIM;
282  REAL* dUat_y = dUat_x + n_padded;
283  REAL* dUat_z = dUat_y + n_padded;
284  REAL* d2Uat = mw_allUat + n_padded * (DIM + 1) * nw + ip * n_padded;
285 
286  REAL* cur_allu = mw_cur_allu + ip * n_padded * 3;
287 
288  PRAGMA_OFFLOAD("omp parallel for")
289  for (int j = 0; j < n_src; j++)
290  {
291  if (j == iat)
292  continue;
293  const int ig = grp_ids[j];
294  const REAL* coefs = mw_coefs[ig];
295  REAL DeltaRInv = mw_DeltaRInv[ig];
296  REAL cutoff_radius = mw_cutoff_radius[ig];
297  const int max_index = mw_max_index[ig];
298 
299  REAL r = dist_old[j];
300  REAL u(0);
301  REAL dudr(0);
302  REAL d2udr2(0);
303  if (r < cutoff_radius)
304  {
305  u = evaluate_impl(dist_old[j], coefs, DeltaRInv, max_index, dudr, d2udr2);
306  dudr *= REAL(1) / r;
307  }
308  // update Uat, dUat, d2Uat
309  REAL cur_u = cur_allu[j];
310  REAL cur_dudr = cur_allu[j + n_padded];
311  REAL cur_d2udr2 = cur_allu[j + n_padded * 2];
312  Uat[j] += cur_u - u;
313  dUat_x[j] -= dipl_x_new[j] * cur_dudr - dipl_x_old[j] * dudr;
314  dUat_y[j] -= dipl_y_new[j] * cur_dudr - dipl_y_old[j] * dudr;
315  dUat_z[j] -= dipl_z_new[j] * cur_dudr - dipl_z_old[j] * dudr;
316  constexpr REAL lapfac(DIM - 1);
317  d2Uat[j] -= cur_d2udr2 + lapfac * cur_dudr - (d2udr2 + lapfac * dudr);
318  }
319  REAL* vgl = mw_vgl + ip * (DIM + 2);
320  Uat[iat] = vgl[0];
321  dUat_x[iat] = vgl[1];
322  dUat_y[iat] = vgl[2];
323  dUat_z[iat] = vgl[3];
324  d2Uat[iat] = vgl[4];
325  }
326 }
#define OHMMS_DIM
Definition: config.h:64
for(int i=0;i< size_test;++i) CHECK(Approx(gauss_random_vals[offset_for_rs+i])
static Real evaluate_impl(Real r, const Real *coefs, const Real DeltaRInv, const int max_index)

◆ put()

bool put ( xmlNodePtr  cur)
inlineoverridevirtual

process xmlnode and registers variables to optimize

Parameters
curxmlNode for a functor

Implements OptimizableFunctorBase.

Definition at line 489 of file BsplineFunctor.h.

References OhmmsAttributeSet::add(), APP_ABORT, qmcplusplus::app_log(), qmcplusplus::app_summary(), BsplineFunctor< REAL >::CuspValue, OptimizableFunctorBase::cutoff_radius, qmcplusplus::Units::charge::e, ReportEngine::error(), BsplineFunctor< REAL >::evaluateDerivatives(), VariableSet::insert(), qmcplusplus::LinearFit(), optimize::LOGLINEAR_P, OptimizableFunctorBase::myVars, BsplineFunctor< REAL >::notOpt, BsplineFunctor< REAL >::NumParams, BsplineFunctor< REAL >::Parameters, BsplineFunctor< REAL >::periodic, VariableSet::print(), OhmmsAttributeSet::put(), putContent(), BsplineFunctor< REAL >::reset(), and BsplineFunctor< REAL >::resize().

490  {
491  ReportEngine PRE("BsplineFunctor", "put(xmlNodePtr)");
492  //CuspValue = -1.0e10;
493  NumParams = 0;
494  //cutoff_radius = 0.0;
495  OhmmsAttributeSet rAttrib;
496  Real radius = -1.0;
497  rAttrib.add(NumParams, "size");
498  rAttrib.add(radius, "rcut");
499  rAttrib.add(radius, "cutoff");
500  rAttrib.put(cur);
501  if (radius < 0.0)
502  if (periodic)
503  {
504  app_log() << " Jastrow cutoff unspecified. Setting to Wigner-Seitz radius = " << cutoff_radius << std::endl;
505  app_log() << std::endl;
506  }
507  else
508  {
509  APP_ABORT(" Jastrow cutoff unspecified. Cutoff must be given when using open boundary conditions");
510  }
511  else if (periodic && radius > cutoff_radius)
512  {
513  if (radius - cutoff_radius > 1e-4)
514  {
515  APP_ABORT(" The Jastrow cutoff specified should not be larger than Wigner-Seitz radius.");
516  }
517  else
518  {
519  app_log() << " The Jastrow cutoff specified is slightly larger than the Wigner-Seitz radius.";
520  app_log() << " Setting to Wigner-Seitz radius = " << cutoff_radius << ".\n";
521  }
522  }
523  else
524  cutoff_radius = radius;
525  if (NumParams == 0)
526  {
527  PRE.error("You must specify a positive number of parameters for the Bspline jastrow function.", true);
528  }
529  app_summary() << " Number of parameters: " << NumParams << std::endl;
530  app_summary() << " Cusp: " << CuspValue << std::endl;
531  app_summary() << " Cutoff radius: " << cutoff_radius << std::endl;
532  resize(NumParams);
533  // Now read coefficents
534  xmlNodePtr xmlCoefs = cur->xmlChildrenNode;
535  while (xmlCoefs != NULL)
536  {
537  std::string cname((const char*)xmlCoefs->name);
538  if (cname == "coefficients")
539  {
540  std::string type("0"), id("0");
541  std::string optimize("yes");
542  OhmmsAttributeSet cAttrib;
543  cAttrib.add(id, "id");
544  cAttrib.add(type, "type");
545  cAttrib.add(optimize, "optimize");
546  cAttrib.put(xmlCoefs);
547  if (type != "Array")
548  {
549  PRE.error("Unknown correlation type " + type + " in BsplineFunctor." + "Resetting to \"Array\"");
550  xmlNewProp(xmlCoefs, (const xmlChar*)"type", (const xmlChar*)"Array");
551  }
552  std::vector<Real> params;
553  putContent(params, xmlCoefs);
554  if (params.size() == NumParams)
555  Parameters = params;
556  else
557  {
558  app_log() << " Changing number of Bspline parameters from " << params.size() << " to " << NumParams
559  << ". Performing fit:\n";
560  // Fit function to new number of parameters
561  const int numPoints = 500;
562  BsplineFunctor<REAL> tmp_func("tmp_func", CuspValue);
563  tmp_func.cutoff_radius = cutoff_radius;
564  tmp_func.resize(params.size());
565  tmp_func.Parameters = params;
566  tmp_func.reset();
567  std::vector<Real> y(numPoints);
568  Matrix<Real> basis(numPoints, NumParams);
569  std::vector<TinyVector<Real, 3>> derivs(NumParams);
570  for (int i = 0; i < numPoints; i++)
571  {
572  Real r = (Real)i / (Real)numPoints * cutoff_radius;
573  y[i] = tmp_func.evaluate(r);
574  evaluateDerivatives(r, derivs);
575  for (int j = 0; j < NumParams; j++)
576  basis(i, j) = derivs[j][0];
577  }
578  resize(NumParams);
579  LinearFit(y, basis, Parameters);
580  app_log() << "New parameters are:\n";
581  for (int i = 0; i < Parameters.size(); i++)
582  app_log() << " " << Parameters[i] << std::endl;
583  }
584  if (optimize == "yes")
585  {
586  notOpt = false;
587  }
588  else
589  {
590  notOpt = true;
591  }
592  for (int i = 0; i < NumParams; i++)
593  {
594  std::stringstream sstr;
595  sstr << id << "_" << i;
597  }
598  int left_pad_space = 5;
599  app_log() << std::endl;
600  myVars.print(app_log(), left_pad_space, true);
601  }
602  xmlCoefs = xmlCoefs->next;
603  }
604  reset();
605  Real zeros = 0;
606  for (int i = 0; i < NumParams; i++)
607  zeros += Parameters[i] * Parameters[i];
608  return zeros > 1.0e-12; //true if Parameters are not zero
609  }
std::ostream & app_log()
Definition: OutputManager.h:65
std::ostream & app_summary()
Definition: OutputManager.h:63
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::vector< Real > Parameters
void insert(const std::string &vname, real_type v, bool enable=true, int type=OTHER_P)
Definition: VariableSet.h:133
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
OptimizableFunctorBase::real_type Real
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
bool putContent(T &a, xmlNodePtr cur)
replaces a&#39;s value with the first "element" in the "string" returned by XMLNodeString{cur}.
Definition: libxmldefs.h:88
bool evaluateDerivatives(Real r, std::vector< TinyVector< Real, 3 >> &derivs) override
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
void print(std::ostream &os, int leftPadSpaces=0, bool printHeader=false) const
void LinearFit(std::vector< T > &y, Matrix< T > &A, std::vector< T > &coefs)
Definition: LinearFit.h:28
void reset() override
reset coefs from Parameters
opt_variables_type myVars
set of variables to be optimized

◆ reportStatus()

void reportStatus ( std::ostream &  os)
inlineoverridevirtual

print the state, e.g., optimizables

Reimplemented from OptimizableObject.

Definition at line 672 of file BsplineFunctor.h.

References OptimizableFunctorBase::myVars, BsplineFunctor< REAL >::notOpt, and VariableSet::print().

673  {
674  if (notOpt)
675  return;
676  myVars.print(os);
677  }
void print(std::ostream &os, int leftPadSpaces=0, bool printHeader=false) const
opt_variables_type myVars
set of variables to be optimized

◆ reset()

void reset ( )
inlineoverridevirtual

reset coefs from Parameters

Implements OptimizableFunctorBase.

Definition at line 115 of file BsplineFunctor.h.

References BsplineFunctor< REAL >::CuspValue, OptimizableFunctorBase::cutoff_radius, BsplineFunctor< REAL >::DeltaR, BsplineFunctor< REAL >::DeltaRInv, BsplineFunctor< REAL >::NumParams, BsplineFunctor< REAL >::Parameters, and BsplineFunctor< REAL >::spline_coefs_.

Referenced by BsplineFunctor< REAL >::initialize(), RadialJastrowBuilder::initTwoBodyFunctor(), BsplineFunctor< REAL >::put(), and BsplineFunctor< REAL >::resetParametersExclusive().

116  {
117  const int numCoefs = NumParams + 4;
118  const int numKnots = numCoefs - 2;
119  DeltaR = cutoff_radius / (Real)(numKnots - 1);
120  DeltaRInv = 1.0 / DeltaR;
121  auto& coefs = *spline_coefs_;
122  for (int i = 0; i < coefs.size(); i++)
123  coefs[i] = 0.0;
124  // Ensure that cusp conditions is satisfied at the origin
125  coefs[1] = Parameters[0];
126  coefs[2] = Parameters[1];
127  coefs[0] = Parameters[1] - 2.0 * DeltaR * CuspValue;
128  for (int i = 2; i < Parameters.size(); i++)
129  coefs[i + 1] = Parameters[i];
130  coefs.updateTo();
131  }
std::vector< Real > Parameters
OptimizableFunctorBase::real_type Real
std::shared_ptr< Vector< Real, OffloadAllocator< Real > > > spline_coefs_

◆ resetParametersExclusive()

void resetParametersExclusive ( const opt_variables_type active)
inlineoverridevirtual

reset the parameters during optimizations.

Exclusive, see checkInVariablesExclusive

Implements OptimizableObject.

Definition at line 694 of file BsplineFunctor.h.

References OptimizableFunctorBase::myVars, BsplineFunctor< REAL >::notOpt, BsplineFunctor< REAL >::Parameters, BsplineFunctor< REAL >::reset(), and VariableSet::where().

695  {
696  if (notOpt)
697  return;
698  for (int i = 0; i < Parameters.size(); ++i)
699  {
700  int loc = myVars.where(i);
701  if (loc >= 0)
702  Parameters[i] = std::real(myVars[i] = active[loc]);
703  }
704  reset();
705  }
QMCTraits::RealType real
std::vector< Real > Parameters
int where(int i) const
return the locator of the i-th Index
Definition: VariableSet.h:90
void reset() override
reset coefs from Parameters
opt_variables_type myVars
set of variables to be optimized

◆ resize()

void resize ( int  n)
inline

Definition at line 101 of file BsplineFunctor.h.

References OptimizableFunctorBase::cutoff_radius, BsplineFunctor< REAL >::DeltaR, BsplineFunctor< REAL >::DeltaRInv, qmcplusplus::n, BsplineFunctor< REAL >::NumParams, BsplineFunctor< REAL >::Parameters, BsplineFunctor< REAL >::spline_coefs_, and BsplineFunctor< REAL >::SplineDerivs.

Referenced by BsplineFunctor< REAL >::initialize(), BsplineFunctor< REAL >::put(), and qmcplusplus::TEST_CASE().

102  {
103  NumParams = n;
104  int numCoefs = NumParams + 4;
105  int numKnots = numCoefs - 2;
106  DeltaR = cutoff_radius / (Real)(numKnots - 1);
107  DeltaRInv = 1.0 / DeltaR;
108  Parameters.resize(n);
109  spline_coefs_ = std::make_shared<Vector<Real, OffloadAllocator<Real>>>(numCoefs);
110  SplineDerivs.resize(numCoefs);
111  }
std::vector< Real > Parameters
OptimizableFunctorBase::real_type Real
std::vector< TinyVector< Real, 3 > > SplineDerivs
std::shared_ptr< Vector< Real, OffloadAllocator< Real > > > spline_coefs_

◆ setCusp()

void setCusp ( Real  cusp)
inlineoverridevirtual

empty virtual function to help builder classes

Reimplemented from OptimizableFunctorBase.

Definition at line 94 of file BsplineFunctor.h.

References BsplineFunctor< REAL >::CuspValue.

◆ setPeriodic()

void setPeriodic ( bool  periodic)
inlineoverridevirtual

empty virtual function to help builder classes

Reimplemented from OptimizableFunctorBase.

Definition at line 96 of file BsplineFunctor.h.

References BsplineFunctor< REAL >::periodic.

Member Data Documentation

◆ A0

◆ A1

◆ A10

◆ A11

◆ A12

◆ A13

◆ A14

◆ A15

◆ A2

◆ A3

◆ A4

◆ A5

◆ A6

◆ A7

◆ A8

◆ A9

◆ CuspValue

◆ d2A0

constexpr Real d2A0 = 0.0
static

Definition at line 58 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d2A1

constexpr Real d2A1 = 0.0
static

Definition at line 58 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d2A10

◆ d2A11

◆ d2A12

constexpr Real d2A12 = 0.0
static

Definition at line 61 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d2A13

constexpr Real d2A13 = 0.0
static

Definition at line 61 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d2A14

◆ d2A15

◆ d2A2

◆ d2A3

◆ d2A4

constexpr Real d2A4 = 0.0
static

Definition at line 59 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d2A5

constexpr Real d2A5 = 0.0
static

Definition at line 59 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d2A6

◆ d2A7

◆ d2A8

constexpr Real d2A8 = 0.0
static

Definition at line 60 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d2A9

constexpr Real d2A9 = 0.0
static

Definition at line 60 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d2Y

◆ d3A0

constexpr Real d3A0 = 0.0
static

Definition at line 63 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A1

constexpr Real d3A1 = 0.0
static

Definition at line 63 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A10

constexpr Real d3A10 = 0.0
static

Definition at line 65 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A11

constexpr Real d3A11 = -3.0
static

Definition at line 65 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A12

constexpr Real d3A12 = 0.0
static

Definition at line 66 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A13

constexpr Real d3A13 = 0.0
static

Definition at line 66 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A14

constexpr Real d3A14 = 0.0
static

Definition at line 66 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A15

constexpr Real d3A15 = 1.0
static

Definition at line 66 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A2

constexpr Real d3A2 = 0.0
static

Definition at line 63 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A3

constexpr Real d3A3 = -1.0
static

Definition at line 63 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A4

constexpr Real d3A4 = 0.0
static

Definition at line 64 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A5

constexpr Real d3A5 = 0.0
static

Definition at line 64 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A6

constexpr Real d3A6 = 0.0
static

Definition at line 64 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A7

constexpr Real d3A7 = 3.0
static

Definition at line 64 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A8

constexpr Real d3A8 = 0.0
static

Definition at line 65 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ d3A9

constexpr Real d3A9 = 0.0
static

Definition at line 65 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ dA0

constexpr Real dA0 = 0.0
static

Definition at line 53 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ dA1

◆ dA10

◆ dA11

◆ dA12

constexpr Real dA12 = 0.0
static

Definition at line 56 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ dA13

◆ dA14

◆ dA15

◆ dA2

◆ dA3

◆ dA4

constexpr Real dA4 = 0.0
static

Definition at line 54 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ dA5

◆ dA6

◆ dA7

◆ dA8

constexpr Real dA8 = 0.0
static

Definition at line 55 of file BsplineFunctor.h.

Referenced by BsplineFunctor< REAL >::evaluate().

◆ dA9

◆ DeltaR

◆ DeltaRInv

◆ dY

◆ elementType

std::string elementType

Definition at line 79 of file BsplineFunctor.h.

◆ fileName

std::string fileName

Definition at line 80 of file BsplineFunctor.h.

◆ notOpt

◆ NumParams

◆ pairType

std::string pairType

Definition at line 79 of file BsplineFunctor.h.

◆ ParameterNames

std::vector<std::string> ParameterNames

Definition at line 78 of file BsplineFunctor.h.

◆ Parameters

◆ periodic

bool periodic

◆ spline_coefs_

◆ SplineDerivs

std::vector<TinyVector<Real, 3> > SplineDerivs

◆ Y


The documentation for this struct was generated from the following files: