From 4941f719e9ce56d554c2a74bbdb4cb6ee45da05b Mon Sep 17 00:00:00 2001
From: loikki <loic.hausammann@protonmail.ch>
Date: Mon, 29 Jul 2019 14:00:50 +0200
Subject: [PATCH] Apply API changes to star formation

---
 src/star_formation/EAGLE/star_formation.h     |  2 +-
 .../EAGLE/star_formation_logger.h             | 43 ++++++++++++++++++-
 .../EAGLE/star_formation_logger_struct.h      | 19 ++++++++
 .../EAGLE/star_formation_struct.h             |  2 +
 src/star_formation/none/star_formation.h      |  2 +-
 .../none/star_formation_logger.h              | 25 ++++++++++-
 .../none/star_formation_logger_struct.h       |  7 +++
 .../none/star_formation_struct.h              |  6 +++
 8 files changed, 101 insertions(+), 5 deletions(-)

diff --git a/src/star_formation/EAGLE/star_formation.h b/src/star_formation/EAGLE/star_formation.h
index 1fc6531656..eb6a74cbd3 100644
--- a/src/star_formation/EAGLE/star_formation.h
+++ b/src/star_formation/EAGLE/star_formation.h
@@ -690,6 +690,6 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const,
  * @param data The global star_formation information.
  */
 __attribute__((always_inline)) INLINE static void star_formation_init_part(
-    struct part* restrict p, const struct star_formation* data) {}
+    struct part* restrict p, struct xpart* restrict xp, const struct star_formation* data) {}
 
 #endif /* SWIFT_EAGLE_STAR_FORMATION_H */
diff --git a/src/star_formation/EAGLE/star_formation_logger.h b/src/star_formation/EAGLE/star_formation_logger.h
index d634c876e5..e992e5d144 100644
--- a/src/star_formation/EAGLE/star_formation_logger.h
+++ b/src/star_formation/EAGLE/star_formation_logger.h
@@ -87,6 +87,28 @@ INLINE static void star_formation_logger_add(
   sf_update->SFR_inactive += sf_add->SFR_inactive;
 }
 
+/**
+ * @brief add a star formation history struct to the engine star formation history
+ * accumulator struct
+ *
+ * @param sf_add the star formation accumulator struct which we want to add to the star
+ * formation history
+ * @param sf_update the star formation structure which we want to update
+ */
+INLINE static void star_formation_logger_add_to_accumulator(
+    struct star_formation_history_accumulator *sf_update,
+    const struct star_formation_history *sf_add) {
+
+  /* Update the SFH structure */
+  sf_update->new_stellar_mass += sf_add->new_stellar_mass;
+
+  sf_update->SFR_active += sf_add->SFR_active;
+
+  sf_update->SFRdt_active += sf_add->SFRdt_active;
+
+  sf_update->SFR_inactive += sf_add->SFR_inactive;
+}
+
 /**
  * @brief Initialize the star formation history structure in the #engine
  *
@@ -105,6 +127,25 @@ INLINE static void star_formation_logger_init(
   sfh->SFR_inactive = 0.f;
 }
 
+/**
+ * @brief Initialize the star formation history structure in the #engine
+ *
+ * @param sfh The pointer to the star formation history structure
+ */
+INLINE static void star_formation_logger_accumulator_init(
+    struct star_formation_history_accumulator *sfh) {
+
+  /* Initialize the collecting SFH structure to zero */
+  sfh->new_stellar_mass = 0.f;
+
+  sfh->SFR_active = 0.f;
+
+  sfh->SFRdt_active = 0.f;
+
+  sfh->SFR_inactive = 0.f;
+}
+
+
 /**
  * @brief Write the final SFH to a file
  *
@@ -117,7 +158,7 @@ INLINE static void star_formation_logger_init(
  */
 INLINE static void star_formation_logger_write_to_log_file(
     FILE *fp, const double time, const double a, const double z,
-    const struct star_formation_history sf, const int step) {
+    const struct star_formation_history_accumulator sf, const int step) {
 
   /* Calculate the total SFR */
   const float totalSFR = sf.SFR_active + sf.SFR_inactive;
diff --git a/src/star_formation/EAGLE/star_formation_logger_struct.h b/src/star_formation/EAGLE/star_formation_logger_struct.h
index 2a23659c4d..b677ee6bc7 100644
--- a/src/star_formation/EAGLE/star_formation_logger_struct.h
+++ b/src/star_formation/EAGLE/star_formation_logger_struct.h
@@ -34,4 +34,23 @@ struct star_formation_history {
   float SFRdt_active;
 };
 
+
+/* Starformation history struct for the engine.
+ Allows to integrate in time some values.
+ Nothing to do in EAGLE => copy of star_formation_history */
+struct star_formation_history_accumulator {
+  /*! Total new stellar mass */
+  float new_stellar_mass;
+
+  /*! SFR of all particles */
+  float SFR_inactive;
+
+  /*! SFR of active particles */
+  float SFR_active;
+
+  /*! SFR*dt of active particles */
+  float SFRdt_active;
+};
+
+
 #endif /* SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H */
diff --git a/src/star_formation/EAGLE/star_formation_struct.h b/src/star_formation/EAGLE/star_formation_struct.h
index 41247e160a..8caac49d4b 100644
--- a/src/star_formation/EAGLE/star_formation_struct.h
+++ b/src/star_formation/EAGLE/star_formation_struct.h
@@ -29,4 +29,6 @@ struct star_formation_xpart_data {
   float SFR;
 };
 
+struct star_formation_part_data {};
+
 #endif /* SWIFT_EAGLE_STAR_FORMATION_STRUCT_H */
diff --git a/src/star_formation/none/star_formation.h b/src/star_formation/none/star_formation.h
index dfe645718d..6ef1c11068 100644
--- a/src/star_formation/none/star_formation.h
+++ b/src/star_formation/none/star_formation.h
@@ -219,6 +219,6 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const,
  * @param data The global star_formation information.
  */
 __attribute__((always_inline)) INLINE static void star_formation_init_part(
-    struct part* restrict p, const struct star_formation* data) {}
+    struct part* restrict p, struct xpart* restrict xp, const struct star_formation* data) {}
 
 #endif /* SWIFT_NONE_STAR_FORMATION_H */
diff --git a/src/star_formation/none/star_formation_logger.h b/src/star_formation/none/star_formation_logger.h
index b4e6987c03..0a90bd4869 100644
--- a/src/star_formation/none/star_formation_logger.h
+++ b/src/star_formation/none/star_formation_logger.h
@@ -59,6 +59,19 @@ INLINE static void star_formation_logger_add(
     struct star_formation_history *sf_update,
     const struct star_formation_history *sf_add) {}
 
+
+/**
+ * @brief add a star formation history accumulator struct to an other star formation history
+ * struct
+ *
+ * @param sf_add the star formation accumulator struct which we want to add to the star
+ * formation history
+ * @param sf_update the star formation structure which we want to update
+ */
+INLINE static void star_formation_logger_add_to_accumulator(
+    struct star_formation_history_accumulator *sf_update,
+    const struct star_formation_history *sf_add) {}
+
 /**
  * @brief Initialize the star formation history structure in the #engine
  *
@@ -67,6 +80,14 @@ INLINE static void star_formation_logger_add(
 INLINE static void star_formation_logger_init(
     struct star_formation_history *sfh) {}
 
+/**
+ * @brief Initialize the star formation history structure in the #engine
+ *
+ * @param sfh The pointer to the star formation history structure
+ */
+INLINE static void star_formation_logger_accumulator_init(
+    struct star_formation_history_accumulator *sfh) {}
+
 /**
  * @brief Write the final SFH to a file
  *
@@ -74,12 +95,12 @@ INLINE static void star_formation_logger_init(
  * @param time the simulation time (time since Big Bang) in internal units.
  * @param a the scale factor.
  * @param z the redshift.
- * @param sf the #star_formation_history struct.
+ * @param sf the #star_formation_history_accumulator struct.
  * @param step The time-step of the simulation.
  */
 INLINE static void star_formation_logger_write_to_log_file(
     FILE *fp, const double time, const double a, const double z,
-    const struct star_formation_history sf, const int step) {}
+    const struct star_formation_history_accumulator sf, const int step) {}
 
 /**
  * @brief Initialize the SFH logger file
diff --git a/src/star_formation/none/star_formation_logger_struct.h b/src/star_formation/none/star_formation_logger_struct.h
index 9efda271da..c80d6b6f3f 100644
--- a/src/star_formation/none/star_formation_logger_struct.h
+++ b/src/star_formation/none/star_formation_logger_struct.h
@@ -22,4 +22,11 @@
 /* Starformation history struct */
 struct star_formation_history {};
 
+
+/* Starformation history accumulator struct.
+   This structure is only defined in the engine and
+   allows the user to integrate some quantities over time.
+*/
+struct star_formation_history_accumulator {};
+
 #endif /* SWIFT_NONE_STAR_FORMATION_STRUCT_H */
diff --git a/src/star_formation/none/star_formation_struct.h b/src/star_formation/none/star_formation_struct.h
index 27a2adaf83..2f5241a58c 100644
--- a/src/star_formation/none/star_formation_struct.h
+++ b/src/star_formation/none/star_formation_struct.h
@@ -25,4 +25,10 @@
  */
 struct star_formation_xpart_data {};
 
+/**
+ * @brief Star-formation-related properties stored in the particle
+ * data.
+ */
+struct star_formation_part_data {};
+
 #endif /* SWIFT_NONE_STAR_FORMATION_STRUCT_H */
-- 
GitLab