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) 2019 QMCPACK developers.
6//
7// File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8//                    Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
9//                    Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10//                    Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11//                    Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
12//                    Luke Shulenburger, lshulen@sandia.gov, Sandia National Laboratories
13//
14// File created by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
15//////////////////////////////////////////////////////////////////////////////////////
16
17$dire_codegen_warning
18
19/** @file UserFunctor.h
20 * @brief User-defined functor
21 */
22#ifndef QMCPLUSPLUS_USERFUNCTOR_H
23#define QMCPLUSPLUS_USERFUNCTOR_H
24#include "Numerics/OptimizableFunctorBase.h"
25#include "OhmmsData/AttributeSet.h"
26#include <cmath>
27// #include <vector>
28#include "OhmmsPETE/TinyVector.h"
29
30
31namespace qmcplusplus
32{
33/** Implements the function
34$func_str
35 *
36 */
37template<class T>
38struct UserFunctor : public OptimizableFunctorBase
39{
40
41$param_defs
42
43  ///default constructor
44  UserFunctor() { reset(); }
45
46// void setCusp(real_type cusp)
47$set_cusp
48
49  OptimizableFunctorBase* makeClone() const { return new UserFunctor(*this); }
50
51  void reset()
52  {
53  }
54
55
56
57// inline real_type evaluate(real_type r) const
58$evaluate_func
59
60// const inline real_type evaluate(real_type r, real_type& dudr, real_type& d2udr2) const
61$evaluate_func_2nd_derivative
62
63// inline real_type evaluate(real_type r, real_type& dudr, real_type& d2udr2, real_type& d3udr3) const
64$evaluate_func_3rd_derivative
65
66
67  inline real_type evaluateV(const int iat,
68                             const int iStart,
69                             const int iEnd,
70                             const T* restrict _distArray,
71                             T* restrict distArrayCompressed) const
72  {
73  // specialized evaluation loop?
74    real_type sum(0);
75    for (int idx = iStart; idx < iEnd; idx++)
76      if (idx != iat)
77        sum += evaluate(_distArray[idx]);
78    return sum;
79  }
80
81  inline void evaluateVGL(const int iat,
82                          const int iStart,
83                          const int iEnd,
84                          const T* distArray,
85                          T* restrict valArray,
86                          T* restrict gradArray,
87                          T* restrict laplArray,
88                          T* restrict distArrayCompressed,
89                          int* restrict distIndices) const
90  {
91    // specialized evaluation loop?
92    for (int idx = iStart; idx < iEnd; idx++)
93    {
94      valArray[idx] = evaluate(distArray[idx], gradArray[idx], laplArray[idx]);
95      gradArray[idx] /= distArray[idx];
96    }
97    if (iat >= iStart && iat < iEnd)
98      valArray[iat] = gradArray[iat] = laplArray[iat] = T(0);
99  }
100
101  inline real_type f(real_type r) { return evaluate(r); }
102
103  inline real_type df(real_type r)
104  {
105    real_type dudr, d2udr2;
106    real_type res = evaluate(r, dudr, d2udr2);
107    return dudr;
108  }
109
110// inline bool evaluateDerivatives(real_type r, std::vector<TinyVector<real_type, 3>>& derivs)
111$evaluate_all_parameter_derivatives
112
113// inline bool evaluateDerivatives(real_type r, std::vector<real_type>& derivs)
114$evaluate_parameter_derivative
115
116//  bool put(xmlNodePtr cur)
117$xml_input
118
119  void checkInVariables(opt_variables_type& active)
120  {
121    active.insertFrom(myVars);
122    //myVars.print(std::cout);
123  }
124
125  void checkOutVariables(const opt_variables_type& active)
126  {
127    myVars.getIndex(active);
128    //myVars.print(std::cout);
129  }
130
131//void resetParameters(const opt_variables_type& active)
132$reset_parameters
133};
134
135
136
137
138} // namespace qmcplusplus
139#endif
140