diff --git a/src/MINT/MINT_call_BSE_stellar_structure.c b/src/MINT/MINT_call_BSE_stellar_structure.c index dde9bb74b644d90f0a5beeb64d747d10c83a5f89..7bfaad215b46b6763648b95524f1f800f0252754 100644 --- a/src/MINT/MINT_call_BSE_stellar_structure.c +++ b/src/MINT/MINT_call_BSE_stellar_structure.c @@ -11,7 +11,16 @@ int MINT_call_BSE_stellar_structure(struct stardata_t * const stardata, /* * Call BSE stellar structure routine from MINT */ - printf("call bse\n"); + Boolean vb = FALSE; + + if(vb) + printf("MINT_call_BSE_stellar_structure: model %d time %30.20e : star %d (%d %d) -> call BSE\n", + stardata->model.model_number, + stardata->model.time, + newstar ? newstar->starnum : oldstar ? oldstar->starnum : -1, + oldstar ? oldstar->stellar_type : -1, + newstar ? newstar->stellar_type : -1 + ); int ret = newstar->stellar_type; if(oldstar != NULL) { @@ -34,23 +43,19 @@ int MINT_call_BSE_stellar_structure(struct stardata_t * const stardata, } /* - * Testing: allocate arrays + * Allocate array space that MINT doesn't need + * but BSE does */ - if(newstar->luminosities == NULL) - { - newstar->luminosities = Malloc(sizeof(double)*LUMS_ARRAY_SIZE); - } - if(newstar->timescales == NULL) - { - newstar->timescales = Malloc(sizeof(double)*TSCLS_ARRAY_SIZE); - } - if(newstar->GB == NULL) - { - newstar->GB = Malloc(sizeof(double)*GB_ARRAY_SIZE); - } + Boolean alloc[3]; + stellar_structure_BSE_alloc_arrays(newstar, + newstar->timescales, + newstar->luminosities, + newstar->GB, + alloc); - printf("MINT call BSE stellar structure %p \n", - (void*)newstar->luminosities); + if(vb) + printf("MINT call BSE stellar structure %p \n", + (void*)newstar->luminosities); stellar_timescales(newstar->stellar_type, newstar->phase_start_mass, @@ -69,6 +74,9 @@ int MINT_call_BSE_stellar_structure(struct stardata_t * const stardata, newstar->timescales, newstar->luminosities, newstar->GB); + + + stellar_structure_BSE_free_arrays(newstar, alloc); } return ret; } diff --git a/src/MINT/MINT_stellar_structure.c b/src/MINT/MINT_stellar_structure.c index c99c794fd2db476ffe33d2292a96e1b0c52ee4bd..0327c487c90cfb047422ece18fee30eb1efa33c9 100644 --- a/src/MINT/MINT_stellar_structure.c +++ b/src/MINT/MINT_stellar_structure.c @@ -38,11 +38,13 @@ int MINT_stellar_structure(struct stardata_t * const stardata, newstar); } -// if(vb) - printf("MINT model %d (%d %d)\n", + if(vb) + printf("MINT_stellar_structure: model %d time %30.20e (stellar types %d %d)\n", stardata->model.model_number, + stardata->model.time, oldstar->stellar_type, newstar->stellar_type); + if(oldstar != NULL) { /* @@ -76,11 +78,13 @@ int MINT_stellar_structure(struct stardata_t * const stardata, newstar->TAMS_core_mass = 0.0; #endif// NUCSYN newstar->tm = newstar->age; - printf("MS ended : L=%g R=%g Mc=%g tm=%g\n", - newstar->TAMS_luminosity, - newstar->TAMS_radius, - newstar->TAMS_core_mass, - newstar->tm); + + if(vb) + printf("MS ended : L=%g R=%g Mc=%g tm=%g\n", + newstar->TAMS_luminosity, + newstar->TAMS_radius, + newstar->TAMS_core_mass, + newstar->tm); } } else if(oldstar->stellar_type == CHeB) @@ -119,7 +123,7 @@ int MINT_stellar_structure(struct stardata_t * const stardata, * Call BSE before MINT? */ const unsigned int action = call_bse_action[newstar->stellar_type]; - vb=1; + if(vb)printf("MINT star %d : t=%30.20e st = %d action = %u %s X=%g Y=%g\n", newstar->starnum, stardata->model.time, @@ -137,6 +141,7 @@ int MINT_stellar_structure(struct stardata_t * const stardata, if(action == MINT_CALL_BSE_BEFORE || action == MINT_CALL_BSE_BOTH) { + if(vb) printf("MINT_stellar_structure : call BSE before MINT\n"); ret = MINT_call_BSE_stellar_structure(stardata, oldstar, newstar, @@ -152,6 +157,7 @@ int MINT_stellar_structure(struct stardata_t * const stardata, */ if(functions[newstar->stellar_type] != NULL) { + if(vb) printf("MINT_stellar_structure : call MINT structure function\n"); ret = functions[newstar->stellar_type](stardata, oldstar, newstar, @@ -168,6 +174,7 @@ int MINT_stellar_structure(struct stardata_t * const stardata, if(action == MINT_CALL_BSE_AFTER || action == MINT_CALL_BSE_BOTH) { + if(vb) printf("MINT_stellar_structure : call BSE after MINT\n"); ret = MINT_call_BSE_stellar_structure(stardata, oldstar, newstar, @@ -178,7 +185,7 @@ int MINT_stellar_structure(struct stardata_t * const stardata, } } -// if(vb) + if(vb) printf("MINT_stellar_structure return %d (stellar types %d %d)\n", ret, oldstar->stellar_type, diff --git a/src/MINT/MINT_stellar_structure_CHeB.c b/src/MINT/MINT_stellar_structure_CHeB.c index ef68664ac990394ddba97fc7a7cb37f1bb653feb..f28b30a22959f38b7dea46d021d5aac667353981 100644 --- a/src/MINT/MINT_stellar_structure_CHeB.c +++ b/src/MINT/MINT_stellar_structure_CHeB.c @@ -14,17 +14,22 @@ Stellar_type MINT_stellar_structure_CHeB(struct stardata_t * RESTRICT const star struct star_t * const newstar, const Caller_id caller_id MAYBE_UNUSED) { + const Boolean vb = FALSE; + /* * Boolean to test for data availability */ const Boolean * const available = stardata->store->MINT_data_available[MINT_TABLE_CHeB]; + if(vb) printf("MINT_stellar_structure_CHeB : MINT data available? %s\n", + Yesno(available!=NULL)); - if(available == FALSE) + if(available == NULL) { /* * MINT table unavailable, call BSE */ newstar->stellar_type = CHeB; + if(vb) printf("MINT_stellar_structure_CHeB : data not available, call BSE\n"); return MINT_call_BSE_stellar_structure(stardata, prevstar, newstar, @@ -65,7 +70,7 @@ Stellar_type MINT_stellar_structure_CHeB(struct stardata_t * RESTRICT const star } } #endif // __DEPRECATED - const Boolean vb = FALSE; + /******************************/ /** Core-helium burning star **/ /******************************/ diff --git a/src/stellar_structure/stellar_structure_BSE.c b/src/stellar_structure/stellar_structure_BSE.c index c8ba372062db9bc2df2c5fb74d74ea778416e424..fdb784cfe1d2babb1af254de0556765ac52aed7f 100644 --- a/src/stellar_structure/stellar_structure_BSE.c +++ b/src/stellar_structure/stellar_structure_BSE.c @@ -21,7 +21,7 @@ int stellar_structure_BSE(struct stardata_t * const stardata, double * const luminosities, double * const GB) { - printf("stellar structure called from %s with age %g (star %d, type %d, timescales %p, luminosities %p, GB %p)\n", + Dprint("stellar structure called from %s with age %g (star %d, type %d, timescales %p, luminosities %p, GB %p)\n", Stellar_structure_caller_string(caller_id), star->age, star->starnum, @@ -71,58 +71,24 @@ int stellar_structure_BSE_with_newstar(struct stardata_t * const stardata, Supernova_type new_SN_type = SN_NONE; - Boolean alloc_timescales, alloc_luminosities, alloc_GB; - if(timescales != NULL) - { - newstar->timescales = timescales; - alloc_timescales = FALSE; - } - else - { - newstar->timescales = - Malloc(sizeof(double) * TSCLS_ARRAY_SIZE); - alloc_timescales = TRUE; - } - - if(luminosities != NULL) - { - newstar->luminosities = luminosities; - alloc_luminosities = FALSE; - } - else - { - newstar->luminosities = - Malloc(sizeof(double) * LUMS_ARRAY_SIZE); - alloc_luminosities = TRUE; - } - - if(GB != NULL) - { - alloc_GB = FALSE; - newstar->GB = GB; - } - else - { - newstar->GB = - Malloc(sizeof(double) * GB_ARRAY_SIZE); - alloc_GB = TRUE; - } + Boolean alloc[3]; + stellar_structure_BSE_alloc_arrays(newstar, timescales, luminosities, GB, alloc); Dprint("timescales = %p (alloced? %s) luminosities = %p (alloced? %s) GB = %p (alloced? %s)\n", (void*)newstar->timescales, - Yesno(alloc_timescales), + Yesno(alloc[0]), (void*)newstar->luminosities, - Yesno(alloc_luminosities), + Yesno(alloc[1]), (void*)newstar->GB, - Yesno(alloc_GB)); + Yesno(alloc[2])); /* * If any of the above is newly allocated, recalculate * the star's timescales and luminosities */ - if(alloc_luminosities == TRUE || - alloc_timescales == TRUE || - alloc_GB == TRUE) + if(alloc[0] == TRUE || + alloc[1] == TRUE || + alloc[2] == TRUE) { Dprint("Calculate timescales\n"); stellar_timescales(newstar->stellar_type, @@ -144,9 +110,9 @@ int stellar_structure_BSE_with_newstar(struct stardata_t * const stardata, stardata->star[0].phase_start_mass, stardata->star[1].phase_start_mass, newstar->mass, - Yesno(alloc_luminosities), - Yesno(alloc_timescales), - Yesno(alloc_GB)); + Yesno(alloc[0]), + Yesno(alloc[1]), + Yesno(alloc[2])); stellar_structure_BSE_given_timescales(newstar, oldstar, @@ -157,18 +123,8 @@ int stellar_structure_BSE_with_newstar(struct stardata_t * const stardata, newstar->tms = newstar->tm; new_SN_type = newstar->SN_type; - if(alloc_timescales) - { - Safe_free(newstar->timescales); - } - if(alloc_luminosities) - { - Safe_free(newstar->luminosities); - } - if(alloc_GB) - { - Safe_free(newstar->GB); - } + stellar_structure_BSE_free_arrays(newstar, + alloc); /* * Propagate SN type diff --git a/src/stellar_structure/stellar_structure_BSE_alloc_arrays.c b/src/stellar_structure/stellar_structure_BSE_alloc_arrays.c new file mode 100644 index 0000000000000000000000000000000000000000..41d61e7f1151b4f29b3d3e61a4fbeb40a94471e3 --- /dev/null +++ b/src/stellar_structure/stellar_structure_BSE_alloc_arrays.c @@ -0,0 +1,50 @@ +#include "../binary_c.h" +No_empty_translation_unit_warning; + +void stellar_structure_BSE_alloc_arrays(struct star_t * const star, + double * const timescales, + double * const luminosities, + double * const GB, + Boolean alloc[3]) +{ + /* + * Allocate arrays for BSE stellar structure call: + * set the alloc[3] array Booleans so they can be freed later + * if required + */ + if(timescales != NULL) + { + star->timescales = timescales; + alloc[0] = FALSE; + } + else + { + star->timescales = + Malloc(sizeof(double) * TSCLS_ARRAY_SIZE); + alloc[0] = TRUE; + } + + if(luminosities != NULL) + { + star->luminosities = luminosities; + alloc[1] = FALSE; + } + else + { + star->luminosities = + Malloc(sizeof(double) * LUMS_ARRAY_SIZE); + alloc[1] = TRUE; + } + + if(GB != NULL) + { + alloc[2] = FALSE; + star->GB = GB; + } + else + { + star->GB = + Malloc(sizeof(double) * GB_ARRAY_SIZE); + alloc[2] = TRUE; + } +} diff --git a/src/stellar_structure/stellar_structure_BSE_free_arrays.c b/src/stellar_structure/stellar_structure_BSE_free_arrays.c new file mode 100644 index 0000000000000000000000000000000000000000..b325c032c233c7b6f1982d05f891cb75bc7bbf8b --- /dev/null +++ b/src/stellar_structure/stellar_structure_BSE_free_arrays.c @@ -0,0 +1,10 @@ +#include "../binary_c.h" +No_empty_translation_unit_warning; + +void stellar_structure_BSE_free_arrays(struct star_t * const star, + Boolean alloc[3]) +{ + if(alloc[0]) Safe_free(star->timescales); + if(alloc[1]) Safe_free(star->luminosities); + if(alloc[2]) Safe_free(star->GB); +} diff --git a/src/stellar_structure/stellar_structure_CHeB.c b/src/stellar_structure/stellar_structure_CHeB.c index 5df8158598ea8221cce7852b587d88d546833290..da58c2791df4217e69611a8af6efabd901ffbb25 100644 --- a/src/stellar_structure/stellar_structure_CHeB.c +++ b/src/stellar_structure/stellar_structure_CHeB.c @@ -46,7 +46,13 @@ static Stellar_type stellar_structure_CHeB_implementation(struct star_t *newstar * Core helium burning star. */ #ifdef MINT - if(stardata->preferences->stellar_structure_algorithm == + /* + * Check caller_id : if we're called from MINT, this is + * because we are a backup call. Prevent recursion. + */ + if(caller_id != STELLAR_STRUCTURE_CALLER_MINT + && + stardata->preferences->stellar_structure_algorithm == STELLAR_STRUCTURE_ALGORITHM_MINT) { /* let MINT handle this phase */ diff --git a/src/stellar_structure/stellar_structure_HG.c b/src/stellar_structure/stellar_structure_HG.c index 0c68d683ac2c5f15dca71919e37b9a099b593dce..03cb1e110c309ec00143c1e80e23477680579597 100644 --- a/src/stellar_structure/stellar_structure_HG.c +++ b/src/stellar_structure/stellar_structure_HG.c @@ -20,7 +20,7 @@ Stellar_type stellar_structure_HG(struct star_t * RESTRICT const newstar, double rho,tau; const double thg = newstar->timescales[T_BGB] - newstar->tm; double mcbgbf; - printf("SHG\n"); + #ifdef MINT if(stardata->preferences->stellar_structure_algorithm == STELLAR_STRUCTURE_ALGORITHM_MINT) diff --git a/src/stellar_structure/stellar_structure_prototypes.h b/src/stellar_structure/stellar_structure_prototypes.h index 53167625ab4fe31dfccfcfdbb120133a12f69133..7af146e6400d9b902008a6afa9446fddc76c24f4 100644 --- a/src/stellar_structure/stellar_structure_prototypes.h +++ b/src/stellar_structure/stellar_structure_prototypes.h @@ -155,5 +155,13 @@ void stellar_structure_small_envelope_miller_bertolami(struct stardata_t * const void BSE_init(struct stardata_t * const stardata); +void stellar_structure_BSE_alloc_arrays(struct star_t * const star, + double * const timescales, + double * const luminosities, + double * const GB, + Boolean alloc[3]); +void stellar_structure_BSE_free_arrays(struct star_t * const star, + Boolean alloc[3]); + #endif /*STELLAR_STRUCTURE_PROTOTYPES_H*/ diff --git a/tbse.mint b/tbse.mint index 5832755236ac307eaf49c2eadc72f67330835dde..363f2e13a8d7117bb0defdb56332421d884e7bc4 100755 --- a/tbse.mint +++ b/tbse.mint @@ -32,7 +32,7 @@ MINT_MS_REJUVENATION=True MINT_DISABLE_GRID_LOAD_WARNINGS=False MINT_DATA_CLEANUP=True MINT_USE_ZAMS_PROFILES=True -MINT_FALLBACK_TO_TEST_DATA=True +MINT_FALLBACK_TO_TEST_DATA=False MINT_DIR=$HOME/data/MINT/data # maximum stellar type allowed : 16 means run them all # a negative number means this is ignored if MASSLESS_REMNANT (15)