From 9ff81d71d844bc61d52c5729ed1859868e715c40 Mon Sep 17 00:00:00 2001
From: loikki <loic.hausammann@protonmail.ch>
Date: Thu, 17 Jan 2019 10:16:29 +0100
Subject: [PATCH] Add ids of interacting spart

---
 src/stars/Default/stars.h      | 2 ++
 src/stars/Default/stars_iact.h | 8 ++++++++
 src/stars/Default/stars_io.h   | 8 +++++++-
 src/stars/Default/stars_part.h | 8 +++++++-
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/stars/Default/stars.h b/src/stars/Default/stars.h
index a8faf43c1a..67c665c766 100644
--- a/src/stars/Default/stars.h
+++ b/src/stars/Default/stars.h
@@ -56,6 +56,7 @@ __attribute__((always_inline)) INLINE static void stars_init_spart(
     struct spart* sp) {
 
 #ifdef DEBUG_INTERACTIONS_STARS
+  for (int i = 0; i < MAX_NUM_OF_NEIGHBOURS_STARS; ++i) sp->ids_ngbs_density[i] = -1;
   sp->num_ngb_density = 0;
 #endif
 
@@ -156,6 +157,7 @@ __attribute__((always_inline)) INLINE static void stars_evolve_spart(
 __attribute__((always_inline)) INLINE static void stars_reset_acceleration(
     struct spart* restrict p) {
 #ifdef DEBUG_INTERACTIONS_STARS
+  for (int i = 0; i < MAX_NUM_OF_NEIGHBOURS_STARS; ++i) p->ids_ngbs_force[i] = -1;
   p->num_ngb_force = 0;
 #endif
 }
diff --git a/src/stars/Default/stars_iact.h b/src/stars/Default/stars_iact.h
index 7e36d4c4af..09c6f16c79 100644
--- a/src/stars/Default/stars_iact.h
+++ b/src/stars/Default/stars_iact.h
@@ -32,6 +32,10 @@ runner_iact_nonsym_stars_density(float r2, const float *dx, float hi, float hj,
   si->density.wcount_dh -= (hydro_dimension * wi + ui * wi_dx);
 
 #ifdef DEBUG_INTERACTIONS_STARS
+  /* Update ngb counters */
+  if (si->num_ngb_density < MAX_NUM_OF_NEIGHBOURS_STARS)
+    si->ids_ngbs_density[si->num_ngb_density] = pj->id;
+
   /* Update ngb counters */
   ++si->num_ngb_density;
 #endif
@@ -55,6 +59,10 @@ runner_iact_nonsym_stars_feedback(float r2, const float *dx, float hi, float hj,
                                   struct part *restrict pj, float a, float H) {
 
 #ifdef DEBUG_INTERACTIONS_STARS
+  /* Update ngb counters */
+  if (si->num_ngb_force < MAX_NUM_OF_NEIGHBOURS_STARS)
+    si->ids_ngbs_force[si->num_ngb_force] = pj->id;
+
   /* Update ngb counters */
   ++si->num_ngb_force;
 #endif
diff --git a/src/stars/Default/stars_io.h b/src/stars/Default/stars_io.h
index fbed04a00e..be849fa290 100644
--- a/src/stars/Default/stars_io.h
+++ b/src/stars/Default/stars_io.h
@@ -78,12 +78,18 @@ INLINE static void stars_write_particles(const struct spart *sparts,
 #ifdef DEBUG_INTERACTIONS_STARS
 
   list += *num_fields;
-  *num_fields += 2;
+  *num_fields += 4;
 
   list[0] = io_make_output_field("Num_ngb_density", INT, 1, UNIT_CONV_NO_UNITS,
                                  sparts, num_ngb_density);
   list[1] = io_make_output_field("Num_ngb_force", INT, 1, UNIT_CONV_NO_UNITS,
                                  sparts, num_ngb_force);
+  list[2] =
+      io_make_output_field("Ids_ngb_density", LONGLONG, MAX_NUM_OF_NEIGHBOURS_STARS,
+                           UNIT_CONV_NO_UNITS, sparts, ids_ngbs_density);
+  list[3] =
+      io_make_output_field("Ids_ngb_force", LONGLONG, MAX_NUM_OF_NEIGHBOURS_STARS,
+                           UNIT_CONV_NO_UNITS, sparts, ids_ngbs_force);
 #endif
 }
 
diff --git a/src/stars/Default/stars_part.h b/src/stars/Default/stars_part.h
index 2ae3747b87..4f90fd75ae 100644
--- a/src/stars/Default/stars_part.h
+++ b/src/stars/Default/stars_part.h
@@ -89,8 +89,14 @@ struct spart {
   /*! Number of interactions in the density SELF and PAIR */
   int num_ngb_density;
 
-  /*! Number of interactions in the force SELF and PAIR */
+  /*! List of interacting particles in the density SELF and PAIR */
+  long long ids_ngbs_density[MAX_NUM_OF_NEIGHBOURS_STARS];
+
+/*! Number of interactions in the force SELF and PAIR */
   int num_ngb_force;
+
+  /*! List of interacting particles in the force SELF and PAIR */
+  long long ids_ngbs_force[MAX_NUM_OF_NEIGHBOURS_STARS];
 #endif
 
 } SWIFT_STRUCT_ALIGN;
-- 
GitLab