diff --git a/src/binary_c_macros.h b/src/binary_c_macros.h index c1e166d17ff0d5bd6bcda3b4a01296f8b6df6a7a..74c3b51669ae877d68665463eda0f722a84b091f 100644 --- a/src/binary_c_macros.h +++ b/src/binary_c_macros.h @@ -369,4 +369,10 @@ enum { #endif// __HAVE_LIBPTHREAD__ +/* + * Timescale that forces re-calculation : this + * cannot be physical + */ +#define FORCE_TIMESCALES_CALCULATION -666.67676767 + #endif /* BINARY_MACROS_H */ diff --git a/src/common_envelope/common_envelope_evolution.h b/src/common_envelope/common_envelope_evolution.h index fcf2a2106c5cbd601d3c4de2e84459991afd00d3..c5080c90bafdfee08b49f9b75bb608a1bc233ec7 100644 --- a/src/common_envelope/common_envelope_evolution.h +++ b/src/common_envelope/common_envelope_evolution.h @@ -367,16 +367,13 @@ No_empty_translation_unit_warning; #define STELLAR_STRUCTUREnewtype \ { \ - Boolean alloc; \ - if(donor->timescales == NULL) \ - { \ - donor->timescales = Malloc(sizeof(double)*TSCLS_ARRAY_SIZE); \ - alloc = TRUE; \ - } \ - else \ - { \ - alloc = FALSE; \ - } \ + Boolean alloc[3]; \ + stellar_structure_BSE_alloc_arrays(donor, \ + donor->timescales, \ + donor->luminosities, \ + donor->GB, \ + alloc); \ + donor->timescales[0] = FORCE_TIMESCALES_CALCULATION; \ stellar_structure(stardata, \ STELLAR_STRUCTURE_CALLER_common_envelope_evolution, \ donor, \ @@ -391,7 +388,7 @@ No_empty_translation_unit_warning; memcpy(&tscls1[0], \ donor->timescales, \ sizeof(double)*TSCLS_ARRAY_SIZE); \ - if(alloc) Safe_free(donor->timescales); \ + stellar_structure_BSE_free_arrays(donor,alloc); \ } @@ -450,12 +447,13 @@ No_empty_translation_unit_warning; donor->mass, \ r1, \ donor->angular_momentum); \ - Boolean alloc = FALSE; \ - if(donor->timescales == NULL) \ - { \ - donor->timescales = Malloc(sizeof(double)*TSCLS_ARRAY_SIZE); \ - alloc = TRUE; \ - } \ + Boolean alloc[3]; \ + stellar_structure_BSE_alloc_arrays(donor, \ + donor->timescales, \ + donor->luminosities, \ + donor->GB, \ + alloc); \ + donor->timescales[0] = FORCE_TIMESCALES_CALCULATION; \ stellar_structure(stardata, \ STELLAR_STRUCTURE_CALLER_common_envelope_evolution, \ donor, \ @@ -472,7 +470,7 @@ No_empty_translation_unit_warning; memcpy(&tscls1[0], \ donor->timescales, \ sizeof(double)*TSCLS_ARRAY_SIZE); \ - if(alloc)Safe_free(donor->timescales); \ + stellar_structure_BSE_free_arrays(donor,alloc); \ } @@ -487,13 +485,13 @@ No_empty_translation_unit_warning; accretor->mass, \ r2, \ accretor->angular_momentum); \ - Boolean alloc = FALSE; \ - if(accretor->timescales == NULL) \ - { \ - accretor->timescales = \ - Malloc(sizeof(double) * TSCLS_ARRAY_SIZE); \ - alloc = TRUE; \ - } \ + Boolean alloc[3]; \ + stellar_structure_BSE_alloc_arrays(accretor, \ + accretor->timescales, \ + accretor->luminosities, \ + accretor->GB, \ + alloc); \ + accretor->timescales[0] = FORCE_TIMESCALES_CALCULATION; \ stellar_structure(stardata, \ STELLAR_STRUCTURE_CALLER_common_envelope_evolution, \ accretor, \ @@ -509,7 +507,8 @@ No_empty_translation_unit_warning; memcpy(&tscls2[0], \ accretor->timescales, \ sizeof(double) * TSCLS_ARRAY_SIZE); \ - if(alloc)Safe_free(accretor->timescales); \ + stellar_structure_BSE_free_arrays(accretor, \ + alloc); \ } diff --git a/src/common_envelope/common_envelope_evolution_BSE.c b/src/common_envelope/common_envelope_evolution_BSE.c index 8e8c838cf76d88cca8716069646d17f109821a73..690b110ccd84d2183f3e1698a569ec5d417a7215 100644 --- a/src/common_envelope/common_envelope_evolution_BSE.c +++ b/src/common_envelope/common_envelope_evolution_BSE.c @@ -258,49 +258,42 @@ int common_envelope_evolution_BSE ( * Obtain the core masses and radii and make sure any nucleosynthesis up to * this point has been done. First, for star 1. */ - //stellar_type = donor->stellar_type; - - /* - * Recalculate structure if required - */ - //STRUCTURE1(DENY_EVENTS); -{ - Boolean deny_was = stardata->model.deny_new_events; - Set_event_denial(DENY_EVENTS); - Dprint("1pre = { stellar_type=%d, m01=%g m1=%g r1=%g J1=%g }n", - donor->stellar_type, - donor->phase_start_mass, - donor->mass, - r1, - donor->angular_momentum); - Boolean alloc = FALSE; - if(donor->timescales == NULL) { - donor->timescales = Malloc(sizeof(double)*TSCLS_ARRAY_SIZE); - alloc = TRUE; - } + Boolean deny_was = stardata->model.deny_new_events; + Set_event_denial(DENY_EVENTS); + Dprint("1pre = { stellar_type=%d, m01=%g m1=%g r1=%g J1=%g }n", + donor->stellar_type, + donor->phase_start_mass, + donor->mass, + r1, + donor->angular_momentum); + Boolean alloc[3]; + stellar_structure_BSE_alloc_arrays(donor, + donor->timescales, + NULL, + NULL, + alloc); + donor->timescales[0] = FORCE_TIMESCALES_CALCULATION; + stellar_structure(stardata, + STELLAR_STRUCTURE_CALLER_common_envelope_evolution, + donor, + NULL, + DISALLOW_SN); + Set_event_denial(deny_was); + tm1 = donor->tm; + tn = donor->tn; + r1 = donor->radius; + rc1 = donor->core_radius; + menv = donor->menv; + k21 = donor->k2; - stellar_structure(stardata, - STELLAR_STRUCTURE_CALLER_common_envelope_evolution, - donor, - NULL, - DISALLOW_SN); + memcpy(&tscls1[0], + donor->timescales, + sizeof(double)*TSCLS_ARRAY_SIZE); - Set_event_denial(deny_was); - tm1 = donor->tm; - tn = donor->tn; - r1 = donor->radius; - rc1 = donor->core_radius; - menv = donor->menv; - /*renv = donor->renv;*/ - k21 = donor->k2; - - memcpy(&tscls1[0], - donor->timescales, - sizeof(double)*TSCLS_ARRAY_SIZE); - if(alloc)Safe_free(donor->timescales); - } + stellar_structure_BSE_free_arrays(donor,alloc); + } /* * menv is the convective envelope mass diff --git a/src/stellar_structure/stellar_structure_BSE.c b/src/stellar_structure/stellar_structure_BSE.c index fdb784cfe1d2babb1af254de0556765ac52aed7f..9912c358f1e33ae10d390e0030aa4d10a8f5bd90 100644 --- a/src/stellar_structure/stellar_structure_BSE.c +++ b/src/stellar_structure/stellar_structure_BSE.c @@ -83,13 +83,15 @@ int stellar_structure_BSE_with_newstar(struct stardata_t * const stardata, Yesno(alloc[2])); /* - * If any of the above is newly allocated, recalculate + * If any of the above is newly allocated, or if the first element + * of the timescales is FORCE_TIMESCALES_CALCULATION, recalculate * the star's timescales and luminosities */ - if(alloc[0] == TRUE || - alloc[1] == TRUE || - alloc[2] == TRUE) - { + if(alloc[0] == TRUE || + alloc[1] == TRUE || + alloc[2] == TRUE || + Fequal(newstar->timescales[0],FORCE_TIMESCALES_CALCULATION) ) + { Dprint("Calculate timescales\n"); stellar_timescales(newstar->stellar_type, newstar->phase_start_mass, diff --git a/src/stellar_structure/stellar_structure_BSE_alloc_arrays.c b/src/stellar_structure/stellar_structure_BSE_alloc_arrays.c index 41d61e7f1151b4f29b3d3e61a4fbeb40a94471e3..7061b7f79c1d33de35fc2a5b246b86c7feccbece 100644 --- a/src/stellar_structure/stellar_structure_BSE_alloc_arrays.c +++ b/src/stellar_structure/stellar_structure_BSE_alloc_arrays.c @@ -12,39 +12,20 @@ void stellar_structure_BSE_alloc_arrays(struct star_t * const star, * 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; - } +#define Check(VAR,N,SIZE) \ + if((VAR) != NULL) \ + { \ + star->VAR = (VAR); \ + alloc[N] = FALSE; \ + } \ + else \ + { \ + star->VAR = \ + Malloc(sizeof(double) * (SIZE)); \ + alloc[N] = 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; - } + Check(timescales,0,TSCLS_ARRAY_SIZE); + Check(luminosities,1,LUMS_ARRAY_SIZE); + Check(GB,2,GB_ARRAY_SIZE); } diff --git a/src/stellar_structure/stellar_structure_BSE_free_arrays.c b/src/stellar_structure/stellar_structure_BSE_free_arrays.c index b325c032c233c7b6f1982d05f891cb75bc7bbf8b..8425f30da0ebd3947bfb62d2452ec568b78f5e9a 100644 --- a/src/stellar_structure/stellar_structure_BSE_free_arrays.c +++ b/src/stellar_structure/stellar_structure_BSE_free_arrays.c @@ -2,8 +2,11 @@ No_empty_translation_unit_warning; void stellar_structure_BSE_free_arrays(struct star_t * const star, - Boolean alloc[3]) + const Boolean alloc[3]) { + /* + * Free arrays used to calculate BSE stellar structure + */ 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_BSE_given_timescales.c b/src/stellar_structure/stellar_structure_BSE_given_timescales.c index d7d751e0807d75470b623af2f5ced94e354d04a6..e62b0a1d9d58d8cd386b0561235f8506da3f0d5c 100644 --- a/src/stellar_structure/stellar_structure_BSE_given_timescales.c +++ b/src/stellar_structure/stellar_structure_BSE_given_timescales.c @@ -198,6 +198,7 @@ int stellar_structure_BSE_given_timescales(struct star_t *newstar, ); /* do not allow CHeB stars to reverse their evolution */ + if( (newstar->age < newstar->timescales[T_BGB] && (newstar->stellar_type<CHeB || diff --git a/src/stellar_structure/stellar_structure_prototypes.h b/src/stellar_structure/stellar_structure_prototypes.h index 7af146e6400d9b902008a6afa9446fddc76c24f4..bb071dcc040d3ab471434b3a2ecfb5cd257f0cd2 100644 --- a/src/stellar_structure/stellar_structure_prototypes.h +++ b/src/stellar_structure/stellar_structure_prototypes.h @@ -161,7 +161,7 @@ void stellar_structure_BSE_alloc_arrays(struct star_t * const star, double * const GB, Boolean alloc[3]); void stellar_structure_BSE_free_arrays(struct star_t * const star, - Boolean alloc[3]); + const Boolean alloc[3]); #endif /*STELLAR_STRUCTURE_PROTOTYPES_H*/