QMCPACK
VirtualParticleSet.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) 2021 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 //
10 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 /** @file VirtualParticleSet.h
15  * A proxy class to the quantum ParticleSet
16  */
17 #ifndef QMCPLUSPLUS_VIRTUAL_PARTICLESET_H
18 #define QMCPLUSPLUS_VIRTUAL_PARTICLESET_H
19 
20 #include "Configuration.h"
21 #include "Particle/ParticleSet.h"
22 #include <ResourceHandle.h>
24 
25 namespace qmcplusplus
26 {
27 // forward declaration.
28 class NonLocalECPComponent;
29 template<typename T>
30 struct NLPPJob;
31 struct VPMultiWalkerMem;
32 
33 /** A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet
34  * Virtual moves are defined as moves being proposed but will never be accepted.
35  * VirtualParticleSet is introduced to avoid changing any internal states of the physical ParticleSet.
36  * For this reason, the physical ParticleSet is always marked const.
37  * It is heavily used by non-local PP evaluations.
38  */
40 {
41 private:
42  /// true, if virtual particles are on a sphere for NLPP
43  bool onSphere;
44  /// multi walker resource
46 
48 
49  /// ParticleSet this object refers to after makeMoves
50  std::optional<std::reference_wrapper<const ParticleSet>> refPS;
51 
52 public:
53  /// Reference particle
54  int refPtcl;
55  /// Reference source particle, used when onSphere=true
57 
58  /// ParticleSet this object refers to
59  const ParticleSet& getRefPS() const { return refPS.value(); }
60 
61  inline bool isOnSphere() const { return onSphere; }
62 
64 
65  /** constructor
66  * @param p ParticleSet whose virtual moves are handled by this object
67  * @param nptcl number of virtual particles
68  * @param dt_count_limit distance tables corresepond to [0, dt_count_limit) of the reference particle set are created
69  */
70  VirtualParticleSet(const ParticleSet& p, int nptcl, size_t dt_count_limit = 0);
71 
73 
74  /// initialize a shared resource and hand it to a collection
75  void createResource(ResourceCollection& collection) const;
76  /** acquire external resource and assocaite it with the list of ParticleSet
77  * Note: use RAII ResourceCollectionTeamLock whenever possible
78  */
79  static void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<VirtualParticleSet>& vp_list);
80  /** release external resource
81  * Note: use RAII ResourceCollectionTeamLock whenever possible
82  */
83  static void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<VirtualParticleSet>& vp_list);
84 
85  /** move virtual particles to new postions and update distance tables
86  * @param refp reference particle set
87  * @param jel reference particle that all the VP moves from
88  * @param deltaV Position delta for virtual moves.
89  * @param sphere set true if VP are on a sphere around the reference source particle
90  * @param iat reference source particle
91  */
92  void makeMoves(const ParticleSet& refp,
93  int jel,
94  const std::vector<PosType>& deltaV,
95  bool sphere = false,
96  int iat = -1);
97 
98  inline size_t getTotalNum() const { return TotalNum; }
99  /**Extract list of Distance Tables
100  */
103  int id);
104  /**Extract list of VP coordinates, flattened over all walkers
105  */
106  static const std::vector<QMCTraits::PosType> extractVPCoords(
108  /** move virtual particles to new postions and update distance tables
109  * @param refp reference particle set
110  * @param jel reference particle that all the VP moves from
111  * @param deltaV Position delta for virtual moves.
112  * @param deltaS Spin delta for virtual moves.
113  * @param sphere set true if VP are on a sphere around the reference source particle
114  * @param iat reference source particle
115  */
116  void makeMovesWithSpin(const ParticleSet& refp,
117  int jel,
118  const std::vector<PosType>& deltaV,
119  const std::vector<RealType>& deltaS,
120  bool sphere = false,
121  int iat = -1);
122 
123  static void mw_makeMoves(const RefVectorWithLeader<VirtualParticleSet>& vp_list,
124  const RefVectorWithLeader<ParticleSet>& p_list,
125  const RefVector<const std::vector<PosType>>& deltaV_list,
126  const RefVector<const NLPPJob<RealType>>& joblist,
127  bool sphere);
128 
130  const RefVectorWithLeader<ParticleSet>& p_list,
131  const RefVector<const std::vector<PosType>>& deltaV_list,
132  const RefVector<const std::vector<RealType>>& deltaS_list,
133  const RefVector<const NLPPJob<RealType>>& joblist,
134  bool sphere);
135 
138  {
139  RefVectorWithLeader<ParticleSet> ref_list(vp_list.getLeader());
140  ref_list.reserve(ref_list.size());
141  for (VirtualParticleSet& vp : vp_list)
142  ref_list.push_back(vp);
143  return ref_list;
144  }
145 
147  {
148  size_t nVPs = 0;
149  for (const VirtualParticleSet& vp : vp_list)
150  nVPs += vp.getTotalNum();
151  return nVPs;
152  }
153 
154  static size_t countVPs(const RefVectorWithLeader<VirtualParticleSet>& vp_list)
155  {
156  size_t nVPs = 0;
157  for (const VirtualParticleSet& vp : vp_list)
158  nVPs += vp.getTotalNum();
159  return nVPs;
160  }
161 };
162 } // namespace qmcplusplus
163 #endif
std::optional< std::reference_wrapper< const ParticleSet > > refPS
ParticleSet this object refers to after makeMoves.
const ParticleSet & getRefPS() const
ParticleSet this object refers to.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void createResource(ResourceCollection &collection) const
initialize a shared resource and hand it to a collection
size_t TotalNum
total number of particles
Definition: ParticleSet.h:642
static void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< VirtualParticleSet > &vp_list)
release external resource Note: use RAII ResourceCollectionTeamLock whenever possible ...
ResourceHandle manages the temporary resource referenced from a collection.
void makeMovesWithSpin(const ParticleSet &refp, int jel, const std::vector< PosType > &deltaV, const std::vector< RealType > &deltaS, bool sphere=false, int iat=-1)
move virtual particles to new postions and update distance tables
int refSourcePtcl
Reference source particle, used when onSphere=true.
A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet Virtu...
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
int refPtcl
Reference particle.
static void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< VirtualParticleSet > &vp_list)
acquire external resource and assocaite it with the list of ParticleSet Note: use RAII ResourceCollec...
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
Vector< int, OffloadPinnedAllocator< int > > & getMultiWalkerRefPctls()
static const std::vector< QMCTraits::PosType > extractVPCoords(const RefVectorWithLeader< const VirtualParticleSet > &vp_list)
Extract list of VP coordinates, flattened over all walkers.
static void mw_makeMoves(const RefVectorWithLeader< VirtualParticleSet > &vp_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVector< const std::vector< PosType >> &deltaV_list, const RefVector< const NLPPJob< RealType >> &joblist, bool sphere)
VirtualParticleSet(const ParticleSet &p, int nptcl, size_t dt_count_limit=0)
constructor
static size_t countVPs(const RefVectorWithLeader< VirtualParticleSet > &vp_list)
static void mw_makeMovesWithSpin(const RefVectorWithLeader< VirtualParticleSet > &vp_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVector< const std::vector< PosType >> &deltaV_list, const RefVector< const std::vector< RealType >> &deltaS_list, const RefVector< const NLPPJob< RealType >> &joblist, bool sphere)
std::vector< std::reference_wrapper< T > > RefVector
static RefVectorWithLeader< ParticleSet > RefVectorWithLeaderParticleSet(const RefVectorWithLeader< VirtualParticleSet > &vp_list)
meta data for NLPP calculation of a pair of ion and electron This is not just meta data...
static size_t countVPs(const RefVectorWithLeader< const VirtualParticleSet > &vp_list)
bool onSphere
true, if virtual particles are on a sphere for NLPP
ResourceHandle< VPMultiWalkerMem > mw_mem_handle_
multi walker resource
static const RefVectorWithLeader< const DistanceTableAB > extractDTRefList(const RefVectorWithLeader< const VirtualParticleSet > &vp_list, int id)
Extract list of Distance Tables.