QMCPACK
CoulombPBCAA.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_COULOMBPBCAA_H
19 #define QMCPLUSPLUS_COULOMBPBCAA_H
20 #include <ResourceHandle.h>
24 #include "Particle/DistanceTable.h"
25 
26 namespace qmcplusplus
27 {
28 
29 template<class T>
30 class OneDimCubicSplineLinearGrid;
31 
32 /** @ingroup hamiltonian
33  *\brief Calculates the AA Coulomb potential using PBCs
34  *
35  * Functionally identical to CoulombPBCAA but uses a templated version of
36  * LRHandler.
37  */
38 struct CoulombPBCAA : public OperatorBase, public ForceBase
39 {
45 
46  /// energy-optimized long range handle. Should be const LRHandlerType eventually
47  std::shared_ptr<LRHandlerType> AA;
48  /// energy-optimized short range pair potential
49  std::shared_ptr<const RadFunctorType> rVs;
50  /// the same as rVs but can be used inside OpenMP offload regions
51  std::shared_ptr<const OffloadSpline> rVs_offload;
52  /// force-optimized long range handle
53  std::shared_ptr<const LRHandlerType> dAA;
54  /// force-optimized short range pair potential
55  std::shared_ptr<const RadFunctorType> rVsforce;
56 
57  bool is_active;
58  bool FirstTime;
59  int SourceID;
65  ///cutoff radius of the short-range part
67  std::string PtclRefName;
68 
69  std::vector<RealType> Zat, Zspec;
70  std::shared_ptr<Vector<RealType, OffloadPinnedAllocator<RealType>>> Zat_offload;
71 
72  std::vector<int> NofSpecies;
73  std::vector<int> SpeciesID;
74 
78  /// Flag for whether to compute forces or not
80  /// Flag for whether to use quasi-2D Ewald
81  const bool quasi2d;
82 
83 #if !defined(REMOVE_TRACEMANAGER)
84  //single particle trace sample
87 #endif
89 
90 
91  /** constructor */
92  CoulombPBCAA(ParticleSet& ref, bool active, bool computeForces, bool use_offload);
93 
94  ~CoulombPBCAA() override;
95 
96  std::string getClassName() const override { return "CoulombPBCAA"; }
97 
98  void resetTargetParticleSet(ParticleSet& P) override;
99 
100  Return_t evaluate(ParticleSet& P) override;
101 
104  const RefVectorWithLeader<ParticleSet>& p_list) const override;
105 
106  /**
107  * Evaluate the contribution of this component of multiple walkers per particle reporting
108  * to registered listeners from Estimators.
109  */
112  const RefVectorWithLeader<ParticleSet>& p_list,
113  const std::vector<ListenerVector<RealType>>& listeners,
114  const std::vector<ListenerVector<RealType>>& ion_listeners) const override;
115 
116 
118  ParticleSet& ions,
119  TrialWaveFunction& psi,
120  ParticleSet::ParticlePos& hf_terms,
121  ParticleSet::ParticlePos& pulay_terms) override;
122  void updateSource(ParticleSet& s) override;
123 
124  /** Do nothing */
125  bool put(xmlNodePtr cur) override { return true; }
126 
127  bool get(std::ostream& os) const override
128  {
129  os << "CoulombPBCAA potential: " << PtclRefName;
130  return true;
131  }
132 
133  std::unique_ptr<OperatorBase> makeClone(ParticleSet& qp, TrialWaveFunction& psi) override;
134 
135  /** Inform objects associated with this operator of per particle listeners.
136  * i.e. turnOnPerParticleSK of particleset qp.
137  */
138  void informOfPerParticleListener() override;
139 
140 #if !defined(REMOVE_TRACEMANAGER)
141  void contributeParticleQuantities() override;
142  void checkoutParticleQuantities(TraceManager& tm) override;
143  Return_t evaluate_sp(ParticleSet& P); //collect
144  void deleteParticleQuantities() override;
145 #endif
146 
148 
149  static std::vector<Return_t> mw_evalSR_offload(const RefVectorWithLeader<OperatorBase>& o_list,
150  const RefVectorWithLeader<ParticleSet>& p_list);
151 
155  Return_t evalConsts(bool report = true);
156 
157  void addObservables(PropertySetType& plist, BufferType& collectables) override;
158 
159  void setObservables(PropertySetType& plist) override
160  {
162  if (ComputeForces)
163  setObservablesF(plist);
164  }
165 
166  void setParticlePropertyList(PropertySetType& plist, int offset) override
167  {
169  if (ComputeForces)
170  setParticleSetF(plist, offset);
171  }
172 
173  /** initialize a shared resource and hand it to a collection
174  */
175  void createResource(ResourceCollection& collection) const override;
176 
177  /** acquire a shared resource from a collection
178  */
179  void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<OperatorBase>& o_list) const override;
180 
181  /** return a shared resource to a collection
182  */
183  void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<OperatorBase>& o_list) const override;
184 
186 
187 private:
189 
190  /// if true use offload
191  const bool use_offload_;
192  /// AA table ID
193  const int d_aa_ID;
194  /// Timer for long range
196  /// Timer for long range
198  /// Timer for offload part
200 
201  /// multiwalker shared resource
204 
205  /** constructor code factored out
206  */
207  void initBreakup(ParticleSet& P);
208 
209  /** Compute the const part of the per particle coulomb self interaction potential.
210  * \param[out] pp_consts constant values for the particles self interaction
211  */
212  void evalPerParticleConsts(Vector<RealType>& pp_consts) const;
213 };
214 
215 } // namespace qmcplusplus
216 #endif
void resetTargetParticleSet(ParticleSet &P) override
Reset the data with the target ParticleSet.
Calculates the AA Coulomb potential using PBCs.
Definition: CoulombPBCAA.h:38
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.
const bool use_offload_
if true use offload
Definition: CoulombPBCAA.h:191
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::shared_ptr< Vector< RealType, OffloadPinnedAllocator< RealType > > > Zat_offload
Definition: CoulombPBCAA.h:70
const int d_aa_ID
AA table ID.
Definition: CoulombPBCAA.h:193
NewTimer & evalLR_timer_
Timer for long range.
Definition: CoulombPBCAA.h:195
void setObservables(PropertySetType &plist) override
Set the values evaluated by this object to plist Default implementation is to assign Value which is u...
Definition: CoulombPBCAA.h:159
Array< TraceReal, 1 > V_const
Definition: CoulombPBCAA.h:86
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
NewTimer & evalSR_timer_
Timer for long range.
Definition: CoulombPBCAA.h:197
std::shared_ptr< const RadFunctorType > rVs
energy-optimized short range pair potential
Definition: CoulombPBCAA.h:49
Declaration of OperatorBase.
std::string getClassName() const override
return class name
Definition: CoulombPBCAA.h:96
Return_t evalSR(ParticleSet &P)
void updateSource(ParticleSet &s) override
Update data associated with a particleset.
An object of this type is a listener expecting a callback to the report function with a vector of val...
Definition: Listener.hpp:38
Timer accumulates time and call counts.
Definition: NewTimer.h:135
Vectorized record engine for scalar properties.
std::vector< int > SpeciesID
Definition: CoulombPBCAA.h:73
LRHandlerType::mRealType mRealType
Definition: CoulombPBCAA.h:43
Return_t evalLR(ParticleSet &P)
std::shared_ptr< const LRHandlerType > dAA
force-optimized long range handle
Definition: CoulombPBCAA.h:53
bool ComputeForces
Flag for whether to compute forces or not.
Definition: CoulombPBCAA.h:79
Attaches a unit to a Vector for IO.
std::shared_ptr< const RadFunctorType > rVsforce
force-optimized short range pair potential
Definition: CoulombPBCAA.h:55
Return_t evalSRwithForces(ParticleSet &P)
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
ParticleSet::Buffer_t BufferType
typedef for the serialized buffer
Definition: OperatorBase.h:75
RealType myRcut
cutoff radius of the short-range part
Definition: CoulombPBCAA.h:66
std::shared_ptr< const OffloadSpline > rVs_offload
the same as rVs but can be used inside OpenMP offload regions
Definition: CoulombPBCAA.h:51
Vector< RealType > dSR
Definition: CoulombPBCAA.h:76
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to a collection
void mw_evaluate(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list) const override
Evaluate the contribution of this component of multiple walkers.
NewTimer & offload_timer_
Timer for offload part.
Definition: CoulombPBCAA.h:199
ResourceHandle< CoulombPBCAAMultiWalkerResource > mw_res_handle_
Definition: CoulombPBCAA.h:202
RealType get_madelung_constant() const
Definition: CoulombPBCAA.h:185
combined OneDimCubicSpline and LinearGrid OneDimCubicSpline contains OneDimGridBase pointer and calls...
void initBreakup(ParticleSet &P)
constructor code factored out
Return_t evalConsts(bool report=true)
OneDimCubicSpline< pRealType > RadFunctorType
void checkoutParticleQuantities(TraceManager &tm) override
void setParticleSetF(QMCTraits::PropertySetType &plist, int offset)
Definition: ForceBase.cpp:113
Matrix< RealType > SR2
Definition: CoulombPBCAA.h:75
const bool quasi2d
Flag for whether to use quasi-2D Ewald.
Definition: CoulombPBCAA.h:81
Vector< ComplexType > del_eikr
Definition: CoulombPBCAA.h:77
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::shared_ptr< LRHandlerType > AA
energy-optimized long range handle. Should be const LRHandlerType eventually
Definition: CoulombPBCAA.h:47
virtual void setParticlePropertyList(PropertySetType &plist, int offset)
void setObservablesF(QMCTraits::PropertySetType &plist)
Definition: ForceBase.cpp:86
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 > Zspec
Definition: CoulombPBCAA.h:69
std::vector< RealType > Zat
Definition: CoulombPBCAA.h:69
Array< TraceReal, 1 > * V_sample
Definition: CoulombPBCAA.h:85
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...
static std::vector< Return_t > mw_evalSR_offload(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< ParticleSet > &p_list)
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 ...
void contributeParticleQuantities() override
LinearGrid< pRealType > GridType
Return_t evalLRwithForces(ParticleSet &P)
void informOfPerParticleListener() override
Inform objects associated with this operator of per particle listeners.
std::vector< int > NofSpecies
Definition: CoulombPBCAA.h:72
Return_t evaluate_sp(ParticleSet &P)
void setParticlePropertyList(PropertySetType &plist, int offset) override
Definition: CoulombPBCAA.h:166
CoulombPBCAA(ParticleSet &ref, bool active, bool computeForces, bool use_offload)
constructor
BareKineticEnergy::Return_t Return_t
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) override
void evalPerParticleConsts(Vector< RealType > &pp_consts) const
Compute the const part of the per particle coulomb self interaction potential.
void deleteParticleQuantities() override
RecordNamedProperty< FullPrecRealType > PropertySetType
define PropertyList_t
Definition: Configuration.h:69
bool put(xmlNodePtr cur) override
Do nothing.
Definition: CoulombPBCAA.h:125