diff --git a/tests/difffloat.py b/tests/difffloat.py index bbb7c95a1e77e04bbe21bec6dc6c5d529cd77c70..d4b48d54cbb9f292ed49b3cc142826cd1d71f87e 100644 --- a/tests/difffloat.py +++ b/tests/difffloat.py @@ -28,12 +28,18 @@ rel_tol = 1e-7 # Comparisons are done both in absolute and relative terms # Individual tolerances for each column can be provided in a file +# The (cube root of) the number of lines to check is provided as +# an optional 4th argument file1 = sys.argv[1] file2 = sys.argv[2] -fileTol = "" +number_to_check = -1 + +if len(sys.argv) == 5: + number_to_check = int(sys.argv[4]) -if len(sys.argv) == 4: +fileTol = "" +if len(sys.argv) >= 4: fileTol = sys.argv[3] data1 = loadtxt(file1) @@ -67,8 +73,17 @@ else: absTol = dataTol[0,:] relTol = dataTol[1,:] +n_lines_to_check = 0 +if number_to_check > 0: + n_lines_to_check = number_to_check**3 + n_lines_to_check = min(n_lines_to_check, n_lines) + print "Checking the first %d particles."%n_lines_to_check +else: + n_lines_to_check = n_lines + print "Checking all particles in the file." + error = False -for i in range(n_lines): +for i in range(n_lines_to_check): for j in range(n_columns): abs_diff = abs(data1[i,j] - data2[i,j]) @@ -80,7 +95,7 @@ for i in range(n_lines): rel_diff = 0. if( abs_diff > absTol[j]): - print "Absolute difference larger than tolerance (%e) on line %d, column %d:"%(absTol[j], i,j) + print "Absolute difference larger than tolerance (%e) for particle %d, column %d:"%(absTol[j], i,j) print "%10s: a = %e"%("File 1", data1[i,j]) print "%10s: b = %e"%("File 2", data2[i,j]) print "%10s: |a-b| = %e"%("Difference", abs_diff) @@ -88,7 +103,7 @@ for i in range(n_lines): error = True if( rel_diff > relTol[j]): - print "Relative difference larger than tolerance (%e) on line %d, column %d:"%(relTol[j], i,j) + print "Relative difference larger than tolerance (%e) for particle %d, column %d:"%(relTol[j], i,j) print "%10s: a = %e"%("File 1", data1[i,j]) print "%10s: b = %e"%("File 2", data2[i,j]) print "%10s: |a-b|/|a+b| = %e"%("Difference", rel_diff) diff --git a/tests/test27cells.sh b/tests/test27cells.sh index 09d2513bd3ef404c7bf434948af7f10306c98ede..0afdc32c95397ce76190e847bdcd04a0b079ef78 100755 --- a/tests/test27cells.sh +++ b/tests/test27cells.sh @@ -3,6 +3,6 @@ rm brute_force_27_standard.dat swift_dopair_27_standard.dat ./test27cells -p 6 -r 1 -d 0 -f standard -python difffloat.py brute_force_27_standard.dat swift_dopair_27_standard.dat tolerance.dat +python difffloat.py brute_force_27_standard.dat swift_dopair_27_standard.dat tolerance.dat 6 exit $? diff --git a/tests/test27cellsPerturbed.sh b/tests/test27cellsPerturbed.sh index 73d2933984d38f7dcc992f07ec2e016f3544b636..a553a2553e92cedee7c2c0679d231ec9d982fc28 100755 --- a/tests/test27cellsPerturbed.sh +++ b/tests/test27cellsPerturbed.sh @@ -3,6 +3,6 @@ rm brute_force_27_perturbed.dat swift_dopair_27_perturbed.dat ./test27cells -p 6 -r 1 -d 0.1 -f perturbed -python difffloat.py brute_force_27_perturbed.dat swift_dopair_27_perturbed.dat tolerance.dat +python difffloat.py brute_force_27_perturbed.dat swift_dopair_27_perturbed.dat tolerance.dat 6 exit $? diff --git a/tests/testPair.c b/tests/testPair.c index 23ce4eb3de460f4e17b7b6f81cb39a628f3d100f..6e46b577ca63a8d3c2edce888a7485af0949813d 100644 --- a/tests/testPair.c +++ b/tests/testPair.c @@ -180,7 +180,7 @@ void runner_dopair1_density(struct runner *r, struct cell *ci, struct cell *cj); int main(int argc, char *argv[]) { size_t particles = 0, runs = 0, volume, type = 0; double offset[3] = {0, 0, 0}, h = 1.1255, size = 1., rho = 1.; - double perturbation = 0.1; + double perturbation = 0.; struct cell *ci, *cj; struct space space; struct engine engine;