QMCPACK
test_srcoul.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) 2019 and QMCPACK developers.
6 //
7 // File developed by: Yubo "Paul" Yang, yubo.paul.yang@gmail.com, University of Illinois Urbana-Champaign
8 //
9 // File created by: Yubo "Paul" Yang, yubo.paul.yang@gmail.com, University of Illinois Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "catch.hpp"
13 
14 #include "Configuration.h"
15 #include "Lattice/CrystalLattice.h"
16 #include "Particle/ParticleSet.h"
18 
19 namespace qmcplusplus
20 {
22 
24 { // stripped down version of LRCoulombSingleton::CoulombFunctor for 3D
25  double norm;
26  inline double operator()(double r, double rinv) const { return rinv; }
27  inline double Vk(double k) const { return 1. / (k * k); }
28  inline double dVk_dk(double k) const { return -2 * norm / (k * k * k); }
29  void reset(ParticleSet& ref) { norm = 4.0 * M_PI / ref.getLRBox().Volume; }
30  void reset(ParticleSet& ref, double rs) { reset(ref); } // ignore rs
31  inline double df(double r) const { return -1. / (r * r); }
32 };
33 
34 /** evalaute bare Coulomb in 3D
35  */
36 TEST_CASE("srcoul", "[lrhandler]")
37 {
39  Lattice.BoxBConds = true;
40  Lattice.LR_dim_cutoff = 30.;
41  Lattice.R.diagonal(5.0);
42  Lattice.reset();
43  CHECK(Lattice.Volume == Approx(125));
44  Lattice.SetLRCutoffs(Lattice.Rv);
45  //Lattice.printCutoffs(app_log());
46  CHECK(Approx(Lattice.LR_rc) == 2.5);
47  CHECK(Approx(Lattice.LR_kc) == 12);
48 
49  const SimulationCell simulation_cell(Lattice);
50  ParticleSet ref(simulation_cell); // handler needs ref.getSimulationCell().getKLists()
51  ref.createSK();
53 
54  handler.initBreakup(ref);
55 
56  std::cout << "handler.MaxKshell is " << handler.MaxKshell << std::endl;
57  CHECK( (std::is_same<OHMMS_PRECISION, OHMMS_PRECISION_FULL>::value ?
58  handler.MaxKshell == 78 : handler.MaxKshell >= 117 && handler.MaxKshell <= 128 ));
59  CHECK(Approx(handler.LR_rc) == 2.5);
60  CHECK(Approx(handler.LR_kc) == 12);
61 
62  mRealType r, dr, rinv;
63  mRealType vsr;
64  int nr = 101;
65  dr = 5.0 / nr; // L/[# of grid points]
66  for (int ir = 1; ir < nr; ir++)
67  {
68  r = ir * dr;
69  rinv = 1. / r;
70  vsr = handler.evaluate(r, rinv);
71  // short-range part must vanish after rcut
72  if (r > 2.5)
73  CHECK(vsr == Approx(0.0));
74  //// !!!! SR values not validated, see "srcoul df" test
75  //CHECK(vsr == Approx(rinv));
76  }
77 }
78 
79 /** evalaute bare Coulomb derivative in 3D
80  */
81 TEST_CASE("srcoul df", "[lrhandler]")
82 {
84  Lattice.BoxBConds = true;
85  Lattice.LR_dim_cutoff = 30.;
86  Lattice.R.diagonal(5.0);
87  Lattice.reset();
88  CHECK(Lattice.Volume == Approx(125));
89  Lattice.SetLRCutoffs(Lattice.Rv);
90  //Lattice.printCutoffs(app_log());
91  CHECK(Approx(Lattice.LR_rc) == 2.5);
92  CHECK(Approx(Lattice.LR_kc) == 12);
93 
94  const SimulationCell simulation_cell(Lattice);
95  ParticleSet ref(simulation_cell); // handler needs ref.getSimulationCell().getKLists()
96  ref.createSK();
98 
99  handler.initBreakup(ref);
100 
101  std::cout << "handler.MaxKshell is " << handler.MaxKshell << std::endl;
102  CHECK( (std::is_same<OHMMS_PRECISION, OHMMS_PRECISION_FULL>::value ?
103  handler.MaxKshell == 78 : handler.MaxKshell >= 117 && handler.MaxKshell <= 128 ));
104  CHECK(Approx(handler.LR_rc) == 2.5);
105  CHECK(Approx(handler.LR_kc) == 12);
106 
108  fref.reset(ref);
109  mRealType r, dr, rinv;
110  mRealType rm, rp; // minus (m), plus (p)
111  mRealType vsrm, vsrp, dvsr, vlrm, vlrp, dvlr;
112  dr = 0.00001; // finite difference step
113  std::vector<mRealType> rlist = {0.1, 0.5, 1.0, 2.0, 2.5};
114  for (auto it = rlist.begin(); it != rlist.end(); ++it)
115  {
116  r = *it;
117  // test short-range piece
118  rm = r - dr;
119  rinv = 1. / rm;
120  vsrm = handler.evaluate(rm, rinv);
121  vlrm = handler.evaluateLR(rm);
122  rp = r + dr;
123  rinv = 1. / rp;
124  vsrp = handler.evaluate(rp, rinv);
125  vlrp = handler.evaluateLR(rp);
126  dvsr = (vsrp - vsrm) / (2 * dr);
127  rinv = 1. / r;
128  CHECK(handler.srDf(r, rinv) == Approx(dvsr));
129  // test long-range piece
130  dvlr = (vlrp - vlrm) / (2 * dr);
131  CHECK(handler.lrDf(r) == Approx(dvlr));
132  // test total derivative
133  CHECK(dvsr + dvlr == Approx(fref.df(r)));
134  }
135 }
136 
137 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
const auto & getLRBox() const
Definition: ParticleSet.h:253
void reset()
Evaluate the reciprocal vectors, volume and metric tensor.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
mRealType LR_kc
Maximum k cutoff.
Definition: LRHandlerBase.h:37
DECLARE_COULOMB_TYPES int MaxKshell
Maxkimum Kshell for the given Kc.
Definition: LRHandlerBase.h:35
TEST_CASE("complex_helper", "[type_traits]")
EwaldHandler3D::mRealType mRealType
Declaration of CrystalLattice<T,D>
void initBreakup(ParticleSet &ref) override
TinyVector< SingleParticlePos, D > Rv
Real-space unit vectors.
mRealType lrDf(mRealType r) const override
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
mRealType srDf(mRealType r, mRealType rinv) const override
evaluate the first derivative of the short range part at r
Scalar_t Volume
Physical properties of a supercell.
TinyVector< int, D > BoxBConds
The boundary condition in each direction.
mRealType LR_rc
Maximum r cutoff.
Definition: LRHandlerBase.h:39
void diagonal(const T &rhs)
Definition: Tensor.h:205
mRealType evaluateLR(mRealType r) const override
evaluate the contribution from the long-range part for for spline
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
void createSK()
create Structure Factor with PBCs
mRealType evaluate(mRealType r, mRealType rinv) const override
Define a LRHandler with two template parameters.
void reset(ParticleSet &ref, double rs)
Definition: test_srcoul.cpp:30
Tensor_t R
Real-space unit vectors. R(i,j) i=vector and j=x,y,z.
double operator()(double r, double rinv) const
Definition: test_srcoul.cpp:26