QMCPACK
PolynomialFunctor3D Struct Reference
+ Inheritance diagram for PolynomialFunctor3D:
+ Collaboration diagram for PolynomialFunctor3D:

Public Types

using value_type = real_type
 
- 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...
 

Public Member Functions

 PolynomialFunctor3D (const std::string &my_name, real_type ee_cusp=0.0, real_type eI_cusp=0.0)
 constructor More...
 
OptimizableFunctorBasemakeClone () const override
 create a clone of this object More...
 
void resize (int neI, int nee)
 
void reset () override
 reset function More...
 
void reset_gamma ()
 
real_type evaluate (real_type r_12, real_type r_1I, real_type r_2I) const
 
real_type evaluateV (int Nptcl, const real_type *restrict r_12_array, const real_type *restrict r_1I_array, const real_type *restrict r_2I_array) const
 
real_type evaluate (real_type r_12, real_type r_1I, real_type r_2I, TinyVector< real_type, 3 > &grad, Tensor< real_type, 3 > &hess) const
 
void evaluateVGL (int Nptcl, const real_type *restrict r_12_array, const real_type *restrict r_1I_array, const real_type *restrict r_2I_array, real_type *restrict val_array, real_type *restrict grad0_array, real_type *restrict grad1_array, real_type *restrict grad2_array, real_type *restrict hess00_array, real_type *restrict hess11_array, real_type *restrict hess22_array, real_type *restrict hess01_array, real_type *restrict hess02_array) const
 
real_type evaluate (const real_type r_12, const real_type r_1I, const real_type r_2I, TinyVector< real_type, 3 > &grad, Tensor< real_type, 3 > &hess, TinyVector< Tensor< real_type, 3 >, 3 > &d3)
 
real_type evaluate (const real_type r, const real_type rinv)
 
bool evaluateDerivativesFD (const real_type r_12, const real_type r_1I, const real_type r_2I, std::vector< double > &d_vals, std::vector< TinyVector< real_type, 3 >> &d_grads, std::vector< Tensor< real_type, 3 >> &d_hess)
 
bool evaluateDerivatives (const real_type r_12, const real_type r_1I, const real_type r_2I, std::vector< real_type > &d_vals)
 calculate derivatives with respect to polynomial parameters More...
 
bool evaluateDerivatives (const real_type r_12, const real_type r_1I, const real_type r_2I, std::vector< real_type > &d_vals, std::vector< TinyVector< real_type, 3 >> &d_grads, std::vector< Tensor< real_type, 3 >> &d_hess)
 
real_type f (real_type r) override
 
real_type df (real_type r) override
 
bool put (xmlNodePtr cur) override
 process xmlnode and registers variables to optimize More...
 
void resetParametersExclusive (const opt_variables_type &active) override
 reset the parameters during optimizations. 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 print (std::ostream &os)
 
int getNumParameters ()
 
- 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 real_type f (real_type r)=0
 evaluate the value at r More...
 
virtual real_type df (real_type r)=0
 evaluate the first derivative More...
 
virtual void setDensity (real_type n)
 empty virtual function to help builder classes More...
 
virtual void setCusp (real_type cusp)
 empty virtual function to help builder classes More...
 
virtual void setPeriodic (bool periodic)
 empty virtual function to help builder classes More...
 
virtual bool evaluateDerivatives (real_type r, std::vector< qmcplusplus::TinyVector< real_type, 3 >> &derivs)
 
virtual bool evaluateDerivatives (real_type r, std::vector< real_type > &derivs)
 
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...
 

Public Attributes

int N_eI
 
int N_ee
 
Array< real_type, 3 > gamma
 
std::vector< int > GammaPerm
 
Array< int, 3 > index
 
std::vector< bool > IndepVar
 
std::vector< real_typeGammaVec
 
std::vector< real_typedval_Vec
 
std::vector< TinyVector< real_type, 3 > > dgrad_Vec
 
std::vector< Tensor< real_type, 3 > > dhess_Vec
 
int NumConstraints
 
int NumGamma
 
Matrix< real_typeConstraintMatrix
 
std::vector< real_typeParameters
 
std::vector< real_typed_valsFD
 
std::vector< TinyVector< real_type, 3 > > d_gradsFD
 
std::vector< Tensor< real_type, 3 > > d_hessFD
 
std::vector< std::string > ParameterNames
 
std::string iSpecies
 
std::string eSpecies1
 
std::string eSpecies2
 
int ResetCount
 
const int C
 
real_type scale
 
bool notOpt
 
- 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...
 

Detailed Description

Definition at line 30 of file PolynomialFunctor3D.h.

Member Typedef Documentation

◆ value_type

Definition at line 32 of file PolynomialFunctor3D.h.

Constructor & Destructor Documentation

◆ PolynomialFunctor3D()

PolynomialFunctor3D ( const std::string &  my_name,
real_type  ee_cusp = 0.0,
real_type  eI_cusp = 0.0 
)
inline

constructor

Definition at line 58 of file PolynomialFunctor3D.h.

References qmcplusplus::abs(), qmcplusplus::app_error(), and OptimizableFunctorBase::cutoff_radius.

Referenced by PolynomialFunctor3D::makeClone().

59  : OptimizableFunctorBase(my_name), N_eI(0), N_ee(0), ResetCount(0), C(3), scale(1.0), notOpt(false)
60  {
61  if (std::abs(ee_cusp) > 0.0 || std::abs(eI_cusp) > 0.0)
62  {
63  app_error() << "PolynomialFunctor3D does not support nonzero cusp.\n";
64  abort();
65  }
66  cutoff_radius = 0.0;
67  }
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
std::ostream & app_error()
Definition: OutputManager.h:67
OptimizableFunctorBase(const std::string &name="")
default constructor

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 1073 of file PolynomialFunctor3D.h.

References VariableSet::insertFrom(), OptimizableFunctorBase::myVars, PolynomialFunctor3D::notOpt, and VariableSet::setIndexDefault().

1074  {
1075  if (notOpt)
1076  return;
1077 
1079  active.insertFrom(myVars);
1080  }
void setIndexDefault()
set default Indices, namely all the variables are active
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 1082 of file PolynomialFunctor3D.h.

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

1083  {
1084  if (notOpt)
1085  return;
1086  myVars.getIndex(active);
1087  }
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)
inlineoverride

Definition at line 969 of file PolynomialFunctor3D.h.

969 { return 0.0; }

◆ evaluate() [1/4]

real_type evaluate ( real_type  r_12,
real_type  r_1I,
real_type  r_2I 
) const
inline

Definition at line 320 of file PolynomialFunctor3D.h.

References PolynomialFunctor3D::C, BLAS::cone, OptimizableFunctorBase::cutoff_radius, BLAS::czero, PolynomialFunctor3D::gamma, qmcplusplus::Units::distance::m, qmcplusplus::n, PolynomialFunctor3D::N_ee, and PolynomialFunctor3D::N_eI.

Referenced by PolynomialFunctor3D::evaluateDerivativesFD(), and qmcplusplus::TEST_CASE().

321  {
322  constexpr real_type czero(0);
323  constexpr real_type cone(1);
324  constexpr real_type chalf(0.5);
325 
326  const real_type L = chalf * cutoff_radius;
327  if (r_1I >= L || r_2I >= L)
328  return czero;
329  real_type val = czero;
330  real_type r2l(cone);
331  for (int l = 0; l <= N_eI; l++)
332  {
333  real_type r2m(r2l);
334  for (int m = 0; m <= N_eI; m++)
335  {
336  real_type r2n(r2m);
337  for (int n = 0; n <= N_ee; n++)
338  {
339  val += gamma(l, m, n) * r2n;
340  r2n *= r_12;
341  }
342  r2m *= r_2I;
343  }
344  r2l *= r_1I;
345  }
346  for (int i = 0; i < C; i++)
347  val *= (r_1I - L) * (r_2I - L);
348  return val;
349  }
constexpr std::complex< float > czero
Definition: BLAS.hpp:51
constexpr std::complex< float > cone
Definition: BLAS.hpp:50
OHMMS_PRECISION real_type

◆ evaluate() [2/4]

real_type evaluate ( real_type  r_12,
real_type  r_1I,
real_type  r_2I,
TinyVector< real_type, 3 > &  grad,
Tensor< real_type, 3 > &  hess 
) const
inline

Definition at line 396 of file PolynomialFunctor3D.h.

References PolynomialFunctor3D::C, BLAS::cone, OptimizableFunctorBase::cutoff_radius, BLAS::czero, PolynomialFunctor3D::gamma, qmcplusplus::Units::distance::m, qmcplusplus::n, PolynomialFunctor3D::N_ee, and PolynomialFunctor3D::N_eI.

401  {
402  constexpr real_type czero(0);
403  constexpr real_type cone(1);
404  constexpr real_type chalf(0.5);
405  constexpr real_type ctwo(2);
406 
407  const real_type L = chalf * cutoff_radius;
408  if (r_1I >= L || r_2I >= L)
409  {
410  grad = czero;
411  hess = czero;
412  return czero;
413  }
414  real_type val = czero;
415  grad = czero;
416  hess = czero;
417  real_type r2l(cone), r2l_1(czero), r2l_2(czero), lf(czero);
418  for (int l = 0; l <= N_eI; l++)
419  {
420  real_type r2m(cone), r2m_1(czero), r2m_2(czero), mf(czero);
421  for (int m = 0; m <= N_eI; m++)
422  {
423  real_type r2n(cone), r2n_1(czero), r2n_2(czero), nf(czero);
424  for (int n = 0; n <= N_ee; n++)
425  {
426  const real_type g = gamma(l, m, n);
427  const real_type g00x = g * r2l * r2m;
428  const real_type g10x = g * r2l_1 * r2m;
429  const real_type g01x = g * r2l * r2m_1;
430  const real_type gxx0 = g * r2n;
431 
432  val += g00x * r2n;
433  grad[0] += g00x * r2n_1;
434  grad[1] += g10x * r2n;
435  grad[2] += g01x * r2n;
436  hess(0, 0) += g00x * r2n_2;
437  hess(0, 1) += g10x * r2n_1;
438  hess(0, 2) += g01x * r2n_1;
439  hess(1, 1) += gxx0 * r2l_2 * r2m;
440  hess(1, 2) += gxx0 * r2l_1 * r2m_1;
441  hess(2, 2) += gxx0 * r2l * r2m_2;
442  nf += cone;
443  r2n_2 = r2n_1 * nf;
444  r2n_1 = r2n * nf;
445  r2n *= r_12;
446  }
447  mf += cone;
448  r2m_2 = r2m_1 * mf;
449  r2m_1 = r2m * mf;
450  r2m *= r_2I;
451  }
452  lf += cone;
453  r2l_2 = r2l_1 * lf;
454  r2l_1 = r2l * lf;
455  r2l *= r_1I;
456  }
457 
458  const real_type r_2I_minus_L = r_2I - L;
459  const real_type r_1I_minus_L = r_1I - L;
460  const real_type both_minus_L = r_2I_minus_L * r_1I_minus_L;
461  for (int i = 0; i < C; i++)
462  {
463  hess(0, 0) = both_minus_L * hess(0, 0);
464  hess(0, 1) = both_minus_L * hess(0, 1) + r_2I_minus_L * grad[0];
465  hess(0, 2) = both_minus_L * hess(0, 2) + r_1I_minus_L * grad[0];
466  hess(1, 1) = both_minus_L * hess(1, 1) + ctwo * r_2I_minus_L * grad[1];
467  hess(1, 2) = both_minus_L * hess(1, 2) + r_1I_minus_L * grad[1] + r_2I_minus_L * grad[2] + val;
468  hess(2, 2) = both_minus_L * hess(2, 2) + ctwo * r_1I_minus_L * grad[2];
469  grad[0] = both_minus_L * grad[0];
470  grad[1] = both_minus_L * grad[1] + r_2I_minus_L * val;
471  grad[2] = both_minus_L * grad[2] + r_1I_minus_L * val;
472  val *= both_minus_L;
473  }
474  hess(1, 0) = hess(0, 1);
475  hess(2, 0) = hess(0, 2);
476  hess(2, 1) = hess(1, 2);
477  return val;
478  }
constexpr std::complex< float > czero
Definition: BLAS.hpp:51
constexpr std::complex< float > cone
Definition: BLAS.hpp:50
OHMMS_PRECISION real_type

◆ evaluate() [3/4]

real_type evaluate ( const real_type  r_12,
const real_type  r_1I,
const real_type  r_2I,
TinyVector< real_type, 3 > &  grad,
Tensor< real_type, 3 > &  hess,
TinyVector< Tensor< real_type, 3 >, 3 > &  d3 
)
inline

Definition at line 589 of file PolynomialFunctor3D.h.

References PolynomialFunctor3D::C, OptimizableFunctorBase::cutoff_radius, PolynomialFunctor3D::gamma, qmcplusplus::Units::distance::m, qmcplusplus::n, PolynomialFunctor3D::N_ee, and PolynomialFunctor3D::N_eI.

595  {
596  grad = 0.0;
597  hess = 0.0;
598  d3 = grad;
599  const real_type L = 0.5 * cutoff_radius;
600  if (r_1I >= L || r_2I >= L)
601  return 0.0;
602  real_type val = 0.0;
603  real_type r2l(1.0), r2l_1(0.0), r2l_2(0.0), r2l_3(0.0), lf(0.0);
604  for (int l = 0; l <= N_eI; l++)
605  {
606  real_type r2m(1.0), r2m_1(0.0), r2m_2(0.0), r2m_3(0.0), mf(0.0);
607  for (int m = 0; m <= N_eI; m++)
608  {
609  real_type r2n(1.0), r2n_1(0.0), r2n_2(0.0), r2n_3(0.0), nf(0.0);
610  for (int n = 0; n <= N_ee; n++)
611  {
612  real_type g = gamma(l, m, n);
613  val += g * r2l * r2m * r2n;
614  grad[0] += nf * g * r2l * r2m * r2n_1;
615  grad[1] += lf * g * r2l_1 * r2m * r2n;
616  grad[2] += mf * g * r2l * r2m_1 * r2n;
617  hess(0, 0) += nf * (nf - 1.0) * g * r2l * r2m * r2n_2;
618  hess(0, 1) += nf * lf * g * r2l_1 * r2m * r2n_1;
619  hess(0, 2) += nf * mf * g * r2l * r2m_1 * r2n_1;
620  hess(1, 1) += lf * (lf - 1.0) * g * r2l_2 * r2m * r2n;
621  hess(1, 2) += lf * mf * g * r2l_1 * r2m_1 * r2n;
622  hess(2, 2) += mf * (mf - 1.0) * g * r2l * r2m_2 * r2n;
623  d3[0](0, 0) += nf * (nf - 1.0) * (nf - 2.0) * g * r2l * r2m * r2n_3;
624  d3[0](0, 1) += nf * (nf - 1.0) * lf * g * r2l_1 * r2m * r2n_2;
625  d3[0](0, 2) += nf * (nf - 1.0) * mf * g * r2l * r2m_1 * r2n_2;
626  d3[0](1, 1) += nf * lf * (lf - 1.0) * g * r2l_2 * r2m * r2n_1;
627  d3[0](1, 2) += nf * lf * mf * g * r2l_1 * r2m_1 * r2n_1;
628  d3[0](2, 2) += nf * mf * (mf - 1.0) * g * r2l * r2m_2 * r2n_1;
629  d3[1](1, 1) += lf * (lf - 1.0) * (lf - 2.0) * g * r2l_3 * r2m * r2n;
630  d3[1](1, 2) += lf * (lf - 1.0) * mf * g * r2l_2 * r2m_1 * r2n;
631  d3[1](2, 2) += lf * mf * (mf - 1.0) * g * r2l_1 * r2m_2 * r2n;
632  d3[2](2, 2) += mf * (mf - 1.0) * (mf - 2.0) * g * r2l * r2m_3 * r2n;
633  r2n_3 = r2n_2;
634  r2n_2 = r2n_1;
635  r2n_1 = r2n;
636  r2n *= r_12;
637  nf += 1.0;
638  }
639  r2m_3 = r2m_2;
640  r2m_2 = r2m_1;
641  r2m_1 = r2m;
642  r2m *= r_2I;
643  mf += 1.0;
644  }
645  r2l_3 = r2l_2;
646  r2l_2 = r2l_1;
647  r2l_1 = r2l;
648  r2l *= r_1I;
649  lf += 1.0;
650  }
651  for (int i = 0; i < C; i++)
652  {
653  d3[0](0, 0) = (r_1I - L) * (r_2I - L) * d3[0](0, 0);
654  d3[0](0, 1) = (r_1I - L) * (r_2I - L) * d3[0](0, 1) + (r_2I - L) * hess(0, 0);
655  d3[0](0, 2) = (r_1I - L) * (r_2I - L) * d3[0](0, 2) + (r_1I - L) * hess(0, 0);
656  d3[0](1, 1) = (r_1I - L) * (r_2I - L) * d3[0](1, 1) + 2.0 * (r_2I - L) * hess(0, 1);
657  d3[0](1, 2) = (r_1I - L) * (r_2I - L) * d3[0](1, 2) + (r_1I - L) * hess(0, 1) + (r_2I - L) * hess(0, 2) + grad[0];
658  d3[0](2, 2) = (r_1I - L) * (r_2I - L) * d3[0](2, 2) + 2.0 * (r_1I - L) * hess(0, 2);
659  d3[1](1, 1) = (r_1I - L) * (r_2I - L) * d3[1](1, 1) + 3.0 * (r_2I - L) * hess(1, 1);
660  d3[1](1, 2) = (r_1I - L) * (r_2I - L) * d3[1](1, 2) + 2.0 * (r_2I - L) * hess(1, 2) + 2.0 * grad[1] +
661  (r_1I - L) * hess(1, 1);
662  d3[1](2, 2) = (r_1I - L) * (r_2I - L) * d3[1](2, 2) + 2.0 * (r_1I - L) * hess(1, 2) + 2.0 * grad[2] +
663  (r_2I - L) * hess(2, 2);
664  d3[2](2, 2) = (r_1I - L) * (r_2I - L) * d3[2](2, 2) + 3.0 * (r_1I - L) * hess(2, 2);
665  hess(0, 0) = (r_1I - L) * (r_2I - L) * hess(0, 0);
666  hess(0, 1) = (r_1I - L) * (r_2I - L) * hess(0, 1) + (r_2I - L) * grad[0];
667  hess(0, 2) = (r_1I - L) * (r_2I - L) * hess(0, 2) + (r_1I - L) * grad[0];
668  hess(1, 1) = (r_1I - L) * (r_2I - L) * hess(1, 1) + 2.0 * (r_2I - L) * grad[1];
669  hess(1, 2) = (r_1I - L) * (r_2I - L) * hess(1, 2) + (r_1I - L) * grad[1] + (r_2I - L) * grad[2] + val;
670  hess(2, 2) = (r_1I - L) * (r_2I - L) * hess(2, 2) + 2.0 * (r_1I - L) * grad[2];
671  grad[0] = (r_1I - L) * (r_2I - L) * grad[0];
672  grad[1] = (r_1I - L) * (r_2I - L) * grad[1] + (r_2I - L) * val;
673  grad[2] = (r_1I - L) * (r_2I - L) * grad[2] + (r_1I - L) * val;
674  val *= (r_1I - L) * (r_2I - L);
675  }
676  hess(1, 0) = hess(0, 1);
677  hess(2, 0) = hess(0, 2);
678  hess(2, 1) = hess(1, 2);
679  d3[0](1, 0) = d3[0](0, 1);
680  d3[0](2, 0) = d3[0](0, 2);
681  d3[0](2, 1) = d3[0](1, 2);
682  d3[1](0, 0) = d3[0](1, 1);
683  d3[1](0, 1) = d3[0](0, 1);
684  d3[1](0, 2) = d3[0](1, 2);
685  d3[1](1, 0) = d3[0](0, 1);
686  d3[1](2, 0) = d3[0](1, 2);
687  d3[1](2, 1) = d3[1](1, 2);
688  d3[2](0, 0) = d3[0](0, 2);
689  d3[2](0, 1) = d3[0](1, 2);
690  d3[2](0, 2) = d3[0](2, 2);
691  d3[2](1, 0) = d3[0](1, 2);
692  d3[2](1, 1) = d3[1](1, 2);
693  d3[2](1, 2) = d3[1](2, 2);
694  d3[2](2, 0) = d3[0](2, 2);
695  d3[2](2, 1) = d3[1](2, 2);
696  return val;
697  }
OHMMS_PRECISION real_type

◆ evaluate() [4/4]

real_type evaluate ( const real_type  r,
const real_type  rinv 
)
inline

Definition at line 700 of file PolynomialFunctor3D.h.

700 { return 0.0; }

◆ evaluateDerivatives() [1/2]

bool evaluateDerivatives ( const real_type  r_12,
const real_type  r_1I,
const real_type  r_2I,
std::vector< real_type > &  d_vals 
)
inline

calculate derivatives with respect to polynomial parameters

Definition at line 737 of file PolynomialFunctor3D.h.

References qmcplusplus::abs(), PolynomialFunctor3D::C, BLAS::cone, PolynomialFunctor3D::ConstraintMatrix, OptimizableFunctorBase::cutoff_radius, BLAS::czero, PolynomialFunctor3D::dval_Vec, qmcplusplus::Units::charge::e, PolynomialFunctor3D::IndepVar, qmcplusplus::Units::distance::m, qmcplusplus::n, PolynomialFunctor3D::N_ee, PolynomialFunctor3D::N_eI, PolynomialFunctor3D::NumGamma, and PolynomialFunctor3D::scale.

741  {
742  const real_type L = 0.5 * cutoff_radius;
743  if (r_1I >= L || r_2I >= L)
744  return false;
745 
746  constexpr real_type czero(0);
747  constexpr real_type cone(1);
748 
749  real_type dval_dgamma;
750 
751  for (int i = 0; i < dval_Vec.size(); i++)
752  dval_Vec[i] = czero;
753 
754  const real_type r_2I_minus_L = r_2I - L;
755  const real_type r_1I_minus_L = r_1I - L;
756  const real_type both_minus_L = r_2I_minus_L * r_1I_minus_L;
757 
758  real_type r2l(cone);
759  for (int l = 0; l <= N_eI; l++)
760  {
761  real_type r2m(cone);
762  for (int m = 0; m <= N_eI; m++)
763  {
764  int num;
765  if (m > l)
766  num = ((2 * N_eI - l + 3) * l / 2 + m - l) * (N_ee + 1);
767  else
768  num = ((2 * N_eI - m + 3) * m / 2 + l - m) * (N_ee + 1);
769  real_type r2n(cone);
770  for (int n = 0; n <= N_ee; n++, num++)
771  {
772  dval_dgamma = r2l * r2m * r2n;
773  for (int i = 0; i < C; i++)
774  dval_dgamma *= both_minus_L;
775 
776  // Now, pack into vectors
777  dval_Vec[num] += scale * dval_dgamma;
778  r2n *= r_12;
779  }
780  r2m *= r_2I;
781  }
782  r2l *= r_1I;
783  }
784  // for (int i=0; i<dval_Vec.size(); i++)
785  // fprintf (stderr, "dval_Vec[%d] = %12.6e\n", i, dval_Vec[i]);
786  ///////////////////////////////////////////
787  // Now, compensate for constraint matrix //
788  ///////////////////////////////////////////
789  std::fill(d_vals.begin(), d_vals.end(), 0.0);
790  int var = 0;
791  for (int i = 0; i < NumGamma; i++)
792  if (IndepVar[i])
793  {
794  d_vals[var] = dval_Vec[i];
795  var++;
796  }
797  int constraint = 0;
798  for (int i = 0; i < NumGamma; i++)
799  {
800  if (!IndepVar[i])
801  {
802  int indep_var = 0;
803  for (int j = 0; j < NumGamma; j++)
804  if (IndepVar[j])
805  {
806  d_vals[indep_var] -= ConstraintMatrix(constraint, j) * dval_Vec[i];
807  indep_var++;
808  }
809  else if (i != j)
810  assert(std::abs(ConstraintMatrix(constraint, j)) < 1.0e-10);
811  constraint++;
812  }
813  }
814  return true;
815  }
std::vector< real_type > dval_Vec
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
constexpr std::complex< float > czero
Definition: BLAS.hpp:51
constexpr std::complex< float > cone
Definition: BLAS.hpp:50
OHMMS_PRECISION real_type

◆ evaluateDerivatives() [2/2]

bool evaluateDerivatives ( const real_type  r_12,
const real_type  r_1I,
const real_type  r_2I,
std::vector< real_type > &  d_vals,
std::vector< TinyVector< real_type, 3 >> &  d_grads,
std::vector< Tensor< real_type, 3 >> &  d_hess 
)
inline

Definition at line 817 of file PolynomialFunctor3D.h.

References qmcplusplus::abs(), PolynomialFunctor3D::C, BLAS::cone, PolynomialFunctor3D::ConstraintMatrix, OptimizableFunctorBase::cutoff_radius, BLAS::czero, PolynomialFunctor3D::d_gradsFD, PolynomialFunctor3D::d_hessFD, PolynomialFunctor3D::d_valsFD, PolynomialFunctor3D::dgrad_Vec, PolynomialFunctor3D::dhess_Vec, PolynomialFunctor3D::dval_Vec, qmcplusplus::Units::charge::e, PolynomialFunctor3D::evaluateDerivativesFD(), PolynomialFunctor3D::IndepVar, qmcplusplus::Units::distance::m, qmcplusplus::n, PolynomialFunctor3D::N_ee, PolynomialFunctor3D::N_eI, PolynomialFunctor3D::NumGamma, PolynomialFunctor3D::Parameters, and PolynomialFunctor3D::scale.

823  {
824  const real_type L = 0.5 * cutoff_radius;
825  if (r_1I >= L || r_2I >= L)
826  return false;
827 
828  constexpr real_type czero(0);
829  constexpr real_type cone(1);
830  constexpr real_type ctwo(2);
831 
832  real_type dval_dgamma;
833  TinyVector<real_type, 3> dgrad_dgamma;
834  Tensor<real_type, 3> dhess_dgamma;
835 
836  for (int i = 0; i < dval_Vec.size(); i++)
837  {
838  dval_Vec[i] = czero;
839  dgrad_Vec[i] = czero;
840  dhess_Vec[i] = czero;
841  }
842 
843  const real_type r_2I_minus_L = r_2I - L;
844  const real_type r_1I_minus_L = r_1I - L;
845  const real_type both_minus_L = r_2I_minus_L * r_1I_minus_L;
846 
847  real_type r2l(cone), r2l_1(czero), r2l_2(czero), lf(czero);
848  for (int l = 0; l <= N_eI; l++)
849  {
850  real_type r2m(cone), r2m_1(czero), r2m_2(czero), mf(czero);
851  for (int m = 0; m <= N_eI; m++)
852  {
853  int num;
854  if (m > l)
855  num = ((2 * N_eI - l + 3) * l / 2 + m - l) * (N_ee + 1);
856  else
857  num = ((2 * N_eI - m + 3) * m / 2 + l - m) * (N_ee + 1);
858  real_type r2n(cone), r2n_1(czero), r2n_2(czero), nf(czero);
859  for (int n = 0; n <= N_ee; n++, num++)
860  {
861  dval_dgamma = r2l * r2m * r2n;
862  dgrad_dgamma[0] = r2l * r2m * r2n_1;
863  dgrad_dgamma[1] = r2l_1 * r2m * r2n;
864  dgrad_dgamma[2] = r2l * r2m_1 * r2n;
865  dhess_dgamma(0, 0) = r2l * r2m * r2n_2;
866  dhess_dgamma(0, 1) = r2l_1 * r2m * r2n_1;
867  dhess_dgamma(0, 2) = r2l * r2m_1 * r2n_1;
868  dhess_dgamma(1, 1) = r2l_2 * r2m * r2n;
869  dhess_dgamma(1, 2) = r2l_1 * r2m_1 * r2n;
870  dhess_dgamma(2, 2) = r2l * r2m_2 * r2n;
871 
872  for (int i = 0; i < C; i++)
873  {
874  dhess_dgamma(0, 0) = both_minus_L * dhess_dgamma(0, 0);
875  dhess_dgamma(0, 1) = both_minus_L * dhess_dgamma(0, 1) + r_2I_minus_L * dgrad_dgamma[0];
876  dhess_dgamma(0, 2) = both_minus_L * dhess_dgamma(0, 2) + r_1I_minus_L * dgrad_dgamma[0];
877  dhess_dgamma(1, 1) = both_minus_L * dhess_dgamma(1, 1) + ctwo * r_2I_minus_L * dgrad_dgamma[1];
878  dhess_dgamma(1, 2) = both_minus_L * dhess_dgamma(1, 2) + r_1I_minus_L * dgrad_dgamma[1] +
879  r_2I_minus_L * dgrad_dgamma[2] + dval_dgamma;
880  dhess_dgamma(2, 2) = both_minus_L * dhess_dgamma(2, 2) + ctwo * r_1I_minus_L * dgrad_dgamma[2];
881  dgrad_dgamma[0] = both_minus_L * dgrad_dgamma[0];
882  dgrad_dgamma[1] = both_minus_L * dgrad_dgamma[1] + r_2I_minus_L * dval_dgamma;
883  dgrad_dgamma[2] = both_minus_L * dgrad_dgamma[2] + r_1I_minus_L * dval_dgamma;
884  dval_dgamma *= both_minus_L;
885  }
886 
887  // Now, pack into vectors
888  dval_Vec[num] += scale * dval_dgamma;
889  for (int i = 0; i < 3; i++)
890  {
891  dgrad_Vec[num][i] += scale * dgrad_dgamma[i];
892  dhess_Vec[num](i, i) += scale * dhess_dgamma(i, i);
893  for (int j = i + 1; j < 3; j++)
894  {
895  dhess_Vec[num](i, j) += scale * dhess_dgamma(i, j);
896  dhess_Vec[num](j, i) = dhess_Vec[num](i, j);
897  }
898  }
899 
900  nf += cone;
901  r2n_2 = r2n_1 * nf;
902  r2n_1 = r2n * nf;
903  r2n *= r_12;
904  }
905  mf += cone;
906  r2m_2 = r2m_1 * mf;
907  r2m_1 = r2m * mf;
908  r2m *= r_2I;
909  }
910  lf += cone;
911  r2l_2 = r2l_1 * lf;
912  r2l_1 = r2l * lf;
913  r2l *= r_1I;
914  }
915  // for (int i=0; i<dval_Vec.size(); i++)
916  // fprintf (stderr, "dval_Vec[%d] = %12.6e\n", i, dval_Vec[i]);
917  ///////////////////////////////////////////
918  // Now, compensate for constraint matrix //
919  ///////////////////////////////////////////
920  std::fill(d_vals.begin(), d_vals.end(), 0.0);
921  int var = 0;
922  for (int i = 0; i < NumGamma; i++)
923  if (IndepVar[i])
924  {
925  d_vals[var] = dval_Vec[i];
926  d_grads[var] = dgrad_Vec[i];
927  d_hess[var] = dhess_Vec[i];
928  var++;
929  }
930  int constraint = 0;
931  for (int i = 0; i < NumGamma; i++)
932  {
933  if (!IndepVar[i])
934  {
935  int indep_var = 0;
936  for (int j = 0; j < NumGamma; j++)
937  if (IndepVar[j])
938  {
939  d_vals[indep_var] -= ConstraintMatrix(constraint, j) * dval_Vec[i];
940  d_grads[indep_var] -= ConstraintMatrix(constraint, j) * dgrad_Vec[i];
941  d_hess[indep_var] -= ConstraintMatrix(constraint, j) * dhess_Vec[i];
942  indep_var++;
943  }
944  else if (i != j)
945  assert(std::abs(ConstraintMatrix(constraint, j)) < 1.0e-10);
946  constraint++;
947  }
948  }
949  return true;
950 #ifdef DEBUG_DERIVS
951  evaluateDerivativesFD(r_12, r_1I, r_2I, d_valsFD, d_gradsFD, d_hessFD);
952  fprintf(stderr, "Param Analytic Finite diffference\n");
953  for (int ip = 0; ip < Parameters.size(); ip++)
954  fprintf(stderr, " %3d %12.6e %12.6e\n", ip, d_vals[ip], d_valsFD[ip]);
955  fprintf(stderr, "Param Analytic Finite diffference\n");
956  for (int ip = 0; ip < Parameters.size(); ip++)
957  fprintf(stderr, " %3d %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e\n", ip, d_grads[ip][0], d_gradsFD[ip][0],
958  d_grads[ip][1], d_gradsFD[ip][1], d_grads[ip][2], d_gradsFD[ip][2]);
959  fprintf(stderr, "Param Analytic Finite diffference\n");
960  for (int ip = 0; ip < Parameters.size(); ip++)
961  for (int dim = 0; dim < 3; dim++)
962  fprintf(stderr, " %3d %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e\n", ip, d_hess[ip](0, dim),
963  d_hessFD[ip](0, dim), d_hess[ip](1, dim), d_hessFD[ip](1, dim), d_hess[ip](2, dim),
964  d_hessFD[ip](2, dim));
965 #endif
966  }
std::vector< real_type > dval_Vec
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
constexpr std::complex< float > czero
Definition: BLAS.hpp:51
constexpr std::complex< float > cone
Definition: BLAS.hpp:50
bool evaluateDerivativesFD(const real_type r_12, const real_type r_1I, const real_type r_2I, std::vector< double > &d_vals, std::vector< TinyVector< real_type, 3 >> &d_grads, std::vector< Tensor< real_type, 3 >> &d_hess)
std::vector< real_type > Parameters
OHMMS_PRECISION real_type
std::vector< TinyVector< real_type, 3 > > d_gradsFD
std::vector< TinyVector< real_type, 3 > > dgrad_Vec
std::vector< Tensor< real_type, 3 > > d_hessFD
std::vector< real_type > d_valsFD
std::vector< Tensor< real_type, 3 > > dhess_Vec

◆ evaluateDerivativesFD()

bool evaluateDerivativesFD ( const real_type  r_12,
const real_type  r_1I,
const real_type  r_2I,
std::vector< double > &  d_vals,
std::vector< TinyVector< real_type, 3 >> &  d_grads,
std::vector< Tensor< real_type, 3 >> &  d_hess 
)
inline

Definition at line 703 of file PolynomialFunctor3D.h.

References PolynomialFunctor3D::evaluate(), PolynomialFunctor3D::Parameters, and PolynomialFunctor3D::reset_gamma().

Referenced by PolynomialFunctor3D::evaluateDerivatives().

709  {
710  const real_type eps = 1.0e-6;
711  assert(d_vals.size() == Parameters.size());
712  assert(d_grads.size() == Parameters.size());
713  assert(d_hess.size() == Parameters.size());
714  for (int ip = 0; ip < Parameters.size(); ip++)
715  {
716  real_type v_plus, v_minus;
717  TinyVector<real_type, 3> g_plus, g_minus;
718  Tensor<real_type, 3> h_plus, h_minus;
719  real_type save_p = Parameters[ip];
720  Parameters[ip] = save_p + eps;
721  reset_gamma();
722  v_plus = evaluate(r_12, r_1I, r_2I, g_plus, h_plus);
723  Parameters[ip] = save_p - eps;
724  reset_gamma();
725  v_minus = evaluate(r_12, r_1I, r_2I, g_minus, h_minus);
726  Parameters[ip] = save_p;
727  reset_gamma();
728  real_type dp_inv = 0.5 / eps;
729  d_vals[ip] = dp_inv * (v_plus - v_minus);
730  d_grads[ip] = dp_inv * (g_plus - g_minus);
731  d_hess[ip] = dp_inv * (h_plus - h_minus);
732  }
733  return true;
734  }
std::vector< real_type > Parameters
real_type evaluate(real_type r_12, real_type r_1I, real_type r_2I) const
OHMMS_PRECISION real_type

◆ evaluateV()

real_type evaluateV ( int  Nptcl,
const real_type *restrict  r_12_array,
const real_type *restrict  r_1I_array,
const real_type *restrict  r_2I_array 
) const
inline

Definition at line 352 of file PolynomialFunctor3D.h.

References PolynomialFunctor3D::C, BLAS::cone, OptimizableFunctorBase::cutoff_radius, BLAS::czero, PolynomialFunctor3D::gamma, qmcplusplus::Units::distance::m, qmcplusplus::n, PolynomialFunctor3D::N_ee, and PolynomialFunctor3D::N_eI.

356  {
357  constexpr real_type czero(0);
358  constexpr real_type cone(1);
359  constexpr real_type chalf(0.5);
360 
361  const real_type L = chalf * cutoff_radius;
362  real_type val_tot = czero;
363 
364 #pragma omp simd aligned(r_12_array, r_1I_array, r_2I_array : QMC_SIMD_ALIGNMENT) reduction(+ : val_tot)
365  for (int ptcl = 0; ptcl < Nptcl; ptcl++)
366  {
367  const real_type r_12 = r_12_array[ptcl];
368  const real_type r_1I = r_1I_array[ptcl];
369  const real_type r_2I = r_2I_array[ptcl];
370  real_type val = czero;
371  real_type r2l(cone);
372  for (int l = 0; l <= N_eI; l++)
373  {
374  real_type r2m(r2l);
375  for (int m = 0; m <= N_eI; m++)
376  {
377  real_type r2n(r2m);
378  for (int n = 0; n <= N_ee; n++)
379  {
380  val += gamma(l, m, n) * r2n;
381  r2n *= r_12;
382  }
383  r2m *= r_2I;
384  }
385  r2l *= r_1I;
386  }
387  const real_type both_minus_L = (r_2I - L) * (r_1I - L);
388  for (int i = 0; i < C; i++)
389  val *= both_minus_L;
390  val_tot += val;
391  }
392 
393  return val_tot;
394  }
constexpr std::complex< float > czero
Definition: BLAS.hpp:51
constexpr std::complex< float > cone
Definition: BLAS.hpp:50
OHMMS_PRECISION real_type

◆ evaluateVGL()

void evaluateVGL ( int  Nptcl,
const real_type *restrict  r_12_array,
const real_type *restrict  r_1I_array,
const real_type *restrict  r_2I_array,
real_type *restrict  val_array,
real_type *restrict  grad0_array,
real_type *restrict  grad1_array,
real_type *restrict  grad2_array,
real_type *restrict  hess00_array,
real_type *restrict  hess11_array,
real_type *restrict  hess22_array,
real_type *restrict  hess01_array,
real_type *restrict  hess02_array 
) const
inline

Definition at line 481 of file PolynomialFunctor3D.h.

References PolynomialFunctor3D::C, BLAS::cone, OptimizableFunctorBase::cutoff_radius, BLAS::czero, PolynomialFunctor3D::gamma, qmcplusplus::Units::distance::m, qmcplusplus::n, PolynomialFunctor3D::N_ee, and PolynomialFunctor3D::N_eI.

494  {
495  constexpr real_type czero(0);
496  constexpr real_type cone(1);
497  constexpr real_type chalf(0.5);
498  constexpr real_type ctwo(2);
499 
500  const real_type L = chalf * cutoff_radius;
501 #pragma omp simd aligned(r_12_array, r_1I_array, r_2I_array, val_array, grad0_array, grad1_array, grad2_array, \
502  hess00_array, hess11_array, hess22_array, hess01_array, hess02_array \
503  : QMC_SIMD_ALIGNMENT)
504  for (int ptcl = 0; ptcl < Nptcl; ptcl++)
505  {
506  const real_type r_12 = r_12_array[ptcl];
507  const real_type r_1I = r_1I_array[ptcl];
508  const real_type r_2I = r_2I_array[ptcl];
509 
510  real_type val(czero);
511  real_type grad0(czero);
512  real_type grad1(czero);
513  real_type grad2(czero);
514  real_type hess00(czero);
515  real_type hess11(czero);
516  real_type hess22(czero);
517  real_type hess01(czero);
518  real_type hess02(czero);
519 
520  real_type r2l(cone), r2l_1(czero), r2l_2(czero), lf(czero);
521  for (int l = 0; l <= N_eI; l++)
522  {
523  real_type r2m(cone), r2m_1(czero), r2m_2(czero), mf(czero);
524  for (int m = 0; m <= N_eI; m++)
525  {
526  real_type r2n(cone), r2n_1(czero), r2n_2(czero), nf(czero);
527  for (int n = 0; n <= N_ee; n++)
528  {
529  const real_type g = gamma(l, m, n);
530  const real_type g00x = g * r2l * r2m;
531  const real_type g10x = g * r2l_1 * r2m;
532  const real_type g01x = g * r2l * r2m_1;
533  const real_type gxx0 = g * r2n;
534 
535  val += g00x * r2n;
536  grad0 += g00x * r2n_1;
537  grad1 += g10x * r2n;
538  grad2 += g01x * r2n;
539  hess00 += g00x * r2n_2;
540  hess01 += g10x * r2n_1;
541  hess02 += g01x * r2n_1;
542  hess11 += gxx0 * r2l_2 * r2m;
543  hess22 += gxx0 * r2l * r2m_2;
544  nf += cone;
545  r2n_2 = r2n_1 * nf;
546  r2n_1 = r2n * nf;
547  r2n *= r_12;
548  }
549  mf += cone;
550  r2m_2 = r2m_1 * mf;
551  r2m_1 = r2m * mf;
552  r2m *= r_2I;
553  }
554  lf += cone;
555  r2l_2 = r2l_1 * lf;
556  r2l_1 = r2l * lf;
557  r2l *= r_1I;
558  }
559 
560  const real_type r_2I_minus_L = r_2I - L;
561  const real_type r_1I_minus_L = r_1I - L;
562  const real_type both_minus_L = r_2I_minus_L * r_1I_minus_L;
563  for (int i = 0; i < C; i++)
564  {
565  hess00 = both_minus_L * hess00;
566  hess01 = both_minus_L * hess01 + r_2I_minus_L * grad0;
567  hess02 = both_minus_L * hess02 + r_1I_minus_L * grad0;
568  hess11 = both_minus_L * hess11 + ctwo * r_2I_minus_L * grad1;
569  hess22 = both_minus_L * hess22 + ctwo * r_1I_minus_L * grad2;
570  grad0 = both_minus_L * grad0;
571  grad1 = both_minus_L * grad1 + r_2I_minus_L * val;
572  grad2 = both_minus_L * grad2 + r_1I_minus_L * val;
573  val *= both_minus_L;
574  }
575 
576  val_array[ptcl] = val;
577  grad0_array[ptcl] = grad0 / r_12;
578  grad1_array[ptcl] = grad1 / r_1I;
579  grad2_array[ptcl] = grad2 / r_2I;
580  hess00_array[ptcl] = hess00;
581  hess11_array[ptcl] = hess11;
582  hess22_array[ptcl] = hess22;
583  hess01_array[ptcl] = hess01 / (r_12 * r_1I);
584  hess02_array[ptcl] = hess02 / (r_12 * r_2I);
585  }
586  }
constexpr std::complex< float > czero
Definition: BLAS.hpp:51
constexpr std::complex< float > cone
Definition: BLAS.hpp:50
OHMMS_PRECISION real_type

◆ f()

real_type f ( real_type  r)
inlineoverride

Definition at line 968 of file PolynomialFunctor3D.h.

968 { return 0.0; }

◆ getNumParameters()

int getNumParameters ( )
inline

Definition at line 1105 of file PolynomialFunctor3D.h.

References PolynomialFunctor3D::Parameters.

1105 { return Parameters.size(); }
std::vector< real_type > Parameters

◆ makeClone()

OptimizableFunctorBase* makeClone ( ) const
inlineoverridevirtual

create a clone of this object

Implements OptimizableFunctorBase.

Definition at line 69 of file PolynomialFunctor3D.h.

References PolynomialFunctor3D::PolynomialFunctor3D().

69 { return new PolynomialFunctor3D(*this); }
PolynomialFunctor3D(const std::string &my_name, real_type ee_cusp=0.0, real_type eI_cusp=0.0)
constructor

◆ print()

void print ( std::ostream &  os)
inline

Definition at line 1089 of file PolynomialFunctor3D.h.

1090  {
1091  /* no longer correct. Ye Luo
1092  int n=100;
1093  real_type d=cutoff_radius/100.,r=0;
1094  real_type u,du,d2du;
1095  for(int i=0; i<n; ++i)
1096  {
1097  u=evaluate(r,du,d2du);
1098  os << std::setw(22) << r << std::setw(22) << u << std::setw(22) << du
1099  << std::setw(22) << d2du << std::endl;
1100  r+=d;
1101  }
1102  */
1103  }

◆ put()

bool put ( xmlNodePtr  cur)
inlineoverridevirtual

process xmlnode and registers variables to optimize

Parameters
curxmlNode for a functor

Implements OptimizableFunctorBase.

Definition at line 971 of file PolynomialFunctor3D.h.

References OhmmsAttributeSet::add(), qmcplusplus::app_log(), qmcplusplus::app_summary(), OptimizableFunctorBase::cutoff_radius, ReportEngine::error(), PolynomialFunctor3D::eSpecies1, PolynomialFunctor3D::eSpecies2, VariableSet::insert(), PolynomialFunctor3D::iSpecies, optimize::LOGLINEAR_P, OptimizableFunctorBase::myVars, PolynomialFunctor3D::N_ee, PolynomialFunctor3D::N_eI, PolynomialFunctor3D::notOpt, PolynomialFunctor3D::Parameters, VariableSet::print(), OhmmsAttributeSet::put(), putContent(), PolynomialFunctor3D::reset_gamma(), and PolynomialFunctor3D::resize().

972  {
973  ReportEngine PRE("PolynomialFunctor3D", "put(xmlNodePtr)");
974  // //CuspValue = -1.0e10;
975  // NumParams_eI = NumParams_ee = 0;
976  cutoff_radius = 0.0;
977  OhmmsAttributeSet rAttrib;
978  rAttrib.add(N_ee, "esize");
979  rAttrib.add(N_eI, "isize");
980  rAttrib.add(cutoff_radius, "rcut");
981  rAttrib.put(cur);
982  if (N_eI == 0)
983  PRE.error("You must specify a positive number for \"isize\"", true);
984  if (N_ee == 0)
985  PRE.error("You must specify a positive number for \"esize\"", true);
986  app_summary() << " Ion: " << iSpecies << " electron-electron: " << eSpecies1 << " - " << eSpecies2
987  << std::endl;
988  app_summary() << " Number of parameters for e-e: " << N_ee << ", for e-I: " << N_eI << std::endl;
989  app_summary() << " Cutoff radius: " << cutoff_radius << std::endl;
990  app_summary() << std::endl;
991  resize(N_eI, N_ee);
992  // Now read coefficents
993  xmlNodePtr xmlCoefs = cur->xmlChildrenNode;
994  while (xmlCoefs != NULL)
995  {
996  std::string cname((const char*)xmlCoefs->name);
997  if (cname == "coefficients")
998  {
999  std::string type("0"), id("0"), opt("yes");
1000  OhmmsAttributeSet cAttrib;
1001  cAttrib.add(id, "id");
1002  cAttrib.add(type, "type");
1003  cAttrib.add(opt, "optimize");
1004  cAttrib.put(xmlCoefs);
1005  notOpt = (opt == "no");
1006  if (type != "Array")
1007  {
1008  PRE.error("Unknown correlation type " + type + " in PolynomialFunctor3D." + "Resetting to \"Array\"");
1009  xmlNewProp(xmlCoefs, (const xmlChar*)"type", (const xmlChar*)"Array");
1010  }
1011  std::vector<real_type> params;
1012  putContent(params, xmlCoefs);
1013  if (params.size() == Parameters.size())
1014  Parameters = params;
1015  else
1016  {
1017  app_log() << "Expected " << Parameters.size() << " parameters,"
1018  << " but found " << params.size() << " in PolynomialFunctor3D.\n";
1019  if (params.size() != 0)
1020  abort(); //you think you know what they should be but don't.
1021  }
1022  // Setup parameter names
1023  for (int i = 0; i < Parameters.size(); i++)
1024  {
1025  std::stringstream sstr;
1026  sstr << id << "_" << i;
1027  ;
1028  if (!notOpt)
1029  myVars.insert(sstr.str(), Parameters[i], optimize::LOGLINEAR_P, true);
1030  }
1031  // for (int i=0; i< N_ee; i++)
1032  // for (int j=0; j < N_eI; j++)
1033  // for (int k=0; k<=j; k++) {
1034  // std::stringstream sstr;
1035  // sstr << id << "_" << i << "_" << j << "_" << k;
1036  // myVars.insert(sstr.str(),Parameters[index],true);
1037  // ParamArray(i,j,k) = ParamArray(i,k,j) = Parameters[index];
1038  // index++;
1039  // }
1040  if (!notOpt)
1041  {
1042  int left_pad_spaces = 6;
1043  myVars.print(app_log(), left_pad_spaces, true);
1044  app_log() << std::endl;
1045  }
1046  }
1047  xmlCoefs = xmlCoefs->next;
1048  }
1049  reset_gamma();
1050  return true;
1051  }
std::ostream & app_log()
Definition: OutputManager.h:65
std::ostream & app_summary()
Definition: OutputManager.h:63
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::vector< real_type > Parameters
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
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
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 print(std::ostream &os, int leftPadSpaces=0, bool printHeader=false) const
opt_variables_type myVars
set of variables to be optimized

◆ reset()

◆ reset_gamma()

void reset_gamma ( )
inline

Definition at line 225 of file PolynomialFunctor3D.h.

References qmcplusplus::abs(), qmcplusplus::app_error(), PolynomialFunctor3D::C, PolynomialFunctor3D::ConstraintMatrix, OptimizableFunctorBase::cutoff_radius, qmcplusplus::Units::charge::e, PolynomialFunctor3D::gamma, PolynomialFunctor3D::GammaVec, PolynomialFunctor3D::IndepVar, PolynomialFunctor3D::index, qmcplusplus::Units::distance::m, qmcplusplus::n, PolynomialFunctor3D::N_ee, PolynomialFunctor3D::N_eI, PolynomialFunctor3D::NumGamma, PolynomialFunctor3D::Parameters, and PolynomialFunctor3D::scale.

Referenced by PolynomialFunctor3D::evaluateDerivativesFD(), PolynomialFunctor3D::put(), PolynomialFunctor3D::reset(), and PolynomialFunctor3D::resetParametersExclusive().

226  {
227  // fprintf (stderr, "Parameters:\n");
228  // for (int i=0; i<Parameters.size(); i++)
229  // fprintf (stderr, " %16.10e\n", Parameters[i]);
230  const double L = 0.5 * cutoff_radius;
231  std::fill(GammaVec.begin(), GammaVec.end(), 0.0);
232  // First, set all independent variables
233  int var = 0;
234  for (int i = 0; i < NumGamma; i++)
235  if (IndepVar[i])
236  GammaVec[i] = scale * Parameters[var++];
237  assert(var == Parameters.size());
238  // Now, set dependent variables
239  var = 0;
240  // std::cerr << "NumConstraints = " << NumConstraints << std::endl;
241  for (int i = 0; i < NumGamma; i++)
242  if (!IndepVar[i])
243  {
244  // fprintf (stderr, "constraintMatrix(%d,%d) = %1.10f\n",
245  // var, i, ConstraintMatrix(var,i));
246  assert(std::abs(ConstraintMatrix(var, i) - 1.0) < 1.0e-6);
247  for (int j = 0; j < NumGamma; j++)
248  if (i != j)
249  GammaVec[i] -= ConstraintMatrix(var, j) * GammaVec[j];
250  var++;
251  }
252  int num = 0;
253  for (int m = 0; m <= N_eI; m++)
254  for (int l = m; l <= N_eI; l++)
255  for (int n = 0; n <= N_ee; n++)
256  // gamma(m,l,n) = gamma(l,m,n) = unpermuted[num++];
257  gamma(m, l, n) = gamma(l, m, n) = GammaVec[num++];
258  // Now check that constraints have been satisfied
259  // e-e constraints
260  for (int k = 0; k <= 2 * N_eI; k++)
261  {
262  real_type sum = 0.0;
263  for (int m = 0; m <= k; m++)
264  {
265  int l = k - m;
266  if (l <= N_eI && m <= N_eI)
267  {
268  int i = index(l, m, 1);
269  if (l > m)
270  sum += 2.0 * GammaVec[i];
271  else if (l == m)
272  sum += GammaVec[i];
273  }
274  }
275  if (std::abs(sum) > 1.0e-9)
276  std::cerr << "error in k = " << k << " sum = " << sum << std::endl;
277  }
278  for (int k = 0; k <= 2 * N_eI; k++)
279  {
280  real_type sum = 0.0;
281  for (int l = 0; l <= k; l++)
282  {
283  int m = k - l;
284  if (m <= N_eI && l <= N_eI)
285  {
286  // fprintf (stderr, "k = %d gamma(%d, %d, 1) = %1.8f\n", k, l, m,
287  // gamma(l,m,1));
288  sum += gamma(l, m, 1);
289  }
290  }
291  if (std::abs(sum) > 1.0e-6)
292  {
293  app_error() << "e-e constraint not satisfied in PolynomialFunctor3D: k=" << k << " sum=" << sum << std::endl;
294  abort();
295  }
296  }
297  // e-I constraints
298  for (int k = 0; k <= N_eI + N_ee; k++)
299  {
300  real_type sum = 0.0;
301  for (int m = 0; m <= k; m++)
302  {
303  int n = k - m;
304  if (m <= N_eI && n <= N_ee)
305  {
306  sum += (real_type)C * gamma(0, m, n) - L * gamma(1, m, n);
307  // fprintf (stderr,
308  // "k = %d gamma(0,%d,%d) = %1.8f gamma(1,%d,%d)=%1.8f\n",
309  // k, m, n, gamma(0,m,n), m, n, gamma(1,m,n));
310  }
311  }
312  if (std::abs(sum) > 1.0e-6)
313  {
314  app_error() << "e-I constraint not satisfied in PolynomialFunctor3D: k=" << k << " sum=" << sum << std::endl;
315  abort();
316  }
317  }
318  }
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
std::ostream & app_error()
Definition: OutputManager.h:67
std::vector< real_type > Parameters
std::vector< real_type > GammaVec
OHMMS_PRECISION real_type
optimize::VariableSet::real_type real_type
typedef for real values

◆ resetParametersExclusive()

void resetParametersExclusive ( const opt_variables_type active)
inlineoverridevirtual

reset the parameters during optimizations.

Exclusive, see checkInVariablesExclusive

Implements OptimizableObject.

Definition at line 1053 of file PolynomialFunctor3D.h.

References OptimizableFunctorBase::myVars, PolynomialFunctor3D::notOpt, PolynomialFunctor3D::Parameters, PolynomialFunctor3D::reset_gamma(), PolynomialFunctor3D::ResetCount, and VariableSet::where().

1054  {
1055  if (notOpt)
1056  return;
1057 
1058  for (int i = 0; i < Parameters.size(); ++i)
1059  {
1060  int loc = myVars.where(i);
1061  if (loc >= 0)
1062  {
1063  Parameters[i] = std::real(myVars[i] = active[loc]);
1064  }
1065  }
1066 
1067  if (ResetCount++ == 100)
1068  ResetCount = 0;
1069 
1070  reset_gamma();
1071  }
QMCTraits::RealType real
std::vector< real_type > Parameters
int where(int i) const
return the locator of the i-th Index
Definition: VariableSet.h:90
opt_variables_type myVars
set of variables to be optimized

◆ resize()

void resize ( int  neI,
int  nee 
)
inline

Definition at line 71 of file PolynomialFunctor3D.h.

References qmcplusplus::abs(), PolynomialFunctor3D::C, PolynomialFunctor3D::ConstraintMatrix, OptimizableFunctorBase::cutoff_radius, PolynomialFunctor3D::d_gradsFD, PolynomialFunctor3D::d_hessFD, PolynomialFunctor3D::d_valsFD, PolynomialFunctor3D::dgrad_Vec, PolynomialFunctor3D::dhess_Vec, PolynomialFunctor3D::dval_Vec, qmcplusplus::Units::charge::e, PolynomialFunctor3D::gamma, PolynomialFunctor3D::GammaPerm, PolynomialFunctor3D::GammaVec, PolynomialFunctor3D::IndepVar, PolynomialFunctor3D::index, qmcplusplus::Units::distance::m, qmcplusplus::n, PolynomialFunctor3D::N_ee, PolynomialFunctor3D::N_eI, PolynomialFunctor3D::NumConstraints, PolynomialFunctor3D::NumGamma, PolynomialFunctor3D::Parameters, Array< T, D, ALLOC >::resize(), Matrix< T, Alloc >::resize(), and Matrix< T, Alloc >::swap_rows().

Referenced by PolynomialFunctor3D::put(), and PolynomialFunctor3D::reset().

72  {
73  N_eI = neI;
74  N_ee = nee;
75  const double L = 0.5 * cutoff_radius;
76  gamma.resize(N_eI + 1, N_eI + 1, N_ee + 1);
77  index.resize(N_eI + 1, N_eI + 1, N_ee + 1);
78  NumGamma = ((N_eI + 1) * (N_eI + 2) / 2 * (N_ee + 1));
79  NumConstraints = (2 * N_eI + 1) + (N_eI + N_ee + 1);
80  int numParams = NumGamma - NumConstraints;
81  Parameters.resize(numParams);
82  d_valsFD.resize(numParams);
83  d_gradsFD.resize(numParams);
84  d_hessFD.resize(numParams);
85  GammaVec.resize(NumGamma);
86  dval_Vec.resize(NumGamma);
87  dgrad_Vec.resize(NumGamma);
88  dhess_Vec.resize(NumGamma);
90  // Assign indices
91  int num = 0;
92  for (int m = 0; m <= N_eI; m++)
93  for (int l = m; l <= N_eI; l++)
94  for (int n = 0; n <= N_ee; n++)
95  index(l, m, n) = index(m, l, n) = num++;
96  assert(num == NumGamma);
97  // std::cerr << "NumGamma = " << NumGamma << std::endl;
98  // Fill up contraint matrix
99  // For 3 constraints and 2 parameters, we would have
100  // |A00 A01 A02 A03 A04| |g0| |0 |
101  // |A11 A11 A12 A13 A14| |g1| |0 |
102  // |A22 A21 A22 A23 A24| |g2| = |0 |
103  // | 0 0 0 1 0 | |g3| |p0|
104  // | 0 0 0 0 1 | |g4| |p1|
105  ConstraintMatrix = 0.0;
106  // std::cerr << "ConstraintMatrix.size = " << ConstraintMatrix.size(0)
107  // << " by " << ConstraintMatrix.size(1) << std::endl;
108  // std::cerr << "index.size() = (" << index.size(0) << ", "
109  // << index.size(1) << ", " << index.size(2) << ").\n";
110  int k;
111  // e-e no-cusp constraint
112  for (k = 0; k <= 2 * N_eI; k++)
113  {
114  for (int m = 0; m <= k; m++)
115  {
116  int l = k - m;
117  if (l <= N_eI && m <= N_eI)
118  {
119  int i = index(l, m, 1);
120  if (l > m)
121  ConstraintMatrix(k, i) = 2.0;
122  else if (l == m)
123  ConstraintMatrix(k, i) = 1.0;
124  }
125  }
126  }
127  // e-I no-cusp constraint
128  for (int kp = 0; kp <= N_eI + N_ee; kp++)
129  {
130  if (kp <= N_ee)
131  {
132  ConstraintMatrix(k + kp, index(0, 0, kp)) = (real_type)C;
133  ConstraintMatrix(k + kp, index(0, 1, kp)) = -L;
134  }
135  for (int l = 1; l <= kp; l++)
136  {
137  int n = kp - l;
138  if (n >= 0 && n <= N_ee && l <= N_eI)
139  {
140  ConstraintMatrix(k + kp, index(l, 0, n)) = (real_type)C;
141  ConstraintMatrix(k + kp, index(l, 1, n)) = -L;
142  }
143  }
144  }
145  // {
146  // fprintf (stderr, "Constraint matrix:\n");
147  // for (int i=0; i<NumConstraints; i++) {
148  // for (int j=0; j<NumGamma; j++)
149  // fprintf (stderr, "%5.2f ", ConstraintMatrix(i,j));
150  // fprintf(stderr, "\n");
151  // }
152  // }
153  // Now, row-reduce constraint matrix
154  GammaPerm.resize(NumGamma);
155  IndepVar.resize(NumGamma, false);
156  // Set identity permutation
157  for (int i = 0; i < NumGamma; i++)
158  GammaPerm[i] = i;
159  int col = -1;
160  for (int row = 0; row < NumConstraints; row++)
161  {
162  int max_loc;
163  real_type max_abs;
164  do
165  {
166  col++;
167  max_loc = row;
168  max_abs = std::abs(ConstraintMatrix(row, col));
169  for (int ri = row + 1; ri < NumConstraints; ri++)
170  {
171  real_type abs_val = std::abs(ConstraintMatrix(ri, col));
172  if (abs_val > max_abs)
173  {
174  max_loc = ri;
175  max_abs = abs_val;
176  }
177  }
178  if (max_abs < 1.0e-6)
179  IndepVar[col] = true;
180  } while (max_abs < 1.0e-6);
181  ConstraintMatrix.swap_rows(row, max_loc);
182  real_type lead_inv = 1.0 / ConstraintMatrix(row, col);
183  for (int c = 0; c < NumGamma; c++)
184  ConstraintMatrix(row, c) *= lead_inv;
185  // Now, eliminate column entries
186  for (int ri = 0; ri < NumConstraints; ri++)
187  {
188  if (ri != row)
189  {
190  real_type val = ConstraintMatrix(ri, col);
191  for (int c = 0; c < NumGamma; c++)
192  ConstraintMatrix(ri, c) -= val * ConstraintMatrix(row, c);
193  }
194  }
195  }
196  for (int c = col + 1; c < NumGamma; c++)
197  IndepVar[c] = true;
198  // fprintf (stderr, "Reduced Constraint matrix:\n");
199  // for (int i=0; i<NumConstraints; i++) {
200  // for (int j=0; j<NumGamma; j++)
201  // fprintf (stderr, "%5.2f ", ConstraintMatrix(i,j));
202  // fprintf(stderr, "\n");
203  // }
204  // fprintf (stderr, "Independent vars = \n");
205  // for (int i=0; i<NumGamma; i++)
206  // if (IndepVar[i])
207  // fprintf (stderr, "%d ", i);
208  // fprintf (stderr, "\n");
209  // fprintf (stderr, "Inverse matrix:\n");
210  // // Now, invert constraint matrix
211  // Invert(ConstraintMatrix.data(), NumGamma, NumGamma);
212  // for (int i=0; i<NumGamma; i++) {
213  // for (int j=0; j<NumGamma; j++)
214  // fprintf (stderr, "%5.2f ", ConstraintMatrix(i,j));
215  // fprintf(stderr, "\n");
216  // }
217  }
std::vector< real_type > dval_Vec
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
void swap_rows(int r1, int r2)
Definition: OhmmsMatrix.h:249
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
std::vector< real_type > Parameters
std::vector< real_type > GammaVec
OHMMS_PRECISION real_type
std::vector< TinyVector< real_type, 3 > > d_gradsFD
std::vector< TinyVector< real_type, 3 > > dgrad_Vec
optimize::VariableSet::real_type real_type
typedef for real values
std::vector< Tensor< real_type, 3 > > d_hessFD
std::vector< real_type > d_valsFD
std::vector< Tensor< real_type, 3 > > dhess_Vec

Member Data Documentation

◆ C

◆ ConstraintMatrix

◆ d_gradsFD

std::vector<TinyVector<real_type, 3> > d_gradsFD

◆ d_hessFD

std::vector<Tensor<real_type, 3> > d_hessFD

◆ d_valsFD

std::vector<real_type> d_valsFD

◆ dgrad_Vec

std::vector<TinyVector<real_type, 3> > dgrad_Vec

◆ dhess_Vec

std::vector<Tensor<real_type, 3> > dhess_Vec

◆ dval_Vec

std::vector<real_type> dval_Vec

◆ eSpecies1

std::string eSpecies1

Definition at line 50 of file PolynomialFunctor3D.h.

Referenced by PolynomialFunctor3D::put().

◆ eSpecies2

std::string eSpecies2

Definition at line 50 of file PolynomialFunctor3D.h.

Referenced by PolynomialFunctor3D::put().

◆ gamma

◆ GammaPerm

std::vector<int> GammaPerm

Definition at line 37 of file PolynomialFunctor3D.h.

Referenced by PolynomialFunctor3D::resize().

◆ GammaVec

std::vector<real_type> GammaVec

◆ IndepVar

◆ index

Array<int, 3> index

◆ iSpecies

std::string iSpecies

Definition at line 50 of file PolynomialFunctor3D.h.

Referenced by PolynomialFunctor3D::put().

◆ N_ee

◆ N_eI

◆ notOpt

◆ NumConstraints

int NumConstraints

Definition at line 44 of file PolynomialFunctor3D.h.

Referenced by PolynomialFunctor3D::resize().

◆ NumGamma

◆ ParameterNames

std::vector<std::string> ParameterNames

Definition at line 49 of file PolynomialFunctor3D.h.

◆ Parameters

◆ ResetCount

int ResetCount

Definition at line 51 of file PolynomialFunctor3D.h.

Referenced by PolynomialFunctor3D::resetParametersExclusive().

◆ scale


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