QMCPACK
test_SpaceGridInput.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) 2023 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
8 //
9 // File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "SpaceGridInput.h"
16 #include "ValidSpaceGridInput.h"
17 #include "OhmmsData/Libxml2Doc.h"
18 namespace qmcplusplus
19 {
20 
21 TEST_CASE("SpaceGridInputs::parseXML::valid", "[estimators]")
22 {
24  for (auto input_xml : input::xml)
25  {
27  bool okay = doc.parseFromString(input_xml);
28  xmlNodePtr node = doc.getRoot();
29 
30  // Will throw if input is invalid.
31  SpaceGridInput spi(node);
32  std::string value_label;
33  auto wrapped_spi = makeSpaceGridInput(node, value_label);
34  }
35 }
36 
37 TEST_CASE("SpaceGridInputs::parseXML::invalid", "[estimators]")
38 {
40  for (auto input_xml : input::xml)
41  {
43  bool okay = doc.parseFromString(input_xml);
44  REQUIRE(okay);
45  xmlNodePtr node = doc.getRoot();
46 
47  auto constructBadSpaceGrid = [](xmlNodePtr cur) { SpaceGridInput spi(cur); };
48  CHECK_THROWS_AS(constructBadSpaceGrid(node), UniformCommunicateError);
49  }
50 }
51 
52 template<typename T>
53 bool checkVec(T& vec, T expected_vec) {
54  return vec == expected_vec;
55 }
56 
57 TEST_CASE("SpaceGridInputs::parseXML::axes", "[estimators]")
58 {
59  using Real = double;
61  auto& input_xml = input::xml[input::WITH_STEP];
63 
64  bool okay = doc.parseFromString(input_xml);
65  REQUIRE(okay);
66  xmlNodePtr node = doc.getRoot();
67 
68  SpaceGridInput sgi(node);
69 
70  auto& axis_p1 = sgi.get_axis_p1s();
71  CHECK(checkVec(axis_p1, {"r1","r2","r3"}));
72  auto& axis_scale = sgi.get_axis_scales();
73  CHECK(checkVec(axis_scale, {6.9,6.9,6.9}));
74  auto& axis_label = sgi.get_axis_labels();
75  CHECK(checkVec(axis_label, {"r","phi","theta"}));
76  auto& axis_grid = sgi.get_axis_grids();
77  qmcplusplus::AxisGrid<Real> expected_1({
78  10,
79  }, //ndom_int
80  {
81  1,
82  }, //ndu_int
83  {
84  0.1,
85  }, //du_int
86  0, //umin
87  1, //umax
88  10, //odu
89  {
90  0,
91  1,
92  2,
93  3,
94  4,
95  5,
96  6,
97  7,
98  8,
99  9,
100  }, //gmap
101  {
102  1,
103  1,
104  1,
105  1,
106  1,
107  1,
108  1,
109  1,
110  1,
111  1,
112  }, //ndu_per_interval
113  10); //dimensions
114  CHECK(axis_grid[0] == expected_1);
115  CHECK(sgi.get_origin_p1() == "ion1");
116  CHECK(sgi.get_origin_p2().empty());
117  CHECK(sgi.get_origin_fraction() == 0.0);
118 }
119 
120 } // namespace qmcplusplus
class that handles xmlDoc
Definition: Libxml2Doc.h:76
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
if(!okay) throw std xmlNodePtr node
const std::string & get_origin_p1() const
std::any makeSpaceGridInput(xmlNodePtr cur, std::string &value_label)
factory function for a SpaceGridInput
TEST_CASE("complex_helper", "[type_traits]")
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
ForceBase::Real Real
Definition: ForceBase.cpp:26
static constexpr std::array< std::string_view, 3 > xml
const std::array< AxisGrid< Real >, OHMMS_DIM > & get_axis_grids() const
const std::array< std::string, OHMMS_DIM > & get_axis_labels() const
REQUIRE(std::filesystem::exists(filename))
This a subclass for runtime errors that will occur on all ranks.
const std::string & get_origin_p2() const
const std::array< Real, OHMMS_DIM > & get_axis_scales() const
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
const std::array< std::string, OHMMS_DIM > & get_axis_p1s() const
bool checkVec(T &vec, T expected_vec)