QMCPACK
test_ewald3d.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 
23 /** evalaute bare Coulomb using EwaldHandler3D
24  */
25 TEST_CASE("ewald3d", "[lrhandler]")
26 {
28  Lattice.BoxBConds = true;
29  Lattice.LR_dim_cutoff = 30.;
30  Lattice.R.diagonal(5.0);
31  Lattice.reset();
32  CHECK(Lattice.Volume == Approx(125));
33  Lattice.SetLRCutoffs(Lattice.Rv);
34  //Lattice.printCutoffs(app_log());
35  CHECK(Lattice.LR_rc == Approx(2.5));
36  CHECK(Lattice.LR_kc == Approx(12));
37 
38  const SimulationCell simulation_cell(Lattice);
39  ParticleSet ref(simulation_cell); // handler needs ref.getSimulationCell().getKLists()
40  ref.createSK();
41  EwaldHandler3D handler(ref, Lattice.LR_kc);
42 
43  // make sure initBreakup changes the default sigma
44  CHECK(handler.Sigma == Approx(Lattice.LR_kc));
45  handler.initBreakup(ref);
46  CHECK(handler.Sigma == Approx(std::sqrt(Lattice.LR_kc / (2.0 * Lattice.LR_rc))));
47 
48  std::cout << "handler.MaxKshell is " << handler.MaxKshell << std::endl;
49  CHECK( (std::is_same<OHMMS_PRECISION, OHMMS_PRECISION_FULL>::value ?
50  handler.MaxKshell == 78 : handler.MaxKshell >= 117 && handler.MaxKshell <= 128 ));
51  CHECK(handler.LR_rc == Approx(2.5));
52  CHECK(handler.LR_kc == Approx(12));
53 
54  mRealType r, dr, rinv;
55  mRealType vsr, vlr;
56  int nr = 101;
57  dr = 5.0 / nr; // L/[# of grid points]
58  for (int ir = 1; ir < nr; ir++)
59  {
60  r = ir * dr;
61  rinv = 1. / r;
62  vsr = handler.evaluate(r, rinv);
63  vlr = handler.evaluateLR(r);
64  // short-range part must vanish after rcut
65  if (r > 2.5)
66  CHECK(vsr == Approx(0.0));
67  // sum must recover the Coulomb potential
68  CHECK(vsr + vlr == Approx(rinv));
69  }
70 }
71 
72 /** evalaute bare Coulomb derivative using EwaldHandler3D
73  */
74 TEST_CASE("ewald3d df", "[lrhandler]")
75 {
77  Lattice.BoxBConds = true;
78  Lattice.LR_dim_cutoff = 30.;
79  Lattice.R.diagonal(5.0);
80  Lattice.reset();
81  CHECK(Lattice.Volume == Approx(125));
82  Lattice.SetLRCutoffs(Lattice.Rv);
83  //Lattice.printCutoffs(app_log());
84  CHECK(Lattice.LR_rc == Approx(2.5));
85  CHECK(Lattice.LR_kc == Approx(12));
86 
87  const SimulationCell simulation_cell(Lattice);
88  ParticleSet ref(simulation_cell); // handler needs ref.getSimulationCell().getKLists()
89  ref.createSK();
90  EwaldHandler3D handler(ref, Lattice.LR_kc);
91 
92  // make sure initBreakup changes the default sigma
93  CHECK(handler.Sigma == Approx(Lattice.LR_kc));
94  handler.initBreakup(ref);
95  CHECK(handler.Sigma == Approx(std::sqrt(Lattice.LR_kc / (2.0 * Lattice.LR_rc))));
96 
97  std::cout << "handler.MaxKshell is " << handler.MaxKshell << std::endl;
98  CHECK( (std::is_same<OHMMS_PRECISION, OHMMS_PRECISION_FULL>::value ?
99  handler.MaxKshell == 78 : handler.MaxKshell >= 117 && handler.MaxKshell <= 128 ));
100  CHECK(handler.LR_rc == Approx(2.5));
101  CHECK(handler.LR_kc == Approx(12));
102 
103  mRealType r, dr, rinv;
104  mRealType rm, rp; // minus (m), plus (p)
105  mRealType vsrm, vsrp, dvsr, vlrm, vlrp, dvlr;
106  dr = 0.00001; // finite difference step
107  std::vector<mRealType> rlist = {0.1, 0.5, 1.0, 2.0, 2.5};
108  for (auto it = rlist.begin(); it != rlist.end(); ++it)
109  {
110  r = *it;
111  // test short-range piece
112  rm = r - dr;
113  rinv = 1. / rm;
114  vsrm = handler.evaluate(rm, rinv);
115  vlrm = handler.evaluateLR(rm);
116  rp = r + dr;
117  rinv = 1. / rp;
118  vsrp = handler.evaluate(rp, rinv);
119  vlrp = handler.evaluateLR(rp);
120  dvsr = (vsrp - vsrm) / (2 * dr);
121  rinv = 1. / r;
122  CHECK(handler.srDf(r, rinv) == Approx(dvsr));
123  // test long-range piece
124  dvlr = (vlrp - vlrm) / (2 * dr);
125  CHECK(handler.lrDf(r) == Approx(dvlr));
126  }
127 }
128 
129 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
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
mRealType Sigma
Related to the Gaussian width: .
Declaration of CrystalLattice<T,D>
TinyVector< SingleParticlePos, D > Rv
Real-space unit vectors.
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
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
mRealType srDf(mRealType r, mRealType rinv) const override
evaluate the first derivative of the short range part at r
mRealType evaluate(mRealType r, mRealType rinv) const override
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
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
void createSK()
create Structure Factor with PBCs
void initBreakup(ParticleSet &ref) override
Tensor_t R
Real-space unit vectors. R(i,j) i=vector and j=x,y,z.
mRealType lrDf(mRealType r) const override
evaluate the first derivative of the long range part (in real space) at r