From a2fb917ee6b17ebfa451656ff5dbfe02f48f45ac Mon Sep 17 00:00:00 2001
From: Jacob Kegerreis <jacob.kegerreis@durham.ac.uk>
Date: Sun, 28 Jun 2020 21:55:51 +0100
Subject: [PATCH] Avoid unusual extrapolating for low u with tables

---
 src/equation_of_state/planetary/sesame.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/equation_of_state/planetary/sesame.h b/src/equation_of_state/planetary/sesame.h
index cb62342c05..f2faa51ad7 100644
--- a/src/equation_of_state/planetary/sesame.h
+++ b/src/equation_of_state/planetary/sesame.h
@@ -385,6 +385,14 @@ INLINE static float SESAME_pressure_from_internal_energy(
   P_2 = mat->table_P_rho_T[idx_rho * mat->num_T + idx_u_1 + 1];
   P_3 = mat->table_P_rho_T[(idx_rho + 1) * mat->num_T + idx_u_2];
   P_4 = mat->table_P_rho_T[(idx_rho + 1) * mat->num_T + idx_u_2 + 1];
+  
+  // If below the minimum u at this rho then just use the lowest table values
+  if ((idx_rho > 0.f) && (
+      (intp_u_1 < 0.f) || (intp_u_2 < 0.f) || (P_1 > P_2) || (P_3 > P_4)
+  )) {
+      intp_u_1 = 0;
+      intp_u_2 = 0;
+  }
 
   // If more than two table values are non-positive then return zero
   int num_non_pos = 0;
-- 
GitLab