QMCPACK
SpaceWarpTransformation.cpp
Go to the documentation of this file.
4 namespace qmcplusplus
5 {
7  : myTableIndex(elns.addTable(ions)), Nelec(elns.getTotalNum()), Nions(ions.getTotalNum()), swpow(4.0)
8 {
10  gradval.resize(Nelec, Nions);
11 }
12 
14 
16 //Space warp functions have the form w_I(r_i) = F(|r_i-R_I)/Sum_J F(|r_i-R_J|). Hence the intermediate we will
17 //precompute is the matrix "warpval[i][J] = F(|r_i-R_J|) and gradval[i][J]=Grad(F(|r_i-R_J|)).
18 //This allows the calculation of any space warp value or gradient by a matrix lookup, combined with a sum over columns.
20 {
21  const auto& d_ab(P.getDistTableAB(myTableIndex));
22  for (size_t iel = 0; iel < Nelec; ++iel)
23  {
24  const auto& dist = d_ab.getDistRow(iel);
25  const auto& dr = d_ab.getDisplRow(iel);
26  for (size_t ionid = 0; ionid < Nions; ++ionid)
27  {
28  warpval[iel][ionid] = f(dist[ionid]);
29  gradval[iel][ionid] = -dr[ionid] *
30  (df(dist[ionid]) / dist[ionid]); //because there's a -1 in distance table displacement definition. R-r :(.
31  }
32  }
33 }
34 
35 //This function handles parsing of the intermediate matrices and construction of the w_I(r_i) and Grad_i(w_I(r_i)) functions
36 // that appear in the space warp transformation formulas.
38 {
39  for (size_t iel = 0; iel < Nelec; iel++)
40  {
41  RealType warpdenom = 0.0;
42  PosType denomgrad = 0.0;
43  for (size_t ionid = 0; ionid < Nions; ionid++)
44  {
45  warpdenom += warpval[iel][ionid];
46  denomgrad += gradval[iel][ionid];
47  }
48  w[iel] = warpval[iel][iat] / warpdenom;
49  grad_w[iel] = gradval[iel][iat] / warpdenom - w[iel] * denomgrad / warpdenom;
50  }
51 }
52 //This function returns Sum_i w_I(r_i) Grad_i(E_L) (as el_contribution) and Sum_i[ w_I(r_i)Grad_i(logpsi)+0.5*Grad_i(w_I(r_i)) (as psi_contribution). See Eq (15) and (16) respectively.
54  const ParticleSet& ions,
55  Force_t& dEl,
56  ParticleGradient& dlogpsi,
57  Force_t& el_contribution,
58  Force_t& psi_contribution)
59 {
60  el_contribution = 0;
61  psi_contribution = 0;
63  Force_t gradw;
64  w.resize(Nelec);
65  gradw.resize(Nelec);
66 
67  PosType gwfn = 0;
68  computeSWTIntermediates(P, ions);
69 
70  for (size_t iat = 0; iat < Nions; iat++)
71  {
72  w = 0;
73  gradw = 0;
74  getSWT(iat, w, gradw);
75  for (size_t iel = 0; iel < Nelec; iel++)
76  {
77  el_contribution[iat] += w[iel] * dEl[iel];
78 
79 #if defined(QMC_COMPLEX)
80  convertToReal(dlogpsi[iel], gwfn);
81 #else
82  gwfn = dlogpsi[iel];
83 #endif
84  psi_contribution[iat] += w[iel] * gwfn + 0.5 * gradw[iel];
85  }
86  }
87  //REMOVE ME
88  //app_log()<<"FINAL SPACE WARP TRANSFORM\n";
89  //app_log()<<" Using dEl="<<dEl<<std::endl;
90  //app_log()<<" Using dlogpsi="<<dlogpsi<<std::endl;
91 
92  //app_log()<<"Space warp EL piece\n";
93  //app_log()<<" EL = "<<el_contribution<<std::endl;
94  //app_log()<<"Space warp logpsi piece\n";
95  //app_log()<<" psipiece = "<<psi_contribution<<std::endl;
96 }
97 
98 } // 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
Matrix< PosType > gradval
Nelec x Nion matrix of F(|r_i-R_J|)
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
RealType df(RealType r)
Derivative of space warp transformation function F(r) w.r.t.
RealType swpow
Power of space warp transformation. Right now, r^{-swpow}.
void convertToReal(const T1 &in, T2 &out)
generic conversion from type T1 to type T2 using implicit conversion
Definition: ConvertToReal.h:32
Matrix< RealType > warpval
Nelec x Nion matrix of F(|r_i-R_J|)
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
Attaches a unit to a Vector for IO.
const int myTableIndex
The electron-ion table index in electron table.
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
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)
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
RealType f(RealType r)
Space warp transformation function F(r).
void computeSWT(ParticleSet &elec, const ParticleSet &ions, Force_t &dEl, ParticleGradient &dlogpsi, Force_t &el_contribution, Force_t &psi_contribution)
Takes in precomputed grad(E_L) and grad(logPsi) and computes the ZV and ZB space warp contributions t...
void computeSWTIntermediates(ParticleSet &P, const ParticleSet &ions)
Computes intermediate matrices required to build all space warp components and gradients.
void getSWT(int iat, ParticleScalar &w, Force_t &grad_w)
Generates required space warp quantities to generate the actual "Space Warp" contribution to the iat-...
SpaceWarpTransformation(ParticleSet &elns, const ParticleSet &ions)