From b69a6ce97cb75f90ea8461be897e1435e2306e17 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Fri, 12 Oct 2018 21:47:36 +0200
Subject: [PATCH] Only check the inhibited status of gparts if they are not
 dummy cache-adding particles.

---
 src/runner_doiact_grav.h | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/runner_doiact_grav.h b/src/runner_doiact_grav.h
index 740556de2a..ebd08a662c 100644
--- a/src/runner_doiact_grav.h
+++ b/src/runner_doiact_grav.h
@@ -238,7 +238,8 @@ static INLINE void runner_dopair_grav_pp_full(
         error("Updating an inhibited particle!");
 
       /* Check that the particle we interact with was not inhibited */
-      if (gpart_is_inhibited(&gparts_j[pjd], e) && mass_j != 0.f)
+      if (pjd < gcount_j && gpart_is_inhibited(&gparts_j[pjd], e) &&
+          mass_j != 0.f)
         error("Inhibited particle used as gravity source.");
 
       /* Check that the particle was initialised */
@@ -259,7 +260,8 @@ static INLINE void runner_dopair_grav_pp_full(
 
 #ifdef SWIFT_DEBUG_CHECKS
       /* Update the interaction counter if it's not a padded gpart */
-      if (pjd < gcount_j) gparts_i[pid].num_interacted++;
+      if (pjd < gcount_j && !gpart_is_inhibited(&gparts_j[pjd], e))
+        gparts_i[pid].num_interacted++;
 #endif
     }
 
@@ -377,7 +379,8 @@ static INLINE void runner_dopair_grav_pp_truncated(
         error("Updating an inhibited particle!");
 
       /* Check that the particle we interact with was not inhibited */
-      if (gpart_is_inhibited(&gparts_j[pjd], e) && mass_j != 0.f)
+      if (pjd < gcount_j && gpart_is_inhibited(&gparts_j[pjd], e) &&
+          mass_j != 0.f)
         error("Inhibited particle used as gravity source.");
 
       /* Check that the particle was initialised */
@@ -398,7 +401,8 @@ static INLINE void runner_dopair_grav_pp_truncated(
 
 #ifdef SWIFT_DEBUG_CHECKS
       /* Update the interaction counter if it's not a padded gpart */
-      if (pjd < gcount_j) gparts_i[pid].num_interacted++;
+      if (pjd < gcount_j && !gpart_is_inhibited(&gparts_j[pjd], e))
+        gparts_i[pid].num_interacted++;
 #endif
     }
 
@@ -963,7 +967,7 @@ static INLINE void runner_doself_grav_pp_full(
         error("Updating an inhibited particle!");
 
       /* Check that the particle we interact with was not inhibited */
-      if (gpart_is_inhibited(&gparts[pjd], e) && mass_j != 0.f)
+      if (pjd < gcount && gpart_is_inhibited(&gparts[pjd], e) && mass_j != 0.f)
         error("Inhibited particle used as gravity source.");
 
       /* Check that the particle was initialised */
@@ -984,7 +988,8 @@ static INLINE void runner_doself_grav_pp_full(
 
 #ifdef SWIFT_DEBUG_CHECKS
       /* Update the interaction counter if it's not a padded gpart */
-      if (pjd < gcount) gparts[pid].num_interacted++;
+      if (pjd < gcount && !gpart_is_inhibited(&gparts[pjd], e))
+        gparts[pid].num_interacted++;
 #endif
     }
 
@@ -1086,7 +1091,7 @@ static INLINE void runner_doself_grav_pp_truncated(
         error("Updating an inhibited particle!");
 
       /* Check that the particle we interact with was not inhibited */
-      if (gpart_is_inhibited(&gparts[pjd], e) && mass_j != 0.f)
+      if (pjd < gcount && gpart_is_inhibited(&gparts[pjd], e) && mass_j != 0.f)
         error("Inhibited particle used as gravity source.");
 
       /* Check that the particle was initialised */
@@ -1107,7 +1112,8 @@ static INLINE void runner_doself_grav_pp_truncated(
 
 #ifdef SWIFT_DEBUG_CHECKS
       /* Update the interaction counter if it's not a padded gpart */
-      if (pjd < gcount) gparts[pid].num_interacted++;
+      if (pjd < gcount && !gpart_is_inhibited(&gparts[pjd], e))
+        gparts[pid].num_interacted++;
 #endif
     }
 
-- 
GitLab