From 7ba85366aaf618f6dab0a9d758929729899ba375 Mon Sep 17 00:00:00 2001
From: Robert Izzard <r.izzard@surrey.ac.uk>
Date: Sat, 7 Aug 2021 15:28:27 +0100
Subject: [PATCH] update MINT_initial_XHc to use the initial hydrogen in the
 table

fix build issue in timestep_CHeB
---
 src/MINT/MINT_initial_XHc.c  | 30 ++++++++++++++++++------------
 src/binary_c_parameters.h    |  2 +-
 src/timestep/timestep_CHeB.c |  8 ++++++--
 3 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/src/MINT/MINT_initial_XHc.c b/src/MINT/MINT_initial_XHc.c
index 158761bc9..e83120ee7 100644
--- a/src/MINT/MINT_initial_XHc.c
+++ b/src/MINT/MINT_initial_XHc.c
@@ -11,27 +11,33 @@ double MINT_initial_XHc(struct stardata_t * const stardata)
      * Determine the initial central hydrogen abundance
      * in the MINT models
      */
-    const double MINT_offset = 0.7 - 0.6985;
+    /*
+     const double MINT_offset = 0.7 - 0.6985;
     const double Z =  Max(0.0,
                           0.760 - 3.0 * stardata->common.metallicity - MINT_offset);
     return Z;
+    */
 
-    int i=1;
+    int i = 1; // XHC column
     const int nperline =
         stardata->store->MINT_tables[MINT_TABLE_MS]->ndata +
         stardata->store->MINT_tables[MINT_TABLE_MS]->nparam;
 
-    while(*(stardata->store->MINT_tables[MINT_TABLE_MS]->data +
-            MINT_MS_CENTRAL_HYDROGEN +
-            i*nperline) >
-          *(stardata->store->MINT_tables[MINT_TABLE_MS]->data +
-            MINT_MS_CENTRAL_HYDROGEN +
-            (i-1)*nperline))
+    double * p = stardata->store->MINT_tables[MINT_TABLE_MS]->data + i;
+    double * const pmin = p;
+    double * const pmax = p + nperline * stardata->store->MINT_tables[MINT_TABLE_MS]->nlines;
+
+    const double XHC0 = *p; /* first value */
+
+    /*
+     * While the abundance is increasing, keep looping through
+     * lines of data. When it
+     */
+    while(p < pmax && *p >= XHC0)
     {
-        i++;
+        p += nperline;
     }
-    return *(stardata->store->MINT_tables[MINT_TABLE_MS]->data +
-             MINT_MS_CENTRAL_HYDROGEN +
-             (i-1)*nperline);
+    p = Max(p - nperline, pmin);
+    return *p;
 }
 #endif //MINT
diff --git a/src/binary_c_parameters.h b/src/binary_c_parameters.h
index 04660e8e8..dcf45b9e9 100644
--- a/src/binary_c_parameters.h
+++ b/src/binary_c_parameters.h
@@ -64,7 +64,7 @@
  *
  * Post-MS evolution has not yet been implemented.
  */
-//#define MINT
+#define MINT
 
 
 /************************************************************
diff --git a/src/timestep/timestep_CHeB.c b/src/timestep/timestep_CHeB.c
index bb7319eae..d3afe5e96 100644
--- a/src/timestep/timestep_CHeB.c
+++ b/src/timestep/timestep_CHeB.c
@@ -5,8 +5,12 @@ No_empty_translation_unit_warning;
 
 void timestep_CHeB(Timestep_prototype_args)
 {
-    if(stardata->preferences->stellar_structure_algorithm == STELLAR_STRUCTURE_ALGORITHM_MINT &&
-       MINT_has_table(MINT_TABLE_CHeB_TA))
+    if(stardata->preferences->stellar_structure_algorithm == STELLAR_STRUCTURE_ALGORITHM_MINT
+#ifdef MINT
+       &&
+       MINT_has_table(MINT_TABLE_CHeB_TA)
+#endif//MINT
+        )
     {
 #ifdef MINT
         double phase_lifetime;
-- 
GitLab