QMCPACK
NonLocalECPotential.deriv.cpp
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 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 //
10 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
16 #include "DistanceTable.h"
17 #include "CPU/BLAS.hpp"
18 #include "Utilities/Timer.h"
19 
20 namespace qmcplusplus
21 {
23  const opt_variables_type& optvars,
24  const Vector<ValueType>& dlogpsi,
25  Vector<ValueType>& dhpsioverpsi)
26 {
27  value_ = 0.0;
28  for (int ipp = 0; ipp < PPset.size(); ipp++)
29  if (PPset[ipp])
30  PPset[ipp]->rotateQuadratureGrid(generateRandomRotationMatrix(*myRNG));
31 
32  /* evaluating TWF ratio values requires calling prepareGroup
33  * In evaluate() we first loop over species and call prepareGroup before looping over all the electrons of a species
34  * Here it is not necessary because TWF::evaluateLog has been called and precomputed data is up-to-date
35  */
36  const auto& myTable = P.getDistTableAB(myTableIndex);
37  for (int jel = 0; jel < P.getTotalNum(); jel++)
38  {
39  const auto& dist = myTable.getDistRow(jel);
40  const auto& displ = myTable.getDisplRow(jel);
41  for (int iat = 0; iat < NumIons; iat++)
42  if (PP[iat] != nullptr && dist[iat] < PP[iat]->getRmax())
43  value_ += PP[iat]->evaluateValueAndDerivatives(P, iat, Psi, jel, dist[iat], -displ[iat], optvars, dlogpsi,
44  dhpsioverpsi);
45  }
46  return value_;
47 }
48 
49 /** evaluate the non-local potential of the iat-th ionic center
50  * @param W electron configuration
51  * @param iat ionic index
52  * @param psi trial wavefunction
53  * @param optvars optimizables
54  * @param dlogpsi derivatives of the wavefunction at W.R
55  * @param hdpsioverpsi derivatives of Vpp
56  * @param return the non-local component
57  *
58  * This is a temporary solution which uses TrialWaveFunction::evaluateDerivatives
59  * assuming that the distance tables are fully updated for each ratio computation.
60  */
62  int iat,
63  TrialWaveFunction& psi,
64  int iel,
65  RealType r,
66  const PosType& dr,
67  const opt_variables_type& optvars,
68  const Vector<ValueType>& dlogpsi,
69  Vector<ValueType>& dhpsioverpsi)
70 {
71  const size_t num_vars = optvars.num_active_vars;
72  dratio.resize(nknot, num_vars);
73  dlogpsi_vp.resize(dlogpsi.size());
74 
75  deltaV.resize(nknot);
76 
77  //displacements wrt W.R[iel]
78  for (int j = 0; j < nknot; j++)
79  deltaV[j] = r * rrotsgrid_m[j] - dr;
80 
81  if (VP)
82  {
83  // Compute ratios with VP
84  VP->makeMoves(W, iel, deltaV, true, iat);
85  psi.evaluateDerivRatios(*VP, optvars, psiratio, dratio);
86  }
87  else
88  {
89  for (int j = 0; j < nknot; j++)
90  {
91  PosType pos_now = W.R[iel];
92  W.makeMove(iel, deltaV[j]);
93  psiratio[j] = psi.calcRatio(W, iel);
94  psi.acceptMove(W, iel);
95  W.acceptMove(iel);
96 
97  //use existing methods
98  std::fill(dlogpsi_vp.begin(), dlogpsi_vp.end(), 0.0);
99  psi.evaluateDerivativesWF(W, optvars, dlogpsi_vp);
100  for (int v = 0; v < dlogpsi_vp.size(); ++v)
101  dratio(j, v) = dlogpsi_vp[v] - dlogpsi[v];
102 
103  W.makeMove(iel, -deltaV[j]);
104  psi.calcRatio(W, iel);
105  psi.acceptMove(W, iel);
106  W.acceptMove(iel);
107  }
108  }
109 
110  for (int j = 0; j < nknot; ++j)
111  psiratio[j] *= sgridweight_m[j];
112 
113  for (int ip = 0; ip < nchannel; ip++)
114  vrad[ip] = nlpp_m[ip]->splint(r) * wgt_angpp_m[ip];
115 
116  RealType pairpot(0);
117  const RealType rinv = RealType(1) / r;
118  // Compute spherical harmonics on grid
119  for (int j = 0, jl = 0; j < nknot; j++)
120  {
121  RealType zz = dot(dr, rrotsgrid_m[j]) * rinv;
122  // Forming the Legendre polynomials
123  lpol[0] = 1.0;
124  RealType lpolprev = 0.0;
125  for (int l = 0; l < lmax; l++)
126  {
127  lpol[l + 1] = (Lfactor1[l] * zz * lpol[l] - l * lpolprev) * Lfactor2[l];
128  lpolprev = lpol[l];
129  }
130 
131  RealType lsum = 0.0;
132  for (int l = 0; l < nchannel; l++)
133  lsum += vrad[l] * lpol[angpp_m[l]];
134 
135  wvec[j] = lsum * psiratio[j];
136  pairpot += std::real(wvec[j]);
137  }
138 
139  BLAS::gemv('N', num_vars, nknot, 1.0, dratio.data(), num_vars, wvec.data(), 1, 1.0, dhpsioverpsi.data(), 1);
140 
141  return pairpot;
142 }
143 
144 } // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
aligned_vector< RealType > wgt_angpp_m
Weight of the angular momentum.
ValueType calcRatio(ParticleSet &P, int iat, ComputeType ct=ComputeType::ALL)
compute psi(R_new) / psi(R_current) ratio It returns a complex value if the wavefunction is complex...
std::vector< RadialPotentialType * > nlpp_m
Non-Local part of the pseudo-potential.
QMCTraits::RealType real
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
const DistRow & getDistRow(int iel) const
return a row of distances for a given target particle
int nchannel
the number of non-local channels
size_t getTotalNum() const
Definition: ParticleSet.h:493
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false)
update the state with the new data
void evaluateDerivativesWF(ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi)
void makeMoves(const ParticleSet &refp, int jel, const std::vector< PosType > &deltaV, bool sphere=false, int iat=-1)
move virtual particles to new postions and update distance tables
Timer class.
std::vector< NonLocalECPComponent * > PP
the set of local-potentials (one for each ion)
int myTableIndex
index of distance table for the ion-el pair
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
RealType Lfactor2[8]
Lfactor1[l]=(l)/(l+1)
static void gemv(int n, int m, const double *restrict amat, const double *restrict x, double *restrict y)
Definition: BLAS.hpp:118
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
std::vector< ValueType > wvec
Working arrays.
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
RealType evaluateValueAndDerivatives(ParticleSet &P, int iat, TrialWaveFunction &psi, int iel, RealType r, const PosType &dr, const opt_variables_type &optvars, const Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi)
evaluate the non-local potential of the iat-th ionic center
SpherGridType rrotsgrid_m
randomized spherical grid
size_type size() const
return the current size
Definition: OhmmsVector.h:162
Return_t evaluateValueAndDerivatives(ParticleSet &P, const opt_variables_type &optvars, const Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
Matrix< ValueType > dratio
scratch spaces used by evaluateValueAndDerivatives
RealType Lfactor1[8]
Lfactor1[l]=(2*l+1)/(l+1)
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
VirtualParticleSet * VP
virtual particle set: delayed initialization
ParticlePos R
Position.
Definition: ParticleSet.h:79
RandomBase< FullPrecRealType > * myRNG
random number generator
QMCTraits::TensorType generateRandomRotationMatrix(RandomBase< QMCTraits::FullPrecRealType > &rng)
Create a random 3D rotation matrix using a random generator.
FullPrecRealType Return_t
type of return value of evaluate
Definition: OperatorBase.h:64
int lmax
Non Local part: angular momentum, potential and grid.
Class to represent a many-body trial wave function.
void makeMove(Index_t iat, const SingleParticlePos &displ, bool maybe_accept=true)
move the iat-th particle to active_pos_
Return_t value_
current value
Definition: OperatorBase.h:524
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
void evaluateDerivRatios(const VirtualParticleSet &VP, const opt_variables_type &optvars, std::vector< ValueType > &ratios, Matrix< ValueType > &dratio)
compute both ratios and deriatives of ratio with respect to the optimizables
std::vector< std::unique_ptr< NonLocalECPComponent > > PPset
unique NonLocalECPComponent to remove
void acceptMove(Index_t iat)
accept the move and update the particle attribute by the proposed move in regular mode ...
std::vector< RealType > sgridweight_m
weight of the spherical grid
aligned_vector< int > angpp_m
Angular momentum map.
TrialWaveFunction & Psi
target TrialWaveFunction
int num_active_vars
number of active variables
Definition: VariableSet.h:60