QMCPACK
test_lattice_parser.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: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
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"
19 #include "ParticleIO/LatticeIO.h"
20 
21 #include <stdio.h>
22 #include <string>
23 
24 using std::string;
25 
26 namespace qmcplusplus
27 {
28 TEST_CASE("read_lattice_xml", "[particle_io][xml]")
29 {
30  SECTION("valid p p p input")
31  {
32  const char* const particles = R"(
33  <tmp>
34  <parameter name="lattice" units="bohr">
35  3.80000000 0.00000000 0.00000000
36  0.00000000 3.80000000 0.00000000
37  0.00000000 0.00000000 3.80000000
38  </parameter>
39  <parameter name="bconds">
40  p p p
41  </parameter>
42  <parameter name="LR_dim_cutoff">20</parameter>
43  </tmp>
44  )";
45 
47  bool okay = doc.parseFromString(particles);
48  REQUIRE(okay);
49 
50  xmlNodePtr root = doc.getRoot();
51 
53  LatticeParser lp(uLattice);
54  REQUIRE_NOTHROW(lp.put(root));
55 
56  CHECK(uLattice.R[0] == Approx(3.8));
57  CHECK(uLattice.Volume == Approx(3.8 * 3.8 * 3.8));
58 
59  CHECK(uLattice.LR_dim_cutoff == Approx(20));
60  }
61 
62  SECTION("invalid n p p input")
63  {
64  const char* const particles = R"(
65  <tmp>
66  <parameter name="lattice" units="bohr">
67  3.80000000 0.00000000 0.00000000
68  0.00000000 3.80000000 0.00000000
69  0.00000000 0.00000000 3.80000000
70  </parameter>
71  <parameter name="bconds">
72  n p p
73  </parameter>
74  <parameter name="LR_dim_cutoff">20</parameter>
75  </tmp>
76  )";
77 
79  bool okay = doc.parseFromString(particles);
80  REQUIRE(okay);
81 
82  xmlNodePtr root = doc.getRoot();
83 
85  LatticeParser lp(uLattice);
86  REQUIRE_THROWS_WITH(lp.put(root),
87  "LatticeParser::put. In \"bconds\", non periodic directions must be placed after the periodic "
88  "ones.");
89  }
90 
91  SECTION("invalid p n p input")
92  {
93  const char* const particles = R"(
94  <tmp>
95  <parameter name="lattice" units="bohr">
96  3.80000000 0.00000000 0.00000000
97  0.00000000 3.80000000 0.00000000
98  0.00000000 0.00000000 3.80000000
99  </parameter>
100  <parameter name="bconds">
101  p n p
102  </parameter>
103  <parameter name="LR_dim_cutoff">20</parameter>
104  </tmp>
105  )";
106 
108  bool okay = doc.parseFromString(particles);
109  REQUIRE(okay);
110 
111  xmlNodePtr root = doc.getRoot();
112 
114  LatticeParser lp(uLattice);
115  REQUIRE_THROWS_WITH(lp.put(root),
116  "LatticeParser::put. In \"bconds\", non periodic directions must be placed after the periodic "
117  "ones.");
118  }
119 }
120 
121 TEST_CASE("read_lattice_xml_lrhandle", "[particle_io][xml]")
122 {
123  SECTION("valid p p n input")
124  {
125  const char* const particles = R"(
126  <tmp>
127  <parameter name="lattice" units="bohr">
128  3.80000000 0.00000000 0.00000000
129  0.00000000 3.80000000 0.00000000
130  0.00000000 0.00000000 10.00000000
131  </parameter>
132  <parameter name="bconds">
133  p p n
134  </parameter>
135  <parameter name="LR_dim_cutoff">30</parameter>
136  <parameter name="LR_handler"> opt_breakup </parameter>
137  </tmp>
138  )";
139 
141  bool okay = doc.parseFromString(particles);
142  REQUIRE(okay);
143 
144  xmlNodePtr root = doc.getRoot();
145 
147  LatticeParser lp(uLattice);
148  REQUIRE_NOTHROW(lp.put(root));
149 
150  CHECK(uLattice.R[8] == Approx(10.0));
151  CHECK(uLattice.LR_dim_cutoff == Approx(30));
152  }
153 
154  SECTION("valid p p n ewald_quasi2d input")
155  {
156  const char* const particles = R"(
157  <tmp>
158  <parameter name="lattice" units="bohr">
159  3.80000000 0.00000000 0.00000000
160  0.00000000 3.80000000 0.00000000
161  0.00000000 0.00000000 10.00000000
162  </parameter>
163  <parameter name="bconds">
164  p p n
165  </parameter>
166  <parameter name="LR_dim_cutoff">30</parameter>
167  <parameter name="LR_handler"> ewald_quasi2d </parameter>
168  </tmp>
169  )";
170 
172  bool okay = doc.parseFromString(particles);
173  REQUIRE(okay);
174 
175  xmlNodePtr root = doc.getRoot();
176 
178  LatticeParser lp(uLattice);
179  REQUIRE_NOTHROW(lp.put(root));
180  }
181 
182  SECTION("invalid p p p ewald_quasi2d input")
183  {
184  const char* const particles = R"(
185  <tmp>
186  <parameter name="lattice" units="bohr">
187  3.80000000 0.00000000 0.00000000
188  0.00000000 3.80000000 0.00000000
189  0.00000000 0.00000000 10.00000000
190  </parameter>
191  <parameter name="bconds">
192  p p p
193  </parameter>
194  <parameter name="LR_dim_cutoff">30</parameter>
195  <parameter name="LR_handler"> ewald_quasi2d </parameter>
196  </tmp>
197  )";
198 
200  bool okay = doc.parseFromString(particles);
201  REQUIRE(okay);
202 
203  xmlNodePtr root = doc.getRoot();
204 
206  LatticeParser lp(uLattice);
207  REQUIRE_THROWS_WITH(lp.put(root),
208  "LatticeParser::put. Quasi 2D Ewald only works with boundary condition 'p p n'!");
209  }
210 }
211 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
class that handles xmlDoc
Definition: Libxml2Doc.h:76
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
bool put(xmlNodePtr cur)
Definition: LatticeIO.cpp:32
TEST_CASE("complex_helper", "[type_traits]")
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
Scalar_t Volume
Physical properties of a supercell.
REQUIRE(std::filesystem::exists(filename))
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Tensor_t R
Real-space unit vectors. R(i,j) i=vector and j=x,y,z.