From 89d490fa4d57bb930f6df3b3b5dfbf25051be123 Mon Sep 17 00:00:00 2001
From: mladenivkovic <mladen.ivkovic@hotmail.com>
Date: Fri, 18 Sep 2020 14:33:15 +0200
Subject: [PATCH] moved rt data struct from xparts to parts struct

---
 src/cell.c                       |  2 +-
 src/distributed_io.c             |  4 ++--
 src/hydro/Gadget2/hydro_part.h   |  6 +++---
 src/line_of_sight.c              |  2 +-
 src/parallel_io.c                |  6 +++---
 src/rt/M1closure/rt.h            |  8 ++++----
 src/rt/M1closure/rt_iact.h       |  2 +-
 src/rt/M1closure/rt_io.h         |  2 +-
 src/rt/M1closure/rt_struct.h     |  4 +++-
 src/rt/debug/rt.h                | 26 +++++++++++++-------------
 src/rt/debug/rt_iact.h           |  4 ++--
 src/rt/debug/rt_io.h             | 12 ++++++------
 src/rt/debug/rt_struct.h         |  4 +++-
 src/rt/none/rt.h                 |  8 ++++----
 src/rt/none/rt_iact.h            |  2 +-
 src/rt/none/rt_io.h              |  2 +-
 src/rt/none/rt_struct.h          |  4 +++-
 src/runner_doiact_functions_rt.h |  8 ++------
 src/serial_io.c                  |  4 ++--
 src/single_io.c                  |  4 ++--
 src/space.c                      |  4 ++--
 21 files changed, 60 insertions(+), 58 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index 675b3f7781..f8b7297b65 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -5282,7 +5282,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) {
         tracers_after_init(p, xp, e->internal_units, e->physical_constants,
                            with_cosmology, e->cosmology, e->hydro_properties,
                            e->cooling_func, e->time);
-        rt_init_xpart(xp);
+        rt_init_part(p);
       }
     }
 
diff --git a/src/distributed_io.c b/src/distributed_io.c
index 220f6e48ef..df1f22f9e4 100644
--- a/src/distributed_io.c
+++ b/src/distributed_io.c
@@ -518,7 +518,7 @@ void write_output_distributed(struct engine* e,
           num_fields +=
               star_formation_write_particles(parts, xparts, list + num_fields);
           if (with_rt) {
-            num_fields += rt_write_particles(xparts, list + num_fields);
+            num_fields += rt_write_particles(parts, list + num_fields);
           }
 
         } else {
@@ -563,7 +563,7 @@ void write_output_distributed(struct engine* e,
           num_fields += star_formation_write_particles(
               parts_written, xparts_written, list + num_fields);
           if (with_rt) {
-            num_fields += rt_write_particles(xparts_written, list + num_fields);
+            num_fields += rt_write_particles(parts_written, list + num_fields);
           }
         }
       } break;
diff --git a/src/hydro/Gadget2/hydro_part.h b/src/hydro/Gadget2/hydro_part.h
index 25dfd9353b..e45b9b7c7f 100644
--- a/src/hydro/Gadget2/hydro_part.h
+++ b/src/hydro/Gadget2/hydro_part.h
@@ -72,9 +72,6 @@ struct xpart {
   /* Additional data used by the feedback */
   struct feedback_part_data feedback_data;
 
-  /* Additional Radiative Transfer Data */
-  struct rt_xpart_data rt_data;
-
 #ifdef WITH_LOGGER
   /* Additional data for the particle logger */
   struct logger_part_data logger_data;
@@ -171,6 +168,9 @@ struct part {
   /*! Additional data used by the pressure floor */
   struct pressure_floor_part_data pressure_floor_data;
 
+  /* Additional Radiative Transfer Data */
+  struct rt_part_data rt_data;
+
   /*! Time-step length */
   timebin_t time_bin;
 
diff --git a/src/line_of_sight.c b/src/line_of_sight.c
index 0fad23b308..3c686f9928 100644
--- a/src/line_of_sight.c
+++ b/src/line_of_sight.c
@@ -457,7 +457,7 @@ void write_los_hdf5_datasets(hid_t grp, const int j, const size_t N,
   num_fields +=
       star_formation_write_particles(parts, xparts, list + num_fields);
   if (with_rt) {
-    num_fields += rt_write_particles(xparts, list + num_fields);
+    num_fields += rt_write_particles(parts, list + num_fields);
   }
 
   /* Loop over each output field */
diff --git a/src/parallel_io.c b/src/parallel_io.c
index 5a298e370a..b34a06fb0f 100644
--- a/src/parallel_io.c
+++ b/src/parallel_io.c
@@ -1271,7 +1271,7 @@ void prepare_file(struct engine* e, const char* fileName,
               velociraptor_write_parts(parts, xparts, list + num_fields);
         }
         if (with_rt) {
-          num_fields += rt_write_particles(xparts, list + num_fields);
+          num_fields += rt_write_particles(parts, list + num_fields);
         }
         break;
 
@@ -1651,7 +1651,7 @@ void write_output_parallel(struct engine* e,
           num_fields +=
               star_formation_write_particles(parts, xparts, list + num_fields);
           if (with_rt) {
-            num_fields += rt_write_particles(xparts, list + num_fields);
+            num_fields += rt_write_particles(parts, list + num_fields);
           }
 
         } else {
@@ -1696,7 +1696,7 @@ void write_output_parallel(struct engine* e,
           num_fields += star_formation_write_particles(
               parts_written, xparts_written, list + num_fields);
           if (with_rt) {
-            num_fields += rt_write_particles(xparts_written, list + num_fields);
+            num_fields += rt_write_particles(parts_written, list + num_fields);
           }
         }
       } break;
diff --git a/src/rt/M1closure/rt.h b/src/rt/M1closure/rt.h
index 7c27dfe3ab..0ab19a251f 100644
--- a/src/rt/M1closure/rt.h
+++ b/src/rt/M1closure/rt.h
@@ -27,14 +27,14 @@
 /**
  * @brief First initialisation of the RT extra hydro particle data.
  */
-__attribute__((always_inline)) INLINE static void rt_first_init_xpart(
-    struct xpart* restrict xp) {}
+__attribute__((always_inline)) INLINE static void rt_first_init_part(
+    struct part* restrict p) {}
 
 /**
  * @brief Initialisation of the RT extra hydro particle data.
  */
-__attribute__((always_inline)) INLINE static void rt_init_xpart(
-    struct xpart* restrict xp) {}
+__attribute__((always_inline)) INLINE static void rt_init_part(
+    struct part* restrict p) {}
 
 /**
  * @brief First initialisation of the RT extra star particle data.
diff --git a/src/rt/M1closure/rt_iact.h b/src/rt/M1closure/rt_iact.h
index af145328b8..05f3c4e1fc 100644
--- a/src/rt/M1closure/rt_iact.h
+++ b/src/rt/M1closure/rt_iact.h
@@ -37,6 +37,6 @@
  */
 __attribute__((always_inline)) INLINE static void runner_iact_rt_inject(
     const float r2, float* dx, const float hi, const float hj,
-    struct spart* restrict si, struct xpart* restrict xpj) {}
+    struct spart* restrict si, struct part* restrict pj) {}
 
 #endif /* SWIFT_RT_IACT_M1CLOSURE_H */
diff --git a/src/rt/M1closure/rt_io.h b/src/rt/M1closure/rt_io.h
index d343fb1a0f..35e573d5b3 100644
--- a/src/rt/M1closure/rt_io.h
+++ b/src/rt/M1closure/rt_io.h
@@ -30,7 +30,7 @@
  * @brief Creates additional output fields for the radiative
  * transfer data of hydro particles.
  */
-INLINE static int rt_write_particles(const struct xpart* xparts,
+INLINE static int rt_write_particles(const struct part* parts,
                                      struct io_props* list) {
   return 0;
 }
diff --git a/src/rt/M1closure/rt_struct.h b/src/rt/M1closure/rt_struct.h
index 7b32497bc6..d6a51d073e 100644
--- a/src/rt/M1closure/rt_struct.h
+++ b/src/rt/M1closure/rt_struct.h
@@ -24,8 +24,10 @@
  * @brief Main header file for no radiative transfer struct.
  */
 
-struct rt_xpart_data {};
+/* Additional RT data in hydro particle struct */
+struct rt_part_data {};
 
+/* Additional RT data in star particle struct */
 struct rt_spart_data {};
 
 #endif /* SWIFT_RT_STRUCT_M1CLOSURE_H */
diff --git a/src/rt/debug/rt.h b/src/rt/debug/rt.h
index c9f837786b..e9a3a3f593 100644
--- a/src/rt/debug/rt.h
+++ b/src/rt/debug/rt.h
@@ -27,26 +27,26 @@
 /**
  * @brief First initialisation of the RT extra hydro particle data.
  */
-__attribute__((always_inline)) INLINE static void rt_first_init_xpart(
-    struct xpart* restrict xp) {
+__attribute__((always_inline)) INLINE static void rt_first_init_part(
+    struct part* restrict p) {
 
-  xp->rt_data.iact_stars = 0;
-  xp->rt_data.calls_tot = 0;
-  xp->rt_data.calls_per_step = 0;
-  xp->rt_data.calls_self = 0;
-  xp->rt_data.calls_pair = 0;
+  p->rt_data.iact_stars = 0;
+  p->rt_data.calls_tot = 0;
+  p->rt_data.calls_per_step = 0;
+  p->rt_data.calls_self = 0;
+  p->rt_data.calls_pair = 0;
 }
 
 /**
  * @brief Initialisation of the RT extra hydro particle data.
  */
-__attribute__((always_inline)) INLINE static void rt_init_xpart(
-    struct xpart* restrict xp) {
+__attribute__((always_inline)) INLINE static void rt_init_part(
+    struct part* restrict p) {
 
-  xp->rt_data.iact_stars = 0;
-  xp->rt_data.calls_per_step = 0;
-  xp->rt_data.calls_self = 0;
-  xp->rt_data.calls_pair = 0;
+  p->rt_data.iact_stars = 0;
+  p->rt_data.calls_per_step = 0;
+  p->rt_data.calls_self = 0;
+  p->rt_data.calls_pair = 0;
 }
 
 /**
diff --git a/src/rt/debug/rt_iact.h b/src/rt/debug/rt_iact.h
index ba3c800480..cd2ec06ca1 100644
--- a/src/rt/debug/rt_iact.h
+++ b/src/rt/debug/rt_iact.h
@@ -37,10 +37,10 @@
  */
 __attribute__((always_inline)) INLINE static void runner_iact_rt_inject(
     const float r2, float* dx, const float hi, const float hj,
-    struct spart* restrict si, struct xpart* restrict xpj) {
+    struct spart* restrict si, struct part* restrict pj) {
 
   struct rt_spart_data* restrict sd = &(si->rt_data);
-  struct rt_xpart_data* restrict pd = &(xpj->rt_data);
+  struct rt_part_data* restrict pd = &(pj->rt_data);
 
   sd->iact_hydro += 1;
   sd->calls_tot += 1;
diff --git a/src/rt/debug/rt_io.h b/src/rt/debug/rt_io.h
index 1af20b6440..1b29a16039 100644
--- a/src/rt/debug/rt_io.h
+++ b/src/rt/debug/rt_io.h
@@ -30,25 +30,25 @@
  * @brief Creates additional output fields for the radiative
  * transfer data of hydro particles.
  */
-INLINE static int rt_write_particles(const struct xpart* xparts,
+INLINE static int rt_write_particles(const struct part* parts,
                                      struct io_props* list) {
 
   list[0] = io_make_output_field("RTStarIact", INT, 1, UNIT_CONV_NO_UNITS, 0,
-                                 xparts, rt_data.iact_stars,
+                                 parts, rt_data.iact_stars,
                                  "number of interactions between this hydro "
                                  "particle and any star particle");
   list[1] = io_make_output_field(
-      "RTTotalCalls", INT, 1, UNIT_CONV_NO_UNITS, 0, xparts, rt_data.calls_tot,
+      "RTTotalCalls", INT, 1, UNIT_CONV_NO_UNITS, 0, parts, rt_data.calls_tot,
       "total number of calls to this particle during the run");
   list[2] = io_make_output_field(
-      "RTCallsThisStep", INT, 1, UNIT_CONV_NO_UNITS, 0, xparts,
+      "RTCallsThisStep", INT, 1, UNIT_CONV_NO_UNITS, 0, parts,
       rt_data.calls_per_step,
       "number of calls to this particle during one time step");
   list[3] = io_make_output_field(
-      "RTCallsSelf", INT, 1, UNIT_CONV_NO_UNITS, 0, xparts, rt_data.calls_self,
+      "RTCallsSelf", INT, 1, UNIT_CONV_NO_UNITS, 0, parts, rt_data.calls_self,
       "number of calls to this particle during one time step in self task");
   list[4] = io_make_output_field(
-      "RTCallsPair", INT, 1, UNIT_CONV_NO_UNITS, 0, xparts, rt_data.calls_pair,
+      "RTCallsPair", INT, 1, UNIT_CONV_NO_UNITS, 0, parts, rt_data.calls_pair,
       "number of calls to this particle during one time step in self task");
 
   return 5;
diff --git a/src/rt/debug/rt_struct.h b/src/rt/debug/rt_struct.h
index 2a4790360a..7255c62c35 100644
--- a/src/rt/debug/rt_struct.h
+++ b/src/rt/debug/rt_struct.h
@@ -24,7 +24,8 @@
  * @brief Main header file for the debug radiative transfer struct.
  */
 
-struct rt_xpart_data {
+/* Additional RT data in hydro particle struct */
+struct rt_part_data {
   int iact_stars; /* how many stars this particle interacted with */
   int calls_tot;  /* total number of calls to this particle during entire run */
   int calls_per_step; /* calls per time step to this particle */
@@ -32,6 +33,7 @@ struct rt_xpart_data {
   int calls_pair;
 };
 
+/* Additional RT data in star particle struct */
 struct rt_spart_data {
   int iact_hydro; /* how many hydro particles this particle interacted with */
   int calls_tot;  /* total number of calls to this particle during entire run */
diff --git a/src/rt/none/rt.h b/src/rt/none/rt.h
index dc7ec33201..30039d8b9d 100644
--- a/src/rt/none/rt.h
+++ b/src/rt/none/rt.h
@@ -27,14 +27,14 @@
 /**
  * @brief First initialisation of the RT extra hydro particle data.
  */
-__attribute__((always_inline)) INLINE static void rt_first_init_xpart(
-    struct xpart* restrict xp) {}
+__attribute__((always_inline)) INLINE static void rt_first_init_part(
+    struct part* restrict p) {}
 
 /**
  * @brief Initialisation of the RT extra hydro particle data.
  */
-__attribute__((always_inline)) INLINE static void rt_init_xpart(
-    struct xpart* restrict xp) {}
+__attribute__((always_inline)) INLINE static void rt_init_part(
+    struct part* restrict p) {}
 
 /**
  * @brief First initialisation of the RT extra star particle data.
diff --git a/src/rt/none/rt_iact.h b/src/rt/none/rt_iact.h
index 9da017fe12..91be57712f 100644
--- a/src/rt/none/rt_iact.h
+++ b/src/rt/none/rt_iact.h
@@ -37,6 +37,6 @@
  */
 __attribute__((always_inline)) INLINE static void runner_iact_rt_inject(
     const float r2, float* dx, const float hi, const float hj,
-    struct spart* restrict si, struct xpart* restrict xpj) {}
+    struct spart* restrict si, struct part* restrict pj) {}
 
 #endif /* SWIFT_RT_IACT_NONE_H */
diff --git a/src/rt/none/rt_io.h b/src/rt/none/rt_io.h
index 98aafa3f39..c19fe308bc 100644
--- a/src/rt/none/rt_io.h
+++ b/src/rt/none/rt_io.h
@@ -30,7 +30,7 @@
  * @brief Creates additional output fields for the radiative
  * transfer data of hydro particles.
  */
-INLINE static int rt_write_particles(const struct xpart* xparts,
+INLINE static int rt_write_particles(const struct part* parts,
                                      struct io_props* list) {
   return 0;
 }
diff --git a/src/rt/none/rt_struct.h b/src/rt/none/rt_struct.h
index 262ab80fbf..e2b46a36f1 100644
--- a/src/rt/none/rt_struct.h
+++ b/src/rt/none/rt_struct.h
@@ -24,8 +24,10 @@
  * @brief Main header file for no radiative transfer struct.
  */
 
-struct rt_xpart_data {};
+/* Additional RT data in hydro particle struct */
+struct rt_part_data {};
 
+/* Additional RT data in star particle struct */
 struct rt_spart_data {};
 
 #endif /* SWIFT_RT_STRUCT_NONE_H */
diff --git a/src/runner_doiact_functions_rt.h b/src/runner_doiact_functions_rt.h
index f657bd716e..d05a41efde 100644
--- a/src/runner_doiact_functions_rt.h
+++ b/src/runner_doiact_functions_rt.h
@@ -45,7 +45,6 @@ void DOSELF1_RT(struct runner *r, struct cell *c, int timer) {
 
   struct spart *restrict sparts = c->stars.parts;
   struct part *restrict parts = c->hydro.parts;
-  struct xpart *restrict xparts = c->hydro.xparts;
 
   const int scount = c->stars.count;
   const int count = c->hydro.count;
@@ -65,7 +64,6 @@ void DOSELF1_RT(struct runner *r, struct cell *c, int timer) {
 
     /* Loop over the (x)parts in cell */
     for (int pid = 0; pid < count; pid++) {
-      struct xpart *restrict xpj = &xparts[pid];
       struct part *restrict pj = &parts[pid];
 
       /* Skip inhibited particles. */
@@ -81,7 +79,7 @@ void DOSELF1_RT(struct runner *r, struct cell *c, int timer) {
       float dx[3] = {six[0] - pjx[0], six[1] - pjx[1], six[2] - pjx[2]};
       const float r2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
 
-      if (r2 < hjg2) IACT_RT(r2, dx, hi, hj, si, xpj);
+      if (r2 < hjg2) IACT_RT(r2, dx, hi, hj, si, pj);
     }
   }
 
@@ -106,7 +104,6 @@ void DOPAIR1_NONSYM_RT(struct runner *r, struct cell *ci, struct cell *cj) {
   const int count_j = cj->hydro.count;
   struct spart *restrict sparts_i = ci->stars.parts;
   struct part *restrict parts_j = cj->hydro.parts;
-  struct xpart *restrict xparts_j = cj->hydro.xparts;
 
   /* Get the relative distance between the pairs, wrapping. */
   double shift[3] = {0.0, 0.0, 0.0};
@@ -136,7 +133,6 @@ void DOPAIR1_NONSYM_RT(struct runner *r, struct cell *ci, struct cell *cj) {
 
       /* Get a pointer to the jth particle. */
       struct part *restrict pj = &parts_j[pjd];
-      struct xpart *restrict xpj = &xparts_j[pjd];
       const float hj = pj->h;
       const float hjg2 = hj * hj * kernel_gamma2;
 
@@ -150,7 +146,7 @@ void DOPAIR1_NONSYM_RT(struct runner *r, struct cell *ci, struct cell *cj) {
       float dx[3] = {six[0] - pjx[0], six[1] - pjx[1], six[2] - pjx[2]};
       const float r2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
 
-      if (r2 < hjg2) IACT_RT(r2, dx, hi, hj, si, xpj);
+      if (r2 < hjg2) IACT_RT(r2, dx, hi, hj, si, pj);
 
     } /* loop over the parts in cj. */
   }   /* loop over the parts in ci. */
diff --git a/src/serial_io.c b/src/serial_io.c
index 2f59f17739..5381e4c4fc 100644
--- a/src/serial_io.c
+++ b/src/serial_io.c
@@ -1227,7 +1227,7 @@ void write_output_serial(struct engine* e,
               num_fields += star_formation_write_particles(parts, xparts,
                                                            list + num_fields);
               if (with_rt) {
-                num_fields += rt_write_particles(xparts, list + num_fields);
+                num_fields += rt_write_particles(parts, list + num_fields);
               }
 
             } else {
@@ -1275,7 +1275,7 @@ void write_output_serial(struct engine* e,
                   parts_written, xparts_written, list + num_fields);
               if (with_rt) {
                 num_fields +=
-                    rt_write_particles(xparts_written, list + num_fields);
+                    rt_write_particles(parts_written, list + num_fields);
               }
             }
           } break;
diff --git a/src/single_io.c b/src/single_io.c
index e52d2c5316..d978e4c472 100644
--- a/src/single_io.c
+++ b/src/single_io.c
@@ -1019,7 +1019,7 @@ void write_output_single(struct engine* e,
           num_fields +=
               star_formation_write_particles(parts, xparts, list + num_fields);
           if (with_rt) {
-            num_fields += rt_write_particles(xparts, list + num_fields);
+            num_fields += rt_write_particles(parts, list + num_fields);
           }
 
         } else {
@@ -1064,7 +1064,7 @@ void write_output_single(struct engine* e,
           num_fields += star_formation_write_particles(
               parts_written, xparts_written, list + num_fields);
           if (with_rt) {
-            num_fields += rt_write_particles(xparts_written, list + num_fields);
+            num_fields += rt_write_particles(parts_written, list + num_fields);
           }
         }
       } break;
diff --git a/src/space.c b/src/space.c
index 78ea6a3e81..83b2bf3275 100644
--- a/src/space.c
+++ b/src/space.c
@@ -4926,7 +4926,7 @@ void space_first_init_parts_mapper(void *restrict map_data, int count,
     black_holes_mark_part_as_not_swallowed(&p[k].black_holes_data);
 
     /* And the radiative transfer */
-    rt_first_init_xpart(&xp[k]);
+    rt_first_init_part(&p[k]);
 
 #ifdef SWIFT_DEBUG_CHECKS
     /* Check part->gpart->part linkeage. */
@@ -5283,7 +5283,7 @@ void space_init_parts_mapper(void *restrict map_data, int count,
     black_holes_init_potential(&parts[k].black_holes_data);
     chemistry_init_part(&parts[k], e->chemistry);
     pressure_floor_init_part(&parts[k], &xparts[k]);
-    rt_init_xpart(&xparts[k]);
+    rt_init_part(&parts[k]);
     star_formation_init_part(&parts[k], e->star_formation);
     tracers_after_init(&parts[k], &xparts[k], e->internal_units,
                        e->physical_constants, with_cosmology, e->cosmology,
-- 
GitLab