QMCPACK
J2KECorrection.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) 2021 QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp.
8 // Amrita Mathuriya, amrita.mathuriya@intel.com, Intel Corp.
9 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //
11 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
12 //////////////////////////////////////////////////////////////////////////////////////
13 // -*- C++ -*-
14 #ifndef QMCPLUSPLUS_J2KECORRECTION_H
15 #define QMCPLUSPLUS_J2KECORRECTION_H
16 
17 #include <cmath>
18 #include <vector>
19 #include <ParticleSet.h>
20 
21 namespace qmcplusplus
22 {
23 // helper class to activate KEcorr during optimizing Jastrow
24 template<typename RT, class FT>
26 {
27  size_t num_groups_;
28  std::vector<size_t> num_elec_in_groups_;
30  RT vol;
31  RT G0mag;
32  const std::vector<FT*>& F_;
33  bool SK_enabled;
34 
35 public:
36  J2KECorrection(const ParticleSet& targetPtcl, const std::vector<FT*>& F)
37  : num_groups_(targetPtcl.groups()),
38  num_elecs_(targetPtcl.getTotalNum()),
39  vol(targetPtcl.getLattice().Volume),
40  F_(F),
41  SK_enabled(targetPtcl.hasSK())
42  {
43  // compute num_elec_in_groups_
44  num_elec_in_groups_.reserve(3);
45  for (int i = 0; i < num_groups_; i++)
46  num_elec_in_groups_.push_back(targetPtcl.last(i) - targetPtcl.first(i));
47 
48  if (SK_enabled)
49  G0mag = std::sqrt(targetPtcl.getSimulationCell().getKLists().ksq[0]);
50  }
51 
53  {
54  if (!SK_enabled)
55  return 0;
56 
57  const int numPoints = 1000;
58  RT uk = 0.0;
59  RT a = 1.0;
60 
61  for (int i = 0; i < num_groups_; i++)
62  {
63  int Ni = num_elec_in_groups_[i];
64  for (int j = 0; j < num_groups_; j++)
65  {
66  int Nj = num_elec_in_groups_[j];
67  if (F_[i * num_groups_ + j])
68  {
69  FT& ufunc = *(F_[i * num_groups_ + j]);
70  RT radius = ufunc.cutoff_radius;
71  RT k = G0mag;
72  RT dr = radius / (RT)(numPoints - 1);
73  for (int ir = 0; ir < numPoints; ir++)
74  {
75  RT r = dr * (RT)ir;
76  RT u = ufunc.evaluate(r);
77  uk += 0.5 * 4.0 * M_PI * r * std::sin(k * r) / k * u * dr * (RT)Nj / (RT)(Ni + Nj);
78  }
79  }
80  }
81  }
82  for (int iter = 0; iter < 20; iter++)
83  a = uk / (4.0 * M_PI * (1.0 / (G0mag * G0mag) - 1.0 / (G0mag * G0mag + 1.0 / a)));
84  return 4.0 * M_PI * a / (4.0 * vol) * num_elecs_;
85  }
86 };
87 } // namespace qmcplusplus
88 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
MakeReturn< UnaryNode< FnSin, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sin(const Vector< T1, C1 > &l)
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
const std::vector< FT * > & F_
const auto & getSimulationCell() const
Definition: ParticleSet.h:250
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
std::vector< size_t > num_elec_in_groups_
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
J2KECorrection(const ParticleSet &targetPtcl, const std::vector< FT *> &F)