QMCPACK
test_particle_pool.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) 2020 QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, mdewing@anl.gov Argonne National Laboratory
8 //
9 // File created by: Mark Dewing, mdewing@anl.gov Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 
16 #include "Message/Communicate.h"
17 #include "OhmmsData/Libxml2Doc.h"
19 
20 
21 #include <stdio.h>
22 #include <string>
23 #include <sstream>
24 #include <type_traits>
25 
26 
27 namespace qmcplusplus
28 {
29 TEST_CASE("ParticleSetPool", "[qmcapp]")
30 {
31  Communicate* c;
33 
34  ParticleSetPool pp(c);
35 
36  // See ParticleIO/tests/test_xml_io.cpp for particle parsing
37  const char* particles = R"(
38 <particleset name="ion0" size="1">
39  <group name="He">
40  <parameter name="charge">2</parameter>
41  </group>
42  <attrib name="position" datatype="posArray">
43  0.1 0.2 0.3
44  </attrib>
45 </particleset>
46 )";
48  bool okay = doc.parseFromString(particles);
49  REQUIRE(okay);
50 
51  xmlNodePtr root = doc.getRoot();
52 
53  pp.put(root);
54 
55  ParticleSet* ions = pp.getParticleSet("ion0");
56  REQUIRE(ions != NULL);
57 
58  ParticleSet* not_here = pp.getParticleSet("does_not_exist");
59  REQUIRE(not_here == NULL);
60 
61  MCWalkerConfiguration* ws = pp.getWalkerSet("ion0");
62  REQUIRE(ws != NULL);
63 
64  REQUIRE_THROWS_AS(pp.getWalkerSet("does_not_exist"), std::runtime_error);
65 
66  auto ps2 = std::make_unique<ParticleSet>(pp.getSimulationCell());
67  ps2->setName("particle_set_2");
68  pp.addParticleSet(std::move(ps2));
69 
70  // should do nothing, since no random particlesets were specified
71  pp.randomize();
72 
73  std::stringstream out;
74  pp.get(out);
75  //std::cout << "ParticleSetPool::get returns " << std::endl;
76  //std::cout << out.str() << std::endl;
77 }
78 
79 TEST_CASE("ParticleSetPool random", "[qmcapp]")
80 {
81  Communicate* c;
83 
84  ParticleSetPool pp(c);
85 
86  // See ParticleIO/tests/test_xml_io.cpp for particle parsing
87  const char* particles = R"(
88 <tmp>
89 <particleset name="ion0" size="1">
90  <group name="He">
91  <parameter name="charge">2</parameter>
92  </group>
93  <attrib name="position" datatype="posArray">
94  0.1 0.2 0.3
95  </attrib>
96 </particleset>
97 <particleset name="elec" random="yes" randomsrc="ion0" spinor="yes">
98  <group name="u" size="4">
99  <parameter name="charge">-1</parameter>
100  </group>
101 </particleset>
102 </tmp>
103 )";
105  bool okay = doc.parseFromString(particles);
106  REQUIRE(okay);
107 
108  xmlNodePtr root = doc.getRoot();
109 
110  xmlNodePtr part_ion = xmlFirstElementChild(root);
111  pp.put(part_ion);
112  pp.put(xmlNextElementSibling(part_ion));
113 
114  ParticleSet* ions = pp.getParticleSet("ion0");
115  REQUIRE(ions != NULL);
116  REQUIRE(!ions->isSpinor());
117 
118  ParticleSet* elec = pp.getParticleSet("elec");
119  REQUIRE(ions != NULL);
120  REQUIRE(elec->isSpinor());
121  REQUIRE(elec->R.size() == 4);
122  REQUIRE(elec->spins.size() == 4);
123 
124 
125  // should do something
126  pp.randomize();
127 
128  REQUIRE(elec->R[0][0] != 0.0);
129  REQUIRE(elec->spins[0] != 0.0);
130 }
131 
132 TEST_CASE("ParticleSetPool putLattice", "[qmcapp]")
133 {
134  Communicate* c;
135  c = OHMMS::Controller;
136 
137  ParticleSetPool pp(c);
138 
139  const char* lattice = R"(<parameter name="lattice"> </parameter>)";
140 
143  REQUIRE(okay);
144 
145  xmlNodePtr root = doc.getRoot();
146  pp.readSimulationCellXML(root);
147 }
148 } // namespace qmcplusplus
MCWalkerConfiguration * getWalkerSet(const std::string &pname)
get a named MCWalkerConfiguration
class that handles xmlDoc
Definition: Libxml2Doc.h:76
A set of walkers that are to be advanced by Metropolis Monte Carlo.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
bool put(xmlNodePtr cur)
process an xml element
TEST_CASE("complex_helper", "[type_traits]")
void addParticleSet(std::unique_ptr< ParticleSet > &&p)
add a ParticleSet* to the pool with its ownership transferred ParticleSet built outside the ParticleS...
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
Wrapping information on parallelism.
Definition: Communicate.h:68
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
bool get(std::ostream &os) const
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
REQUIRE(std::filesystem::exists(filename))
ParticleSet * getParticleSet(const std::string &pname)
get a named ParticleSet
Manage a collection of ParticleSet objects.
bool readSimulationCellXML(xmlNodePtr cur)
initialize the supercell shared by all the particle sets
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
void randomize()
randomize a particleset particleset/=&#39;yes&#39; && particleset exists
const auto & getSimulationCell() const
get simulation cell
Declaration of ParticleSetPool.