QMCPACK
SoaCuspCorrection.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) 2021 QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp.
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 /** @file SoaCuspCorrection.cpp
14  */
15 #include "SoaCuspCorrection.h"
17 
18 namespace qmcplusplus
19 {
21  : myTableIndex(els.addTable(ions)), MaxOrbSize(norbs)
22 {
23  NumCenters = ions.getTotalNum();
24  NumTargets = els.getTotalNum();
25  LOBasisSet.resize(NumCenters);
27 }
28 
30 
31 inline void SoaCuspCorrection::evaluateVGL(const ParticleSet& P, int iat, VGLVector& vgl)
32 {
33  assert(MaxOrbSize >= vgl.size());
34  myVGL = 0.0;
35 
36  const auto& d_table = P.getDistTableAB(myTableIndex);
37  const auto& dist = (P.getActivePtcl() == iat) ? d_table.getTempDists() : d_table.getDistRow(iat);
38  const auto& displ = (P.getActivePtcl() == iat) ? d_table.getTempDispls() : d_table.getDisplRow(iat);
39  for (int c = 0; c < NumCenters; c++)
40  if (LOBasisSet[c])
41  LOBasisSet[c]->evaluate_vgl(dist[c], displ[c], myVGL[0], myVGL[1], myVGL[2], myVGL[3], myVGL[4]);
42 
43  {
44  const auto v_in = myVGL[0];
45  const auto gx_in = myVGL[1];
46  const auto gy_in = myVGL[2];
47  const auto gz_in = myVGL[3];
48  const auto l_in = myVGL[4];
49  auto v_out = vgl.data(0);
50  auto gx_out = vgl.data(1);
51  auto gy_out = vgl.data(2);
52  auto gz_out = vgl.data(3);
53  auto l_out = vgl.data(4);
54  for (size_t i = 0; i < vgl.size(); ++i)
55  {
56  v_out[i] += v_in[i];
57  gx_out[i] += gx_in[i];
58  gy_out[i] += gy_in[i];
59  gz_out[i] += gz_in[i];
60  l_out[i] += l_in[i];
61  }
62  }
63 }
64 
66  int iat,
67  ValueVector& psi,
68  GradVector& dpsi,
69  ValueVector& d2psi)
70 {
71  assert(MaxOrbSize >= psi.size());
72  myVGL = 0.0;
73 
74  const auto& d_table = P.getDistTableAB(myTableIndex);
75  const auto& dist = (P.getActivePtcl() == iat) ? d_table.getTempDists() : d_table.getDistRow(iat);
76  const auto& displ = (P.getActivePtcl() == iat) ? d_table.getTempDispls() : d_table.getDisplRow(iat);
77  for (int c = 0; c < NumCenters; c++)
78  if (LOBasisSet[c])
79  LOBasisSet[c]->evaluate_vgl(dist[c], displ[c], myVGL[0], myVGL[1], myVGL[2], myVGL[3], myVGL[4]);
80 
81  const auto v_in = myVGL[0];
82  const auto gx_in = myVGL[1];
83  const auto gy_in = myVGL[2];
84  const auto gz_in = myVGL[3];
85  const auto l_in = myVGL[4];
86  for (size_t i = 0; i < psi.size(); ++i)
87  {
88  psi[i] += v_in[i];
89  dpsi[i][0] += gx_in[i];
90  dpsi[i][1] += gy_in[i];
91  dpsi[i][2] += gz_in[i];
92  d2psi[i] += l_in[i];
93  }
94 }
95 
97  int iat,
98  int idx,
99  ValueMatrix& psi,
100  GradMatrix& dpsi,
101  ValueMatrix& d2psi)
102 {
103  assert(MaxOrbSize >= psi.cols());
104  myVGL = 0.0;
105 
106  const auto& d_table = P.getDistTableAB(myTableIndex);
107  const auto& dist = (P.getActivePtcl() == iat) ? d_table.getTempDists() : d_table.getDistRow(iat);
108  const auto& displ = (P.getActivePtcl() == iat) ? d_table.getTempDispls() : d_table.getDisplRow(iat);
109  for (int c = 0; c < NumCenters; c++)
110  if (LOBasisSet[c])
111  LOBasisSet[c]->evaluate_vgl(dist[c], displ[c], myVGL[0], myVGL[1], myVGL[2], myVGL[3], myVGL[4]);
112 
113  const auto v_in = myVGL[0];
114  const auto gx_in = myVGL[1];
115  const auto gy_in = myVGL[2];
116  const auto gz_in = myVGL[3];
117  const auto l_in = myVGL[4];
118  for (size_t i = 0; i < psi.cols(); ++i)
119  {
120  psi[idx][i] += v_in[i];
121  dpsi[idx][i][0] += gx_in[i];
122  dpsi[idx][i][1] += gy_in[i];
123  dpsi[idx][i][2] += gz_in[i];
124  d2psi[idx][i] += l_in[i];
125  }
126 }
127 
129 {
130  assert(MaxOrbSize >= psi.size());
131  ValueType* tmp_vals = myVGL[0];
132 
133  std::fill_n(tmp_vals, myVGL.size(), 0.0);
134 
135  const auto& d_table = P.getDistTableAB(myTableIndex);
136  const auto& dist = (P.getActivePtcl() == iat) ? d_table.getTempDists() : d_table.getDistRow(iat);
137 
138  //THIS IS SERIAL, only way to avoid this is to use myVGL
139  for (int c = 0; c < NumCenters; c++)
140  if (LOBasisSet[c])
141  LOBasisSet[c]->evaluate(dist[c], tmp_vals);
142 
143  { //collect
144  const auto v_in = myVGL[0];
145  for (size_t i = 0; i < psi.size(); ++i)
146  psi[i] += v_in[i];
147  }
148 }
149 
150 void SoaCuspCorrection::add(int icenter, std::unique_ptr<COT> aos)
151 {
152  assert(MaxOrbSize == aos->getNumOrbs() && "All the centers should support the same number of orbitals!");
153  LOBasisSet[icenter].reset(aos.release());
154 }
155 
156 } // namespace qmcplusplus
Index_t getActivePtcl() const
return active particle id
Definition: ParticleSet.h:260
Convert CorrectingOrbitalBasisSet using MultiQuinticSpline1D<T>
size_t NumCenters
number of centers, e.g., ions
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
size_t getTotalNum() const
Definition: ParticleSet.h:493
void fill_n(T *x, size_t count, const T &value)
Definition: OMPstd.hpp:21
void evaluate_vgl(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi)
SoA adaptor class for Vector<TinyVector<T,D> >
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
size_type size() const
Definition: OhmmsMatrix.h:76
const DistRow & getTempDists() const
return the temporary distances when a move is proposed
const size_t MaxOrbSize
Maximal number of supported MOs this is not the AO basis because cusp correction is applied on the MO...
QMCTraits::ValueType ValueType
A localized basis set derived from BasisSetBase<typename COT::ValueType>
void evaluateV(const ParticleSet &P, int iat, ValueVector &psi)
compute values for the iat-paricle move
void evaluateVGL(const ParticleSet &P, int iat, VGLVector &vgl)
compute VGL
const int myTableIndex
number of quantum particles
size_t NumTargets
number of quantum particles
void add(int icenter, std::unique_ptr< COT > aos)
add a new set of Centered Atomic Orbitals
size_type size() const
return the physical size
SoaCuspCorrection(ParticleSet &ions, ParticleSet &els, size_t norbs)
constructor
std::vector< std::shared_ptr< const COT > > LOBasisSet
container of the unique pointers to the Atomic Orbitals