Tinker9 70bd052 (Thu Nov 9 12:11:35 2023 -0800)
Loading...
Searching...
No Matches
Classes | Macros | Functions
Unit Tests

Classes

class  tinker::TestFile
 Writes a file to disk in its constructor and removes the file in its destructor, unless the file is set to be kept. More...
 
class  tinker::TestRemoveFileOnExit
 Removes the file in its destructor as necessary. More...
 
class  tinker::TestReference
 Reads reference values from a text file. More...
 

Macros

#define COMPARE_INTS(i1, refi)   REQUIRE(i1 == refi)
 Compares two integers. More...
 
#define COMPARE_INTS_EPS(i1, refi, epsi)
 Approximately compares two integers. More...
 
#define COMPARE_REALS(v1, refv, eps)   REQUIRE(v1 == Approx(refv).margin(eps))
 Compares two floating-point numbers with a margin of error. More...
 
#define COMPARE_ENERGY(gpuptr, ref_eng, eps)
 Reduces the energy from the energy buffer and compares to the reference value with a margin of error. More...
 
#define COMPARE_COUNT(gpuptr, ref_count)
 Reduces the number of interactions from the count buffer and compares to the reference value. More...
 
#define COMPARE_VIR9(vir1, ref_v, eps)
 Compares a virial tensor to the reference values with a margin of error. More...
 
#define COMPARE_VIR(gpuptr, ref_v, eps)
 Reduces a virial tensor from a virial buffer and compares to the reference values with a margin of error. More...
 
#define COMPARE_VIR2(gpuptr, gpuptr2, ref_v, eps)
 Reduces two virial tensors from two virial buffers and compares the sum to the reference with a margin of error. More...
 
#define COMPARE_GRADIENT(ref_grad, eps)   COMPARE_GRADIENT2(ref_grad, eps, [](int, int) { return true; })
 Copies out gradients from device to host and compares to the reference values with a margin of error. More...
 
#define COMPARE_GRADIENT2(ref_grad, eps, check_ij)
 Compares the flitered gradients[i][j] components. More...
 

Functions

double tinker::testGetEps (double epsSingle, double epsDouble)
 Returns tolerance eps depending on the predefined floating-point precision. More...
 
void tinker::testBeginWithArgs (int argc, const char **argv)
 Initializes the test. More...
 
void tinker::testEnd ()
 Ends the test. More...
 
void tinker::testMdInit (double t=0, double atm=0)
 Initializes MD in the test. More...
 

Detailed Description


Class Documentation

◆ tinker::TestFile

class tinker::TestFile

Writes a file to disk in its constructor and removes the file in its destructor, unless the file is set to be kept.

Public Member Functions

 TestFile (std::string src, std::string dst="", std::string extra="")
 Copies file from source to destination with optional extra content appended to the new copy. More...
 
 ~TestFile ()
 Removes the file on disk on exit. More...
 
void __keep ()
 Prevents the file from being deleted. More...
 

Constructor & Destructor Documentation

◆ TestFile()

tinker::TestFile::TestFile ( std::string  src,
std::string  dst = "",
std::string  extra = "" 
)

Copies file from source to destination with optional extra content appended to the new copy.

Parameters
srcPath to the source file. If empty, extra will be written to dst which must be a valid path for the new file.
dstPath to the new file. If empty, the source file is copied to the current working directory.
extraOptional extra content.

◆ ~TestFile()

tinker::TestFile::~TestFile ( )

Removes the file on disk on exit.

Member Function Documentation

◆ __keep()

void tinker::TestFile::__keep ( )

Prevents the file from being deleted.

◆ tinker::TestRemoveFileOnExit

class tinker::TestRemoveFileOnExit

Removes the file in its destructor as necessary.

Public Member Functions

 TestRemoveFileOnExit (std::string fileToDelete)
 Filename. More...
 
 ~TestRemoveFileOnExit ()
 Removes the file in the destructor. More...
 

Constructor & Destructor Documentation

◆ TestRemoveFileOnExit()

tinker::TestRemoveFileOnExit::TestRemoveFileOnExit ( std::string  fileToDelete)

Filename.

◆ ~TestRemoveFileOnExit()

tinker::TestRemoveFileOnExit::~TestRemoveFileOnExit ( )

Removes the file in the destructor.

◆ tinker::TestReference

class tinker::TestReference

Reads reference values from a text file.

Public Member Functions

 ~TestReference ()
 
 TestReference (std::string pathToRefFile)
 
int getCount () const
 
double getEnergy () const
 
const double(* getVirial () const)[3]
 
const double(* getGradient () const)[3]
 
void getEnergyCountByName (std::string name, double &energy, int &count)
 

Constructor & Destructor Documentation

◆ ~TestReference()

tinker::TestReference::~TestReference ( )

◆ TestReference()

tinker::TestReference::TestReference ( std::string  pathToRefFile)

Member Function Documentation

◆ getCount()

int tinker::TestReference::getCount ( ) const

◆ getEnergy()

double tinker::TestReference::getEnergy ( ) const

◆ getEnergyCountByName()

void tinker::TestReference::getEnergyCountByName ( std::string  name,
double &  energy,
int &  count 
)

◆ getGradient()

const double(* tinker::TestReference::getGradient ( ) )[3] const

◆ getVirial()

const double(* tinker::TestReference::getVirial ( ) )[3] const

Macro Definition Documentation

◆ COMPARE_COUNT

#define COMPARE_COUNT (   gpuptr,
  ref_count 
)
Value:
{ \
int count = countReduce(gpuptr); \
REQUIRE(count == ref_count); \
}

Reduces the number of interactions from the count buffer and compares to the reference value.

◆ COMPARE_ENERGY

#define COMPARE_ENERGY (   gpuptr,
  ref_eng,
  eps 
)
Value:
{ \
double eng = energyReduce(gpuptr); \
REQUIRE(eng == Approx(ref_eng).margin(eps)); \
}

Reduces the energy from the energy buffer and compares to the reference value with a margin of error.

◆ COMPARE_GRADIENT

#define COMPARE_GRADIENT (   ref_grad,
  eps 
)    COMPARE_GRADIENT2(ref_grad, eps, [](int, int) { return true; })

Copies out gradients from device to host and compares to the reference values with a margin of error.

◆ COMPARE_GRADIENT2

#define COMPARE_GRADIENT2 (   ref_grad,
  eps,
  check_ij 
)
Value:
{ \
std::vector<double> gradx(n), grady(n), gradz(n); \
copyGradient(calc::grad, gradx.data(), grady.data(), gradz.data()); \
for (int i = 0; i < n; ++i) { \
if (check_ij(i, 0)) REQUIRE(gradx[i] == Approx(ref_grad[i][0]).margin(eps)); \
if (check_ij(i, 1)) REQUIRE(grady[i] == Approx(ref_grad[i][1]).margin(eps)); \
if (check_ij(i, 2)) REQUIRE(gradz[i] == Approx(ref_grad[i][2]).margin(eps)); \
} \
}

Compares the flitered gradients[i][j] components.

◆ COMPARE_INTS

#define COMPARE_INTS (   i1,
  refi 
)    REQUIRE(i1 == refi)

Compares two integers.

◆ COMPARE_INTS_EPS

#define COMPARE_INTS_EPS (   i1,
  refi,
  epsi 
)
Value:
{ \
int c1 = i1; \
int r1 = refi; \
REQUIRE(r1 - epsi <= c1); \
REQUIRE(c1 <= r1 + epsi); \
}

Approximately compares two integers.

◆ COMPARE_REALS

#define COMPARE_REALS (   v1,
  refv,
  eps 
)    REQUIRE(v1 == Approx(refv).margin(eps))

Compares two floating-point numbers with a margin of error.

◆ COMPARE_VIR

#define COMPARE_VIR (   gpuptr,
  ref_v,
  eps 
)
Value:
{ \
virial_prec vir1[9]; \
virialReduce(vir1, gpuptr); \
REQUIRE(vir1[0] == Approx(ref_v[0][0]).margin(eps)); \
REQUIRE(vir1[1] == Approx(ref_v[0][1]).margin(eps)); \
REQUIRE(vir1[2] == Approx(ref_v[0][2]).margin(eps)); \
REQUIRE(vir1[3] == Approx(ref_v[1][0]).margin(eps)); \
REQUIRE(vir1[4] == Approx(ref_v[1][1]).margin(eps)); \
REQUIRE(vir1[5] == Approx(ref_v[1][2]).margin(eps)); \
REQUIRE(vir1[6] == Approx(ref_v[2][0]).margin(eps)); \
REQUIRE(vir1[7] == Approx(ref_v[2][1]).margin(eps)); \
REQUIRE(vir1[8] == Approx(ref_v[2][2]).margin(eps)); \
}

Reduces a virial tensor from a virial buffer and compares to the reference values with a margin of error.

◆ COMPARE_VIR2

#define COMPARE_VIR2 (   gpuptr,
  gpuptr2,
  ref_v,
  eps 
)
Value:
{ \
virial_prec vir1[9], vir2[9]; \
virialReduce(vir1, gpuptr); \
virialReduce(vir2, gpuptr2); \
REQUIRE(vir1[0] + vir2[0] == Approx(ref_v[0][0]).margin(eps)); \
REQUIRE(vir1[1] + vir2[1] == Approx(ref_v[0][1]).margin(eps)); \
REQUIRE(vir1[2] + vir2[2] == Approx(ref_v[0][2]).margin(eps)); \
REQUIRE(vir1[3] + vir2[3] == Approx(ref_v[1][0]).margin(eps)); \
REQUIRE(vir1[4] + vir2[4] == Approx(ref_v[1][1]).margin(eps)); \
REQUIRE(vir1[5] + vir2[5] == Approx(ref_v[1][2]).margin(eps)); \
REQUIRE(vir1[6] + vir2[6] == Approx(ref_v[2][0]).margin(eps)); \
REQUIRE(vir1[7] + vir2[7] == Approx(ref_v[2][1]).margin(eps)); \
REQUIRE(vir1[8] + vir2[8] == Approx(ref_v[2][2]).margin(eps)); \
}

Reduces two virial tensors from two virial buffers and compares the sum to the reference with a margin of error.

◆ COMPARE_VIR9

#define COMPARE_VIR9 (   vir1,
  ref_v,
  eps 
)
Value:
{ \
REQUIRE(vir1[0] == Approx(ref_v[0][0]).margin(eps)); \
REQUIRE(vir1[1] == Approx(ref_v[0][1]).margin(eps)); \
REQUIRE(vir1[2] == Approx(ref_v[0][2]).margin(eps)); \
REQUIRE(vir1[3] == Approx(ref_v[1][0]).margin(eps)); \
REQUIRE(vir1[4] == Approx(ref_v[1][1]).margin(eps)); \
REQUIRE(vir1[5] == Approx(ref_v[1][2]).margin(eps)); \
REQUIRE(vir1[6] == Approx(ref_v[2][0]).margin(eps)); \
REQUIRE(vir1[7] == Approx(ref_v[2][1]).margin(eps)); \
REQUIRE(vir1[8] == Approx(ref_v[2][2]).margin(eps)); \
}

Compares a virial tensor to the reference values with a margin of error.

Function Documentation

◆ testBeginWithArgs()

void tinker::testBeginWithArgs ( int  argc,
const char **  argv 
)

Initializes the test.

◆ testEnd()

void tinker::testEnd ( )

Ends the test.

◆ testGetEps()

double tinker::testGetEps ( double  epsSingle,
double  epsDouble 
)

Returns tolerance eps depending on the predefined floating-point precision.

Parameters
epsSingleLarger eps value for lower floating-point precision.
epsDoubleSmaller eps value for higher floating-point precision.

◆ testMdInit()

void tinker::testMdInit ( double  t = 0,
double  atm = 0 
)

Initializes MD in the test.

Parameters
tTemperature in Kelvin.
atmAtmosphere in atm.