From 593c120bc3910e8ea778abb17d3ff184b4b4d26c Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Wed, 2 May 2018 22:20:15 +0200
Subject: [PATCH] Better error messages for the case where the distance is 0
 between two gparts. Only crash if the softening is also 0.

---
 src/runner_doiact_grav.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/runner_doiact_grav.h b/src/runner_doiact_grav.h
index b795270b2e..9e03e6989b 100644
--- a/src/runner_doiact_grav.h
+++ b/src/runner_doiact_grav.h
@@ -234,7 +234,7 @@ static INLINE void runner_dopair_grav_pp_full(const struct engine *e,
       const float r2 = dx * dx + dy * dy + dz * dz;
 
 #ifdef SWIFT_DEBUG_CHECKS
-      if (r2 == 0.f && h_i == 0.)
+      if (r2 == 0.f && h2_i == 0.)
         error("Interacting particles with 0 distance and 0 softening.");
 
       /* Check that particles have been drifted to the current time */
@@ -329,7 +329,8 @@ static INLINE void runner_dopair_grav_pp_truncated(
       const float r2 = dx * dx + dy * dy + dz * dz;
 
 #ifdef SWIFT_DEBUG_CHECKS
-      if (r2 == 0.f) error("Interacting particles with 0 distance");
+      if (r2 == 0.f && h2_i == 0.)
+        error("Interacting particles with 0 distance and 0 softening.");
 
       /* Check that particles have been drifted to the current time */
       if (gparts_i[pid].ti_drift != e->ti_current)
@@ -724,7 +725,8 @@ static INLINE void runner_doself_grav_pp_full(struct runner *r,
       const float r2 = dx * dx + dy * dy + dz * dz;
 
 #ifdef SWIFT_DEBUG_CHECKS
-      if (r2 == 0.f) error("Interacting particles with 0 distance");
+      if (r2 == 0.f && h2_i == 0.)
+        error("Interacting particles with 0 distance and 0 softening.");
 
       /* Check that particles have been drifted to the current time */
       if (gparts[pid].ti_drift != e->ti_current)
@@ -854,7 +856,8 @@ static INLINE void runner_doself_grav_pp_truncated(struct runner *r,
       const float r2 = dx * dx + dy * dy + dz * dz;
 
 #ifdef SWIFT_DEBUG_CHECKS
-      if (r2 == 0.f) error("Interacting particles with 0 distance");
+      if (r2 == 0.f && h2_i == 0.)
+        error("Interacting particles with 0 distance and 0 softening.");
 
       /* Check that particles have been drifted to the current time */
       if (gparts[pid].ti_drift != e->ti_current)
-- 
GitLab