Commit d6ab77d4 authored by Matthieu Schaller's avatar Matthieu Schaller

Adapted the diffing script for various tolerance levels in each column

parent 362716ac
......@@ -45,4 +45,4 @@ test27cells_SOURCES = test27cells.c
# Files necessary for distribution
EXTRA_DIST = testReading.sh makeInput.py testPair.sh testPairPerturbed.sh \
test27cells.sh test27cellsPerturbed.sh
test27cells.sh test27cellsPerturbed.sh tolerance.dat
......@@ -25,20 +25,24 @@ rel_tol = 1e-7
# Compares the content of two ASCII tables of floats line by line and
# reports all differences beyond the given tolerances
# Comparisons are done both in absolute and relative values
# Comparisons are done both in absolute and relative terms
# Individual tolerances for each column can be provided in a file
file1 = sys.argv[1]
file2 = sys.argv[2]
fileTol = ""
if len(sys.argv) >= 5:
abs_tol = float(sys.argv[3])
rel_tol = float(sys.argv[4])
if len(sys.argv) == 4:
fileTol = sys.argv[3]
print "Absolute difference tolerance:", abs_tol
print "Relative difference tolerance:", rel_tol
data1 = loadtxt(file1)
data2 = loadtxt(file2)
if fileTol != "":
dataTol = loadtxt(fileTol)
n_linesTol = shape(dataTol)[0]
n_columnsTol = shape(dataTol)[1]
if shape(data1) != shape(data2):
print "Non-matching array sizes in the files", file1, "and", file2, "."
......@@ -47,6 +51,22 @@ if shape(data1) != shape(data2):
n_lines = shape(data1)[0]
n_columns = shape(data1)[1]
if fileTol != "":
if n_linesTol != 2:
print "Incorrect number of lines in tolerance file '%s'."%fileTol
if n_columnsTol != n_columns:
print "Incorrect number of columns in tolerance file '%s'."%fileTol
if fileTol == "":
print "Absolute difference tolerance:", abs_tol
print "Relative difference tolerance:", rel_tol
absTol = ones(n_columns) * abs_tol
relTol = ones(n_columns) * rel_tol
else:
print "Tolerances read from file"
absTol = dataTol[0,:]
relTol = dataTol[1,:]
error = False
for i in range(n_lines):
for j in range(n_columns):
......@@ -58,17 +78,17 @@ for i in range(n_lines):
rel_diff = abs(data1[i,j] - data2[i,j]) / sum
else:
rel_diff = 0.
if( abs_diff > abs_tol):
print "Absolute difference larger than tolerance (%e) on line %d, column %d:"%(abs_tol, i,j)
if( abs_diff > absTol[j]):
print "Absolute difference larger than tolerance (%e) on line %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)
print ""
error = True
if( rel_diff > rel_tol):
print "Relative difference larger than tolerance (%e) on line %d, column %d:"%(rel_tol, i,j)
if( rel_diff > relTol[j]):
print "Relative difference larger than tolerance (%e) on line %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)
......
......@@ -138,8 +138,8 @@ void dump_particle_fields(char *fileName, struct cell *main_cell,
/* Write header */
fprintf(file,
"# %4s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s "
"%10s %10s %10s\n",
"# %4s %10s %10s %10s %10s %10s %10s %13s %13s %13s %13s %13s "
"%13s %13s %13s\n",
"ID", "pos_x", "pos_y", "pos_z", "v_x", "v_y", "v_z", "rho", "rho_dh",
"wcount", "wcount_dh", "div_v", "curl_vx", "curl_vy", "curl_vz");
......@@ -148,8 +148,8 @@ void dump_particle_fields(char *fileName, struct cell *main_cell,
/* Write main cell */
for (size_t pid = 0; pid < main_cell->count; pid++) {
fprintf(file,
"%6llu %10f %10f %10f %10f %10f %10f %10f %10f %10f %10f %10f "
"%10f %10f %10f\n",
"%6llu %10f %10f %10f %10f %10f %10f %13e %13e %13e %13e %13e "
"%13e %13e %13e\n",
main_cell->parts[pid].id, main_cell->parts[pid].x[0],
main_cell->parts[pid].x[1], main_cell->parts[pid].x[2],
main_cell->parts[pid].v[0], main_cell->parts[pid].v[1],
......@@ -176,8 +176,8 @@ void dump_particle_fields(char *fileName, struct cell *main_cell,
for (size_t pjd = 0; pjd < cj->count; pjd++) {
fprintf(
file,
"%6llu %10f %10f %10f %10f %10f %10f %10f %10f %10f %10f %10f "
"%10f %10f %10f\n",
"%6llu %10f %10f %10f %10f %10f %10f %13e %13e %13e %13e %13e "
"%13e %13e %13e\n",
cj->parts[pjd].id, cj->parts[pjd].x[0], cj->parts[pjd].x[1],
cj->parts[pjd].x[2], cj->parts[pjd].v[0], cj->parts[pjd].v[1],
cj->parts[pjd].v[2], cj->parts[pjd].rho, cj->parts[pjd].rho_dh,
......
......@@ -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 1e-5 5e-6
python difffloat.py brute_force_27_standard.dat swift_dopair_27_standard.dat tolerance.dat
exit $?
......@@ -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 1e-5 5e-6
python difffloat.py brute_force_27_perturbed.dat swift_dopair_27_perturbed.dat tolerance.dat
exit $?
......@@ -35,7 +35,8 @@ double random_uniform(double a, double b) {
* particles are generated on a mesh with unit spacing
*/
struct cell *make_cell(size_t n, double *offset, double size, double h,
double density, unsigned long long *partId, double pert) {
double density, unsigned long long *partId,
double pert) {
const size_t count = n * n * n;
const double volume = size * size * size;
struct cell *cell = malloc(sizeof(struct cell));
......@@ -64,7 +65,7 @@ struct cell *make_cell(size_t n, double *offset, double size, double h,
// part->v[0] = part->x[0] - 1.5;
// part->v[1] = part->x[1] - 1.5;
// part->v[2] = part->x[2] - 1.5;
part->v[0] = random_uniform(-0.05, 0.05);
part->v[0] = random_uniform(-0.05, 0.05);
part->v[1] = random_uniform(-0.05, 0.05);
part->v[2] = random_uniform(-0.05, 0.05);
part->h = size * h / (float)n;
......@@ -127,8 +128,8 @@ void dump_particle_fields(char *fileName, struct cell *ci, struct cell *cj) {
/* Write header */
fprintf(file,
"# %4s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s "
"%10s %10s %10s\n",
"# %4s %10s %10s %10s %10s %10s %10s %13s %13s %13s %13s %13s "
"%13s %13s %13s\n",
"ID", "pos_x", "pos_y", "pos_z", "v_x", "v_y", "v_z", "rho", "rho_dh",
"wcount", "wcount_dh", "div_v", "curl_vx", "curl_vy", "curl_vz");
......@@ -136,34 +137,28 @@ void dump_particle_fields(char *fileName, struct cell *ci, struct cell *cj) {
for (size_t pid = 0; pid < ci->count; pid++) {
fprintf(file,
"%6llu %10f %10f %10f %10f %10f %10f %10f %10f %10f %10f %10f "
"%10f %10f %10f\n",
ci->parts[pid].id, ci->parts[pid].x[0],
ci->parts[pid].x[1], ci->parts[pid].x[2],
ci->parts[pid].v[0], ci->parts[pid].v[1],
ci->parts[pid].v[2], ci->parts[pid].rho,
ci->parts[pid].rho_dh, ci->parts[pid].density.wcount,
ci->parts[pid].density.wcount_dh,
"%6llu %10f %10f %10f %10f %10f %10f %13e %13e %13e %13e %13e "
"%13e %13e %13e\n",
ci->parts[pid].id, ci->parts[pid].x[0], ci->parts[pid].x[1],
ci->parts[pid].x[2], ci->parts[pid].v[0], ci->parts[pid].v[1],
ci->parts[pid].v[2], ci->parts[pid].rho, ci->parts[pid].rho_dh,
ci->parts[pid].density.wcount, ci->parts[pid].density.wcount_dh,
ci->parts[pid].div_v, ci->parts[pid].density.rot_v[0],
ci->parts[pid].density.rot_v[1],
ci->parts[pid].density.rot_v[2]);
ci->parts[pid].density.rot_v[1], ci->parts[pid].density.rot_v[2]);
}
fprintf(file, "# cj --------------------------------------------\n");
for (size_t pjd = 0; pjd < cj->count; pjd++) {
fprintf(file,
"%6llu %10f %10f %10f %10f %10f %10f %10f %10f %10f %10f %10f "
"%10f %10f %10f\n",
cj->parts[pjd].id, cj->parts[pjd].x[0],
cj->parts[pjd].x[1], cj->parts[pjd].x[2],
cj->parts[pjd].v[0], cj->parts[pjd].v[1],
cj->parts[pjd].v[2], cj->parts[pjd].rho,
cj->parts[pjd].rho_dh, cj->parts[pjd].density.wcount,
cj->parts[pjd].density.wcount_dh,
"%6llu %10f %10f %10f %10f %10f %10f %13e %13e %13e %13e %13e "
"%13e %13e %13e\n",
cj->parts[pjd].id, cj->parts[pjd].x[0], cj->parts[pjd].x[1],
cj->parts[pjd].x[2], cj->parts[pjd].v[0], cj->parts[pjd].v[1],
cj->parts[pjd].v[2], cj->parts[pjd].rho, cj->parts[pjd].rho_dh,
cj->parts[pjd].density.wcount, cj->parts[pjd].density.wcount_dh,
cj->parts[pjd].div_v, cj->parts[pjd].density.rot_v[0],
cj->parts[pjd].density.rot_v[1],
cj->parts[pjd].density.rot_v[2]);
cj->parts[pjd].density.rot_v[1], cj->parts[pjd].density.rot_v[2]);
}
fclose(file);
......
......@@ -3,6 +3,6 @@ rm brute_force_standard.dat swift_dopair_standard.dat
./testPair -p 6 -r 1 -d 0 -f standard
python difffloat.py brute_force_standard.dat swift_dopair_standard.dat 1e-5 5e-6
python difffloat.py brute_force_standard.dat swift_dopair_standard.dat tolerance.dat
exit $?
......@@ -3,6 +3,6 @@ rm brute_force_perturbed.dat swift_dopair_perturbed.dat
./testPair -p 6 -r 1 -d 0.1 -f perturbed
python difffloat.py brute_force_perturbed.dat swift_dopair_perturbed.dat 1e-5 5e-6
python difffloat.py brute_force_perturbed.dat swift_dopair_perturbed.dat tolerance.dat
exit $?
# ID pos_x pos_y pos_z v_x v_y v_z rho rho_dh wcount wcount_dh div_v curl_vx curl_vy curl_vz
0 1e-6 1e-6 1e-6 1e-6 1e-6 1e-6 1e-5 1e-5 2e-5 3e-4 1e-5 1e-5 1e-5 1e-5
0 1e-6 1e-6 1e-6 1e-6 1e-6 1e-6 1e-5 1e-5 1e-5 1e-5 1e-4 1e-4 1e-4 1e-4
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment