QMCPACK
NonLocalECPComponent.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: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
11 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
12 //
13 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
14 //////////////////////////////////////////////////////////////////////////////////////
15 
16 
17 #ifndef QMCPLUSPLUS_NONLOCAL_ECPOTENTIAL_COMPONENT_H
18 #define QMCPLUSPLUS_NONLOCAL_ECPOTENTIAL_COMPONENT_H
21 #include <ResourceCollection.h>
22 #include <TrialWaveFunction.h>
27 #include "NLPPJob.h"
28 
29 namespace qmcplusplus
30 {
31 namespace testing
32 {
33 class TestNonLocalECPotential;
34 }
35 
36 /** Contains a set of radial grid potentials around a center.
37 */
39 {
40 private:
41  using SpherGridType = std::vector<PosType>;
44 
45  /** For fast derivative evaluation
46  */
49 
50  ///Non Local part: angular momentum, potential and grid
51  int lmax;
52  ///the number of non-local channels
53  int nchannel;
54  ///the number of nknot
55  int nknot;
56  ///Maximum cutoff the non-local pseudopotential
58  ///Angular momentum map
60  ///Weight of the angular momentum
62  /// Lfactor1[l]=(2*l+1)/(l+1)
64  /// Lfactor1[l]=(l)/(l+1)
66  ///Non-Local part of the pseudo-potential
67  std::vector<RadialPotentialType*> nlpp_m;
68  ///fixed Spherical Grid for species
70  ///randomized spherical grid
72  ///weight of the spherical grid
73  std::vector<RealType> sgridweight_m;
74  ///Working arrays
75  std::vector<ValueType> wvec;
76 
77  //Position delta for virtual moves.
78  std::vector<PosType> deltaV;
79  //Array for P_l[cos(theta)].
80  std::vector<RealType> lpol;
81  //Array for P'_l[cos(theta)]
82  std::vector<RealType> dlpol;
83  //Array for v_l(r).
84  std::vector<RealType> vrad;
85  //Array for (2l+1)*v'_l(r)/r.
86  std::vector<RealType> dvrad;
87  //$\Psi(...q...)/\Psi(...r...)$ for all quadrature points q.
88  std::vector<ValueType> psiratio;
89  //$\nabla \Psi(...q...)/\Psi(...r...)$ for all quadrature points q.
90  // $\nabla$ is w.r.t. the electron coordinates involved in the quadrature.
91  std::vector<PosType> gradpsiratio;
92  //This stores gradient of v(r):
93  std::vector<PosType> vgrad;
94  //This stores the gradient of the cos(theta) term in force expression.
95  std::vector<PosType> cosgrad;
96  //This stores grad psi/psi - dot(u,grad psi)
97  std::vector<PosType> wfngrad;
98  //This stores potential contribution per knot:
99  std::vector<RealType> knot_pots;
100 
101  /// scratch spaces used by evaluateValueAndDerivatives
104 
105  // For Pulay correction to the force
106  std::vector<RealType> WarpNorm;
109  /// First index is knot, second is electron
111  ///The gradient of the wave function w.r.t. the ion position
113 
114  ///virtual particle set: delayed initialization
116 
117  /// build QP position deltas from the reference electron using internally stored random grid points
118  void buildQuadraturePointDeltaPositions(RealType r, const PosType& dr, std::vector<PosType>& deltaV) const;
119 
120  /** finalize the calculation of $\frac{V\Psi_T}{\Psi_T}$
121  */
123 
124  /// Can disable grid randomization for testing
126 
127 public:
129 
130  /// Make a copy but have it associated with pset instead of nl_ecpc's pset
132 
134 
135  ///add a new Non Local component
136  void add(int l, RadialPotentialType* pp);
137 
138  ///add knots to the spherical grid
139  void addknot(const PosType& xyz, RealType weight)
140  {
141  sgridxyz_m.push_back(xyz);
142  sgridweight_m.push_back(weight);
143  }
144 
146 
147  void resize_warrays(int n, int m, int l);
148 
149  void rotateQuadratureGrid(const TensorType& rmat);
150  template<typename T>
151  void rotateQuadratureGrid(std::vector<T>& sphere, const TensorType& rmat);
152 
153  /** contribute local non-local move data
154  * @param iel reference electron id.
155  * @param Txy nonlocal move data.
156  */
157  void contributeTxy(int iel, std::vector<NonLocalData>& Txy) const;
158 
159  /** @brief Evaluate the nonlocal pp contribution via randomized quadrature grid
160  * to total energy from ion "iat" and electron "iel".
161  *
162  * @param W electron particle set.
163  * @param iat index of ion.
164  * @param Psi trial wave function object
165  * @param iel index of electron
166  * @param r the distance between ion iat and electron iel.
167  * @param dr displacement from ion iat to electron iel.
168  * @param use_DLA if ture, use determinant localization approximation (DLA).
169  *
170  * @return RealType Contribution to $\frac{V\Psi_T}{\Psi_T}$ from ion iat and electron iel.
171  */
173  int iat,
174  TrialWaveFunction& Psi,
175  int iel,
176  RealType r,
177  const PosType& dr,
178  bool use_DLA);
179 
180  /** @brief Evaluate the nonlocal pp contribution via randomized quadrature grid
181  * to total energy from ion "iat" and electron "iel" for a batch of walkers.
182  *
183  * @param ecp_component_list a list of ECP components
184  * @param p_list a list of electron particle set.
185  * @param psi_list a list of trial wave function object
186  * @param joblist a list of ion-electron pairs
187  * @param pairpots a list of contribution to $\frac{V\Psi_T}{\Psi_T}$ from ion iat and electron iel.
188  * @param use_DLA if ture, use determinant localization approximation (DLA).
189  *
190  * Note: ecp_component_list allows including different NLPP component for different walkers.
191  * electrons in iel_list must be of the same group (spin)
192  */
193  static void mw_evaluateOne(const RefVectorWithLeader<NonLocalECPComponent>& ecp_component_list,
194  const RefVectorWithLeader<ParticleSet>& p_list,
196  const RefVector<const NLPPJob<RealType>>& joblist,
197  std::vector<RealType>& pairpots,
198  ResourceCollection& collection,
199  bool use_DLA);
200 
201  /** @brief Evaluate the nonlocal pp contribution via randomized quadrature grid
202  * to total energy from ion "iat" and electron "iel".
203  *
204  * @param W electron particle set.
205  * @param iat index of ion.
206  * @param Psi trial wave function object
207  * @param iel index of electron
208  * @param r the distance between ion iat and electron iel.
209  * @param dr displacement from ion iat to electron iel.
210  * @param force_iat 3d vector for Hellman-Feynman contribution. This gets modified.
211  *
212  * @return RealType Contribution to $\frac{V\Psi_T}{\Psi_T}$ from ion iat and electron iel.
213  */
215  int iat,
216  TrialWaveFunction& Psi,
217  int iel,
218  RealType r,
219  const PosType& dr,
220  PosType& force_iat);
221 
222  /** @brief Evaluate the nonlocal pp energy, Hellman-Feynman force, and "Pulay" force contribution
223  * via randomized quadrature grid from ion "iat" and electron "iel".
224  *
225  * @param W electron particle set.
226  * @param ions ion particle set.
227  * @param iat index of ion.
228  * @param Psi trial wave function object
229  * @param iel index of electron
230  * @param r the distance between ion iat and electron iel.
231  * @param dr displacement from ion iat to electron iel.
232  * @param force_iat 3d vector for Hellman-Feynman contribution. This gets modified.
233  * @param pulay_terms Nion x 3 object, holding a contribution for each ionic gradient from \Psi_T.
234  *
235  * @return RealType Contribution to $\frac{V\Psi_T}{\Psi_T}$ from ion iat and electron iel.
236  */
238  ParticleSet& ions,
239  int iat,
240  TrialWaveFunction& Psi,
241  int iel,
242  RealType r,
243  const PosType& dr,
244  PosType& force_iat,
245  ParticleSet::ParticlePos& pulay_terms);
246 
247  // This function needs to be updated to SoA. myTableIndex is introduced temporarily.
249  int iat,
250  TrialWaveFunction& psi,
251  int iel,
252  RealType r,
253  const PosType& dr,
254  const opt_variables_type& optvars,
255  const Vector<ValueType>& dlogpsi,
256  Vector<ValueType>& dhpsioverpsi);
257 
258  /**
259  * @brief Evaluate contribution to B of election iel and ion iat. Filippi scheme for computing fast derivatives.
260  * Sum over ions and electrons occurs at the NonLocalECPotential level.
261 
262  * @param[in] P, target particle set (electrons)
263  * @param[in] iat, ion ID
264  * @param[in] psi, Trial Wavefunction wrapper for fast derivatives.
265  * @param[in] iel, electron ID
266  * @param[in] r, distance between iat and iel.
267  * @param[in] dr, displacement vector between iat and iel.
268  * @param[in,out] B. Adds the contribution of iel and iat to the B matrix. Dimensions: [group][particle][orb]
269  * @return Void
270  */
272  const int iat,
273  const TWFFastDerivWrapper& psi,
274  const int iel,
275  const RealType r,
276  const PosType& dr,
277  std::vector<ValueMatrix>& B);
278 
279  /**
280  * @brief Evaluate contribution to dB/dR of election iel and ion iat. Filippi scheme for computing fast derivatives.
281  * Sum over ions and electrons occurs at the NonLocalECPotential level.
282 
283  * @param[in] P, target particle set (electrons)
284  * @param[in] source, ion particle set
285  * @param[in] iat, ion ID
286  * @param[in] iat_src, this is the ion ID w.r.t. which the ion derivatives are taken. NOT ALWAYS EQUAL TO IAT
287  * @param[in] psi, Trial Wavefunction wrapper for fast derivatives.
288  * @param[in] iel, electron ID
289  * @param[in] r, distance between iat and iel.
290  * @param[in] dr, displacement vector between iat and iel.
291  * @param[in,out] dB. Adds the contribution of iel and iat to the dB/dR_iat_src matrix. Dimension [xyz_component][group][particle][orb]
292  * @return Void
293  */
295  ParticleSet& source,
296  const int iat,
297  const int iat_src,
298  const TWFFastDerivWrapper& psi,
299  const int iel,
300  const RealType r,
301  const PosType& dr,
302  std::vector<std::vector<ValueMatrix>>& dB);
303 
304  void print(std::ostream& os);
305 
306  void initVirtualParticle(const ParticleSet& qp);
307  void deleteVirtualParticle();
308 
309  inline void setRmax(int rmax) { Rmax = rmax; }
310  inline RealType getRmax() const { return Rmax; }
311  inline int getNknot() const { return nknot; }
312  inline void setLmax(int Lmax) { lmax = Lmax; }
313  inline int getLmax() const { return lmax; }
314  const VirtualParticleSet* getVP() const { return VP; };
315 
316  // copy sgridxyz_m to rrotsgrid_m without rotation. For testing only.
318 
319  friend struct ECPComponentBuilder;
320  // a lazy temporal solution
322 
323  // for testing
325 };
326 
327 
328 } // namespace qmcplusplus
329 #endif
void contributeTxy(int iel, std::vector< NonLocalData > &Txy) const
contribute local non-local move data
Contains a set of radial grid potentials around a center.
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
aligned_vector< RealType > wgt_angpp_m
Weight of the angular momentum.
void add(int l, RadialPotentialType *pp)
add a new Non Local component
std::vector< T, aligned_allocator< T > > aligned_vector
std::vector< RadialPotentialType * > nlpp_m
Non-Local part of the pseudo-potential.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
class to violate access control because evaluation of NonLocalECPotential uses RNG which we may not b...
int nchannel
the number of non-local channels
void evaluateOneBodyOpMatrixdRContribution(ParticleSet &P, ParticleSet &source, const int iat, const int iat_src, const TWFFastDerivWrapper &psi, const int iel, const RealType r, const PosType &dr, std::vector< std::vector< ValueMatrix >> &dB)
Evaluate contribution to dB/dR of election iel and ion iat.
A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet Virtu...
Matrix< PosType > Gnew
First index is knot, second is electron.
friend void copyGridUnrotatedForTest(NonLocalECPComponent &nlpp)
Definition: test_ecp.cpp:153
Declaration of OperatorBase.
bool do_randomize_grid_
Can disable grid randomization for testing.
OrbitalSetTraits< ValueType >::ValueMatrix ValueMatrix
Definition: SPOSet.h:50
RealType Rmax
Maximum cutoff the non-local pseudopotential.
Attaches a unit to a Vector for IO.
TWFFastDerivWrapper is a wrapper class for TrialWavefunction that provides separate and low level acc...
RealType Lfactor2[8]
Lfactor1[l]=(l)/(l+1)
ParticleSet::ParticleGradient Gion
The gradient of the wave function w.r.t. the ion position.
An abstract base class to implement a One-Dimensional grid.
OrbitalSetTraits< ValueType >::GradMatrix GradMatrix
Definition: SPOSet.h:52
void evaluateOneBodyOpMatrixContribution(ParticleSet &P, const int iat, const TWFFastDerivWrapper &psi, const int iel, const RealType r, const PosType &dr, std::vector< ValueMatrix > &B)
Evaluate contribution to B of election iel and ion iat.
std::vector< ValueType > wvec
Working arrays.
SPOSet::ValueMatrix ValueMatrix
For fast derivative evaluation.
Decalaration of One-Dimesional grids.
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
void addknot(const PosType &xyz, RealType weight)
add knots to the spherical grid
ParticleSet::ParticleLaplacian dL
static void mw_evaluateOne(const RefVectorWithLeader< NonLocalECPComponent > &ecp_component_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVectorWithLeader< TrialWaveFunction > &psi_list, const RefVector< const NLPPJob< RealType >> &joblist, std::vector< RealType > &pairpots, ResourceCollection &collection, bool use_DLA)
Evaluate the nonlocal pp contribution via randomized quadrature grid to total energy from ion "iat" a...
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
RealType evaluateOne(ParticleSet &W, int iat, TrialWaveFunction &Psi, int iel, RealType r, const PosType &dr, bool use_DLA)
Evaluate the nonlocal pp contribution via randomized quadrature grid to total energy from ion "iat" a...
Declaration of a TrialWaveFunction.
std::vector< std::reference_wrapper< T > > RefVector
const VirtualParticleSet * getVP() const
int lmax
Non Local part: angular momentum, potential and grid.
Class to represent a many-body trial wave function.
void set_randomize_grid(bool do_randomize_grid_)
ParticleSet::ParticleGradient dG
RealType evaluateOneWithForces(ParticleSet &W, int iat, TrialWaveFunction &Psi, int iel, RealType r, const PosType &dr, PosType &force_iat)
Evaluate the nonlocal pp contribution via randomized quadrature grid to total energy from ion "iat" a...
ParticleAttrib< QTFull::GradType > ParticleGradient
Definition: Configuration.h:95
meta data for NLPP calculation of a pair of ion and electron This is not just meta data...
void initVirtualParticle(const ParticleSet &qp)
double B(double x, int k, int i, const std::vector< double > &t)
traits for QMC variables
Definition: Configuration.h:49
void buildQuadraturePointDeltaPositions(RealType r, const PosType &dr, std::vector< PosType > &deltaV) const
build QP position deltas from the reference electron using internally stored random grid points ...
void resize_warrays(int n, int m, int l)
QTBase::TensorType TensorType
Definition: Configuration.h:63
RealType calculateProjector(RealType r, const PosType &dr)
finalize the calculation of ${V}{}$
std::vector< RealType > sgridweight_m
weight of the spherical grid
aligned_vector< int > angpp_m
Angular momentum map.
SpherGridType sgridxyz_m
fixed Spherical Grid for species
void rotateQuadratureGrid(const TensorType &rmat)
Randomly rotate sgrid_m.