QMCPACK
GaussianTimesRN.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: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef QMCPLUSPLUS_RADIALGRIDFUNCTOR_GAUSSIANTIMESRN_H
16 #define QMCPLUSPLUS_RADIALGRIDFUNCTOR_GAUSSIANTIMESRN_H
17 
18 // this reference to OptimizableFunctorBase.h in QMCWaveFunctions is ugly
20 #include "OhmmsData/AttributeSet.h"
21 #include <cmath>
22 
23 namespace qmcplusplus
24 {
25 template<class T>
27 {
28  using value_type = T;
30 
32  {
35  int Power;
36 
41 
42  //BasicGaussian(): Sigma(1.0), Coeff(1.0), Power(0) { }
43  inline BasicGaussian(real_type sig = 1.0, real_type c = 1.0, int p = 0) : Sigma(sig), Coeff(c), Power(p)
44  {
45  reset();
46  }
47 
48  inline void resetGaussian(real_type sig, real_type c, int p)
49  {
50  Sigma = sig;
51  Coeff = c;
52  Power = p;
53  reset();
54  }
55 
56  inline void reset()
57  {
58  MinusSigma = -Sigma;
59  CoeffP = -2.0 * Sigma * Coeff;
60  CoeffPP = 4.0 * Sigma * Sigma * Coeff;
61  PowerC = static_cast<T>(Power) * Coeff;
62  }
63 
64  inline void setgrid(real_type r) {}
65 
67  {
68  if (Power == 0)
69  return Coeff * std::exp(MinusSigma * rr);
70  else if (Power == 1)
71  return r * Coeff * std::exp(MinusSigma * rr);
72  else
73  return std::pow(r, Power) * Coeff * std::exp(MinusSigma * rr);
74  }
75 
77  {
78  if (Power == 0)
79  return CoeffP * r * std::exp(MinusSigma * rr);
80  else if (Power == 1)
81  return (Coeff + CoeffP * r) * std::exp(MinusSigma * rr);
82  else
83  {
84  return std::pow(r, Power - 1) * (PowerC + CoeffP * rr) * std::exp(MinusSigma * rr);
85  }
86  }
87 
89  {
90  T v = std::exp(MinusSigma * rr);
91  if (Power == 0)
92  {
93  du += CoeffP * r * v;
94  d2u += (CoeffP + CoeffPP * rr) * v;
95  return Coeff * v;
96  }
97  else
98  {
99  return std::pow(r, Power) * Coeff * v;
100  }
101  }
102  };
103 
105  std::string nodeName;
106  std::string expName;
107  std::string coeffName;
108  std::string powerName;
109  std::vector<xmlNodePtr> InParam;
110  std::vector<BasicGaussian> gset;
111 
112  explicit GaussianTimesRN(const char* node_name = "radfunc",
113  const char* exp_name = "exponent",
114  const char* c_name = "contraction",
115  const char* p_name = "power")
116  : basePower(0), nodeName(node_name), expName(exp_name), coeffName(c_name), powerName(p_name)
117  {}
118 
119  ~GaussianTimesRN() override {}
120 
121  OptimizableFunctorBase* makeClone() const override { return new GaussianTimesRN<T>(*this); }
122 
123  void reset() override;
124 
126  void checkOutVariables(const opt_variables_type& active) override {}
127  void resetParametersExclusive(const opt_variables_type& active) override
128  {
129  ///DO NOTHING FOR NOW
130  }
131 
132  /** return the number Gaussians
133  */
134  inline int size() const { return gset.size(); }
135 
136  inline real_type f(real_type r) override
137  {
138  real_type res = 0;
139  real_type r2 = r * r;
140  typename std::vector<BasicGaussian>::iterator it(gset.begin());
141  typename std::vector<BasicGaussian>::iterator it_end(gset.end());
142  while (it != it_end)
143  {
144  res += (*it).f(r, r2);
145  ++it;
146  }
147  return res;
148  }
149 
150  inline real_type df(real_type r) override
151  {
152  real_type res = 0;
153  real_type r2 = r * r;
154  typename std::vector<BasicGaussian>::iterator it(gset.begin());
155  typename std::vector<BasicGaussian>::iterator it_end(gset.end());
156  while (it != it_end)
157  {
158  res += (*it).df(r, r2);
159  ++it;
160  }
161  return res;
162  }
163 
165  {
166  Y = 0.0;
167  real_type rr = r * r;
168  typename std::vector<BasicGaussian>::iterator it(gset.begin()), it_end(gset.end());
169  while (it != it_end)
170  {
171  Y += (*it).f(r, rr);
172  ++it;
173  }
174  return Y;
175  }
176 
177  inline void evaluateAll(real_type r, real_type rinv)
178  {
179  Y = 0.0;
180  dY = 0.0;
181  d2Y = 0.0;
182  real_type rr = r * r;
183  typename std::vector<BasicGaussian>::iterator it(gset.begin()), it_end(gset.end());
184  while (it != it_end)
185  {
186  Y += (*it).evaluate(r, rr, dY, d2Y);
187  ++it;
188  }
189  }
190 
191  bool put(xmlNodePtr cur) override;
192 
193  /** process cur xmlnode
194  * @param cur root node
195  * @param baseOff offset to the basePower
196  */
197  bool putBasisGroup(xmlNodePtr cur, int baseOff = 0);
198 };
199 
200 template<class T>
201 bool GaussianTimesRN<T>::put(xmlNodePtr cur)
202 {
203  InParam.push_back(cur);
204  return true;
205 }
206 
207 template<class T>
209 {
210  if (InParam.empty())
211  {
212  for (int i = 0; i < gset.size(); i++)
213  gset[i].reset();
214  }
215  else
216  {
217  int n = gset.size();
218  while (n < InParam.size())
219  {
220  gset.push_back(BasicGaussian());
221  n++;
222  }
223  for (int i = 0; i < InParam.size(); i++)
224  {
225  T alpha(1.0), c(1.0);
226  int np(0);
227  OhmmsAttributeSet radAttrib;
228  radAttrib.add(alpha, expName);
229  radAttrib.add(c, coeffName);
230  radAttrib.add(np, powerName);
231  radAttrib.put(InParam[i]);
232  gset[i].resetGaussian(alpha, c, np + basePower);
233  }
234  }
235 }
236 
237 template<class T>
238 bool GaussianTimesRN<T>::putBasisGroup(xmlNodePtr cur, int baseOff)
239 {
240  const std::string t(getXMLAttributeValue(cur, "basePower"));
241  if (!t.empty())
242  basePower = std::stoi(t);
243  basePower += baseOff;
244  cur = cur->children;
245  while (cur != NULL)
246  {
247  std::string cname((const char*)cur->name);
248  if (cname == "radfunc")
249  {
250  put(cur);
251  }
252  cur = cur->next;
253  }
254  reset();
255  return true;
256 }
257 
258 } // namespace qmcplusplus
259 #endif
real_type df(real_type r) override
evaluate the first derivative
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
real_type f(real_type r) override
evaluate the value at r
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
bool putBasisGroup(xmlNodePtr cur, int baseOff=0)
process cur xmlnode
Define a base class for one-dimensional functions with optimizable variables.
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)
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
std::vector< BasicGaussian > gset
void checkInVariablesExclusive(opt_variables_type &active) override
check in variational parameters to the global list of parameters used by the optimizer.
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
BasicGaussian(real_type sig=1.0, real_type c=1.0, int p=0)
OptimizableFunctorBase * makeClone() const override
create a clone of this object
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
void evaluateAll(real_type r, real_type rinv)
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
Base class for any functor with optimizable parameters.
real_type f(real_type r, real_type rr)
void reset() override
reset function
std::vector< xmlNodePtr > InParam
real_type evaluate(real_type r, real_type rr, real_type &du, real_type &d2u)
bool put(xmlNodePtr cur) override
process xmlnode and registers variables to optimize
real_type evaluate(real_type r, real_type rinv)
real_type df(real_type r, real_type rr)
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 resetGaussian(real_type sig, real_type c, int p)
void resetParametersExclusive(const opt_variables_type &active) override
reset the parameters during optimizations.
optimize::VariableSet::real_type real_type
typedef for real values
GaussianTimesRN(const char *node_name="radfunc", const char *exp_name="exponent", const char *c_name="contraction", const char *p_name="power")
int size() const
return the number Gaussians