QMCPACK
LocalECPotential.cpp
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: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 #include "Particle/ParticleSet.h"
17 #include "Particle/DistanceTable.h"
19 #include "LocalECPotential.h"
21 
22 namespace qmcplusplus
23 {
24 LocalECPotential::LocalECPotential(const ParticleSet& ions, ParticleSet& els) : IonConfig(ions), Peln(els), Pion(ions)
25 {
27  twoBodyQuantumDomain(ions, els);
28  NumIons = ions.getTotalNum();
29  myTableIndex = els.addTable(ions);
30  //allocate null
31  PPset.resize(ions.getSpeciesSet().getTotalNum());
32  PP.resize(NumIons, nullptr);
33  Zeff.resize(NumIons, 0.0);
34  gZeff.resize(ions.getSpeciesSet().getTotalNum(), 0);
35 }
36 
38 {
39  int tid = P.addTable(IonConfig);
40  if (tid != myTableIndex)
41  {
42  APP_ABORT(" LocalECPotential::resetTargetParticleSet found a different distance table index.");
43  }
44 }
45 
46 void LocalECPotential::add(int groupID, std::unique_ptr<RadialPotentialType>&& ppot, RealType z)
47 {
48  for (int iat = 0; iat < PP.size(); iat++)
49  {
50  if (IonConfig.GroupID[iat] == groupID)
51  {
52  PP[iat] = ppot.get();
53  Zeff[iat] = z;
54  }
55  }
56  PPset[groupID] = std::move(ppot);
57  gZeff[groupID] = z;
58 }
59 
60 #if !defined(REMOVE_TRACEMANAGER)
62 
64 {
67  {
70  }
71 }
72 
74 {
76  {
77  delete Ve_sample;
78  delete Vi_sample;
79  }
80 }
81 #endif
82 
83 
85 {
86 #if !defined(REMOVE_TRACEMANAGER)
88  value_ = evaluate_sp(P);
89  else
90 #endif
91  {
92  const auto& d_table(P.getDistTableAB(myTableIndex));
93  value_ = 0.0;
94  const size_t Nelec = P.getTotalNum();
95  for (size_t iel = 0; iel < Nelec; ++iel)
96  {
97  const auto& dist = d_table.getDistRow(iel);
98  Return_t esum(0);
99  for (size_t iat = 0; iat < NumIons; ++iat)
100  if (PP[iat] != nullptr)
101  esum += PP[iat]->splint(dist[iat]) * Zeff[iat] / dist[iat];
102  value_ -= esum;
103  }
104  }
105  return value_;
106 }
107 
109  ParticleSet& ions,
110  TrialWaveFunction& psi,
111  ParticleSet::ParticlePos& hf_terms,
112  ParticleSet::ParticlePos& pulay_terms)
113 {
114  const auto& d_table(P.getDistTableAB(myTableIndex));
115  value_ = 0.0;
116  const size_t Nelec = P.getTotalNum();
117  for (size_t iel = 0; iel < Nelec; ++iel)
118  {
119  const auto& dist = d_table.getDistRow(iel);
120  const auto& dr = d_table.getDisplRow(iel);
121  Return_t esum(0);
122  //value, radial derivative, and 2nd derivative of spline r*V.
123  RealType v(0.0), dv(0.0), d2v(0.0);
124  //radial derivative dV/dr
125  RealType dvdr(0.0);
126  RealType rinv(1.0);
127  for (size_t iat = 0; iat < NumIons; ++iat)
128  {
129  if (PP[iat] != nullptr)
130  {
131  rinv = 1.0 / dist[iat];
132  v = PP[iat]->splint(dist[iat], dv, d2v);
133  dvdr = -Zeff[iat] * (dv - v * rinv) * rinv; //the minus is because of charge of electron.
134  hf_terms[iat] += dvdr * dr[iat] * rinv;
135  esum += -Zeff[iat] * v * rinv;
136  }
137  }
138  value_ += esum;
139  }
140  return value_;
141 }
142 
143 #if !defined(REMOVE_TRACEMANAGER)
145 {
146  const auto& d_table(P.getDistTableAB(myTableIndex));
147  value_ = 0.0;
148  Array<RealType, 1>& Ve_samp = *Ve_sample;
149  Array<RealType, 1>& Vi_samp = *Vi_sample;
150  Ve_samp = 0.0;
151  Vi_samp = 0.0;
152 
153  const size_t Nelec = P.getTotalNum();
154  for (size_t iel = 0; iel < Nelec; ++iel)
155  {
156  const auto& dist = d_table.getDistRow(iel);
157  Return_t esum(0), pairpot;
158  for (size_t iat = 0; iat < NumIons; ++iat)
159  if (PP[iat] != nullptr)
160  {
161  pairpot = -0.5 * PP[iat]->splint(dist[iat]) * Zeff[iat] / dist[iat];
162  Vi_samp(iat) += pairpot;
163  Ve_samp(iel) += pairpot;
164  esum += pairpot;
165  }
166  value_ += esum;
167  }
168  value_ *= 2.0;
169 
170 #if defined(TRACE_CHECK)
171  RealType Vnow = Value;
172  RealType Visum = Vi_samp.sum();
173  RealType Vesum = Ve_samp.sum();
174  RealType Vsum = Vesum + Visum;
175  RealType Vorig = evaluate_orig(P);
176  if (std::abs(Vsum - Vnow) > TraceManager::trace_tol)
177  {
178  app_log() << "accumtest: LocalECPotential::evaluate()" << std::endl;
179  app_log() << "accumtest: tot:" << Vnow << std::endl;
180  app_log() << "accumtest: sum:" << Vsum << std::endl;
181  APP_ABORT("Trace check failed");
182  }
183  if (std::abs(Vesum - Visum) > TraceManager::trace_tol)
184  {
185  app_log() << "sharetest: LocalECPotential::evaluate()" << std::endl;
186  app_log() << "sharetest: e share:" << Vesum << std::endl;
187  app_log() << "sharetest: i share:" << Visum << std::endl;
188  APP_ABORT("Trace check failed");
189  }
190  if (std::abs(Vorig - Vnow) > TraceManager::trace_tol)
191  {
192  app_log() << "versiontest: LocalECPotential::evaluate()" << std::endl;
193  app_log() << "versiontest: orig:" << Vorig << std::endl;
194  app_log() << "versiontest: mod:" << Vnow << std::endl;
195  APP_ABORT("Trace check failed");
196  }
197 #endif
198  return value_;
199 }
200 #endif
201 
202 
204 {
205  const auto& d_table(P.getDistTableAB(myTableIndex));
206  value_ = 0.0;
207  const size_t Nelec = P.getTotalNum();
208  for (size_t iel = 0; iel < Nelec; ++iel)
209  {
210  const auto& dist = d_table.getDistRow(iel);
211  Return_t esum(0);
212  for (size_t iat = 0; iat < NumIons; ++iat)
213  if (PP[iat] != nullptr)
214  esum += PP[iat]->splint(dist[iat]) * Zeff[iat] / dist[iat];
215  value_ -= esum;
216  }
217  return value_;
218 }
219 
220 std::unique_ptr<OperatorBase> LocalECPotential::makeClone(ParticleSet& qp, TrialWaveFunction& psi)
221 {
222  std::unique_ptr<LocalECPotential> myclone = std::make_unique<LocalECPotential>(IonConfig, qp);
223 
224  for (int ig = 0; ig < PPset.size(); ++ig)
225  {
226  if (PPset[ig])
227  {
228  myclone->add(ig, std::unique_ptr<RadialPotentialType>(PPset[ig]->makeClone()), gZeff[ig]);
229  }
230  }
231  return myclone;
232 }
233 } // namespace qmcplusplus
Array< TraceReal, 1 > * Vi_sample
void twoBodyQuantumDomain(const ParticleSet &P)
set quantum domain for two-body operator
void resetTargetParticleSet(ParticleSet &P) override
Reset the data with the target ParticleSet.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
bool streaming_array(const std::string &name)
Definition: TraceManager.h:249
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::ostream & app_log()
Definition: OutputManager.h:65
Declaration of OperatorBase.
std::vector< RealType > Zeff
effective charge per ion
const ParticleSet & IonConfig
reference to the ionic configuration
int myTableIndex
distance table index
Attaches a unit to a Vector for IO.
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
TraceRequest request_
whether traces are being collected
Definition: OperatorBase.h:531
Return_t evaluate_sp(ParticleSet &P)
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
int getTotalNum() const
return the number of species
Definition: SpeciesSet.h:55
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
Array< TraceReal, 1 > * Ve_sample
single particle trace samples
std::string name_
name of this object
Definition: OperatorBase.h:527
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
std::vector< std::unique_ptr< RadialPotentialType > > PPset
unique set of local ECP to cleanup
LocalECPotential(const ParticleSet &ions, ParticleSet &els)
std::vector< RadialPotentialType * > PP
PP[iat] is the local potential for the iat-th particle.
Return_t evaluate_orig(ParticleSet &P)
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
void checkoutParticleQuantities(TraceManager &tm) override
void setEnergyDomain(EnergyDomains edomain)
Set the Energy Domain.
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
Array< TraceReal, D > * checkout_real(const std::string &name, int n1=1, int n2=0, int n3=0, int n4=0)
void add(int groupID, std::unique_ptr< RadialPotentialType > &&ppot, RealType z)
Add a RadialPotentialType of a species.
std::vector< RealType > gZeff
effective charge per species
FullPrecRealType Return_t
type of return value of evaluate
Definition: OperatorBase.h:64
Type_t sum() const
Definition: OhmmsArray.h:214
Class to represent a many-body trial wave function.
Return_t value_
current value
Definition: OperatorBase.h:524
void contribute_array(const std::string &name, bool default_quantity=false)
Definition: TraceManager.h:198
int NumIons
the number of ioncs
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) override
void contributeParticleQuantities() override
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...
void deleteParticleQuantities() override