From 2b171049f35aa17887545f849d3ac8767ab930e2 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Wed, 17 May 2017 15:02:36 +0100
Subject: [PATCH] Updated the scripts running the tests to actually crash if
 they fail at any iteration and not just on the last one. Code formatting. Do
 not compile the FFT functions if FFTW is not found.

---
 src/engine.c                      | 10 +++++-----
 src/runner_doiact_fft.c           |  4 ++++
 src/space.c                       | 24 ++++++++++++------------
 tests/difffloat.py                |  2 +-
 tests/test125cells.c              |  2 ++
 tests/test125cells.sh.in          | 12 +++++++++++-
 tests/test125cellsPerturbed.sh.in | 12 +++++++++++-
 tests/test27cells.sh.in           | 14 ++++++++++++--
 tests/test27cellsPerturbed.sh.in  | 12 +++++++++++-
 tests/tolerance_125_perturbed.dat |  2 +-
 tests/tolerance_27_perturbed.dat  |  4 ++--
 11 files changed, 72 insertions(+), 26 deletions(-)

diff --git a/src/engine.c b/src/engine.c
index 295fdb824b..28b1d4b2e8 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -1669,10 +1669,10 @@ void engine_make_self_gravity_tasks(struct engine *e) {
 
     /* Make the ghosts implicit and add the dependencies */
     for (int n = 0; n < n_ghosts / 2; ++n) {
-      ghosts[2 * n + 0] = scheduler_addtask(sched, task_type_grav_ghost,
-                                            task_subtype_none, 0, 0, NULL, NULL);
-      ghosts[2 * n + 1] = scheduler_addtask(sched, task_type_grav_ghost,
-                                            task_subtype_none, 0, 0, NULL, NULL);
+      ghosts[2 * n + 0] = scheduler_addtask(
+          sched, task_type_grav_ghost, task_subtype_none, 0, 0, NULL, NULL);
+      ghosts[2 * n + 1] = scheduler_addtask(
+          sched, task_type_grav_ghost, task_subtype_none, 0, 0, NULL, NULL);
       ghosts[2 * n + 0]->implicit = 1;
       ghosts[2 * n + 1]->implicit = 1;
       scheduler_addunlock(sched, ghosts[2 * n + 0], s->grav_top_level);
@@ -3063,7 +3063,7 @@ void engine_print_stats(struct engine *e) {
                           e->policy & engine_policy_self_gravity);
 
   /* Be verbose about this */
-  if(e->nodeID == 0) message("Saving statistics at t=%e.", e->time);
+  if (e->nodeID == 0) message("Saving statistics at t=%e.", e->time);
 #else
   if (e->verbose) message("Saving statistics at t=%e.", e->time);
 #endif
diff --git a/src/runner_doiact_fft.c b/src/runner_doiact_fft.c
index 01ccb3446d..a3e3f38fba 100644
--- a/src/runner_doiact_fft.c
+++ b/src/runner_doiact_fft.c
@@ -37,6 +37,8 @@
 #include "space.h"
 #include "timers.h"
 
+#ifdef HAVE_FFTW
+
 /**
  * @brief Returns 1D index of a 3D NxNxN array using row-major style.
  *
@@ -137,6 +139,8 @@ __attribute__((always_inline)) INLINE static void mesh_to_multipole_CIC(
   m->pot.F_000 += pot[row_major_id(i + 1, j + 1, k + 1, N)] * dx * dy * dz;
 }
 
+#endif
+
 /**
  * @brief Computes the potential on the top multipoles using a Fourier transform
  *
diff --git a/src/space.c b/src/space.c
index 9cb7e5f961..b1612876b6 100644
--- a/src/space.c
+++ b/src/space.c
@@ -2432,19 +2432,20 @@ void space_getcells(struct space *s, int nr_cells, struct cell **cells) {
 }
 
 void space_synchronize_particle_positions_mapper(void *map_data, int nr_gparts,
-						 void *extra_data) {
+                                                 void *extra_data) {
   /* Unpack the data */
   struct gpart *restrict gparts = (struct gpart *)map_data;
-  struct space *s = (struct space*) extra_data;
+  struct space *s = (struct space *)extra_data;
 
   for (int k = 0; k < nr_gparts; k++) {
 
     /* Get the particle */
     const struct gpart *restrict gp = &gparts[k];
 
-    if(gp->type == swift_type_dark_matter) continue;
-    
-    else if(gp->type == swift_type_gas) {
+    if (gp->type == swift_type_dark_matter)
+      continue;
+
+    else if (gp->type == swift_type_gas) {
 
       /* Get it's gassy friend */
       struct part *p = &s->parts[-gp->id_or_neg_offset];
@@ -2460,7 +2461,7 @@ void space_synchronize_particle_positions_mapper(void *map_data, int nr_gparts,
       xp->v_full[2] = gp->v_full[2];
     }
 
-    else if(gp->type == swift_type_star) {
+    else if (gp->type == swift_type_star) {
 
       /* Get it's stellar friend */
       struct spart *sp = &s->sparts[-gp->id_or_neg_offset];
@@ -2470,17 +2471,16 @@ void space_synchronize_particle_positions_mapper(void *map_data, int nr_gparts,
       sp->x[1] = gp->x[1];
       sp->x[2] = gp->x[2];
     }
-
   }
 }
 
-
 void space_synchronize_particle_positions(struct space *s) {
 
-  if ((s->nr_gparts > 0 && s->nr_parts > 0) || 
-      (s->nr_gparts > 0 && s->nr_sparts > 0))  
-    threadpool_map(&s->e->threadpool, space_synchronize_particle_positions_mapper, 
-		   s->gparts, s->nr_gparts, sizeof(struct gpart), 1000, (void*)s);
+  if ((s->nr_gparts > 0 && s->nr_parts > 0) ||
+      (s->nr_gparts > 0 && s->nr_sparts > 0))
+    threadpool_map(&s->e->threadpool,
+                   space_synchronize_particle_positions_mapper, s->gparts,
+                   s->nr_gparts, sizeof(struct gpart), 1000, (void *)s);
 }
 
 /**
diff --git a/tests/difffloat.py b/tests/difffloat.py
index f989ccb56f..0bdc706a1c 100644
--- a/tests/difffloat.py
+++ b/tests/difffloat.py
@@ -107,7 +107,7 @@ for i in range(n_lines_to_check):
             print ""
             error = True
 
-        if abs(data1[i,j]) + abs(data2[i,j]) < 1e-6 : continue
+        if abs(data1[i,j]) < 4e-6 and abs(data2[i,j]) < 4e-6 : continue
 
         # Ignore pathological cases with rho_dh
         if ignoreSmallRhoDh and j == 8 and abs(data1[i,j]) < 2e-4: continue
diff --git a/tests/test125cells.c b/tests/test125cells.c
index b424187b74..e4c73b5e75 100644
--- a/tests/test125cells.c
+++ b/tests/test125cells.c
@@ -237,6 +237,8 @@ void reset_particles(struct cell *c, struct hydro_space *hs,
  * separation.
  * @param density The density of the fluid.
  * @param partId The running counter of IDs.
+ * @param pert The perturbation to apply to the particles in the cell in units
+ *of the inter-particle separation.
  * @param vel The type of velocity field.
  * @param press The type of pressure field.
  */
diff --git a/tests/test125cells.sh.in b/tests/test125cells.sh.in
index dbaf6ebd59..d6d3ddc5b6 100755
--- a/tests/test125cells.sh.in
+++ b/tests/test125cells.sh.in
@@ -7,15 +7,25 @@ do
 
 	rm -f brute_force_125_standard.dat swift_dopair_125_standard.dat
 
+	echo "Running ./test125cells -n 6 -r 1 -v $v -p $p -f standard"
 	./test125cells -n 6 -r 1 -v $v -p $p -f standard
 
 	if [ -e brute_force_125_standard.dat ]
 	then
-	    python @srcdir@/difffloat.py brute_force_125_standard.dat swift_dopair_125_standard.dat @srcdir@/tolerance_125_normal.dat 6
+	    if python @srcdir@/difffloat.py brute_force_125_standard.dat swift_dopair_125_standard.dat @srcdir@/tolerance_125_normal.dat 6
+	    then
+		echo "Accuracy test passed"
+	    else
+		echo "Accuracy test failed"
+		exit 1
+	    fi
 	else
+	    echo "Error Missing test output file"
 	    exit 1
         fi
 
+	echo "------------"
+
     done
 done
 	
diff --git a/tests/test125cellsPerturbed.sh.in b/tests/test125cellsPerturbed.sh.in
index 887eef4f6a..9a5cfc07c9 100755
--- a/tests/test125cellsPerturbed.sh.in
+++ b/tests/test125cellsPerturbed.sh.in
@@ -7,15 +7,25 @@ do
 
 	rm -f brute_force_125_perturbed.dat swift_dopair_125_perturbed.dat
 
+	echo "Running ./test125cells -n 6 -r 1 -d 0.1 -v $v -p $p -f perturbed"
 	./test125cells -n 6 -r 1 -d 0.1 -v $v -p $p -f perturbed
 
 	if [ -e brute_force_125_perturbed.dat ]
 	then
-	    python @srcdir@/difffloat.py brute_force_125_perturbed.dat swift_dopair_125_perturbed.dat @srcdir@/tolerance_125_perturbed.dat 6
+	    if python @srcdir@/difffloat.py brute_force_125_perturbed.dat swift_dopair_125_perturbed.dat @srcdir@/tolerance_125_perturbed.dat 6
+	    then
+		echo "Accuracy test passed"
+	    else
+		echo "Accuracy test failed"
+		exit 1
+	    fi
 	else
+	    echo "Error Missing test output file"
 	    exit 1
         fi
 
+	echo "------------"
+
     done
 done
 
diff --git a/tests/test27cells.sh.in b/tests/test27cells.sh.in
index 07b6b92a82..4312ce55e1 100755
--- a/tests/test27cells.sh.in
+++ b/tests/test27cells.sh.in
@@ -3,18 +3,28 @@
 for v in {0..3}
 do
     echo ""
-
+	
     rm -f brute_force_27_standard.dat swift_dopair_27_standard.dat
 
+    echo "Running ./test27cells -n 6 -r 1 -d 0 -f standard -v $v -a 1e-4"
     ./test27cells -n 6 -r 1 -d 0 -f standard -v $v -a 1e-4
 
     if [ -e brute_force_27_standard.dat ]
     then
-	python @srcdir@/difffloat.py brute_force_27_standard.dat swift_dopair_27_standard.dat @srcdir@/tolerance_27_normal.dat 6
+	if python @srcdir@/difffloat.py brute_force_27_standard.dat swift_dopair_27_standard.dat @srcdir@/tolerance_27_normal.dat 6
+	then
+	    echo "Accuracy test passed"
+	else
+	    echo "Accuracy test failed"
+	    exit 1
+	fi
     else
+	echo "Error Missing test output file"
 	exit 1
     fi
 
+    echo "------------"
+    
 done
 
 exit $?
diff --git a/tests/test27cellsPerturbed.sh.in b/tests/test27cellsPerturbed.sh.in
index 1eb7b31bcd..2f2e1db763 100755
--- a/tests/test27cellsPerturbed.sh.in
+++ b/tests/test27cellsPerturbed.sh.in
@@ -6,15 +6,25 @@ do
 
     rm -f brute_force_27_perturbed.dat swift_dopair_27_perturbed.dat
 
+    echo "Running ./test27cells -n 6 -r 1 -d 0.1 -f perturbed -v $v -a 5e-4"
     ./test27cells -n 6 -r 1 -d 0.1 -f perturbed -v $v -a 5e-4
 
     if [ -e brute_force_27_perturbed.dat ]
     then
-	python @srcdir@/difffloat.py brute_force_27_perturbed.dat swift_dopair_27_perturbed.dat @srcdir@/tolerance_27_perturbed.dat 6 1
+	if python @srcdir@/difffloat.py brute_force_27_perturbed.dat swift_dopair_27_perturbed.dat @srcdir@/tolerance_27_perturbed.dat 6 1
+	then
+	    echo "Accuracy test passed"
+	else
+	    echo "Accuracy test failed"
+	    exit 1
+	fi
     else
+	echo "Error Missing test output file"
 	exit 1
     fi
 
+    echo "------------"
+
 done
 
 exit $?
diff --git a/tests/tolerance_125_perturbed.dat b/tests/tolerance_125_perturbed.dat
index c9ad23d447..04e642b28c 100644
--- a/tests/tolerance_125_perturbed.dat
+++ b/tests/tolerance_125_perturbed.dat
@@ -1,3 +1,3 @@
 #   ID    pos_x    pos_y    pos_z      v_x      v_y      v_z        h      rho    div_v        S        u        P        c      a_x      a_y      a_z     h_dt    v_sig    dS/dt    du/dt
     0	  1e-4	   1e-4	    1e-4       1e-4	1e-4	 1e-4	    1e-4   1e-4	  1e-4	       1e-4	1e-4	 1e-4	  1e-4	 1e-4	  1e-4	   1e-4	   1e-4	   1e-4	    1e-4     1e-4
-    0	  1e-4	   1e-4	    1e-4       1e-4	1e-4	 1e-4	    1e-4   1e-4	  1e-4	       1e-4	1e-4	 1e-4	  1e-4	 1e-4	  1e-4	   1e-4	   1e-4	   1e-4	    1e-4     1e-4
+    0	  1e-4	   1e-4	    1e-4       1e-4	1e-4	 1e-4	    1e-4   1e-4	  1e-4	       1e-4	1e-4	 1e-4	  1e-4	 5e-3	  5e-3	   5e-3	   1e-4	   1e-4	    1e-4     1e-4
diff --git a/tests/tolerance_27_perturbed.dat b/tests/tolerance_27_perturbed.dat
index b6ed8c2c18..9c6ee8c77c 100644
--- a/tests/tolerance_27_perturbed.dat
+++ b/tests/tolerance_27_perturbed.dat
@@ -1,3 +1,3 @@
 #   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	   1.2e-6     1e-4	    5e-5       2e-3		 3.1e-6	     3e-6	   3e-6		 3e-6
-    0	    1e-6       1e-6	  1e-6 	       1e-6 	  1e-6	     1e-6	   1e-6	      2e-3	    1e-5       1e-4		 2e-5	     2e-3	   2e-3	 	 2e-3
+    0	    1e-6       1e-6	  1e-6 	       1e-6 	  1e-6	     1e-6	   1.2e-6     1e-4	    5e-5       2e-3		 4e-6	     3e-6	   3e-6		 3e-6
+    0	    1e-6       1e-6	  1e-6 	       1e-6 	  1e-6	     1e-6	   1e-6	      2e-3	    1e-5       1e-4		 4e-5	     2e-3	   2e-3	 	 2e-3
-- 
GitLab