QMCPACK
CoulombPBCAB.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) 2022 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 // Peter W. Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
13 //
14 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
15 //////////////////////////////////////////////////////////////////////////////////////
16 
17 
18 #ifndef QMCPLUSPLUS_COULOMBPBCAB_H
19 #define QMCPLUSPLUS_COULOMBPBCAB_H
20 #include <ResourceHandle.h>
28 #include "Particle/DistanceTable.h"
29 
30 namespace qmcplusplus
31 {
32 /** @ingroup hamiltonian
33  *\brief Calculates the AA Coulomb potential using PBCs
34  *
35  * Functionally identical to CoulombPBCAB but uses a templated version of
36  * LRHandler.
37  */
38 class CoulombPBCAB : public OperatorBase, public ForceBase
39 {
40 public:
45 
46  ///long-range Handler. Should be const LRHandlerType eventually
47  std::shared_ptr<LRHandlerType> AB;
48  ///long-range derivative handler
49  std::shared_ptr<const LRHandlerType> dAB;
50  ///locator of the distance table
51  const int myTableIndex;
52  ///number of species of A particle set
54  ///number of species of B particle set
56  ///number of particles of A
57  int NptclA;
58  ///number of particles of B
59  int NptclB;
60  ///const energy after breakup
62  ///cutoff radius of the short-range part
64  ///Always mave a radial functor for the bare coulomb
65  std::shared_ptr<const RadFunctorType> V0;
66  ///Radial functor for bare coulomb, optimized for forces
67  std::shared_ptr<const RadFunctorType> fV0;
68  ///Radial functor for derivative of bare coulomb, optimized for forces
69  std::shared_ptr<const RadFunctorType> dfV0;
70  /// Flag for whether to compute forces or not
72 
73  ///number of particles per species of A
74  std::vector<int> NofSpeciesA;
75  ///number of particles per species of B
76  std::vector<int> NofSpeciesB;
77  ///Zat[iat] charge for the iat-th particle of A
78  std::vector<RealType> Zat;
79  ///Qat[iat] charge for the iat-th particle of B
80  std::vector<RealType> Qat;
81  ///Zspec[spec] charge for the spec-th species of A
82  std::vector<RealType> Zspec;
83  ///Qspec[spec] charge for the spec-th species of B
84  std::vector<RealType> Qspec;
85  ///Short-range potential for each ion
86  std::vector<const RadFunctorType*> Vat;
87  ///Short-range potential for each species
88  std::vector<std::shared_ptr<RadFunctorType>> Vspec;
89  ///Short-range potential (r*V) and potential derivative d/dr(rV) derivative for each ion
90  ///Required for force evaluations.
91  std::vector<const RadFunctorType*> fVat;
92  std::vector<const RadFunctorType*> fdVat;
93  ////Short-range potential (r*V) and potential derivative d/dr(rV) derivative for each species
94  std::vector<std::shared_ptr<const RadFunctorType>> fVspec;
95  std::vector<std::shared_ptr<const RadFunctorType>> fdVspec;
96  /*@{
97  * @brief temporary data for pbyp evaluation
98  */
99  ///short-range part for the moved particle
101  ///long-range part for the moved particle
103  ///short-range per particle
105  ///long-range per particle
107  /*@}*/
108 
109  //This is set to true if the K_c of structure-factors are different
112 
113 #if !defined(REMOVE_TRACEMANAGER)
114  //particle trace samples
119 #endif
120  // \todo Coulomb class is walker agnositic, it should not record a particular electron particle set.
121  // kept for the trace manager. Delete this particle set reference when support for TraceManager is permanently
122  // removed which should coincide with the removal of the legacy drivers.
124 
125  CoulombPBCAB(ParticleSet& ions, ParticleSet& elns, bool computeForces = false);
126 
127  ///// copy constructor
128  //CoulombPBCAB(const CoulombPBCAB& c);
129 
130  ~CoulombPBCAB() override;
131 
132  void resetTargetParticleSet(ParticleSet& P) override;
133 
134  std::string getClassName() const override { return "CoulombPBCAB"; }
135 
136 #if !defined(REMOVE_TRACEMANAGER)
137  void contributeParticleQuantities() override;
138  void checkoutParticleQuantities(TraceManager& tm) override;
139  Return_t evaluate_sp(ParticleSet& P); //collect
140  void deleteParticleQuantities() override;
141 #endif
142 
143 
144  Return_t evaluate(ParticleSet& P) override;
145 
146  /** Evaluate the contribution of this component of multiple walkers per particle reporting
147  * to registered listeners from Estimators.
148  */
151  const RefVectorWithLeader<ParticleSet>& p_list,
152  const std::vector<ListenerVector<RealType>>& listeners,
153  const std::vector<ListenerVector<RealType>>& ion_listeners) const override;
154 
155 
157  ParticleSet& ions,
158  TrialWaveFunction& psi,
159  ParticleSet::ParticlePos& hf_terms,
160  ParticleSet::ParticlePos& pulay_terms) override;
161 
162  /** Do nothing */
163  bool put(xmlNodePtr cur) override { return true; }
164 
165  bool get(std::ostream& os) const override
166  {
167  os << "CoulombPBCAB potential source: " << pset_ions_.getName();
168  return true;
169  }
170 
171  std::unique_ptr<OperatorBase> makeClone(ParticleSet& qp, TrialWaveFunction& psi) override;
172 
173  ///Computes the short-range contribution to the coulomb energy.
175  ///Computes the long-range contribution to the coulomb energy.
177  ///Computes the short-range contribution to the coulomb energy and forces.
179  ///Computes the long-range contribution to the coulomb energy and forces.
181  ///Evaluates madelung and background contributions to total energy.
182  Return_t evalConsts(const ParticleSet& P, bool report = true);
183  ///Adds a local pseudopotential channel "ppot" to all source species of type "groupID".
184  void add(int groupID, std::unique_ptr<RadFunctorType>&& ppot);
185 
186  void addObservables(PropertySetType& plist, BufferType& collectables) override;
187 
188  void setObservables(PropertySetType& plist) override
189  {
191  if (ComputeForces)
192  setObservablesF(plist);
193  }
194 
195  void setParticlePropertyList(PropertySetType& plist, int offset) override
196  {
198  if (ComputeForces)
199  setParticleSetF(plist, offset);
200  }
201 
202  const ParticleSet& getSourcePSet() const { return pset_ions_; }
203 
204  /** initialize a shared resource and hand it to a collection
205  */
206  void createResource(ResourceCollection& collection) const override;
207 
208  /** acquire a shared resource from a collection
209  */
210  void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<OperatorBase>& o_list) const override;
211 
212  /** return a shared resource to a collection
213  */
214  void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<OperatorBase>& o_list) const override;
215 
216  /** Call to inform objects associated with this operator of per particle listeners.
217  * should be called before createResources
218  */
219  void informOfPerParticleListener() override;
220 
221 protected:
222  /** Creates the long-range handlers, then splines and stores it by particle and species for quick evaluation.
223  * this is just constructor code factored out.
224  * It is called by the derived class CoulombPBCAB_CUDA
225  */
226  void initBreakup(ParticleSet& P);
227 
228 private:
229  ///source particle set
231 
234 
235  /** Compute the const part of the per particle coulomb AB potential.
236  * \param[out] pp_consts_src constant values for the source particles aka ions aka A
237  * \param[out] pp_consts_trg constant values for the target particles aka electrons aka B
238  */
239  void evalPerParticleConsts(Vector<RealType>& pp_consts_src, Vector<RealType>& pp_consts_trg) const;
240 };
241 
242 } // namespace qmcplusplus
243 #endif
Array< TraceReal, 1 > * Vi_sample
Definition: CoulombPBCAB.h:116
std::vector< const RadFunctorType * > fdVat
Definition: CoulombPBCAB.h:92
int NumSpeciesB
number of species of B particle set
Definition: CoulombPBCAB.h:55
void resetTargetParticleSet(ParticleSet &P) override
Reset the data with the target ParticleSet.
std::shared_ptr< const RadFunctorType > fV0
Radial functor for bare coulomb, optimized for forces.
Definition: CoulombPBCAB.h:67
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
const std::string & getName() const
return the name
Return_t evaluateWithIonDerivs(ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_terms, ParticleSet::ParticlePos &pulay_terms) override
Evaluate contribution to local energy and derivatives w.r.t ionic coordinates from OperatorBase...
One-Dimensional linear-grid.
Return_t myConst
const energy after breakup
Definition: CoulombPBCAB.h:61
std::vector< const RadFunctorType * > Vat
Short-range potential for each ion.
Definition: CoulombPBCAB.h:86
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Calculates the AA Coulomb potential using PBCs.
Definition: CoulombPBCAB.h:38
Array< TraceReal, 1 > Vi_const
Definition: CoulombPBCAB.h:118
std::shared_ptr< LRHandlerType > AB
long-range Handler. Should be const LRHandlerType eventually
Definition: CoulombPBCAB.h:47
void setObservables(PropertySetType &plist) override
Set the values evaluated by this object to plist Default implementation is to assign Value which is u...
Definition: CoulombPBCAB.h:188
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const override
acquire a shared resource from a collection
ResourceHandle manages the temporary resource referenced from a collection.
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const override
return a shared resource to a collection
EwaldHandler3D::mRealType mRealType
Soa Container for D-dim vectors.
std::vector< std::shared_ptr< RadFunctorType > > Vspec
Short-range potential for each species.
Definition: CoulombPBCAB.h:88
Declaration of OperatorBase.
std::string getClassName() const override
return class name
Definition: CoulombPBCAB.h:134
An object of this type is a listener expecting a callback to the report function with a vector of val...
Definition: Listener.hpp:38
std::vector< std::shared_ptr< const RadFunctorType > > fVspec
Definition: CoulombPBCAB.h:94
Vectorized record engine for scalar properties.
LRHandlerType::mRealType mRealType
Definition: CoulombPBCAB.h:44
Vector< RealType > LRpart
long-range per particle
Definition: CoulombPBCAB.h:106
bool ComputeForces
Flag for whether to compute forces or not.
Definition: CoulombPBCAB.h:71
Attaches a unit to a Vector for IO.
const int myTableIndex
locator of the distance table
Definition: CoulombPBCAB.h:51
std::shared_ptr< const RadFunctorType > V0
Always mave a radial functor for the bare coulomb.
Definition: CoulombPBCAB.h:65
std::shared_ptr< const RadFunctorType > dfV0
Radial functor for derivative of bare coulomb, optimized for forces.
Definition: CoulombPBCAB.h:69
Decalaration of One-Dimesional grids.
std::vector< std::shared_ptr< const RadFunctorType > > fdVspec
Definition: CoulombPBCAB.h:95
Array< TraceReal, 1 > * Ve_sample
Definition: CoulombPBCAB.h:115
RealType LRtmp
long-range part for the moved particle
Definition: CoulombPBCAB.h:102
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
ParticleSet::Buffer_t BufferType
typedef for the serialized buffer
Definition: OperatorBase.h:75
int NptclB
number of particles of B
Definition: CoulombPBCAB.h:59
RealType myRcut
cutoff radius of the short-range part
Definition: CoulombPBCAB.h:63
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to a collection
Return_t evaluate_sp(ParticleSet &P)
void initBreakup(ParticleSet &P)
Creates the long-range handlers, then splines and stores it by particle and species for quick evaluat...
int NptclA
number of particles of A
Definition: CoulombPBCAB.h:57
OneDimCubicSpline< pRealType > RadFunctorType
Array< TraceReal, 1 > Ve_const
Definition: CoulombPBCAB.h:117
void checkoutParticleQuantities(TraceManager &tm) override
void setParticleSetF(QMCTraits::PropertySetType &plist, int offset)
Definition: ForceBase.cpp:113
int NumSpeciesA
number of species of A particle set
Definition: CoulombPBCAB.h:53
std::vector< RealType > Qspec
Qspec[spec] charge for the spec-th species of B.
Definition: CoulombPBCAB.h:84
ParticleSet & pset_ions_
source particle set
Definition: CoulombPBCAB.h:230
void add(int groupID, std::unique_ptr< RadFunctorType > &&ppot)
Adds a local pseudopotential channel "ppot" to all source species of type "groupID".
Vector< RealType > SRpart
short-range per particle
Definition: CoulombPBCAB.h:104
std::vector< int > NofSpeciesA
number of particles per species of A
Definition: CoulombPBCAB.h:74
void evalPerParticleConsts(Vector< RealType > &pp_consts_src, Vector< RealType > &pp_consts_trg) const
Compute the const part of the per particle coulomb AB potential.
CoulombPBCAB(ParticleSet &ions, ParticleSet &elns, bool computeForces=false)
An abstract class for Local Energy operators.
Definition: OperatorBase.h:59
FullPrecRealType Return_t
type of return value of evaluate
Definition: OperatorBase.h:64
std::vector< const RadFunctorType * > fVat
Short-range potential (r*V) and potential derivative d/dr(rV) derivative for each ion Required for fo...
Definition: CoulombPBCAB.h:91
ResourceHandle< CoulombPBCABMultiWalkerResource > mw_res_handle_
Definition: CoulombPBCAB.h:232
virtual void setParticlePropertyList(PropertySetType &plist, int offset)
void setObservablesF(QMCTraits::PropertySetType &plist)
Definition: ForceBase.cpp:86
Return_t evalLRwithForces(ParticleSet &P)
Computes the long-range contribution to the coulomb energy and forces.
Class to represent a many-body trial wave function.
void addObservables(PropertySetType &plist, BufferType &collectables) override
named values to the property list Default implementaton uses addValue(plist_)
std::vector< RealType > Qat
Qat[iat] charge for the iat-th particle of B.
Definition: CoulombPBCAB.h:80
std::vector< RealType > Zspec
Zspec[spec] charge for the spec-th species of A.
Definition: CoulombPBCAB.h:82
std::vector< RealType > Zat
Zat[iat] charge for the iat-th particle of A.
Definition: CoulombPBCAB.h:78
std::shared_ptr< const LRHandlerType > dAB
long-range derivative handler
Definition: CoulombPBCAB.h:49
Define a LRHandler with two template parameters.
base class for LRHandlerTemp<FUNC,BASIS> and DummyLRHanlder<typename Func>
Definition: LRHandlerBase.h:30
virtual void setObservables(PropertySetType &plist)
Set the values evaluated by this object to plist Default implementation is to assign Value which is u...
const ParticleSet & getSourcePSet() const
Definition: CoulombPBCAB.h:202
void mw_evaluatePerParticle(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< RealType >> &listeners, const std::vector< ListenerVector< RealType >> &ion_listeners) const override
Evaluate the contribution of this component of multiple walkers per particle reporting to registered ...
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) override
void contributeParticleQuantities() override
RealType SRtmp
short-range part for the moved particle
Definition: CoulombPBCAB.h:100
LinearGrid< pRealType > GridType
void informOfPerParticleListener() override
Call to inform objects associated with this operator of per particle listeners.
Return_t evalLR(ParticleSet &P)
Computes the long-range contribution to the coulomb energy.
std::vector< int > NofSpeciesB
number of particles per species of B
Definition: CoulombPBCAB.h:76
void setParticlePropertyList(PropertySetType &plist, int offset) override
Definition: CoulombPBCAB.h:195
Return_t evalSR(ParticleSet &P)
Computes the short-range contribution to the coulomb energy.
BareKineticEnergy::Return_t Return_t
Return_t evalSRwithForces(ParticleSet &P)
Computes the short-range contribution to the coulomb energy and forces.
void deleteParticleQuantities() override
Return_t evalConsts(const ParticleSet &P, bool report=true)
Evaluates madelung and background contributions to total energy.
RecordNamedProperty< FullPrecRealType > PropertySetType
define PropertyList_t
Definition: Configuration.h:69
bool put(xmlNodePtr cur) override
Do nothing.
Definition: CoulombPBCAB.h:163