QMCPACK
test_xml_mass.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 
16 #include "OhmmsData/Libxml2Doc.h"
17 #include "OhmmsPETE/Tensor.h"
18 #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("read_particle_mass_same_xml", "[particle_io][xml]")
29 {
30  // test that particle masses are properly read in
31 
32 
33  const char* particles = R"(<tmp>
34 <particleset name="e" random="yes">
35  <group name="u" size="4" mass="1.0">
36  <parameter name="charge" > -1 </parameter>
37  <parameter name="mass" > 1.0 </parameter>
38  </group>
39  <group name="d" size="4" mass="1.0">
40  <parameter name="charge" > -1 </parameter>
41  <parameter name="mass" > 1.0 </parameter>
42  </group>
43 </particleset>
44 <particleset name="ion0">
45  <group name="H" size="8" mass="1836.15">
46  <parameter name="charge" > 1 </parameter>
47  <parameter name="valence" > 1 </parameter>
48  <parameter name="atomicnumber" > 1 </parameter>
49  <parameter name="mass" > 1836.15 </parameter>
50  <attrib name="position" datatype="posArray" condition="0">
51  0.00000000 0.00000000 0.00000000
52  2.11170946 0.00000000 0.00000000
53  0.00000000 2.11170946 0.00000000
54  2.11170946 2.11170946 0.00000000
55  0.00000000 0.00000000 2.11170946
56  2.11170946 0.00000000 2.11170946
57  0.00000000 2.11170946 2.11170946
58  2.11170946 2.11170946 2.11170946
59  </attrib>
60  </group>
61 </particleset>
62 </tmp>
63 )"; // simple cubic lattice at rs=1.31
64 
66  bool okay = doc.parseFromString(particles);
67  REQUIRE(okay);
68 
69  xmlNodePtr root = doc.getRoot();
70  xmlNodePtr part1 = xmlFirstElementChild(root);
71  xmlNodePtr part2 = xmlNextElementSibling(part1);
72 
73  const SimulationCell simulation_cell;
74  ParticleSet ions(simulation_cell), electrons(simulation_cell);
75 
76  XMLParticleParser parse_electrons(electrons);
77  parse_electrons.readXML(part1);
78  REQUIRE(electrons.getName() == "e");
79 
80  XMLParticleParser parse_ions(ions);
81  parse_ions.readXML(part2);
82  REQUIRE(ions.getName() == "ion0");
83 
84  REQUIRE(ions.isSameMass());
85  REQUIRE(electrons.isSameMass());
86 
87  // test electrons
88  SpeciesSet& tspecies(electrons.getSpeciesSet());
89  int massind = tspecies.addAttribute("mass");
90  char order[] = "uuuudddd";
91  for (int iat = 0; iat < electrons.getTotalNum(); iat++)
92  {
93  int species_id = electrons.GroupID[iat];
94  std::string species_name = tspecies.speciesName[species_id];
95  REQUIRE(*species_name.c_str() == order[iat]);
96  CHECK(tspecies(massind, species_id) == Approx(1.0));
97  }
98 
99  // test ions
100  SpeciesSet& pspecies(ions.getSpeciesSet());
101  int pmassind = pspecies.addAttribute("mass");
102  char porder[] = "HHHHHHHH";
103  for (int iat = 0; iat < ions.getTotalNum(); iat++)
104  {
105  int species_id = ions.GroupID[iat];
106  std::string species_name = pspecies.speciesName[species_id];
107  REQUIRE(*species_name.c_str() == porder[iat]);
108  CHECK(pspecies(pmassind, species_id) == Approx(1836.15));
109  }
110 } // TEST_CASE read_particle_mass_same_xml
111 
112 } // namespace qmcplusplus
class that handles xmlDoc
Definition: Libxml2Doc.h:76
const std::string & getName() const
return the name
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
size_t getTotalNum() const
Definition: ParticleSet.h:493
TEST_CASE("complex_helper", "[type_traits]")
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
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
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
REQUIRE(std::filesystem::exists(filename))
bool readXML(xmlNodePtr cur)
process xmlnode <particleset/> which contains everything about the particle set to initialize ...
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33