From b698f4bbeb50cffe711439a2bcac5fee1d14c712 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Mon, 11 Feb 2019 15:28:29 +0100
Subject: [PATCH] Prevent the use of the EAGLE entropy floor with the Cool
 limiter at a higher density than the Jeans one.

---
 doc/RTD/source/SubgridModels/EAGLE/index.rst |  9 ++++++---
 src/entropy_floor/EAGLE/entropy_floor.h      | 11 +++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/doc/RTD/source/SubgridModels/EAGLE/index.rst b/doc/RTD/source/SubgridModels/EAGLE/index.rst
index aab9de72ab..0587f3f2e0 100644
--- a/doc/RTD/source/SubgridModels/EAGLE/index.rst
+++ b/doc/RTD/source/SubgridModels/EAGLE/index.rst
@@ -26,9 +26,9 @@ low-density high-metallicity particles to cool below the warm phase because
 of over-cooling induced by the absence of metal diffusion. This limit plays
 only a small role in practice. The second limit, labelled as ``Jeans``, is
 used to prevent the fragmentation of high-density gas into clumps that
-cannot be resolved by the solver. The two limits are sketched on the
-following figure. An additional over-density criterion is applied to
-prevent gas not collapsed into structures from being affected.
+cannot be resolved by the coupled hydro+gravity solver. The two limits are
+sketched on the following figure. An additional over-density criterion is
+applied to prevent gas not collapsed into structures from being affected.
 
 .. figure:: EAGLE_entropy_floor.svg
     :width: 400px
@@ -69,6 +69,9 @@ EAGLE run, that section of the parameter file reads:
      Cool_gamma_effective:            1.        # Slope the of the EAGLE Cool limiter entropy floor
 
 
+Note that the model only makes sense if the ``Cool`` threshold is at a lower
+density than the ``Jeans`` threshold.
+
 .. _EAGLE_chemical_tracers:
 
 Chemical tracers
diff --git a/src/entropy_floor/EAGLE/entropy_floor.h b/src/entropy_floor/EAGLE/entropy_floor.h
index 8ea1e8631c..ab6413a8b0 100644
--- a/src/entropy_floor/EAGLE/entropy_floor.h
+++ b/src/entropy_floor/EAGLE/entropy_floor.h
@@ -168,6 +168,17 @@ static INLINE void entropy_floor_init(struct entropy_floor_properties *props,
   props->Cool_gamma_effective =
       parser_get_param_float(params, "EAGLEEntropyFloor:Cool_gamma_effective");
 
+  /* Cross-check that the input makes sense */
+  if (props->Cool_density_threshold_H_p_cm3 >=
+      props->Jeans_density_threshold_H_p_cm3) {
+    error(
+        "Invalid values for the entrop floor density thresholds. The 'Jeans' "
+        "threshold (%e cm^-3) should be at a higher density than the 'Cool' "
+        "threshold (%e cm^-3)",
+        props->Jeans_density_threshold_H_p_cm3,
+        props->Cool_density_threshold_H_p_cm3);
+  }
+
   /* Initial Hydrogen abundance (mass fraction) */
   const double X_H = hydro_props->hydrogen_mass_fraction;
 
-- 
GitLab