From 90207e8d40c876b57f3784dfa3e4ffb9173b4ae8 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Sun, 3 Feb 2019 12:53:34 +0100
Subject: [PATCH] Update the other hydro schemes to also compile with the star
 formation model and entropy floor model.

---
 doc/RTD/source/SubgridModels/EAGLE/index.rst  |  7 +++
 src/hydro/Gadget2/hydro_part.h                |  2 +-
 src/hydro/GizmoMFM/hydro_part.h               |  4 ++
 src/hydro/GizmoMFV/hydro_part.h               |  4 ++
 src/hydro/Minimal/hydro.h                     | 17 +++++
 src/hydro/Minimal/hydro_part.h                |  4 ++
 src/hydro/Planetary/hydro.h                   | 18 ++++++
 src/hydro/Planetary/hydro_part.h              |  6 +-
 src/hydro/PressureEnergy/hydro.h              | 17 +++++
 src/hydro/PressureEnergy/hydro_part.h         |  6 +-
 .../PressureEnergyMorrisMonaghanAV/hydro.h    | 62 +++++++++++++++++--
 .../hydro_part.h                              |  6 +-
 src/hydro/PressureEntropy/hydro.h             | 15 +++++
 src/hydro/PressureEntropy/hydro_part.h        |  6 +-
 14 files changed, 163 insertions(+), 11 deletions(-)

diff --git a/doc/RTD/source/SubgridModels/EAGLE/index.rst b/doc/RTD/source/SubgridModels/EAGLE/index.rst
index e2489452ef..cc353469bd 100644
--- a/doc/RTD/source/SubgridModels/EAGLE/index.rst
+++ b/doc/RTD/source/SubgridModels/EAGLE/index.rst
@@ -9,6 +9,13 @@ This section of the documentation gives a brief description of the
 different components of the EAGLE sub-grid model. We mostly focus on
 the parameters and values output in the snapshots.
 
+.. _EAGLE_entropy_floors:
+
+Entropy floors
+~~~~~~~~~~~~~~
+
+
+
 .. _EAGLE_chemical_tracers:
 
 Chemical tracers
diff --git a/src/hydro/Gadget2/hydro_part.h b/src/hydro/Gadget2/hydro_part.h
index f817d2cf9b..6b028b0497 100644
--- a/src/hydro/Gadget2/hydro_part.h
+++ b/src/hydro/Gadget2/hydro_part.h
@@ -61,7 +61,7 @@ struct xpart {
   /* Additional data used by the tracers */
   struct tracers_xpart_data tracers_data;
 
-  /* Additional data used by the tracers */
+  /* Additional data used by the star formation */
   struct star_formation_xpart_data sf_data;
 
 #ifdef WITH_LOGGER
diff --git a/src/hydro/GizmoMFM/hydro_part.h b/src/hydro/GizmoMFM/hydro_part.h
index a05cae18aa..c4884ebc40 100644
--- a/src/hydro/GizmoMFM/hydro_part.h
+++ b/src/hydro/GizmoMFM/hydro_part.h
@@ -21,6 +21,7 @@
 
 #include "chemistry_struct.h"
 #include "cooling_struct.h"
+#include "star_formation_struct.h"
 #include "tracers_struct.h"
 
 /* Extra particle data not needed during the computation. */
@@ -44,6 +45,9 @@ struct xpart {
   /* Additional data used by the tracers */
   struct tracers_xpart_data tracers_data;
 
+  /* Additional data used by the star formation */
+  struct star_formation_xpart_data sf_data;
+
 } SWIFT_STRUCT_ALIGN;
 
 /* Data of a single particle. */
diff --git a/src/hydro/GizmoMFV/hydro_part.h b/src/hydro/GizmoMFV/hydro_part.h
index 8794b59771..c6bbaeb1c8 100644
--- a/src/hydro/GizmoMFV/hydro_part.h
+++ b/src/hydro/GizmoMFV/hydro_part.h
@@ -21,6 +21,7 @@
 
 #include "chemistry_struct.h"
 #include "cooling_struct.h"
+#include "star_formation_struct.h"
 #include "tracers_struct.h"
 
 /* Extra particle data not needed during the computation. */
@@ -44,6 +45,9 @@ struct xpart {
   /* Additional data used by the tracers */
   struct tracers_xpart_data tracers_data;
 
+  /* Additional data used by the star formation */
+  struct star_formation_xpart_data sf_data;
+
 } SWIFT_STRUCT_ALIGN;
 
 /* Data of a single particle. */
diff --git a/src/hydro/Minimal/hydro.h b/src/hydro/Minimal/hydro.h
index 2af6eb47e8..a580846830 100644
--- a/src/hydro/Minimal/hydro.h
+++ b/src/hydro/Minimal/hydro.h
@@ -337,6 +337,23 @@ hydro_set_physical_internal_energy_dt(struct part *restrict p,
   p->u_dt = du_dt / cosmo->a_factor_internal_energy;
 }
 
+/**
+ * @brief Sets the physical entropy of a particle
+ *
+ * @param p The particle of interest.
+ * @param xp The extended particle data.
+ * @param cosmo Cosmology data structure
+ * @param entropy The physical entropy
+ */
+__attribute__((always_inline)) INLINE static void hydro_set_physical_entropy(
+    struct part *p, struct xpart *xp, const struct cosmology *cosmo,
+    const float entropy) {
+
+  /* Note there is no conversion from physical to comoving entropy */
+  const float comoving_entropy = entropy;
+  xp->u_full = gas_internal_energy_from_entropy(p->rho, comoving_entropy);
+}
+
 /**
  * @brief Computes the hydro time-step of a given particle
  *
diff --git a/src/hydro/Minimal/hydro_part.h b/src/hydro/Minimal/hydro_part.h
index 80e472194e..2068c08b01 100644
--- a/src/hydro/Minimal/hydro_part.h
+++ b/src/hydro/Minimal/hydro_part.h
@@ -34,6 +34,7 @@
 
 #include "chemistry_struct.h"
 #include "cooling_struct.h"
+#include "star_formation_struct.h"
 #include "tracers_struct.h"
 
 /**
@@ -66,6 +67,9 @@ struct xpart {
   /* Additional data used by the tracers */
   struct tracers_xpart_data tracers_data;
 
+  /* Additional data used by the tracers */
+  struct star_formation_xpart_data sf_data;
+
 } SWIFT_STRUCT_ALIGN;
 
 /**
diff --git a/src/hydro/Planetary/hydro.h b/src/hydro/Planetary/hydro.h
index 68dfa3eb82..fbe0b6c8b9 100644
--- a/src/hydro/Planetary/hydro.h
+++ b/src/hydro/Planetary/hydro.h
@@ -360,6 +360,24 @@ hydro_set_physical_internal_energy_dt(struct part *restrict p,
   p->u_dt = du_dt / cosmo->a_factor_internal_energy;
 }
 
+/**
+ * @brief Sets the physical entropy of a particle
+ *
+ * @param p The particle of interest.
+ * @param xp The extended particle data.
+ * @param cosmo Cosmology data structure
+ * @param entropy The physical entropy
+ */
+__attribute__((always_inline)) INLINE static void hydro_set_physical_entropy(
+    struct part *p, struct xpart *xp, const struct cosmology *cosmo,
+    const float entropy) {
+
+  /* Note there is no conversion from physical to comoving entropy */
+  const float comoving_entropy = entropy;
+  xp->u_full =
+      gas_internal_energy_from_entropy(p->rho, comoving_entropy, p->mat_id);
+}
+
 /**
  * @brief Computes the hydro time-step of a given particle
  *
diff --git a/src/hydro/Planetary/hydro_part.h b/src/hydro/Planetary/hydro_part.h
index 1955366da7..383d803fd9 100644
--- a/src/hydro/Planetary/hydro_part.h
+++ b/src/hydro/Planetary/hydro_part.h
@@ -36,6 +36,7 @@
 #include "chemistry_struct.h"
 #include "cooling_struct.h"
 #include "equation_of_state.h"  // For enum material_id
+#include "star_formation_struct.h"
 #include "tracers_struct.h"
 
 /**
@@ -65,9 +66,12 @@ struct xpart {
   /*! Additional data used to record cooling information */
   struct cooling_xpart_data cooling_data;
 
-  /* Additional data used by the tracers */
+  /*! Additional data used by the tracers */
   struct tracers_xpart_data tracers_data;
 
+  /* Additional data used by the star formation */
+  struct star_formation_xpart_data sf_data;
+
 } SWIFT_STRUCT_ALIGN;
 
 /**
diff --git a/src/hydro/PressureEnergy/hydro.h b/src/hydro/PressureEnergy/hydro.h
index 7b6c302fb7..4af00f7a65 100644
--- a/src/hydro/PressureEnergy/hydro.h
+++ b/src/hydro/PressureEnergy/hydro.h
@@ -362,6 +362,23 @@ hydro_set_physical_internal_energy_dt(struct part *restrict p,
   p->u_dt = du_dt / cosmo->a_factor_internal_energy;
 }
 
+/**
+ * @brief Sets the physical entropy of a particle
+ *
+ * @param p The particle of interest.
+ * @param xp The extended particle data.
+ * @param cosmo Cosmology data structure
+ * @param entropy The physical entropy
+ */
+__attribute__((always_inline)) INLINE static void hydro_set_physical_entropy(
+    struct part *p, struct xpart *xp, const struct cosmology *cosmo,
+    const float entropy) {
+
+  /* Note there is no conversion from physical to comoving entropy */
+  const float comoving_entropy = entropy;
+  xp->u_full = gas_internal_energy_from_entropy(p->rho, comoving_entropy);
+}
+
 /**
  * @brief Computes the hydro time-step of a given particle
  *
diff --git a/src/hydro/PressureEnergy/hydro_part.h b/src/hydro/PressureEnergy/hydro_part.h
index 218fbf5dc1..6a2d890049 100644
--- a/src/hydro/PressureEnergy/hydro_part.h
+++ b/src/hydro/PressureEnergy/hydro_part.h
@@ -33,6 +33,7 @@
 
 #include "chemistry_struct.h"
 #include "cooling_struct.h"
+#include "star_formation_struct.h"
 #include "tracers_struct.h"
 
 /**
@@ -62,9 +63,12 @@ struct xpart {
   /*! Additional data used to record cooling information */
   struct cooling_xpart_data cooling_data;
 
-  /* Additional data used by the tracers */
+  /*! Additional data used by the tracers */
   struct tracers_xpart_data tracers_data;
 
+  /*! Additional data used by the star formation */
+  struct star_formation_xpart_data sf_data;
+
 } SWIFT_STRUCT_ALIGN;
 
 /**
diff --git a/src/hydro/PressureEnergyMorrisMonaghanAV/hydro.h b/src/hydro/PressureEnergyMorrisMonaghanAV/hydro.h
index 9767a165d3..b50ca4e254 100644
--- a/src/hydro/PressureEnergyMorrisMonaghanAV/hydro.h
+++ b/src/hydro/PressureEnergyMorrisMonaghanAV/hydro.h
@@ -143,11 +143,12 @@ __attribute__((always_inline)) INLINE static float hydro_get_comoving_entropy(
  * @param cosmo The cosmological model.
  */
 __attribute__((always_inline)) INLINE static float hydro_get_physical_entropy(
-    const struct part *restrict p, const struct cosmology *cosmo) {
+    const struct part *restrict p, const struct xpart *restrict xp,
+    const struct cosmology *cosmo) {
 
   /* Note: no cosmological conversion required here with our choice of
    * coordinates. */
-  return gas_entropy_from_internal_energy(p->rho, p->u);
+  return gas_entropy_from_internal_energy(p->rho, xp->u_full);
 }
 
 /**
@@ -306,12 +307,27 @@ __attribute__((always_inline)) INLINE static void hydro_get_drifted_velocities(
  *
  * @param p The particle of interest
  */
-__attribute__((always_inline)) INLINE static float hydro_get_internal_energy_dt(
-    const struct part *restrict p) {
+__attribute__((always_inline)) INLINE static float
+hydro_get_comoving_internal_energy_dt(const struct part *restrict p) {
 
   return p->u_dt;
 }
 
+/**
+ * @brief Returns the time derivative of internal energy of a particle
+ *
+ * We assume a constant density.
+ *
+ * @param p The particle of interest
+ * @param cosmo Cosmology data structure
+ */
+__attribute__((always_inline)) INLINE static float
+hydro_get_physical_internal_energy_dt(const struct part *restrict p,
+                                      const struct cosmology *cosmo) {
+
+  return p->u_dt * cosmo->a_factor_internal_energy;
+}
+
 /**
  * @brief Sets the time derivative of internal energy of a particle
  *
@@ -320,12 +336,46 @@ __attribute__((always_inline)) INLINE static float hydro_get_internal_energy_dt(
  * @param p The particle of interest.
  * @param du_dt The new time derivative of the internal energy.
  */
-__attribute__((always_inline)) INLINE static void hydro_set_internal_energy_dt(
-    struct part *restrict p, float du_dt) {
+__attribute__((always_inline)) INLINE static void
+hydro_set_comoving_internal_energy_dt(struct part *restrict p, float du_dt) {
 
   p->u_dt = du_dt;
 }
 
+/**
+ * @brief Returns the time derivative of internal energy of a particle
+ *
+ * We assume a constant density.
+ *
+ * @param p The particle of interest.
+ * @param cosmo Cosmology data structure
+ * @param du_dt The new time derivative of the internal energy.
+ */
+__attribute__((always_inline)) INLINE static void
+hydro_set_physical_internal_energy_dt(struct part *restrict p,
+                                      const struct cosmology *cosmo,
+                                      float du_dt) {
+
+  p->u_dt = du_dt / cosmo->a_factor_internal_energy;
+}
+
+/**
+ * @brief Sets the physical entropy of a particle
+ *
+ * @param p The particle of interest.
+ * @param xp The extended particle data.
+ * @param cosmo Cosmology data structure
+ * @param entropy The physical entropy
+ */
+__attribute__((always_inline)) INLINE static void hydro_set_physical_entropy(
+    struct part *p, struct xpart *xp, const struct cosmology *cosmo,
+    const float entropy) {
+
+  /* Note there is no conversion from physical to comoving entropy */
+  const float comoving_entropy = entropy;
+  xp->u_full = gas_internal_energy_from_entropy(p->rho, comoving_entropy);
+}
+
 /**
  * @brief Computes the hydro time-step of a given particle
  *
diff --git a/src/hydro/PressureEnergyMorrisMonaghanAV/hydro_part.h b/src/hydro/PressureEnergyMorrisMonaghanAV/hydro_part.h
index d66249ea17..b75313b58e 100644
--- a/src/hydro/PressureEnergyMorrisMonaghanAV/hydro_part.h
+++ b/src/hydro/PressureEnergyMorrisMonaghanAV/hydro_part.h
@@ -34,6 +34,7 @@
 
 #include "chemistry_struct.h"
 #include "cooling_struct.h"
+#include "star_formation_struct.h"
 #include "tracers_struct.h"
 
 /**
@@ -63,9 +64,12 @@ struct xpart {
   /*! Additional data used to record cooling information */
   struct cooling_xpart_data cooling_data;
 
-  /* Additional data used by the tracers */
+  /*! Additional data used by the tracers */
   struct tracers_xpart_data tracers_data;
 
+  /*! Additional data used by the star formation */
+  struct star_formation_xpart_data sf_data;
+
 } SWIFT_STRUCT_ALIGN;
 
 /**
diff --git a/src/hydro/PressureEntropy/hydro.h b/src/hydro/PressureEntropy/hydro.h
index 2e8d2d5db6..40b3f42eae 100644
--- a/src/hydro/PressureEntropy/hydro.h
+++ b/src/hydro/PressureEntropy/hydro.h
@@ -327,6 +327,21 @@ hydro_set_physical_internal_energy_dt(struct part *restrict p,
   p->entropy_dt =
       gas_entropy_from_internal_energy(p->rho_bar * cosmo->a3_inv, du_dt);
 }
+/**
+ * @brief Sets the physical entropy of a particle
+ *
+ * @param p The particle of interest.
+ * @param xp The extended particle data.
+ * @param cosmo Cosmology data structure
+ * @param entropy The physical entropy
+ */
+__attribute__((always_inline)) INLINE static void hydro_set_physical_entropy(
+    struct part *p, struct xpart *xp, const struct cosmology *cosmo,
+    const float entropy) {
+
+  /* Note there is no conversion from physical to comoving entropy */
+  xp->entropy_full = entropy;
+}
 
 /**
  * @brief Computes the hydro time-step of a given particle
diff --git a/src/hydro/PressureEntropy/hydro_part.h b/src/hydro/PressureEntropy/hydro_part.h
index a404a897b0..992ed4654e 100644
--- a/src/hydro/PressureEntropy/hydro_part.h
+++ b/src/hydro/PressureEntropy/hydro_part.h
@@ -32,6 +32,7 @@
 
 #include "chemistry_struct.h"
 #include "cooling_struct.h"
+#include "star_formation_struct.h"
 #include "tracers_struct.h"
 
 /* Extra particle data not needed during the SPH loops over neighbours. */
@@ -55,9 +56,12 @@ struct xpart {
   /*! Additional data used to record cooling information */
   struct cooling_xpart_data cooling_data;
 
-  /* Additional data used by the tracers */
+  /*! Additional data used by the tracers */
   struct tracers_xpart_data tracers_data;
 
+  /*! Additional data used by the star formation */
+  struct star_formation_xpart_data sf_data;
+
 } SWIFT_STRUCT_ALIGN;
 
 /* Data of a single particle. */
-- 
GitLab