Tinker9 70bd052 (Thu Nov 9 12:11:35 2023 -0800)
Loading...
Searching...
No Matches
testrt.h
1#pragma once
2#include "ff/energy.h"
3
4#include "tinker9.h"
5
6#include <string>
7#include <vector>
8
9namespace tinker {
12
15{
16private:
17 std::string name;
18 bool good;
19
20public:
21 TestFile(std::string src,
23 std::string dst = "",
24 std::string extra = ""
25 );
27 void __keep();
28};
29
32{
33private:
34 std::string m_name;
35
36public:
37 TestRemoveFileOnExit(std::string fileToDelete);
39};
40
43{
44private:
45 class Impl;
46 Impl* pimpl;
47
48public:
50 TestReference(std::string pathToRefFile);
51 int getCount() const;
52 double getEnergy() const;
53 const double (*getVirial() const)[3];
54 const double (*getGradient() const)[3];
55 void getEnergyCountByName(std::string name, double& energy, int& count);
56};
57
59double testGetEps(double epsSingle,
60 double epsDouble
61);
62
64void testBeginWithArgs(int argc, const char** argv);
65
67void testEnd();
68
70void testMdInit(double t = 0,
71 double atm = 0
72);
73
75}
76
79
94#define COMPARE_INTS(i1, refi) REQUIRE(i1 == refi)
95#define COMPARE_INTS_EPS(i1, refi, epsi) \
96 { \
97 int c1 = i1; \
98 int r1 = refi; \
99 REQUIRE(r1 - epsi <= c1); \
100 REQUIRE(c1 <= r1 + epsi); \
101 }
102#define COMPARE_REALS(v1, refv, eps) REQUIRE(v1 == Approx(refv).margin(eps))
103#define COMPARE_ENERGY(gpuptr, ref_eng, eps) \
104 { \
105 double eng = energyReduce(gpuptr); \
106 REQUIRE(eng == Approx(ref_eng).margin(eps)); \
107 }
108#define COMPARE_COUNT(gpuptr, ref_count) \
109 { \
110 int count = countReduce(gpuptr); \
111 REQUIRE(count == ref_count); \
112 }
113
122#define COMPARE_VIR9(vir1, ref_v, eps) \
123 { \
124 REQUIRE(vir1[0] == Approx(ref_v[0][0]).margin(eps)); \
125 REQUIRE(vir1[1] == Approx(ref_v[0][1]).margin(eps)); \
126 REQUIRE(vir1[2] == Approx(ref_v[0][2]).margin(eps)); \
127 REQUIRE(vir1[3] == Approx(ref_v[1][0]).margin(eps)); \
128 REQUIRE(vir1[4] == Approx(ref_v[1][1]).margin(eps)); \
129 REQUIRE(vir1[5] == Approx(ref_v[1][2]).margin(eps)); \
130 REQUIRE(vir1[6] == Approx(ref_v[2][0]).margin(eps)); \
131 REQUIRE(vir1[7] == Approx(ref_v[2][1]).margin(eps)); \
132 REQUIRE(vir1[8] == Approx(ref_v[2][2]).margin(eps)); \
133 }
134#define COMPARE_VIR(gpuptr, ref_v, eps) \
135 { \
136 virial_prec vir1[9]; \
137 virialReduce(vir1, gpuptr); \
138 REQUIRE(vir1[0] == Approx(ref_v[0][0]).margin(eps)); \
139 REQUIRE(vir1[1] == Approx(ref_v[0][1]).margin(eps)); \
140 REQUIRE(vir1[2] == Approx(ref_v[0][2]).margin(eps)); \
141 REQUIRE(vir1[3] == Approx(ref_v[1][0]).margin(eps)); \
142 REQUIRE(vir1[4] == Approx(ref_v[1][1]).margin(eps)); \
143 REQUIRE(vir1[5] == Approx(ref_v[1][2]).margin(eps)); \
144 REQUIRE(vir1[6] == Approx(ref_v[2][0]).margin(eps)); \
145 REQUIRE(vir1[7] == Approx(ref_v[2][1]).margin(eps)); \
146 REQUIRE(vir1[8] == Approx(ref_v[2][2]).margin(eps)); \
147 }
148#define COMPARE_VIR2(gpuptr, gpuptr2, ref_v, eps) \
149 { \
150 virial_prec vir1[9], vir2[9]; \
151 virialReduce(vir1, gpuptr); \
152 virialReduce(vir2, gpuptr2); \
153 REQUIRE(vir1[0] + vir2[0] == Approx(ref_v[0][0]).margin(eps)); \
154 REQUIRE(vir1[1] + vir2[1] == Approx(ref_v[0][1]).margin(eps)); \
155 REQUIRE(vir1[2] + vir2[2] == Approx(ref_v[0][2]).margin(eps)); \
156 REQUIRE(vir1[3] + vir2[3] == Approx(ref_v[1][0]).margin(eps)); \
157 REQUIRE(vir1[4] + vir2[4] == Approx(ref_v[1][1]).margin(eps)); \
158 REQUIRE(vir1[5] + vir2[5] == Approx(ref_v[1][2]).margin(eps)); \
159 REQUIRE(vir1[6] + vir2[6] == Approx(ref_v[2][0]).margin(eps)); \
160 REQUIRE(vir1[7] + vir2[7] == Approx(ref_v[2][1]).margin(eps)); \
161 REQUIRE(vir1[8] + vir2[8] == Approx(ref_v[2][2]).margin(eps)); \
162 }
163
169#define COMPARE_GRADIENT2(ref_grad, eps, check_ij) \
170 { \
171 std::vector<double> gradx(n), grady(n), gradz(n); \
172 copyGradient(calc::grad, gradx.data(), grady.data(), gradz.data()); \
173 for (int i = 0; i < n; ++i) { \
174 if (check_ij(i, 0)) REQUIRE(gradx[i] == Approx(ref_grad[i][0]).margin(eps)); \
175 if (check_ij(i, 1)) REQUIRE(grady[i] == Approx(ref_grad[i][1]).margin(eps)); \
176 if (check_ij(i, 2)) REQUIRE(gradz[i] == Approx(ref_grad[i][2]).margin(eps)); \
177 } \
178 }
179#define COMPARE_GRADIENT(ref_grad, eps) COMPARE_GRADIENT2(ref_grad, eps, [](int, int) { return true; })
void energy(int vers)
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.
~TestRemoveFileOnExit()
Removes the file in the destructor.
void getEnergyCountByName(std::string name, double &energy, int &count)
double getEnergy() const
TestRemoveFileOnExit(std::string fileToDelete)
Filename.
const double(* getGradient() const)[3]
TestReference(std::string pathToRefFile)
void __keep()
Prevents the file from being deleted.
const double(* getVirial() const)[3]
~TestFile()
Removes the file on disk on exit.
Writes a file to disk in its constructor and removes the file in its destructor, unless the file is s...
Definition: testrt.h:15
Reads reference values from a text file.
Definition: testrt.h:43
Removes the file in its destructor as necessary.
Definition: testrt.h:32
void testBeginWithArgs(int argc, const char **argv)
Initializes the test.
double testGetEps(double epsSingle, double epsDouble)
Returns tolerance eps depending on the predefined floating-point precision.
void testEnd()
Ends the test.
void testMdInit(double t=0, double atm=0)
Initializes MD in the test.
Definition: testrt.h:9