Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
testing_utilities.h
1
9#pragma once
10
11// STL includes
12#include <iomanip>
13#include <limits>
14#include <sstream>
15#include <string>
16
17#include "../system_tests/system_tester.h" // provide systemTest class
18#include "../utils/basic_structs.h"
19
20// =============================================================================
21// NOTE: Global variables are declared as extern at the end of this file
22// =============================================================================
23
30namespace testing_utilities
31{
32// =========================================================================
53int64_t ulpsDistanceDbl(double const &a, double const &b);
54// =========================================================================
55
56// =========================================================================
95bool nearlyEqualDbl(double const &a, double const &b, double &absoluteDiff, int64_t &ulpsDiff,
96 double const &fixedEpsilon = 1E-14, int64_t const &ulpsEpsilon = 4);
97// =========================================================================
98
99void wrapperEqual(int i, int j, int k, std::string const &dataSetName, double test_value, double fid_value,
100 double fixedEpsilon);
101
102void analyticConstant(system_test::SystemTestRunner testObject, std::string const &dataSetName, double value);
103
104void analyticSine(system_test::SystemTestRunner testObject, std::string const &dataSetName, double constant,
105 double amplitude, double kx, double ky, double kz, double phase, double tolerance);
106
107// =========================================================================
123template <int checkType = 0>
124void Check_Results(double fiducialNumber, double testNumber, std::string const &outString, double fixedEpsilon = -999,
125 int64_t ulpsEpsilon = -999)
126{
127 // Check for equality and if not equal return difference
128 double absoluteDiff;
129 int64_t ulpsDiff;
130 bool areEqual;
131
132 if ((fixedEpsilon < 0) and (ulpsEpsilon < 0)) {
133 areEqual = testing_utilities::nearlyEqualDbl(fiducialNumber, testNumber, absoluteDiff, ulpsDiff);
134 } else if ((fixedEpsilon > 0) and (ulpsEpsilon < 0)) {
135 areEqual = testing_utilities::nearlyEqualDbl(fiducialNumber, testNumber, absoluteDiff, ulpsDiff, fixedEpsilon);
136 } else {
137 areEqual = testing_utilities::nearlyEqualDbl(fiducialNumber, testNumber, absoluteDiff, ulpsDiff, fixedEpsilon,
138 ulpsEpsilon);
139 }
140
141 std::stringstream outputMessage;
142 outputMessage << std::setprecision(std::numeric_limits<double>::max_digits10) << "Difference in " << outString
143 << std::endl
144 << "The fiducial value is: " << fiducialNumber << std::endl
145 << "The test value is: " << testNumber << std::endl
146 << "The absolute difference is: " << absoluteDiff << std::endl
147 << "The ULP difference is: " << ulpsDiff << std::endl;
148
149 if (checkType == 0) {
150 EXPECT_TRUE(areEqual) << outputMessage.str();
151 } else if (checkType == 1) {
152 ASSERT_TRUE(areEqual) << outputMessage.str();
153 } else {
154 throw std::runtime_error(
155 "Incorrect template argument passed to "
156 "Check_Results. Options are 0 and 1 but " +
157 std::to_string(checkType) + " was passed");
158 }
159}
160// =========================================================================
161
162// =========================================================================
169{
170 private:
172 std::string _string;
173
174 public:
181 void init(std::string const &inputPath) { _string = inputPath; };
182
188 std::string getString() { return _string; };
189 GlobalString() = default;
190 ~GlobalString() = default;
191};
192// =========================================================================
193
202 reconstruction::InterfaceState const &fiducial_data, size_t const direction)
203{
204 std::string const message = "Direction " + std::to_string(direction);
205
206 testing_utilities::Check_Results(test_data.density, fiducial_data.density, "density " + message);
207 testing_utilities::Check_Results(test_data.energy, fiducial_data.energy, "energy " + message);
208 testing_utilities::Check_Results(test_data.pressure, fiducial_data.pressure, "pressure " + message);
209 testing_utilities::Check_Results(test_data.velocity.x(), fiducial_data.velocity.x(), "velocity.x " + message);
210 testing_utilities::Check_Results(test_data.velocity.y(), fiducial_data.velocity.y(), "velocity.y " + message);
211 testing_utilities::Check_Results(test_data.velocity.z(), fiducial_data.velocity.z(), "velocity.z " + message);
212 testing_utilities::Check_Results(test_data.momentum.x(), fiducial_data.momentum.x(), "momentum.x " + message);
213 testing_utilities::Check_Results(test_data.momentum.y(), fiducial_data.momentum.y(), "momentum.y " + message);
214 testing_utilities::Check_Results(test_data.momentum.z(), fiducial_data.momentum.z(), "momentum.z " + message);
215
216#ifdef MHD
217 testing_utilities::Check_Results(test_data.total_pressure, fiducial_data.total_pressure, "total_pressure" + message);
218 testing_utilities::Check_Results(test_data.magnetic.x(), fiducial_data.magnetic.x(), "magnetic.x " + message);
219 testing_utilities::Check_Results(test_data.magnetic.y(), fiducial_data.magnetic.y(), "magnetic.y " + message);
220 testing_utilities::Check_Results(test_data.magnetic.z(), fiducial_data.magnetic.z(), "magnetic.z " + message);
221#endif // MHD
222}
223} // namespace testing_utilities
224
225// Declare the global string variables so everything that imports this file
226// has access to them
228extern testing_utilities::GlobalString globalChollaBuild;
229extern testing_utilities::GlobalString globalChollaMachine;
230extern testing_utilities::GlobalString globalMpiLauncher;
231extern bool globalRunCholla;
232extern bool globalCompareSystemTestResults;
Definition system_tester.h:97
Holds a single std::string that's intended to be read only and global. Use for storing the path of th...
Definition testing_utilities.h:169
std::string getString()
Get the String object.
Definition testing_utilities.h:188
void init(std::string const &inputPath)
Initializes the _path member variable. Should only be called once in main.
Definition testing_utilities.h:181
testing_utilities::GlobalString globalChollaRoot
This is the global variable to store the path to the root of Cholla.
Definition main_tests.cpp:21
A namespace for various testing related utility functions. Many of those functions will likely use th...
Definition testing_utilities.cpp:22
bool nearlyEqualDbl(double const &a, double const &b, double &absoluteDiff, int64_t &ulpsDiff, double const &fixedEpsilon, int64_t const &ulpsEpsilon)
Check if two doubles are nearly equal.
Definition testing_utilities.cpp:64
int64_t ulpsDistanceDbl(double const &a, double const &b)
Compute the Units in the Last Place (ULP) difference between two doubles.
Definition testing_utilities.cpp:24
void Check_Results(double fiducialNumber, double testNumber, std::string const &outString, double fixedEpsilon=-999, int64_t ulpsEpsilon=-999)
A simple function to compare two doubles with the nearlyEqualDbl function, perform a GTest assert on ...
Definition testing_utilities.h:124
void Check_Interface(reconstruction::InterfaceState const &test_data, reconstruction::InterfaceState const &fiducial_data, size_t const direction)
Function for checking if every member in a reconstruction::InterfaceState struct matches the fiducial...
Definition testing_utilities.h:201
__device__ __host__ T & x() noexcept
Directly access the x, y, and z elements. Const version is needed if the object instance is declared ...
Definition basic_structs.h:68
Definition basic_structs.h:165
Real pressure
Note that pressure here is the gas pressure not the total pressure which would include the magnetic c...
Definition basic_structs.h:169