QMCPACK
test_stress.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: Yubo "Paul" Yang, yyang173@illinois.edu, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Yubo "Paul" Yang, yyang173@illinois.edu, 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"
22 
23 #include <stdio.h>
24 #include <string>
25 
26 using std::string;
27 
28 namespace qmcplusplus
29 {
30 // PBC case
31 TEST_CASE("Stress BCC H Ewald3D", "[hamiltonian]")
32 {
34  lattice.BoxBConds = true; // periodic
35  lattice.R.diagonal(3.24957306);
36  lattice.LR_dim_cutoff = 40;
37  lattice.reset();
38 
39  const SimulationCell simulation_cell(lattice);
40  ParticleSet ions(simulation_cell);
41  ParticleSet elec(simulation_cell);
42 
43  ions.setName("ion");
44  ions.create({2});
45  ions.R[0] = {0.0, 0.0, 0.0};
46  ions.R[1] = {1.62478653, 1.62478653, 1.62478653};
47  SpeciesSet& ion_species = ions.getSpeciesSet();
48  int pIdx = ion_species.addSpecies("H");
49  int pChargeIdx = ion_species.addAttribute("charge");
50  ion_species(pChargeIdx, pIdx) = 1;
51  ions.resetGroups();
52  ions.createSK();
53  ions.update();
54 
55  elec.setName("elec");
56  elec.create({2});
57  elec.R[0] = {0.4, 0.4, 0.4};
58  elec.R[1] = {2.02478653, 2.02478653, 2.02478653};
59  SpeciesSet& tspecies = elec.getSpeciesSet();
60  int upIdx = tspecies.addSpecies("u");
61  int chargeIdx = tspecies.addAttribute("charge");
62  int massIdx = tspecies.addAttribute("mass");
63  tspecies(chargeIdx, upIdx) = -1;
64  tspecies(massIdx, upIdx) = 1.0;
65 
66  // The call to resetGroups is needed transfer the SpeciesSet
67  // settings to the ParticleSet
68  elec.resetGroups();
69  elec.createSK();
70 
71  RuntimeOptions runtime_options;
72  TrialWaveFunction psi(runtime_options);
73 
74  LRCoulombSingleton::CoulombHandler = std::make_unique<EwaldHandler3D>(ions);
75  LRCoulombSingleton::CoulombHandler->initBreakup(ions);
76  LRCoulombSingleton::CoulombDerivHandler = std::make_unique<EwaldHandler3D>(ions);
77  LRCoulombSingleton::CoulombDerivHandler->initBreakup(ions);
78 
79  StressPBC est(ions, elec, psi);
80 
81  elec.update();
82  est.evaluate(elec);
83 
84  // i-i = e-e stress is validated against Quantum Espresso's ewald method
85  // they are also double checked using finite-difference
86  CHECK(est.getStressEE()(0, 0) == Approx(-0.01087883));
87  CHECK(est.getStressEE()(0, 1) == Approx(0.0));
88  CHECK(est.getStressEE()(0, 2) == Approx(0.0));
89  CHECK(est.getStressEE()(1, 0) == Approx(0.0));
90  CHECK(est.getStressEE()(1, 1) == Approx(-0.01087883));
91  CHECK(est.getStressEE()(1, 2) == Approx(0.0));
92  CHECK(est.getStressEE()(2, 0) == Approx(0.0));
93  CHECK(est.getStressEE()(2, 1) == Approx(0.0));
94  CHECK(est.getStressEE()(2, 2) == Approx(-0.01087883));
95 
96  //Electron-Ion stress diagonal is internally validated using fd.
97  CHECK(est.getStressEI()(0, 0) == Approx(-0.00745376));
98  //CHECK(est.getStressEI()(0, 1) == Approx(0.0));
99  //CHECK(est.getStressEI()(0, 2) == Approx(0.0));
100  //CHECK(est.getStressEI()(1, 0) == Approx(0.0));
101  CHECK(est.getStressEI()(1, 1) == Approx(-0.00745376));
102  //CHECK(est.getStressEI()(1, 2) == Approx(0.0));
103  //CHECK(est.getStressEI()(2, 0) == Approx(0.0));
104  //CHECK(est.getStressEI()(2, 1) == Approx(0.0));
105  CHECK(est.getStressEI()(2, 2) == Approx(-0.00745376));
106 
107  LRCoulombSingleton::CoulombHandler.reset(nullptr);
108 
110 }
111 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
void setName(const std::string &aname)
Definition: ParticleSet.h:237
static std::unique_ptr< LRHandlerType > CoulombDerivHandler
Stores the force/stress optimized LR handler.
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]")
const SymTensor< Real, OHMMS_DIM > & getStressEE() const noexcept
Definition: ForceBase.h:72
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 evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
Definition: StressPBC.cpp:262
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
Declaration of a TrialWaveFunction.
Class to represent a many-body trial wave function.
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
void createSK()
create Structure Factor with PBCs
const SymTensor< Real, OHMMS_DIM > & getStressEI() const noexcept
Definition: ForceBase.h:73
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33