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 #include "Optimize/VariableSet.h" 22 #include "OhmmsData/OhmmsElementBase.h" 23 #include "OhmmsPETE/TinyVector.h" 24 //#include <cstdio> 25 #include <iostream> 26 27 /** Base class for any functor with optimizable parameters 28 * 29 * Derived classes from OptimizableFunctorBase are called "functor"s and 30 * can be used as a template signature for Jastrow functions. 31 * - OneBodyJastroOrbital<FUNC> 32 * - TwoBodyJastroOrbital<FUNC> 33 * Functor in qmcpack denotes any function which returns a value at a point, e.g., 34 * GTO, STO, one-dimensional splines etc. OptimizableFunctorBase is introduced for 35 * optimizations. The virtual functions are intended for non-critical operations that 36 * are executed infrequently during optimizations. 37 * 38 * This class handles myVars of opt_variables_type (Optimize/VariableSet.h). A derived class 39 * can insert any number of variables it handles during optimizations, by calling 40 * myVars.insert(name,value); 41 * Unlike VarList which uses map, VariableSet is serialized in that the internal order is according 42 * to insert calls. 43 */ 44 struct OptimizableFunctorBase 45 { 46 ///typedef for real values 47 typedef optimize::VariableSet::real_type real_type; 48 ///typedef for variableset: this is going to be replaced 49 typedef optimize::VariableSet opt_variables_type; 50 ///typedef for name-value lists 51 typedef optimize::VariableSet::variable_map_type variable_map_type; 52 ///maximum cutoff 53 real_type cutoff_radius = 0.0; 54 ///set of variables to be optimized 55 opt_variables_type myVars; 56 ///default constructor OptimizableFunctorBaseOptimizableFunctorBase57 inline OptimizableFunctorBase() {} 58 ///virtual destrutor ~OptimizableFunctorBaseOptimizableFunctorBase59 virtual ~OptimizableFunctorBase() {} 60 getIndexOptimizableFunctorBase61 inline void getIndex(const opt_variables_type& active) { myVars.getIndex(active); } 62 63 virtual void checkInVariables(opt_variables_type& active) = 0; 64 65 virtual void checkOutVariables(const opt_variables_type& active) = 0; 66 67 /** reset the optimizable variables 68 * @param active list of active optimizable variables 69 */ 70 virtual void resetParameters(const opt_variables_type& active) = 0; 71 /** create a clone of this object 72 */ 73 virtual OptimizableFunctorBase* makeClone() const = 0; 74 75 /** reset function 76 */ 77 virtual void reset() = 0; 78 79 /** evaluate the value at r 80 * @param r distance 81 * 82 * virtual function necessary for a transformation to a numerical functor 83 */ 84 virtual real_type f(real_type r) = 0; 85 86 /** evaluate the first derivative 87 * @param r distance 88 * 89 * virtual function necessary for a transformation to a numerical functor 90 */ 91 virtual real_type df(real_type r) = 0; 92 93 /** process xmlnode and registers variables to optimize 94 * @param cur xmlNode for a functor 95 */ 96 virtual bool put(xmlNodePtr cur) = 0; 97 98 /** empty virtual function to help builder classes 99 */ setDensityOptimizableFunctorBase100 virtual void setDensity(real_type n) {} 101 102 /** empty virtual function to help builder classes 103 */ setCuspOptimizableFunctorBase104 virtual void setCusp(real_type cusp) {} 105 106 /** empty virtual function to help builder classes 107 */ setPeriodicOptimizableFunctorBase108 virtual void setPeriodic(bool periodic) {} 109 evaluateDerivativesOptimizableFunctorBase110 virtual inline bool evaluateDerivatives(real_type r, std::vector<qmcplusplus::TinyVector<real_type, 3>>& derivs) 111 { 112 return false; 113 } 114 115 // mmorales: don't know how to solve a template problem for cusp correction, 116 // so for now I do this setGridManagerOptimizableFunctorBase117 virtual void setGridManager(bool willmanage) {} 118 }; 119 120 void print(OptimizableFunctorBase& func, std::ostream& os); 121 122 123 #endif 124