QMCPACK
LatticeGaussianProduct.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: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 #include "LatticeGaussianProduct.h"
17 
18 namespace qmcplusplus
19 {
23 
25 {
26  NumTargetPtcls = ptcls.getTotalNum();
27  NumCenters = centers.getTotalNum();
28  myTableID = ptcls.addTable(CenterRef);
30  dU.resize(NumTargetPtcls);
32  FirstAddressOfdU = &(dU[0][0]);
34 }
35 
37 
38 /**
39  *@param P input configuration containing N particles
40  *@param G a vector containing N gradients
41  *@param L a vector containing N laplacians
42  *@return The wavefunction value \f$exp(-J({\bf R}))\f$
43  *
44  *Upon exit, the gradient \f$G[i]={\bf \nabla}_i J({\bf R})\f$
45  *and the laplacian \f$L[i]=\nabla^2_i J({\bf R})\f$ are accumulated.
46  *While evaluating the value of the Jastrow for a set of
47  *particles add the gradient and laplacian contribution of the
48  *Jastrow to G(radient) and L(aplacian) for local energy calculations
49  *such that \f[ G[i]+={\bf \nabla}_i J({\bf R}) \f]
50  *and \f[ L[i]+=\nabla^2_i J({\bf R}). \f]
51  */
55 {
56  const auto& d_table = P.getDistTableAB(myTableID);
57  int icent = 0;
58  log_value_ = 0.0;
59  RealType dist = 0.0;
60  PosType disp = 0.0;
61  for (int iat = 0; iat < NumTargetPtcls; iat++)
62  {
63  U[iat] = 0.0;
64  dU[iat] = 0.0;
65  d2U[iat] = 0.0;
66  RealType a = ParticleAlpha[iat];
67  if (a > 0.0)
68  {
69  dist = d_table.getDistRow(iat)[icent];
70  disp = -1.0 * d_table.getDisplRow(iat)[icent];
71  log_value_ -= a * dist * dist;
72  U[iat] += a * dist * dist;
73  G[iat] -= 2.0 * a * disp;
74  L[iat] -= 6.0 * a;
75  icent++;
76  }
77  }
78  return log_value_;
79 }
80 
81 /** evaluate the ratio \f$exp(U(iat)-U_0(iat))\f$
82  * @param P active particle set
83  * @param iat particle that has been moved.
84  */
86 {
87  const auto& d_table = P.getDistTableAB(myTableID);
88  int icent = ParticleCenter[iat];
89  if (icent == -1)
90  return 1.0;
91  RealType newdist = d_table.getTempDists()[icent];
92  curVal = ParticleAlpha[iat] * (newdist * newdist);
93  return std::exp(static_cast<PsiValue>(U[iat] - curVal));
94 }
95 
96 
98 {
99  const auto& d_table = P.getDistTableAB(myTableID);
100  int icent = ParticleCenter[iat];
101  if (icent == -1)
102  return GradType();
103  RealType a = ParticleAlpha[iat];
104  PosType newdisp = -1.0 * d_table.getTempDispls()[icent];
105  curGrad = -2.0 * a * newdisp;
106  return curGrad;
107 }
108 
109 
111 {
112  const auto& d_table = P.getDistTableAB(myTableID);
113  int icent = ParticleCenter[iat];
114  if (icent == -1)
115  return 1.0;
116  RealType a = ParticleAlpha[iat];
117  RealType newdist = d_table.getTempDists()[icent];
118  PosType newdisp = -1.0 * d_table.getTempDispls()[icent];
119  curVal = a * newdist * newdist;
120  curGrad = -2.0 * a * newdisp;
121  grad_iat += curGrad;
122  return std::exp(static_cast<PsiValue>(U[iat] - curVal));
123 }
124 
126 
127 void LatticeGaussianProduct::acceptMove(ParticleSet& P, int iat, bool safe_to_delay)
128 {
129  U[iat] = curVal;
130  dU[iat] = curGrad;
131  d2U[iat] = curLap;
132 }
133 
137 {
138  const auto& d_table = P.getDistTableAB(myTableID);
139  RealType dist = 0.0;
140  PosType disp = 0.0;
141  int icent = 0;
142  log_value_ = 0.0;
143  U = 0.0;
144  dU = 0.0;
145  d2U = 0.0;
146  for (int iat = 0; iat < NumTargetPtcls; iat++)
147  {
148  RealType a = ParticleAlpha[iat];
149  if (a > 0.0)
150  {
151  dist = d_table.getDistRow(iat)[icent];
152  disp = -1.0 * d_table.getDisplRow(iat)[icent];
153  log_value_ -= a * dist * dist;
154  U[iat] += a * dist * dist;
155  dU[iat] -= 2.0 * a * disp;
156  d2U[iat] -= 6.0 * a;
157  dG[iat] -= 2.0 * a * disp;
158  dL[iat] -= 6.0 * a;
159  icent++;
160  }
161  }
162 }
163 
164 /** equivalent to evalaute with additional data management */
166 {
167  evaluateLogAndStore(P, P.G, P.L);
168  // Add U, d2U and dU. Keep the order!!!
169  buf.add(U.begin(), U.end());
170  buf.add(d2U.begin(), d2U.end());
172 }
173 
175  WFBufferType& buf,
176  bool fromscratch = false)
177 {
178  evaluateLogAndStore(P, P.G, P.L);
179  buf.put(U.first_address(), U.last_address());
182  return log_value_;
183 }
184 
185 /** copy the current data from a buffer
186  *@param P the ParticleSet to operate on
187  *@param buf PooledData which stores the data for each walker
188  *
189  *copyFromBuffer uses the data stored by registerData
190  */
192 {
193  buf.get(U.first_address(), U.last_address());
196 }
197 
198 std::unique_ptr<WaveFunctionComponent> LatticeGaussianProduct::makeClone(ParticleSet& tqp) const
199 {
200  auto j1copy = std::make_unique<LatticeGaussianProduct>(CenterRef, tqp);
201  j1copy->ParticleAlpha = ParticleAlpha;
202  j1copy->ParticleCenter = ParticleCenter;
203  return j1copy;
204 }
205 
206 }; // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
ParticleSet & CenterRef
orbital centers
void evaluateLogAndStore(const ParticleSet &P, ParticleSet::ParticleGradient &dG, ParticleSet::ParticleLaplacian &dL)
std::unique_ptr< WaveFunctionComponent > makeClone(ParticleSet &tqp) const override
make clone
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
WaveFunctionComponent::PsiValue PsiValue
Definition: SlaterDet.cpp:25
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::GradType GradType
Definition: Configuration.h:62
void registerData(ParticleSet &P, WFBufferType &buf) override
equivalent to evalaute with additional data management
LatticeGaussianProduct(ParticleSet &centers, ParticleSet &ptcls)
void restore(int iat) override
If a move for iat-th particle is rejected, restore to the content.
PsiValue ratioGrad(ParticleSet &P, int iat, GradType &grad_iat) override
evaluate the ratio of the new to old WaveFunctionComponent value and the new gradient ...
size_t getTotalNum() const
Definition: ParticleSet.h:493
LatticeGaussianProduct::GradType GradType
Attaches a unit to a Vector for IO.
ParticleLaplacian L
laplacians of the particles
Definition: ParticleSet.h:85
#define OHMMS_DIM
Definition: config.h:64
std::complex< QTFull::RealType > LogValue
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
PsiValue ratio(ParticleSet &P, int iat) override
evaluate the ratio
QTBase::ValueType ValueType
Definition: Configuration.h:60
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
copy the current data from a buffer
ParticleGradient G
gradients of the particles
Definition: ParticleSet.h:83
pointer last_address()
Definition: OhmmsVector.h:258
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch) override
For particle-by-particle move.
LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
GradType evalGrad(ParticleSet &P, int iat) override
return the current gradient for the iat-th particle
LatticeGaussianProduct::ValueType ValueType
Simple gaussian functions used for orbitals for ions.
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false) override
a move for iat-th particle is accepted.
void put(std::complex< T1 > &x)
Definition: PooledMemory.h:165
pointer first_address()
Definition: OhmmsVector.h:255
void add(std::complex< T1 > &x)
Definition: PooledMemory.h:113
void get(std::complex< T1 > &x)
Definition: PooledMemory.h:132