QMCPACK
UserFunctor< T > Struct Template Reference

Implements the function f = A*r/(B*r + 1) - A/B. More...

+ Inheritance diagram for UserFunctor< T >:
+ Collaboration diagram for UserFunctor< T >:

Public Member Functions

 UserFunctor (const std::string &my_name)
 default constructor More...
 
void setCusp (real_type cusp) override
 empty virtual function to help builder classes More...
 
OptimizableFunctorBasemakeClone () const override
 create a clone of this object More...
 
void reset () override
 reset function More...
 
real_type evaluate (real_type r) const
 
real_type evaluate (real_type r, real_type &dudr, real_type &d2udr2) const
 
real_type evaluate (real_type r, real_type &dudr, real_type &d2udr2, real_type &d3udr3) const
 
real_type evaluateV (const int iat, const int iStart, const int iEnd, const T *restrict _distArray, T *restrict distArrayCompressed) const
 
void evaluateVGL (const int iat, const int iStart, const int iEnd, const T *distArray, T *restrict valArray, T *restrict gradArray, T *restrict laplArray, T *restrict distArrayCompressed, int *restrict distIndices) const
 
real_type f (real_type r) override
 evaluate the value at r More...
 
real_type df (real_type r) override
 evaluate the first derivative More...
 
bool evaluateDerivatives (real_type r, std::vector< TinyVector< real_type, 3 >> &derivs) override
 
bool evaluateDerivatives (real_type r, std::vector< real_type > &derivs) override
 compute derivatives with respect to variational parameters More...
 
bool put (xmlNodePtr cur) override
 process xmlnode and registers variables to optimize More...
 
void checkInVariablesExclusive (opt_variables_type &active) override
 check in variational parameters to the global list of parameters used by the optimizer. More...
 
void checkOutVariables (const opt_variables_type &active) override
 check out variational optimizable variables More...
 
void resetParametersExclusive (const opt_variables_type &active) override
 reset the parameters during optimizations. More...
 
- 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 setPeriodic (bool periodic)
 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
 
virtual void reportStatus (std::ostream &os)
 print the state, e.g., optimizables More...
 
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_evaluateV (const int num_groups, const UserFunctor *const functors[], const int n_src, const int *grp_ids, const int num_pairs, const int *ref_at, const T *mw_dist, const int dist_stride, T *mw_vals, Vector< char, OffloadPinnedAllocator< char >> &transfer_buffer)
 evaluate sum of the pair potentials FIXME More...
 
static void mw_evaluateVGL (const int iat, const int num_groups, const UserFunctor *const functors[], const int n_src, const int *grp_ids, const int nw, T *mw_vgl, const int n_padded, const T *mw_dist, T *mw_cur_allu, Vector< char, OffloadPinnedAllocator< char >> &transfer_buffer)
 
static void mw_updateVGL (const int iat, const std::vector< bool > &isAccepted, const int num_groups, const UserFunctor *const functors[], const int n_src, const int *grp_ids, const int nw, T *mw_vgl, const int n_padded, const T *mw_dist, T *mw_allUat, T *mw_cur_allu, Vector< char, OffloadPinnedAllocator< char >> &transfer_buffer)
 

Public Attributes

bool Opt_A
 Is optimizable. More...
 
real_type A
 Value. More...
 
std::string ID_A
 Id in XML input. More...
 
bool Opt_B
 Is optimizable. More...
 
real_type B
 Value. More...
 
std::string ID_B
 Id in XML input. More...
 
- 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...
 

Additional Inherited Members

- 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...
 

Detailed Description

template<class T>
struct qmcplusplus::UserFunctor< T >

Implements the function f = A*r/(B*r + 1) - A/B.

Definition at line 47 of file UserFunctor.h.

Constructor & Destructor Documentation

◆ UserFunctor()

UserFunctor ( const std::string &  my_name)
inline

default constructor

Definition at line 66 of file UserFunctor.h.

References UserFunctor< T >::reset().

Referenced by UserFunctor< T >::makeClone().

66 : OptimizableFunctorBase(my_name) { reset(); }
OptimizableFunctorBase(const std::string &name="")
default constructor
void reset() override
reset function
Definition: UserFunctor.h:80

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 307 of file UserFunctor.h.

References VariableSet::insertFrom(), and OptimizableFunctorBase::myVars.

Referenced by qmcplusplus::TEST_CASE().

308  {
309  active.insertFrom(myVars);
310  }
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 312 of file UserFunctor.h.

References VariableSet::getIndex(), and OptimizableFunctorBase::myVars.

313  {
314  myVars.getIndex(active);
315  }
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_type df ( real_type  r)
inlineoverridevirtual

evaluate the first derivative

Parameters
rdistance

virtual function necessary for a transformation to a numerical functor

Implements OptimizableFunctorBase.

Definition at line 187 of file UserFunctor.h.

References UserFunctor< T >::evaluate().

188  {
189  real_type dudr, d2udr2;
190  real_type res = evaluate(r, dudr, d2udr2);
191  return dudr;
192  }
OHMMS_PRECISION real_type
real_type evaluate(real_type r) const
Definition: UserFunctor.h:85

◆ evaluate() [1/3]

real_type evaluate ( real_type  r) const
inline

◆ evaluate() [2/3]

real_type evaluate ( real_type  r,
real_type dudr,
real_type d2udr2 
) const
inline

Definition at line 90 of file UserFunctor.h.

References UserFunctor< T >::A, and UserFunctor< T >::B.

91  {
92  dudr = -A * B * r / ((B * r + 1) * (B * r + 1)) + A / (B * r + 1);
93  d2udr2 = 2 * A * B * (B * r / (B * r + 1) - 1) / ((B * r + 1) * (B * r + 1));
94  return A * r / (B * r + 1) - A / B;
95  }
real_type A
Value.
Definition: UserFunctor.h:52
real_type B
Value.
Definition: UserFunctor.h:60

◆ evaluate() [3/3]

real_type evaluate ( real_type  r,
real_type dudr,
real_type d2udr2,
real_type d3udr3 
) const
inline

Definition at line 100 of file UserFunctor.h.

References UserFunctor< T >::A, UserFunctor< T >::B, and qmcplusplus::pow().

101  {
102  dudr = -A * B * r / ((B * r + 1) * (B * r + 1)) + A / (B * r + 1);
103  d2udr2 = 2 * A * B * (B * r / (B * r + 1) - 1) / ((B * r + 1) * (B * r + 1));
104  d3udr3 = 6 * A * ((B) * (B)) * (-B * r / (B * r + 1) + 1) / std::pow(B * r + 1, 3);
105  return A * r / (B * r + 1) - A / B;
106  }
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
real_type A
Value.
Definition: UserFunctor.h:52
real_type B
Value.
Definition: UserFunctor.h:60

◆ evaluateDerivatives() [1/2]

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

Reimplemented from OptimizableFunctorBase.

Definition at line 213 of file UserFunctor.h.

References UserFunctor< T >::A, UserFunctor< T >::B, UserFunctor< T >::Opt_A, UserFunctor< T >::Opt_B, and qmcplusplus::pow().

Referenced by qmcplusplus::TEST_CASE().

214  {
215  int i = 0;
216 
217  if (Opt_A)
218  {
219  derivs[i][0] = r / (B * r + 1) - 1 / B;
220  derivs[i][1] = -B * r / ((B * r + 1) * (B * r + 1)) + 1.0 / (B * r + 1);
221  derivs[i][2] = 2 * B * (B * r / (B * r + 1) - 1) / ((B * r + 1) * (B * r + 1));
222  ++i;
223  }
224 
225  if (Opt_B)
226  {
227  derivs[i][0] = -A * ((r) * (r)) / ((B * r + 1) * (B * r + 1)) + A / ((B) * (B));
228  derivs[i][1] = 2 * A * B * ((r) * (r)) / std::pow(B * r + 1, 3) - 2 * A * r / ((B * r + 1) * (B * r + 1));
229  derivs[i][2] = -4 * A * B * r * (B * r / (B * r + 1) - 1) / std::pow(B * r + 1, 3) +
230  2 * A * B * (-B * ((r) * (r)) / ((B * r + 1) * (B * r + 1)) + r / (B * r + 1)) / ((B * r + 1) * (B * r + 1)) +
231  2 * A * (B * r / (B * r + 1) - 1) / ((B * r + 1) * (B * r + 1));
232  ++i;
233  }
234 
235  return true;
236  }
bool Opt_A
Is optimizable.
Definition: UserFunctor.h:50
bool Opt_B
Is optimizable.
Definition: UserFunctor.h:58
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
real_type A
Value.
Definition: UserFunctor.h:52
real_type B
Value.
Definition: UserFunctor.h:60

◆ evaluateDerivatives() [2/2]

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

compute derivatives with respect to variational parameters

Reimplemented from OptimizableFunctorBase.

Definition at line 240 of file UserFunctor.h.

References UserFunctor< T >::A, UserFunctor< T >::B, UserFunctor< T >::Opt_A, and UserFunctor< T >::Opt_B.

241  {
242  int i = 0;
243 
244  if (Opt_A)
245  {
246  derivs[i] = r / (B * r + 1) - 1 / B;
247  ++i;
248  }
249 
250  if (Opt_B)
251  {
252  derivs[i] = -A * ((r) * (r)) / ((B * r + 1) * (B * r + 1)) + A / ((B) * (B));
253  ++i;
254  }
255 
256 
257  return true;
258  }
bool Opt_A
Is optimizable.
Definition: UserFunctor.h:50
bool Opt_B
Is optimizable.
Definition: UserFunctor.h:58
real_type A
Value.
Definition: UserFunctor.h:52
real_type B
Value.
Definition: UserFunctor.h:60

◆ evaluateV()

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

Definition at line 109 of file UserFunctor.h.

References UserFunctor< T >::evaluate().

114  {
115  // specialized evaluation loop?
116  real_type sum(0);
117  for (int idx = iStart; idx < iEnd; idx++)
118  if (idx != iat)
119  sum += evaluate(_distArray[idx]);
120  return sum;
121  }
OHMMS_PRECISION real_type
real_type evaluate(real_type r) const
Definition: UserFunctor.h:85

◆ evaluateVGL()

void evaluateVGL ( const int  iat,
const int  iStart,
const int  iEnd,
const T *  distArray,
T *restrict  valArray,
T *restrict  gradArray,
T *restrict  laplArray,
T *restrict  distArrayCompressed,
int *restrict  distIndices 
) const
inline

Definition at line 150 of file UserFunctor.h.

References UserFunctor< T >::evaluate().

159  {
160  // specialized evaluation loop?
161  for (int idx = iStart; idx < iEnd; idx++)
162  {
163  valArray[idx] = evaluate(distArray[idx], gradArray[idx], laplArray[idx]);
164  gradArray[idx] /= distArray[idx];
165  }
166  if (iat >= iStart && iat < iEnd)
167  valArray[iat] = gradArray[iat] = laplArray[iat] = T(0);
168  }
real_type evaluate(real_type r) const
Definition: UserFunctor.h:85

◆ f()

real_type f ( real_type  r)
inlineoverridevirtual

evaluate the value at r

Parameters
rdistance

virtual function necessary for a transformation to a numerical functor

Implements OptimizableFunctorBase.

Definition at line 185 of file UserFunctor.h.

References UserFunctor< T >::evaluate().

185 { return evaluate(r); }
real_type evaluate(real_type r) const
Definition: UserFunctor.h:85

◆ makeClone()

OptimizableFunctorBase* makeClone ( ) const
inlineoverridevirtual

create a clone of this object

Implements OptimizableFunctorBase.

Definition at line 78 of file UserFunctor.h.

References UserFunctor< T >::UserFunctor().

78 { return new UserFunctor(*this); }
UserFunctor(const std::string &my_name)
default constructor
Definition: UserFunctor.h:66

◆ mw_evaluateV()

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

evaluate sum of the pair potentials FIXME

Returns
$\sum u(r_j)$ for r_j < cutoff_radius

Definition at line 126 of file UserFunctor.h.

136  {
137  for (int ip = 0; ip < num_pairs; ip++)
138  {
139  mw_vals[ip] = 0;
140  for (int j = 0; j < n_src; j++)
141  {
142  const int ig = grp_ids[j];
143  auto& functor(*functors[ig]);
144  if (j != ref_at[ip])
145  mw_vals[ip] += functor.evaluate(mw_dist[ip * dist_stride + j]);
146  }
147  }
148  }

◆ mw_evaluateVGL()

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

Definition at line 170 of file UserFunctor.h.

181  {
182  throw std::runtime_error("UserFunctor mw_evaluateVGL not implemented!");
183  }

◆ mw_updateVGL()

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

Definition at line 194 of file UserFunctor.h.

207  {
208  throw std::runtime_error("UserFunctor mw_updateVGL not implemented!");
209  }

◆ put()

bool put ( xmlNodePtr  cur)
inlineoverridevirtual

process xmlnode and registers variables to optimize

Parameters
curxmlNode for a functor

Implements OptimizableFunctorBase.

Definition at line 263 of file UserFunctor.h.

References UserFunctor< T >::A, OhmmsAttributeSet::add(), UserFunctor< T >::B, VariableSet::clear(), UserFunctor< T >::ID_A, UserFunctor< T >::ID_B, VariableSet::insert(), OptimizableFunctorBase::myVars, UserFunctor< T >::Opt_A, UserFunctor< T >::Opt_B, optimize::OTHER_P, OhmmsAttributeSet::put(), putContent(), and UserFunctor< T >::reset().

Referenced by qmcplusplus::TEST_CASE().

264  {
265  cur = cur->xmlChildrenNode;
266  while (cur != NULL)
267  {
268  std::string cname((const char*)(cur->name));
269  if (cname == "var") //only accept var
270  {
271  std::string id_in;
272  std::string p_name;
273  OhmmsAttributeSet rAttrib;
274  rAttrib.add(id_in, "id");
275  rAttrib.add(p_name, "name");
276  rAttrib.put(cur);
277 
278  if (p_name == "A")
279  {
280  ID_A = id_in;
281  putContent(A, cur);
282  Opt_A = true;
283  }
284 
285  if (p_name == "B")
286  {
287  ID_B = id_in;
288  putContent(B, cur);
289  Opt_B = true;
290  }
291  }
292  cur = cur->next;
293  }
294  reset();
295  myVars.clear();
296 
297  if (Opt_A)
299 
300  if (Opt_B)
302 
303  return true;
304  }
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::string ID_A
Id in XML input.
Definition: UserFunctor.h:54
bool Opt_A
Is optimizable.
Definition: UserFunctor.h:50
bool Opt_B
Is optimizable.
Definition: UserFunctor.h:58
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
void clear()
clear the variable set
Definition: VariableSet.cpp:28
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
std::string ID_B
Id in XML input.
Definition: UserFunctor.h:62
real_type A
Value.
Definition: UserFunctor.h:52
void reset() override
reset function
Definition: UserFunctor.h:80
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
real_type B
Value.
Definition: UserFunctor.h:60
opt_variables_type myVars
set of variables to be optimized

◆ reset()

void reset ( )
inlineoverridevirtual

◆ resetParametersExclusive()

void resetParametersExclusive ( const opt_variables_type active)
inlineoverridevirtual

reset the parameters during optimizations.

Exclusive, see checkInVariablesExclusive

Implements OptimizableObject.

Definition at line 317 of file UserFunctor.h.

References UserFunctor< T >::A, UserFunctor< T >::B, OptimizableFunctorBase::myVars, UserFunctor< T >::Opt_A, UserFunctor< T >::Opt_B, UserFunctor< T >::reset(), VariableSet::size(), and VariableSet::where().

Referenced by qmcplusplus::TEST_CASE().

318  {
319  if (myVars.size())
320  {
321  int ia = myVars.where(0);
322  if (ia > -1)
323  {
324  int i = 0;
325 
326  if (Opt_A)
327  A = std::real(myVars[i++] = active[ia++]);
328 
329  if (Opt_B)
330  B = std::real(myVars[i++] = active[ia++]);
331  }
332  reset();
333  }
334  }
QMCTraits::RealType real
bool Opt_A
Is optimizable.
Definition: UserFunctor.h:50
bool Opt_B
Is optimizable.
Definition: UserFunctor.h:58
int where(int i) const
return the locator of the i-th Index
Definition: VariableSet.h:90
size_type size() const
return the size
Definition: VariableSet.h:88
real_type A
Value.
Definition: UserFunctor.h:52
void reset() override
reset function
Definition: UserFunctor.h:80
real_type B
Value.
Definition: UserFunctor.h:60
opt_variables_type myVars
set of variables to be optimized

◆ setCusp()

void setCusp ( real_type  cusp)
inlineoverridevirtual

empty virtual function to help builder classes

Reimplemented from OptimizableFunctorBase.

Definition at line 70 of file UserFunctor.h.

References UserFunctor< T >::A, UserFunctor< T >::Opt_A, and UserFunctor< T >::reset().

Referenced by qmcplusplus::TEST_CASE().

71  {
72  A = cusp;
73  Opt_A = false;
74  reset();
75  }
bool Opt_A
Is optimizable.
Definition: UserFunctor.h:50
real_type A
Value.
Definition: UserFunctor.h:52
void reset() override
reset function
Definition: UserFunctor.h:80

Member Data Documentation

◆ A

◆ B

◆ ID_A

std::string ID_A

Id in XML input.

Definition at line 54 of file UserFunctor.h.

Referenced by UserFunctor< T >::put().

◆ ID_B

std::string ID_B

Id in XML input.

Definition at line 62 of file UserFunctor.h.

Referenced by UserFunctor< T >::put().

◆ Opt_A

◆ Opt_B

bool Opt_B

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