QMCPACK
OptimizableFunctorBase.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Luke Shulenburger, lshulen@sandia.gov, Sandia National Laboratories
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 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 /** @file OptimizableFunctorBase.h
17  * @brief Define a base class for one-dimensional functions with optimizable variables
18  */
19 #ifndef QMCPLUSPLUS_OPTIMIZABLEFUNCTORBASE_H
20 #define QMCPLUSPLUS_OPTIMIZABLEFUNCTORBASE_H
21 
22 #include "OptimizableObject.h"
24 #include "OhmmsPETE/TinyVector.h"
25 //#include <cstdio>
26 #include <iostream>
27 
28 namespace qmcplusplus
29 {
30 /** Base class for any functor with optimizable parameters
31  *
32  * Derived classes from OptimizableFunctorBase are called "functor"s and
33  * can be used as a template signature for Jastrow functions.
34  * - OneBodyJastroOrbital<FUNC>
35  * - TwoBodyJastroOrbital<FUNC>
36  * Functor in qmcpack denotes any function which returns a value at a point, e.g.,
37  * GTO, STO, one-dimensional splines etc. OptimizableFunctorBase is introduced for
38  * optimizations. The virtual functions are intended for non-critical operations that
39  * are executed infrequently during optimizations.
40  *
41  * This class handles myVars of opt_variables_type (VariableSet.h). A derived class
42  * can insert any number of variables it handles during optimizations, by calling
43  * myVars.insert(name,value);
44  * Unlike VarList which uses map, VariableSet is serialized in that the internal order is according
45  * to insert calls.
46  */
48 {
49  ///typedef for real values
51  ///typedef for variableset: this is going to be replaced
53  ///maximum cutoff
55  ///set of variables to be optimized
57  ///default constructor
58  inline OptimizableFunctorBase(const std::string& name = "") : OptimizableObject(name) {}
59  ///virtual destrutor
60  virtual ~OptimizableFunctorBase() = default;
61 
62  /** check in variational parameters to the global list of parameters used by the optimizer.
63  * @param active a super set of optimizable variables
64  */
66 
67  /** check out variational optimizable variables
68  * @param active a super set of optimizable variables
69  */
70  virtual void checkOutVariables(const opt_variables_type& active) = 0;
71 
72  /** reset the parameters during optimizations
73  */
75 
76  inline void getIndex(const opt_variables_type& active) { myVars.getIndex(active); }
77 
78  /** create a clone of this object
79  */
80  virtual OptimizableFunctorBase* makeClone() const = 0;
81 
82  /** reset function
83  */
84  virtual void reset() = 0;
85 
86  /** evaluate the value at r
87  * @param r distance
88  *
89  * virtual function necessary for a transformation to a numerical functor
90  */
91  virtual real_type f(real_type r) = 0;
92 
93  /** evaluate the first derivative
94  * @param r distance
95  *
96  * virtual function necessary for a transformation to a numerical functor
97  */
98  virtual real_type df(real_type r) = 0;
99 
100  /** process xmlnode and registers variables to optimize
101  * @param cur xmlNode for a functor
102  */
103  virtual bool put(xmlNodePtr cur) = 0;
104 
105  /** empty virtual function to help builder classes
106  */
107  virtual void setDensity(real_type n) {}
108 
109  /** empty virtual function to help builder classes
110  */
111  virtual void setCusp(real_type cusp) {}
112 
113  /** empty virtual function to help builder classes
114  */
115  virtual void setPeriodic(bool periodic) {}
116 
117  virtual inline bool evaluateDerivatives(real_type r, std::vector<qmcplusplus::TinyVector<real_type, 3>>& derivs)
118  {
119  return false;
120  }
121 
122  virtual inline bool evaluateDerivatives(real_type r, std::vector<real_type>& derivs) { return false; }
123 
124  // mmorales: don't know how to solve a template problem for cusp correction,
125  // so for now I do this
126  virtual void setGridManager(bool willmanage) {}
127 };
128 
129 /** evaluates a functor (value and derivative) and dumps the quantities to output
130  * @param func the functor for which the value and derivative is evaluated
131  * @param os the output stream to write the quantities to
132  * @param extent the functor is evaluated from [0, extent) unless extent < 0, in which case the functor is evaluated from [0, cutoff_radius)
133  */
134 void print(OptimizableFunctorBase& func, std::ostream& os, double extent = -1.0);
135 
136 /// return the id of the first coefficients. If not found, return an emtpy string
137 std::string extractCoefficientsID(xmlNodePtr cur);
138 
139 } // namespace qmcplusplus
140 
141 #endif
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
void getIndex(const opt_variables_type &active)
Declaration of OptimizableObject.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void print(OptimizableFunctorBase &func, std::ostream &os, double extent)
evaluates a functor (value and derivative) and dumps the quantities to output
OptimizableFunctorBase(const std::string &name="")
default constructor
virtual bool evaluateDerivatives(real_type r, std::vector< real_type > &derivs)
virtual real_type f(real_type r)=0
evaluate the value at r
virtual ~OptimizableFunctorBase()=default
virtual destrutor
virtual void checkInVariablesExclusive(opt_variables_type &active)=0
check in variational parameters to the global list of parameters used by the optimizer.
Declaration of OhmmsElementBase and define xml-related macros.
virtual void reset()=0
reset function
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
OHMMS_PRECISION real_type
virtual bool put(xmlNodePtr cur)=0
process xmlnode and registers variables to optimize
virtual bool evaluateDerivatives(real_type r, std::vector< qmcplusplus::TinyVector< real_type, 3 >> &derivs)
Base class for any functor with optimizable parameters.
virtual OptimizableFunctorBase * makeClone() const =0
create a clone of this object
virtual void checkOutVariables(const opt_variables_type &active)=0
check out variational optimizable variables
virtual void setCusp(real_type cusp)
empty virtual function to help builder classes
virtual void setGridManager(bool willmanage)
qmcplusplus::QMCTraits::RealType real_type
Definition: VariableSet.h:51
virtual real_type df(real_type r)=0
evaluate the first derivative
virtual void setPeriodic(bool periodic)
empty virtual function to help builder classes
std::string extractCoefficientsID(xmlNodePtr cur)
return the id of the first coefficients. If not found, return an emtpy string
virtual void setDensity(real_type n)
empty virtual function to help builder classes
optimize::VariableSet::real_type real_type
typedef for real values
int getIndex(const std::string &vname) const
return the Index vaule for the named parameter
virtual void resetParametersExclusive(const opt_variables_type &active)=0
reset the parameters during optimizations.
opt_variables_type myVars
set of variables to be optimized