From 640b1dfb4b882c88aecfdb0b2c548099d04425e6 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Fri, 27 Jan 2017 14:19:05 +0000
Subject: [PATCH] Add a check to make sure periodic boundary conditions are
 correctly applied when rebuilding.

---
 src/space.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/space.c b/src/space.c
index 8d5dc34dc7..0bbf178068 100644
--- a/src/space.c
+++ b/src/space.c
@@ -844,6 +844,13 @@ void space_parts_get_cell_index_mapper(void *map_data, int nr_parts,
         cell_getid(cdim, pos_x * ih_x, pos_y * ih_y, pos_z * ih_z);
     ind[k] = index;
 
+#ifdef SWIFT_DEBUG_CHECKS
+    if(pos_x > dim_x || pos_y > dim_y || pos_z > pos_z ||
+       pos_x < 0. || pos_y < 0. || pos_z < 0.)
+      error("Particle outside of simulation box. p->x=[%e %e %e]", 
+	    pos_x, pos_y, pos_z);
+#endif
+
     /* Update the position */
     p->x[0] = pos_x;
     p->x[1] = pos_y;
-- 
GitLab