QMCPACK
ForceChiesaPBCAA.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: Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 //
10 // File created by: Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #include "ForceChiesaPBCAA.h"
15 #include "Particle/DistanceTable.h"
16 #include "Message/Communicate.h"
20 #include "OhmmsData/ParameterSet.h"
21 #include "OhmmsData/AttributeSet.h"
22 
23 namespace qmcplusplus
24 {
26  : ForceBase(ions, elns),
27  PtclA(ions),
28  first_time(firsttime),
29  d_aa_ID(ions.addTable(ions)),
30  d_ei_ID(elns.addTable(ions))
31 {
32  ReportEngine PRE("ForceChiesaPBCAA", "ForceChiesaPBCAA");
33  name_ = "Chiesa_Force_Base_PBCAB";
34  prefix_ = "FChiesaPBC";
35  //Defaults for the chiesa S-wave polynomial filtering.
36  Rcut = 0.4;
37  m_exp = 2;
38  N_basis = 4;
39  forces_ = 0.0;
40  forces_ion_ion_ = 0.0;
41  ions.turnOnPerParticleSK();
42  //This sets up the long range breakups.
43  initBreakup(elns);
44  if (first_time == true)
45  { // calculate ion-ion forces and print in output
46  ions.update();
47  evaluateLR_AA();
48  evaluateSR_AA();
49  app_log() << "IonIon Force" << std::endl;
50  app_log() << forces_ion_ion_ << std::endl;
51  first_time = false;
52  }
53 }
54 
56 {
58  h.resize(N_basis);
59  c.resize(N_basis);
60  for (int k = 0; k < N_basis; k++)
61  {
62  h[k] = std::pow(Rcut, (k + 2)) / static_cast<RealType>(k + 2);
63  for (int j = 0; j < N_basis; j++)
64  {
65  Sinv(k, j) = std::pow(Rcut, (m_exp + k + j + 3)) / static_cast<RealType>(m_exp + k + j + 3);
66  }
67  }
68  // in Numerics/DeterminantOperators.h
69  invert_matrix(Sinv, false);
70  // in Numerics/MatrixOperators.h
72 }
73 
75 {
76  SpeciesSet& tspeciesA(PtclA.getSpeciesSet());
77  SpeciesSet& tspeciesB(P.getSpeciesSet());
78  int ChargeAttribIndxA = tspeciesA.addAttribute("charge");
79  int ChargeAttribIndxB = tspeciesB.addAttribute("charge");
81  NptclB = P.getTotalNum();
82  NumSpeciesA = tspeciesA.TotalNum;
83  NumSpeciesB = tspeciesB.TotalNum;
84  //Store information about charges and number of each species
85  Zat.resize(NptclA);
86  Zspec.resize(NumSpeciesA);
87  Qat.resize(NptclB);
88  Qspec.resize(NumSpeciesB);
89  for (int spec = 0; spec < NumSpeciesA; spec++)
90  {
91  Zspec[spec] = tspeciesA(ChargeAttribIndxA, spec);
92  }
93  for (int spec = 0; spec < NumSpeciesB; spec++)
94  {
95  Qspec[spec] = tspeciesB(ChargeAttribIndxB, spec);
96  }
97  for (int iat = 0; iat < NptclA; iat++)
98  Zat[iat] = Zspec[PtclA.GroupID[iat]];
99  for (int iat = 0; iat < NptclB; iat++)
100  Qat[iat] = Qspec[P.GroupID[iat]];
102 }
103 
105 {
106  std::vector<TinyVector<RealType, DIM>> grad(PtclA.getTotalNum());
107  for (int j = 0; j < NumSpeciesB; j++)
108  {
109  for (int iat = 0; iat < grad.size(); iat++)
110  grad[iat] = TinyVector<RealType, DIM>(0.0, 0.0, 0.0);
111  dAB->evaluateGrad(PtclA, P, j, Zat, grad);
112  for (int iat = 0; iat < grad.size(); iat++)
113  {
114  forces_[iat] += Qspec[j] * grad[iat];
115  }
116  } // electron species
117 }
118 
120 {
121  const auto& d_ab(P.getDistTableAB(d_ei_ID));
122  for (size_t jat = 0; jat < NptclB; ++jat)
123  {
124  const auto& dist = d_ab.getDistRow(jat);
125  const auto& displ = d_ab.getDisplRow(jat);
126  for (size_t iat = 0; iat < NptclA; ++iat)
127  {
128  const RealType r = dist[iat];
129  const RealType rinv = RealType(1) / r;
130  RealType g_f = g_filter(r);
131  RealType V = -dAB->srDf(r, rinv);
132  PosType drhat = rinv * displ[iat];
133  forces_[iat] += g_f * Zat[iat] * Qat[jat] * V * drhat;
134  }
135  }
136 }
137 
139 {
140  const auto& d_aa(PtclA.getDistTableAA(d_aa_ID));
141  for (size_t ipart = 1; ipart < NptclA; ipart++)
142  {
143  const auto& dist = d_aa.getDistRow(ipart);
144  const auto& displ = d_aa.getDisplRow(ipart);
145  for (size_t jpart = 0; jpart < ipart; ++jpart)
146  {
147  RealType V = -dAB->srDf(dist[jpart], RealType(1) / dist[jpart]);
148  PosType grad = -Zat[jpart] * Zat[ipart] * V / dist[jpart] * displ[jpart];
149  forces_ion_ion_[ipart] += grad;
150  forces_ion_ion_[jpart] -= grad;
151  }
152  }
153 }
154 
156 {
157  std::vector<TinyVector<RealType, DIM>> grad(PtclA.getTotalNum());
158  for (int spec2 = 0; spec2 < NumSpeciesA; spec2++)
159  {
160  RealType Z2 = Zspec[spec2];
161  for (int iat = 0; iat < grad.size(); iat++)
162  grad[iat] = TinyVector<RealType, DIM>(0.0);
163  dAB->evaluateGrad(PtclA, PtclA, spec2, Zat, grad);
164 
165  for (int iat = 0; iat < grad.size(); iat++)
166  {
167  forces_ion_ion_[iat] += Z2 * grad[iat];
168  }
169  } //spec2
170 }
171 
172 
174 {
175  forces_ = 0.0;
176  evaluateLR(P);
177  evaluateSR(P);
178  if (add_ion_ion_ == true)
180  return 0.0;
181 }
182 
184 {
185  if (r >= Rcut)
186  {
187  return 1.0;
188  }
189  else
190  {
191  RealType g_q = 0.0;
192  for (int q = 0; q < N_basis; q++)
193  {
194  g_q += c[q] * std::pow(r, m_exp + q + 1);
195  }
196 
197  return g_q;
198  }
199 }
200 
201 bool ForceChiesaPBCAA::put(xmlNodePtr cur)
202 {
203  std::string ionionforce("yes");
204  OhmmsAttributeSet attr;
205  attr.add(prefix_, "name");
206  attr.add(ionionforce, "add_ion_ion_");
207  attr.put(cur);
208  add_ion_ion_ = (ionionforce == "yes") || (ionionforce == "true");
209  app_log() << "ionionforce = " << ionionforce << std::endl;
210  app_log() << "add_ion_ion_=" << add_ion_ion_ << std::endl;
211  ParameterSet fcep_param_set;
212  fcep_param_set.add(Rcut, "rcut");
213  fcep_param_set.add(N_basis, "nbasis");
214  fcep_param_set.add(m_exp, "weight_exp");
215  fcep_param_set.put(cur);
216  app_log() << " ForceChiesaPBCAA Parameters" << std::endl;
217  app_log() << " ForceChiesaPBCAA::Rcut=" << Rcut << std::endl;
218  app_log() << " ForceChiesaPBCAA::N_basis=" << N_basis << std::endl;
219  app_log() << " ForceChiesaPBCAA::m_exp=" << m_exp << std::endl;
220  InitMatrix();
221  return true;
222 }
223 
224 void ForceChiesaPBCAA::resetTargetParticleSet(ParticleSet& P) { dAB->resetTargetParticleSet(P); }
225 
227 {
228  my_index_ = plist.add(name_.c_str());
229  addObservablesF(plist);
230 }
231 
232 std::unique_ptr<OperatorBase> ForceChiesaPBCAA::makeClone(ParticleSet& qp, TrialWaveFunction& psi)
233 {
234  std::unique_ptr<ForceChiesaPBCAA> tmp = std::make_unique<ForceChiesaPBCAA>(PtclA, qp, false);
235  tmp->Rcut = Rcut; // parameter: radial distance within which estimator is used
236  tmp->m_exp = m_exp; // parameter: exponent in polynomial fit
237  tmp->N_basis = N_basis; // parameter: size of polynomial basis set
238  tmp->Sinv.resize(N_basis, N_basis);
239  tmp->Sinv = Sinv; // terms in fitting polynomial
240  tmp->h.resize(N_basis);
241  tmp->h = h; // terms in fitting polynomial
242  tmp->c.resize(N_basis);
243  tmp->c = c; // polynomial coefficients
244  tmp->add_ion_ion_ = add_ion_ion_;
245  tmp->forces_ion_ion_ = forces_ion_ion_;
246  tmp->initBreakup(qp);
247  return tmp;
248 }
249 } // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
MatrixA::value_type invert_matrix(MatrixA &M, bool getdet=true)
invert a matrix
static std::unique_ptr< LRHandlerType > getDerivHandler(ParticleSet &ref)
This returns a force/stress optimized LR handler. If non existent, it creates one.
std::unique_ptr< LRHandlerType > dAB
long-range Handler
ParticleSet & PtclA
source particle set
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
const DistanceTableAA & getDistTableAA(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAA
QTBase::RealType RealType
Definition: Configuration.h:58
ParticleSet::ParticlePos forces_
Definition: ForceBase.h:87
size_t getTotalNum() const
Definition: ParticleSet.h:493
int my_index_
starting index of this object
Definition: OperatorBase.h:535
int NptclA
number of particles of A
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::vector< RealType > Zat
Zat[iat] charge for the iat-th particle of A.
void addObservablesF(QMCTraits::PropertySetType &plist)
Definition: ForceBase.cpp:47
Vectorized record engine for scalar properties.
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
void update(bool skipSK=false)
update the internal data
std::string prefix_
Definition: ForceBase.h:96
int addAttribute(const std::string &aname)
for a new attribute, allocate the data, !More often used to get the index of a species ...
Definition: SpeciesSet.cpp:45
bool put(std::istream &is) override
read from std::istream
Definition: ParameterSet.h:42
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
for(int i=0;i< size_test;++i) CHECK(Approx(gauss_random_vals[offset_for_rs+i])
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
void turnOnPerParticleSK()
Turn on per particle storage in Structure Factor.
void initBreakup(ParticleSet &P)
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
int NumSpeciesB
number of species of B particle set
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
std::string name_
name of this object
Definition: OperatorBase.h:527
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
void addObservables(PropertySetType &plist, BufferType &collectables) override
named values to the property list Default implementaton uses addValue(plist_)
class to handle a set of parameters
Definition: ParameterSet.h:27
int NptclB
number of particles of B
bool add_ion_ion_
Determines if ion-ion force will be added to electron-ion force in derived force estimators. If false, forces_ion_ion_=0.0.
Definition: ForceBase.h:84
void product(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
static function to perform C=AB for real matrices
int add(const std::string &aname)
Final class and should not be derived.
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
declaration of ProgressReportEngine
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
std::vector< RealType > Qat
Qat[iat] charge for the iat-th particle of B.
int NumSpeciesA
number of species of A particle set
void add(PDT &aparam, const std::string &aname_in, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new parameter corresponding to an xmlNode <parameter>
FullPrecRealType Return_t
type of return value of evaluate
Definition: OperatorBase.h:64
Define determinant operators.
Class to represent a many-body trial wave function.
void resetTargetParticleSet(ParticleSet &P) override
Reset the data with the target ParticleSet.
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) final
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
ParticleSet::ParticlePos forces_ion_ion_
Definition: ForceBase.h:88
std::vector< RealType > Zspec
Zspec[spec] charge for the spec-th species of A.
bool put(xmlNodePtr cur) override
Read the input parameter.
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
ForceChiesaPBCAA(ParticleSet &ions, ParticleSet &elns, bool firsttime=true)
std::vector< RealType > Qspec
Qspec[spec] charge for the spec-th species of B.