QMCPACK
test_ParticleSet.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 "OhmmsPETE/OhmmsMatrix.h"
16 #include "OhmmsPETE/TinyVector.h"
17 #include "Lattice/CrystalLattice.h"
18 #include "Lattice/ParticleBConds.h"
19 #include "Particle/ParticleSet.h"
20 #include "Particle/DistanceTable.h"
21 
22 namespace qmcplusplus
23 {
24 TEST_CASE("ParticleSet distance table management", "[particle]")
25 {
26  const SimulationCell simulation_cell;
27  ParticleSet ions(simulation_cell);
28  ParticleSet elecs(simulation_cell);
29 
30  ions.setName("ions");
31  elecs.setName("electrons");
32 
33  const int ii_table_id = ions.addTable(ions);
34  const int ie_table_id = ions.addTable(elecs);
35  const int ei_table_id = elecs.addTable(ions);
36  const int ee_table_id = elecs.addTable(elecs);
37 
38  REQUIRE(ii_table_id == 0);
39  REQUIRE(ie_table_id == 1);
40  REQUIRE(ei_table_id == 0);
41  REQUIRE(ee_table_id == 1);
42 
43  // second query
44  const int ii_table_id2 = ions.addTable(ions);
45  const int ie_table_id2 = ions.addTable(elecs);
46  const int ei_table_id2 = elecs.addTable(ions);
47  const int ee_table_id2 = elecs.addTable(elecs);
48 
49  REQUIRE(ii_table_id2 == 0);
50  REQUIRE(ie_table_id2 == 1);
51  REQUIRE(ei_table_id2 == 0);
52  REQUIRE(ee_table_id2 == 1);
53 
54  REQUIRE(&(ions.getDistTable(ii_table_id2).get_origin()) == &ions);
55  REQUIRE(&(ions.getDistTable(ie_table_id2).get_origin()) == &elecs);
56  REQUIRE(&(elecs.getDistTable(ei_table_id2).get_origin()) == &ions);
57  REQUIRE(&(elecs.getDistTable(ee_table_id2).get_origin()) == &elecs);
58 
59  ParticleSet elecs_copy(elecs);
60  REQUIRE(elecs_copy.getDistTable(ei_table_id2).get_origin().getName() == "ions");
61  REQUIRE(elecs_copy.getDistTable(ee_table_id2).get_origin().getName() == "electrons");
62 }
63 
64 TEST_CASE("symmetric_distance_table OpenBC", "[particle]")
65 {
66  const SimulationCell simulation_cell;
67  ParticleSet source(simulation_cell);
68 
69  source.setName("electrons");
70 
71  source.create({2});
72  source.R[0] = {0.0, 1.0, 2.0};
73  source.R[1] = {1.1, 1.0, 3.2};
74  source.update();
75  /// make sure getCoordinates().getAllParticlePos() is updated no matter SoA or AoS.
76  CHECK(source.getCoordinates().getAllParticlePos()[0][1] == Approx(1.0));
77  CHECK(source.getCoordinates().getAllParticlePos()[1][2] == Approx(3.2));
78 
79  const int TableID = source.addTable(source);
80  source.update();
81  const auto& d_aa = source.getDistTableAA(TableID);
82  const auto& aa_dists = d_aa.getDistances();
83  const auto& aa_displs = d_aa.getDisplacements();
84 
85  CHECK(aa_dists[1][0] == Approx(1.62788206));
86  CHECK(aa_displs[1][0][0] == Approx(-1.1));
87  CHECK(aa_displs[1][0][1] == Approx(0.0));
88  CHECK(aa_displs[1][0][2] == Approx(-1.2));
89 }
90 
91 TEST_CASE("symmetric_distance_table PBC", "[particle]")
92 {
94  Lattice.BoxBConds = true; // periodic
95  Lattice.R = ParticleSet::Tensor_t(6.74632230, 6.74632230, 0.00000000, 0.00000000, 3.37316115, 3.37316115, 3.37316115,
96  0.00000000, 3.37316115);
97  Lattice.reset();
98 
99  const SimulationCell simulation_cell(Lattice);
100  ParticleSet source(simulation_cell);
101 
102  source.setName("electrons");
103 
104  source.create({4});
105  source.R[0] = ParticleSet::PosType(0.00000000, 0.00000000, 0.00000000);
106  source.R[1] = ParticleSet::PosType(1.68658058, 1.68658058, 1.68658058);
107  source.R[2] = ParticleSet::PosType(3.37316115, 3.37316115, 0.00000000);
108  source.R[3] = ParticleSet::PosType(5.05974172, 5.05974172, 1.68658058);
109 
110  const int TableID = source.addTable(source);
111  source.update();
112  const auto& d_aa = source.getDistTableAA(TableID);
113  const auto& aa_dists = d_aa.getDistances();
114  const auto& aa_displs = d_aa.getDisplacements();
115 
116  CHECK(aa_dists[2][1] == Approx(2.9212432441));
117  CHECK(aa_displs[2][1][0] == Approx(-1.68658057));
118  CHECK(aa_displs[2][1][1] == Approx(-1.68658057));
119  CHECK(aa_displs[2][1][2] == Approx(1.68658057));
120 }
121 
122 TEST_CASE("particle set lattice with vacuum", "[particle]")
123 {
124  // PPP case
126  Lattice.BoxBConds = true;
127  Lattice.R = {1.0, 2.0, 3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
128 
129  Lattice.VacuumScale = 2.0;
130  Lattice.reset();
131  {
132  const SimulationCell simulation_cell(Lattice);
133  ParticleSet source(simulation_cell);
134  source.setName("electrons");
135  source.createSK();
136 
138  CHECK(source.getLRBox().R(0, 0) == 1.0);
139  CHECK(source.getLRBox().R(0, 1) == 2.0);
140  CHECK(source.getLRBox().R(0, 2) == 3.0);
141  }
142 
143  // PPN case
144  Lattice.BoxBConds[2] = false;
145  Lattice.reset();
146  {
147  const SimulationCell simulation_cell(Lattice);
148  ParticleSet source(simulation_cell);
149  source.setName("electrons");
150  source.createSK();
151 
153  CHECK(source.getLRBox().R(2, 0) == 0.0);
154  CHECK(source.getLRBox().R(2, 1) == 0.0);
155  CHECK(source.getLRBox().R(2, 2) == 2.0);
156  }
157 
158  // PNN case
159  Lattice.BoxBConds[1] = false;
160  Lattice.reset();
161  {
162  const SimulationCell simulation_cell(Lattice);
163  ParticleSet source(simulation_cell);
164  source.setName("electrons");
165  source.createSK();
166 
168  CHECK(source.getLRBox().R(0, 0) == 1.0);
169  CHECK(source.getLRBox().R(0, 1) == 2.0);
170  CHECK(source.getLRBox().R(0, 2) == 3.0);
171  CHECK(source.getLRBox().R(1, 0) == 0.0);
172  CHECK(source.getLRBox().R(1, 1) == 2.0);
173  CHECK(source.getLRBox().R(1, 2) == 0.0);
174  CHECK(source.getLRBox().R(2, 0) == 0.0);
175  CHECK(source.getLRBox().R(2, 1) == 0.0);
176  CHECK(source.getLRBox().R(2, 2) == 2.0);
177  }
178 }
179 
180 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
const auto & getLRBox() const
Definition: ParticleSet.h:253
void setName(const std::string &aname)
Definition: ParticleSet.h:237
int SuperCellEnum
supercell enumeration
void reset()
Evaluate the reciprocal vectors, volume and metric tensor.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
const DistanceTableAA & getDistTableAA(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAA
ParticleLayout::Tensor_t Tensor_t
Definition: Configuration.h:88
virtual const PosVectorSoa & getAllParticlePos() const =0
all particle position accessor
TEST_CASE("complex_helper", "[type_traits]")
T VacuumScale
The scale factor for adding vacuum.
void update(bool skipSK=false)
update the internal data
Declaration of CrystalLattice<T,D>
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
TinyVector< int, D > BoxBConds
The boundary condition in each direction.
REQUIRE(std::filesystem::exists(filename))
ParticlePos R
Position.
Definition: ParticleSet.h:79
QTBase::PosType PosType
Definition: Configuration.h:61
auto & getDistTable(int table_ID) const
get a distance table by table_ID
Definition: ParticleSet.h:190
void create(const std::vector< int > &agroup)
create grouped particles
const DynamicCoordinates & getCoordinates() const
Definition: ParticleSet.h:246
const std::vector< DistRow > & getDistances() const
return full table distances
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
void createSK()
create Structure Factor with PBCs
Tensor_t R
Real-space unit vectors. R(i,j) i=vector and j=x,y,z.