Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
Classes | Functions
testing_utilities Namespace Reference

A namespace for various testing related utility functions. Many of those functions will likely use the STL so this namespace should not be considered compatible with CUDA/HIP. More...

Classes

class  GlobalString
 Holds a single std::string that's intended to be read only and global. Use for storing the path of the root directory of Cholla. More...
 

Functions

int64_t ulpsDistanceDbl (double const &a, double const &b)
 Compute the Units in the Last Place (ULP) difference between two doubles.
 
bool nearlyEqualDbl (double const &a, double const &b, double &absoluteDiff, int64_t &ulpsDiff, double const &fixedEpsilon=1E-14, int64_t const &ulpsEpsilon=4)
 Check if two doubles are nearly equal.
 
void wrapperEqual (int i, int j, int k, std::string const &dataSetName, double test_value, double fid_value, double fixedEpsilon=5.0E-12)
 
void analyticConstant (system_test::SystemTestRunner testObject, std::string const &dataSetName, double value)
 
void analyticSine (system_test::SystemTestRunner testObject, std::string const &dataSetName, double constant, double amplitude, double kx, double ky, double kz, double phase, double tolerance)
 
template<int checkType = 0>
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 the result, and print out the values.
 
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 values.
 

Detailed Description

A namespace for various testing related utility functions. Many of those functions will likely use the STL so this namespace should not be considered compatible with CUDA/HIP.

Function Documentation

◆ Check_Interface()

void testing_utilities::Check_Interface ( reconstruction::InterfaceState const &  test_data,
reconstruction::InterfaceState const &  fiducial_data,
size_t const  direction 
)
inline

Function for checking if every member in a reconstruction::InterfaceState struct matches the fiducial values.

Parameters
[in]test_dataThe data to test
[in]fiducial_dataThe fiducial data
[in]directionWhat direction the test was run in.

◆ Check_Results()

template<int checkType = 0>
void testing_utilities::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 the result, and print out the values.

Template Parameters
checkTypeThe type of GTest assertion to use. "0" for and "EXPECT" and "1" for an "ASSERT"
Parameters
[in]fiducialNumberThe fiducial number to test against
[in]testNumberThe unverified number to test
[in]outStringA string to be printed in the first line of the output message. Format will be "Difference in outString"
[in]fixedEpsilonThe fixed epsilon to use in the comparison. Negative values are ignored and default behaviour is used
[in]ulpsEpsilonThe ULP epsilon to use in the comparison. Negative values are ignored and default behaviour is used

◆ nearlyEqualDbl()

bool testing_utilities::nearlyEqualDbl ( double const &  a,
double const &  b,
double &  absoluteDiff,
int64_t &  ulpsDiff,
double const &  fixedEpsilon = 1E-14,
int64_t const &  ulpsEpsilon = 4 
)

Check if two doubles are nearly equal.

This function checks if two doubles are "nearly equal" which is defined as either: A) the absolute difference between them is less than the fixedEpsilon argument or B) the units in the last place (ULP) difference is less than the ulpsEpsilon argument. Both of the epsilon arguments have default values which generally should not need to be changed.

Why does fixedEpsilon default to 1E-14? Running the Sod shock tube when Cholla was compiled with GCC 9.3.0 vs. XL 16.1.1-10 on Summit lead to absolute differences in the results up to 1.77636E-15. A priori we chose that a difference between two numbers that was less than one order of magnitude greater than the difference between compilers would be considered "equal". I.e. since the maximum absolute error between the GCC and XL compilers was ~1.7E-15 our allowed margin of error should be ~1E-14.

Why does ulpsEpsilon default to 4? Repeating the test above I computed the largest ULP difference that wasn't caught by the absolute difference requirement of 1E-14. It turns out that there were no uncaught differences at all so I kept ulpsEpsilon at 4 since that's the Googletest default for their floating point assertions

Parameters
[in]aThe first double you wish to compare. Order doesn't matter.
[in]bThe first double you wish to compare. Order doesn't matter.
[out]absoluteDiffThe absolute difference between the numbers. Only returned if the numbers are not equal. If the numbers are equal then behaviour is undefined
[out]ulpsDiffThe ULP difference between the numbers. Only returned if the numbers are not equal. If the numbers are equal then behaviour is undefined
[in]fixedEpsilonThe allowed difference in real numbers. Defaults to 1E-14
[in]ulpsEpsilonThe allowed difference of ULPs. Defaults to 4
Returns
bool Whether or not the numbers are equal

◆ ulpsDistanceDbl()

int64_t testing_utilities::ulpsDistanceDbl ( double const &  a,
double const &  b 
)

Compute the Units in the Last Place (ULP) difference between two doubles.

This function is modified from Comparing Floating-Point Numbers Is Tricky by Matt Kline which is in turn based on Comparing Floating Point Numbers, 2012 Edition by Bruce Dawson. The latter seems to be the bible of floating point comparison and is the basis of Googletests ASSERT_DOUBLE_EQ assertion.

This particular function checks that the two numbers if the numbers are perfectly equal, +0, -0, Nan, inf, or differently signed then it computes the ULP difference between them are returns it

Parameters
[in]aThe first double you wish to compare. Order doesn't matter.
[in]bThe second double you wish to compare. Order doesn't matter.
Returns
int64_t The ULP distance between a and b.