From 911d24f7031bcf1af8aa60e7f007dc5c45c96fa4 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Mon, 17 Dec 2018 20:27:17 +0100
Subject: [PATCH] When rebuilding in non-periodic world, do crash if a particle
 is out of the box.

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

diff --git a/src/space.c b/src/space.c
index 6401be586b..35aaffa66d 100644
--- a/src/space.c
+++ b/src/space.c
@@ -1757,6 +1757,17 @@ void space_parts_get_cell_index_mapper(void *map_data, int nr_parts,
     const double old_pos_y = p->x[1];
     const double old_pos_z = p->x[2];
 
+#ifdef SWIFT_DEBUG_CHECKS
+    if (!s->periodic) {
+      if (old_pos_x < 0. || old_pos_x > dim_x)
+        error("Particle outside of volume along X.");
+      if (old_pos_y < 0. || old_pos_y > dim_y)
+        error("Particle outside of volume along Y.");
+      if (old_pos_z < 0. || old_pos_z > dim_z)
+        error("Particle outside of volume along Z.");
+    }
+#endif
+
     /* Put it back into the simulation volume */
     const double pos_x = box_wrap(old_pos_x, 0.0, dim_x);
     const double pos_y = box_wrap(old_pos_y, 0.0, dim_y);
@@ -1864,6 +1875,17 @@ void space_gparts_get_cell_index_mapper(void *map_data, int nr_gparts,
     const double old_pos_y = gp->x[1];
     const double old_pos_z = gp->x[2];
 
+#ifdef SWIFT_DEBUG_CHECKS
+    if (!s->periodic) {
+      if (old_pos_x < 0. || old_pos_x > dim_x)
+        error("Particle outside of volume along X.");
+      if (old_pos_y < 0. || old_pos_y > dim_y)
+        error("Particle outside of volume along Y.");
+      if (old_pos_z < 0. || old_pos_z > dim_z)
+        error("Particle outside of volume along Z.");
+    }
+#endif
+
     /* Put it back into the simulation volume */
     const double pos_x = box_wrap(old_pos_x, 0.0, dim_x);
     const double pos_y = box_wrap(old_pos_y, 0.0, dim_y);
@@ -1977,6 +1999,17 @@ void space_sparts_get_cell_index_mapper(void *map_data, int nr_sparts,
     const double old_pos_y = sp->x[1];
     const double old_pos_z = sp->x[2];
 
+#ifdef SWIFT_DEBUG_CHECKS
+    if (!s->periodic) {
+      if (old_pos_x < 0. || old_pos_x > dim_x)
+        error("Particle outside of volume along X.");
+      if (old_pos_y < 0. || old_pos_y > dim_y)
+        error("Particle outside of volume along Y.");
+      if (old_pos_z < 0. || old_pos_z > dim_z)
+        error("Particle outside of volume along Z.");
+    }
+#endif
+
     /* Put it back into the simulation volume */
     const double pos_x = box_wrap(old_pos_x, 0.0, dim_x);
     const double pos_y = box_wrap(old_pos_y, 0.0, dim_y);
-- 
GitLab