From d22a3689573a7b0480f48bbae0884ff7b3ea3aa5 Mon Sep 17 00:00:00 2001
From: mladenivkovic <mladen.ivkovic@hotmail.com>
Date: Fri, 4 Sep 2020 23:39:58 +0200
Subject: [PATCH] added rt struct

---
 src/hydro/Gadget2/hydro_part.h |  4 ++++
 src/rt/debug/rt.h              | 40 +++++++++++++++++++++++++++++++++
 src/rt/debug/rt_struct.h       | 41 ++++++++++++++++++++++++++++++++++
 src/rt_struct.h                | 41 ++++++++++++++++++++++++++++++++++
 src/space.c                    |  8 +++++++
 src/stars/GEAR/stars.h         |  2 ++
 src/stars/GEAR/stars_part.h    |  4 ++++
 7 files changed, 140 insertions(+)
 create mode 100644 src/rt/debug/rt_struct.h
 create mode 100644 src/rt_struct.h

diff --git a/src/hydro/Gadget2/hydro_part.h b/src/hydro/Gadget2/hydro_part.h
index 453c27f6a6..ce63da6a29 100644
--- a/src/hydro/Gadget2/hydro_part.h
+++ b/src/hydro/Gadget2/hydro_part.h
@@ -40,6 +40,7 @@
 #include "star_formation_struct.h"
 #include "timestep_limiter_struct.h"
 #include "tracers_struct.h"
+#include "rt_struct.h"
 
 /* Extra particle data not needed during the SPH loops over neighbours. */
 struct xpart {
@@ -71,6 +72,9 @@ 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;
diff --git a/src/rt/debug/rt.h b/src/rt/debug/rt.h
index b387dec1f8..170f4ea20b 100644
--- a/src/rt/debug/rt.h
+++ b/src/rt/debug/rt.h
@@ -31,4 +31,44 @@ __attribute__((always_inline)) INLINE static void rt_dummy_function(void) {
   message("Called debug RT scheme.");
 }
 
+
+/**
+ * @brief First initialisation of the RT extra hydro partilce data.
+ */
+__attribute__((always_inline)) INLINE static void rt_first_init_xpart(struct xpart* restrict xp) {
+
+  xp->rt_data.iact_stars = 0;
+  xp->rt_data.calls_tot = 0;
+  xp->rt_data.calls_per_step = 0;
+}
+
+/**
+ * @brief Initialisation of the RT extra hydro partilce data.
+ */
+__attribute__((always_inline)) INLINE static void rt_init_xpart(struct xpart* restrict xp) {
+
+  xp->rt_data.iact_stars = 0;
+  xp->rt_data.calls_per_step = 0;
+}
+
+
+/**
+ * @brief First initialisation of the RT extra star partilce data.
+ */
+__attribute__((always_inline)) INLINE static void rt_first_init_spart( struct spart* restrict sp) {
+
+  sp->rt_data.iact_hydro = 0;
+  sp->rt_data.calls_tot = 0;
+  sp->rt_data.calls_per_step = 0;
+}
+
+
+/**
+ * @brief First initialisation of the RT extra star partilce data.
+ */
+__attribute__((always_inline)) INLINE static void rt_init_spart( struct spart* restrict sp) {
+
+  sp->rt_data.iact_hydro = 0;
+  sp->rt_data.calls_per_step = 0;
+}
 #endif /* SWIFT_RT_DEBUG_H */
diff --git a/src/rt/debug/rt_struct.h b/src/rt/debug/rt_struct.h
new file mode 100644
index 0000000000..13007f4907
--- /dev/null
+++ b/src/rt/debug/rt_struct.h
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * This file is part of SWIFT.
+ * Copyright (c) 2020 Mladen Ivkovic (mladen.ivkovic@hotmail.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ ******************************************************************************/
+#ifndef SWIFT_RT_STRUCT_DEBUG_H
+#define SWIFT_RT_STRUCT_DEBUG_H
+
+/**
+ * @file src/rt/debug/rt_struct.h
+ * @brief Main header file for the debug radiative transfer struct.
+ */
+
+struct rt_xpart_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 */
+};
+
+
+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 */
+  int calls_per_step; /* calls per time step to this particle */
+};
+
+
+#endif /* SWIFT_RT_STRUCT_DEBUG_H */
diff --git a/src/rt_struct.h b/src/rt_struct.h
new file mode 100644
index 0000000000..5907920dc3
--- /dev/null
+++ b/src/rt_struct.h
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * This file is part of SWIFT.
+ * Copyright (c) 2020 Mladen Ivkovic (mladen.ivkovic@hotmail.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ ******************************************************************************/
+#ifndef SWIFT_RT_STRUCT_H
+#define SWIFT_RT_STRUCT_H
+
+/**
+ * @file src/rt_struct.h
+ * @brief Branches between the different radiative transfer structs.
+ */
+
+/* Config parameters. */
+#include "../config.h"
+
+/* Import the right RT struct definition */
+#if defined(RT_NONE)
+#include "./rt/none/rt_struct.h"
+#elif defined(RT_DEBUG)
+#include "./rt/debug/rt_struct.h"
+#elif defined(RT_M1)
+#include "./rt/M1closure/rt_struct.h"
+#else
+#error "Invalid choice of radiation scheme"
+#endif
+
+#endif /* SWIFT_RT_STRUCT_H */
diff --git a/src/space.c b/src/space.c
index 1ed1409e1c..87f627826c 100644
--- a/src/space.c
+++ b/src/space.c
@@ -59,6 +59,7 @@
 #include "pressure_floor.h"
 #include "proxy.h"
 #include "restart.h"
+#include "rt.h"
 #include "sink.h"
 #include "sort_part.h"
 #include "space_unique_id.h"
@@ -4923,6 +4924,9 @@ void space_first_init_parts_mapper(void *restrict map_data, int count,
     /* And the black hole markers */
     black_holes_mark_part_as_not_swallowed(&p[k].black_holes_data);
 
+    /* And the radiative transfer */
+    rt_first_init_xpart(&xp[k]);
+
 #ifdef SWIFT_DEBUG_CHECKS
     /* Check part->gpart->part linkeage. */
     if (p[k].gpart && p[k].gpart->id_or_neg_offset != -(k + delta))
@@ -5082,6 +5086,9 @@ void space_first_init_sparts_mapper(void *restrict map_data, int count,
     /* Also initialise the chemistry */
     chemistry_first_init_spart(chemistry, &sp[k]);
 
+    /* And radiative transfer data */
+    rt_first_init_spart(&sp[k]);
+
 #ifdef SWIFT_DEBUG_CHECKS
     if (sp[k].gpart && sp[k].gpart->id_or_neg_offset != -(k + delta))
       error("Invalid gpart -> spart link");
@@ -5275,6 +5282,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]);
     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,
diff --git a/src/stars/GEAR/stars.h b/src/stars/GEAR/stars.h
index 70f8c0a75f..534334e87f 100644
--- a/src/stars/GEAR/stars.h
+++ b/src/stars/GEAR/stars.h
@@ -20,6 +20,7 @@
 #define SWIFT_GEAR_STARS_H
 
 #include "minmax.h"
+#include "rt.h"
 
 #include <float.h>
 
@@ -50,6 +51,7 @@ __attribute__((always_inline)) INLINE static void stars_init_spart(
 
   sp->density.wcount = 0.f;
   sp->density.wcount_dh = 0.f;
+  rt_init_spart(sp);
 }
 
 /**
diff --git a/src/stars/GEAR/stars_part.h b/src/stars/GEAR/stars_part.h
index 8cc8025c7d..2d7735b8ef 100644
--- a/src/stars/GEAR/stars_part.h
+++ b/src/stars/GEAR/stars_part.h
@@ -27,6 +27,7 @@
 #include "feedback_struct.h"
 #include "star_formation_struct.h"
 #include "tracers_struct.h"
+#include "rt_struct.h"
 
 /**
  * @brief Particle fields for the star particles.
@@ -91,6 +92,9 @@ struct spart {
   /*! Chemistry structure */
   struct chemistry_spart_data chemistry_data;
 
+  /*! Radiative Transfer data */
+  struct rt_spart_data rt_data;
+
   /*! Particle time bin */
   timebin_t time_bin;
 
-- 
GitLab