QMCPACK
test_coulomb_pbcAA_ewald.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: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "OhmmsData/Libxml2Doc.h"
16 #include "OhmmsPETE/OhmmsMatrix.h"
17 #include "Particle/ParticleSet.h"
20 
21 #include <stdio.h>
22 #include <string>
23 
24 using std::string;
25 
26 namespace qmcplusplus
27 {
28 TEST_CASE("Coulomb PBC A-A Ewald3D", "[hamiltonian]")
29 {
31  lattice.BoxBConds = true; // periodic
32  lattice.R.diagonal(1.0);
33  lattice.reset();
34 
35  const SimulationCell simulation_cell(lattice);
36  ParticleSet ions(simulation_cell);
37 
38  ions.setName("ion");
39  ions.create({1});
40  ions.R[0] = {0.0, 0.0, 0.0};
41  SpeciesSet& ion_species = ions.getSpeciesSet();
42  int pIdx = ion_species.addSpecies("H");
43  int pChargeIdx = ion_species.addAttribute("charge");
44  ion_species(pChargeIdx, pIdx) = 1;
45  ions.createSK();
46 
47  LRCoulombSingleton::CoulombHandler = std::make_unique<EwaldHandler3D>(ions);
48  LRCoulombSingleton::CoulombHandler->initBreakup(ions);
49 
50 
51  CoulombPBCAA caa(ions, false, false, false);
52  // Background charge term
53  double consts = caa.evalConsts();
54  CHECK(consts == Approx(-3.142553)); // not validated
55 
56  double val = caa.evaluate(ions);
57  CHECK(val == Approx(-1.418927)); // not validated
58 
60 }
61 
62 TEST_CASE("Coulomb PBC A-A BCC H Ewald3D", "[hamiltonian]")
63 {
65  lattice.BoxBConds = true; // periodic
66  lattice.R.diagonal(3.77945227);
67  lattice.reset();
68 
69  const SimulationCell simulation_cell(lattice);
70  ParticleSet ions(simulation_cell);
71  ParticleSet elec(simulation_cell);
72 
73  ions.setName("ion");
74  ions.create({2});
75  ions.R[0] = {0.0, 0.0, 0.0};
76  ions.R[1] = {1.88972614, 1.88972614, 1.88972614};
77  SpeciesSet& ion_species = ions.getSpeciesSet();
78  int pIdx = ion_species.addSpecies("H");
79  int pChargeIdx = ion_species.addAttribute("charge");
80  ion_species(pChargeIdx, pIdx) = 1;
81  ions.createSK();
82 
83  LRCoulombSingleton::CoulombHandler = std::make_unique<EwaldHandler3D>(ions);
84  LRCoulombSingleton::CoulombHandler->initBreakup(ions);
85 
86  CoulombPBCAA caa(ions, false, false, false);
87 
88  // Background charge term
89  double consts = caa.evalConsts();
90  CHECK(consts == Approx(-1.690675)); // not validated
91 
92  double val = caa.evaluate(elec);
93  CHECK(val == Approx(-0.963074)); // not validated
94 
96 }
97 
98 TEST_CASE("Coulomb PBC A-A elec Ewald3D", "[hamiltonian]")
99 {
101  lattice.BoxBConds = true; // periodic
102  lattice.R.diagonal(1.0);
103  lattice.reset();
104 
105  const SimulationCell simulation_cell(lattice);
106  ParticleSet elec(simulation_cell);
107 
108  elec.setName("elec");
109  elec.create({1});
110  elec.R[0] = {0.0, 0.5, 0.0};
111  SpeciesSet& tspecies = elec.getSpeciesSet();
112  int upIdx = tspecies.addSpecies("u");
113  int chargeIdx = tspecies.addAttribute("charge");
114  int massIdx = tspecies.addAttribute("mass");
115  tspecies(chargeIdx, upIdx) = -1;
116  tspecies(massIdx, upIdx) = 1.0;
117 
118  elec.createSK();
119  elec.update();
120 
121  LRCoulombSingleton::CoulombHandler = std::make_unique<EwaldHandler3D>(elec);
122  LRCoulombSingleton::CoulombHandler->initBreakup(elec);
123 
124  CoulombPBCAA caa(elec, true, false, false);
125 
126  // Self-energy correction, no background charge for e-e interaction
127  double consts = caa.evalConsts();
128  CHECK(consts == Approx(-3.142553));
129 
130  double val = caa.evaluate(elec);
131  CHECK(val == Approx(-1.418927)); // not validated
132 
133  LRCoulombSingleton::CoulombHandler.reset(nullptr);
134 }
135 
136 
137 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
void setName(const std::string &aname)
Definition: ParticleSet.h:237
Calculates the AA Coulomb potential using PBCs.
Definition: CoulombPBCAA.h:38
int addSpecies(const std::string &aname)
When a name species does not exist, add a new species.
Definition: SpeciesSet.cpp:33
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
void update(bool skipSK=false)
update the internal data
static std::unique_ptr< LRHandlerType > CoulombHandler
Stores the energ optimized LR handler.
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
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
Return_t evalConsts(bool report=true)
ParticlePos R
Position.
Definition: ParticleSet.h:79
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void create(const std::vector< int > &agroup)
create grouped particles
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
void createSK()
create Structure Factor with PBCs
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.