QMCPACK
test_ParseGridInput.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 W. Doak, doakpw@ornl.gov, Oak Ridge National Lab
8 //
9 // File created by: Peter W. Doak, doakpw@ornl.gov, Oak Ridge National Lab
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 /** \file
13  * This unit test was added long after the initial implementation of this grid spec
14  * the "correct" values are produced from the ported code as the original code is
15  * design does not easy allow a unit test. It may not cover edge case behavior of the
16  * original code in QMCHamiltonian/SpaceGrid.cpp
17  */
18 #include "catch.hpp"
19 
20 #include "ParseGridInput.hpp"
22 #include <StlPrettyPrint.hpp>
24 
25 namespace qmcplusplus
26 {
27 
28 template<typename T>
29 std::ostream& operator<<(std::ostream& out, const AxisGrid<T>& rhs)
30 {
31  out << "{";
32  out << NativePrint(rhs.ndom_int) << ", //ndom_int\n";
33  out << NativePrint(rhs.ndu_int) << ", //ndu_int\n";
34  out << NativePrint(rhs.du_int) << ", //du_int\n";
35  out << rhs.umin << ", //umin\n";
36  out << rhs.umax << ", //umax\n";
37  out << rhs.odu << ", //odu\n";
38  out << NativePrint(rhs.gmap) << ", //gmap\n";
39  out << NativePrint(rhs.ndu_per_interval) << ", //ndu_per_interval\n";
40  out << rhs.dimensions << "} //dimensions\n";
41  return out;
42 }
43 
44 TEMPLATE_TEST_CASE("ParseGridInput::Good", "[estimators]", float, double)
45 {
46  using Real = TestType;
47  using namespace std::string_literals;
48 
49  std::istringstream grid_input_1("0 (0.1) 1"s);
50  AxisGrid<Real> axis_grid_1 = parseGridInput<Real>(grid_input_1);
51  AxisGrid<Real> expected_1{{
52  10,
53  }, //ndom_int
54  {
55  1,
56  }, //ndu_int
57  {
58  0.1,
59  }, //du_int
60  0, //umin
61  1, //umax
62  10, //odu
63  {
64  0,
65  1,
66  2,
67  3,
68  4,
69  5,
70  6,
71  7,
72  8,
73  9,
74  }, //gmap
75  {
76  1,
77  1,
78  1,
79  1,
80  1,
81  1,
82  1,
83  1,
84  1,
85  1,
86  }, //ndu_per_interval
87  10}; //dimensions
88 
89  CHECK(axis_grid_1 == expected_1);
90 
91  std::istringstream grid_input_2("0.1 (10) 0.2 (20) 0.4 (10) 0.8"s);
92  AxisGrid<Real> axis_grid_2 = parseGridInput<Real>(grid_input_2);
93  AxisGrid<Real> expected_2{{
94  10,
95  20,
96  10,
97  }, //ndom_int
98  {
99  1,
100  1,
101  4,
102  }, //ndu_int
103  {
104  0.01,
105  0.01,
106  0.04,
107  }, //du_int
108  0.1, //umin
109  0.8, //umax
110  100, //odu
111  {
112  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
113  18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 30, 30, 30, 31, 31,
114  31, 31, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35,
115  36, 36, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 39,
116  }, //gmap
117  {
118  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
119  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
120  }, //ndu_per_interval
121  40}; //dimensions
122 
123  CHECK(axis_grid_2 == expected_2);
124 }
125 
126 TEMPLATE_TEST_CASE("ParseGridInput::Bad", "[estimators]", float, double)
127 {
128  using Real = TestType;
129  using namespace std::string_literals;
130 
131  std::istringstream grid_input_1("1.1 (0.1) 1.5"s);
132  CHECK_THROWS_AS(parseGridInput<Real>(grid_input_1), UniformCommunicateError);
133 
134  std::istringstream grid_input_2("0.8 (0.1) 0.5"s);
135  CHECK_THROWS_AS(parseGridInput<Real>(grid_input_2), UniformCommunicateError);
136 
137  std::istringstream grid_input_3("0.8 (0.1) 1.5"s);
138  CHECK_THROWS_AS(parseGridInput<Real>(grid_input_3), UniformCommunicateError);
139 
140  std::istringstream grid_input_4("0.1 (0.3) 0.2"s);
141  CHECK_THROWS_AS(parseGridInput<Real>(grid_input_4), UniformCommunicateError);
142 
143  std::istringstream grid_input_5("0.1 (10) 0.2 (20) 0.35 (10) 0.73"s);
144  CHECK_THROWS_AS(parseGridInput<Real>(grid_input_5), UniformCommunicateError);
145 }
146 
147 TEMPLATE_TEST_CASE("ParseGridInput_constructors", "[estimators]", float, double)
148 {
149  using Real = TestType;
150  AxisGrid<Real> start_grid{{
151  10,
152  }, //ndom_int
153  {
154  1,
155  }, //ndu_int
156  {
157  0.1,
158  }, //du_int
159  0, //umin
160  1, //umax
161  10, //odu
162  {
163  0,
164  1,
165  2,
166  3,
167  4,
168  5,
169  6,
170  7,
171  8,
172  9,
173  }, //gmap
174  {
175  1,
176  1,
177  1,
178  1,
179  1,
180  1,
181  1,
182  1,
183  1,
184  1,
185  }, //ndu_per_interval
186  10}; //dimensions
187  AxisGrid<Real> copied_grid(start_grid);
188  AxisGrid<Real> assigned_grid(start_grid);
189 
190  CHECK(start_grid == copied_grid);
191  CHECK(start_grid == assigned_grid);
192 }
193 
194 } // namespace qmcplusplus
The operator<< functions provide output for data structures that can be used to directly initialize t...
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
This wrapper is to allow us to leave the user facing operator<< for classes alone.
ForceBase::Real Real
Definition: ForceBase.cpp:26
This a subclass for runtime errors that will occur on all ranks.
The AxisGrid data structure and the ParseGridInput factor parsing in a manner usable in acustom handl...
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
TEMPLATE_TEST_CASE("RandomRotationMatrix", "[numerics]", float, double)