diff --git a/meson.build b/meson.build index 5ddbb9173f000c3a44ccd77309f0a4e509ba4e04..9ae9278ec6cfcc8f1ff7bf9a5dd7491ae45238f9 100644 --- a/meson.build +++ b/meson.build @@ -455,9 +455,9 @@ else # Note: we disable some of them '-fno-associative-math', '-fno-math-errno', - #'-ffinite-math-only', # not good + '-ffinite-math-only', # not good '-fno-rounding-math', - #'-fno-signaling-nans', # should be off : nan-signalling is required + '-fno-signaling-nans', # should be off : nan-signalling is required '-fcx-limited-range', '-fexcess-precision=fast', # never allow unsafe math optimizations diff --git a/src/binary_c_debug.h b/src/binary_c_debug.h index b74b8954d942136de46b501e8a70eebb6be0d9ab..b11e707f1d2a631e1172b1c14eeaa5fb32df3a2d 100644 --- a/src/binary_c_debug.h +++ b/src/binary_c_debug.h @@ -78,7 +78,7 @@ * the same, but stardata is defined everywhere as a global * variable. */ -#define Debug_expression (TRUE) +#define Debug_expression () /* * If you define Debug_stop_expression, and it is at any time TRUE, @@ -106,7 +106,7 @@ * this is not shown. */ -#define Debug_show_expression " %d %d ",stardata->model.model_number,stardata->star[0].stellar_type +#define Debug_show_expression " " //#undef Debug_show_expression /* diff --git a/src/binary_c_error_codes.h b/src/binary_c_error_codes.h index d7c00f5261eaed070fb0491f1624383145d30d55..d33e78735cf2cac0af2e14dfee3568b2bd9726dd 100644 --- a/src/binary_c_error_codes.h +++ b/src/binary_c_error_codes.h @@ -41,4 +41,12 @@ static char * binary_c_error_code_strings[] MAYBE_UNUSED = { BINARY_C_ERROR_CODE #undef X +#define Binary_c_error_code_is_bad(CODE) ( \ + (CODE)!=BINARY_C_NORMAL_EXIT && \ + (CODE)!=BINARY_C_QUIET_EXIT && \ + (CODE)!=BINARY_C_SPECIAL_EXIT && \ + (CODE)!=BINARY_C_NORMAL_BATCHMODE_EXIT \ + ) + + #endif // BINARY_C_ERROR_CODES_H diff --git a/src/binary_c_parameters.h b/src/binary_c_parameters.h index dcf45b9e92efd776ae8ebf2d805b5bfc06621f3a..04660e8e891b4cf2015af47e834dc0051a3d629c 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/evolution/set_next_timestep.c b/src/evolution/set_next_timestep.c index e1ca855c001c2f467595c65f904ccc178bd41fbd..3d28b44030ab87062c2453cf2e1a3fa7f84d1ff7 100644 --- a/src/evolution/set_next_timestep.c +++ b/src/evolution/set_next_timestep.c @@ -37,6 +37,17 @@ void set_next_timestep(struct stardata_t * RESTRICT const stardata) stardata->model.dtm); } + /* + * Apply nonstellar timestep + */ + double dtm = time_remaining; + nonstellar_timestep(stardata,&dtm); + stardata->model.dtm = + Is_zero(stardata->model.dtm) ? + dtm : + Min(stardata->model.dtm, + dtm); + Dprint("nonstellar timestep %g\n",stardata->model.dtm); /* * Save the timestep on the first diff --git a/src/exit_binaryc.c b/src/exit_binaryc.c index 3070294702302cf4851be32c425895160d37de19..5a3a3fe24f9f830fae726c2238076c54a930824b 100644 --- a/src/exit_binaryc.c +++ b/src/exit_binaryc.c @@ -4,7 +4,6 @@ * * Note the unusual header file list: please do not change it! :) */ - #include <stdlib.h> #include <stdarg.h> @@ -94,6 +93,7 @@ void Gnu_format_args(6,7) #endif //BATCHMODE } + Dprint("calling exit_binary_c_handler\n"); va_list args,dummy MAYBE_UNUSED; va_start(args,format); va_start(dummy,format); @@ -264,10 +264,7 @@ static void No_return Gnu_format_args(8,0) * Non-batchmode or batchmode is off : actually exit */ Dprint("binary_c : we really want to exit (not a batchmode long jump)\n"); - if((binary_c_error_code!=BINARY_C_NORMAL_EXIT && - binary_c_error_code!=BINARY_C_QUIET_EXIT && - binary_c_error_code!=BINARY_C_SPECIAL_EXIT && - binary_c_error_code!=BINARY_C_NORMAL_BATCHMODE_EXIT) || (DEBUG)) + if(Binary_c_error_code_is_bad(binary_c_error_code) || (DEBUG)) { /* * If stdout is not a terminal, e.g. it's a file, @@ -321,7 +318,9 @@ static void No_return Gnu_format_args(8,0) /* * Free all allocated memory, including the preferences, store and tmpstore */ + printf("try to free memory\n");fflush(NULL); if(stardata!=NULL) free_memory(&stardata,TRUE,TRUE,TRUE,TRUE,TRUE); + printf("now try to exit\n");fflush(NULL); #undef exit diff --git a/src/logging/logfile_string.c b/src/logging/logfile_string.c index 45d0c37773edba4bbc4631e4b2ea507e3dc63caf..aba948b6bf485c48ad586a11823cc0d86717fed3 100644 --- a/src/logging/logfile_string.c +++ b/src/logging/logfile_string.c @@ -128,7 +128,7 @@ char * logfile_string(const double time, #else snprintf(logstring, LOGSTRINGLENGTH, - "%s%11.4lf%s%9.3lf%s%s%9.3lf%s%s%3s%s%s%3s%s%s%13.5g%s%s%8.3g%c%s%s%6.2lf%s%s%s%s%8.3lf%s%s%s%8.3lf%s %s%s%s", + "%s%11.4lf%s%9.3lf%s%s%9.3lf%s%s%3s%s%s%3s%s%s%13.5g%s%s%9.3g%c%s%s%6.2lf%s%s%s%s%8.3lf%s%s%s%8.3lf%s %s%s%s", File_log_colour(stardata->store->colours[ORANGE]), time, File_log_colour(stardata->store->colours[RED]), diff --git a/src/logging/open_log_files.c b/src/logging/open_log_files.c index 3ad788844776fd993c72c9772a01b5225ac1471a..896e4ddb5bdaa83022944533b6e0d7421d80974a 100644 --- a/src/logging/open_log_files.c +++ b/src/logging/open_log_files.c @@ -45,7 +45,7 @@ void open_log_files(FILE *(*log_fp), { /* redirect output to stdout */ *log_fp=stdout; - fprintf(*log_fp,"%s TIME M1 M2 K1 K2 SEP%s PER%s ECC%s R1/ROL1 R2/ROL2 TYPE", + fprintf(*log_fp,"%s TIME M1 M2 K1 K2 SEP%s PER%s ECC%s R1/ROL1 R2/ROL2 TYPE", File_log_colour(stardata->store->colours[WHITE]), logspace, logspace, @@ -64,7 +64,7 @@ void open_log_files(FILE *(*log_fp), { /* redirect output to stderr */ *log_fp=stderr; - fprintf(*log_fp," TIME M1%s M2%s K1%s K2%s SEP%s PER%s ECC%s R1/ROL1%s R2/ROL2%s TYPE%s", + fprintf(*log_fp," TIME M1%s M2%s K1%s K2%s SEP%s PER%s ECC%s R1/ROL1%s R2/ROL2%s TYPE%s", File_log_colour(stardata->store->colours[WHITE]), logspace, logspace, @@ -105,7 +105,7 @@ void open_log_files(FILE *(*log_fp), else { fprintf(*log_fp, - "%s TIME M1%s M2%s K1%s K2%s SEP%s PER%s ECC%s R1/ROL1%s R2/ROL2%s TYPE RANDOM_SEED=%ld RANDOM_COUNT=%ld%s", + "%s TIME M1%s M2%s K1%s K2%s SEP%s PER%s ECC%s R1/ROL1%s R2/ROL2%s TYPE RANDOM_SEED=%ld RANDOM_COUNT=%ld%s", File_log_colour(stardata->store->colours[WHITE]), logspace, logspace, diff --git a/src/memory/free_memory.c b/src/memory/free_memory.c index 1610becb4112a6ede216684556f626ef97952b77..9fcc16d4d6eb80fc2f08d5434696d7e757c908c2 100644 --- a/src/memory/free_memory.c +++ b/src/memory/free_memory.c @@ -46,12 +46,14 @@ void free_memory(struct stardata_t ** RESTRICT const sp, * Free persistent data including calls to routines * to output the data if required. */ - if(free_persistent == TRUE) + if(stardata != NULL && free_persistent == TRUE) { FMDebug("persistent_data %p\n",(void*)stardata->persistent_data); - free_persistent_data(*sp); + free_persistent_data(stardata); } + FMDebug("done that\n"); + #ifdef MEMMAP FMDebug("Call munmap\n"); munmap(stardata->biglog,BIGLOG_SIZE); diff --git a/src/memory/free_persistent_data.c b/src/memory/free_persistent_data.c index 8bd9e6b5a119fbb56674c4a5ee529715dee6e63a..b278e2a32b7808076ce4429ff35015340f28c26c 100644 --- a/src/memory/free_persistent_data.c +++ b/src/memory/free_persistent_data.c @@ -13,6 +13,7 @@ void free_persistent_data(struct stardata_t * const stardata) (void*)stardata, (void*)(stardata?stardata->persistent_data:NULL)); + if(stardata != NULL && stardata->persistent_data != NULL) { @@ -24,14 +25,20 @@ void free_persistent_data(struct stardata_t * const stardata) #ifdef STELLAR_POPULATIONS_ENSEMBLE Dprint("free ensemble hash at %p ?\n", (void*)stardata->persistent_data->ensemble_hash); + if(stardata->persistent_data->ensemble_hash != NULL) { Dprint("call ensemble log\n"); + stardata->model.ensemble_hash = stardata->persistent_data->ensemble_hash; - ensemble_log(stardata,TRUE); + if(!Binary_c_error_code_is_bad(stardata->error_code)) + { + ensemble_log(stardata,TRUE); + } RCHash_free(stardata->persistent_data->ensemble_hash); Dprint("freed: hash is now %p\n", (void*)stardata->persistent_data->ensemble_hash); + stardata->persistent_data->ensemble_hash = NULL; stardata->model.ensemble_hash = NULL; } @@ -40,12 +47,15 @@ void free_persistent_data(struct stardata_t * const stardata) Dprint("freeing stardata=%p -> persistent_data = %p\n", (void*)stardata, (void*)stardata->persistent_data); + Safe_free(stardata->persistent_data); + } else { Dprint("free persistent data called on stardata = %p stardata->persistent_data = %p\n", (void*)stardata, (void*)(stardata->persistent_data)); + } } diff --git a/src/stellar_structure/stellar_structure_AGB.c b/src/stellar_structure/stellar_structure_AGB.c index caf4e338e2865148cfca5a4086d97d8a9ad973f3..3867874e4a4bc8fe1d5b5dd4e873bd864e3fcf41 100644 --- a/src/stellar_structure/stellar_structure_AGB.c +++ b/src/stellar_structure/stellar_structure_AGB.c @@ -152,8 +152,6 @@ Stellar_type stellar_structure_AGB(struct star_t * const oldstar, force_supernova = FALSE; } /* - * RGI - * * Only allow stars with CO core mass less than the * maximum_CO_mass_for_thermal_pulses to have thermal pulses, or * those that are already thermally pulsing. @@ -161,10 +159,15 @@ Stellar_type stellar_structure_AGB(struct star_t * const oldstar, * This is because more massive stars should explode * soon after the AGB begins, and probably don't ever * have thermal pulses. + * + * We also check that TPAGB stars have core masses + * < MCh: if not, treat them as EAGB i.e. allow + * them to explode */ else if((newstar->stellar_type == TPAGB || (Is_not_zero(newstar->core_mass[CORE_CO]) && - newstar->core_mass[CORE_He] < MCh && + (newstar->stellar_type == EAGB || + newstar->core_mass[CORE_He] < MCh) && newstar->core_mass[CORE_CO] < maximum_degenerate_CO_mcbagb))) { /* TPAGB star */ diff --git a/src/stellar_timescales/stellar_timescales_high_mass_GB.c b/src/stellar_timescales/stellar_timescales_high_mass_GB.c index 23b6eee8130e653a225a6a2edbfc26bf9ee5fe34..3b4542a94ac3c1275cfea752dfa3110e71704b4c 100644 --- a/src/stellar_timescales/stellar_timescales_high_mass_GB.c +++ b/src/stellar_timescales/stellar_timescales_high_mass_GB.c @@ -2,7 +2,7 @@ No_empty_translation_unit_warning; #ifdef BSE -void stellar_timescales_high_mass_GB(struct stardata_t * const stardata, +void stellar_timescales_high_mass_GB(struct stardata_t * const stardata MAYBE_UNUSED, const double mass, const double mp2, double * const timescales, diff --git a/src/timestep/stellar_timestep.c b/src/timestep/stellar_timestep.c index 0efba17e7bef2e696db0b768740d7d8b7fbd6889..d7998d83b7c3d9603b69cb072ef7d1e5b13484cf 100644 --- a/src/timestep/stellar_timestep.c +++ b/src/timestep/stellar_timestep.c @@ -2,7 +2,7 @@ No_empty_translation_unit_warning; #include "timestep.h" -#undef MINT + void stellar_timestep(Timestep_prototype_args) { /* @@ -133,15 +133,13 @@ void stellar_timestep(Timestep_prototype_args) timestep_limits(Timestep_call_args); timestep_logging(Timestep_call_args); - timestep_fixed_timesteps(Timestep_call_args); timestep_modulation(Timestep_call_args); timestep_hard_limits(Timestep_call_args); + //nonstellar_timestep(stardata,dt); star->stellar_timestep = *dt; - - if(stardata->preferences->timestep_logging == TRUE && - stardata->star[0].stellar_type==HG) + if(stardata->preferences->timestep_logging == TRUE) { fprintf(stdout, "%sstellar_timestep at t=%23.15g model %d reject_same %s reject_shorten %s out star %d stellar_type %d (m=%g mc=%g L=%g R=%g RL=%g (1-R/RL=%g) minit=%g menv=%g SN=%d J*=%g; a=%g e=%g Jorb=%g, ω*=%g ωorb=%g tcirc=%g y), age=%20.12g, tm=%20.12g, tn=%20.12g >>> %sdt=%20.12g Myr%s <<< time_remaining=%g : set by %s%s%s (%d) : logtnow=%g logtnext=%g (Fequal? %s Times_are_equal? %s : diff %g) triggerd? %d %s\n", diff --git a/src/timestep/timestep_fixed_timesteps.c b/src/timestep/timestep_fixed_timesteps.c index d78a862be22e7b63e089a7cdbb037954f648a47d..4316a23f7be5d65fd3357bb78c0c225f02b5641b 100644 --- a/src/timestep/timestep_fixed_timesteps.c +++ b/src/timestep/timestep_fixed_timesteps.c @@ -2,7 +2,9 @@ No_empty_translation_unit_warning; -void timestep_fixed_timesteps(Timestep_prototype_args) +void timestep_fixed_timesteps(struct stardata_t * const stardata, + struct star_t * const star, + double * const dtm) { /* * Limit the timestep according to the various @@ -11,7 +13,7 @@ void timestep_fixed_timesteps(Timestep_prototype_args) int i; for(i=0;i<FIXED_TIMESTEP_NUMBER;i++) { - struct binary_c_fixed_timestep_t * t = stardata->model.fixed_timesteps + i; + struct binary_c_fixed_timestep_t * const t = stardata->model.fixed_timesteps + i; if(t->enabled == TRUE) { @@ -36,14 +38,18 @@ void timestep_fixed_timesteps(Timestep_prototype_args) dtlim = (t->logarithmic ? exp10(t->next) : t->next) - stardata->model.time; } - Dprint("Set dtlim = %30.20g : next time will be %30.20g : Times_are_equal? %s\n", + Dprint("At t = %g : Set dtlim = %30.20g : next time will be %30.20g : Times_are_equal? %s\n", + T, dtlim, - log10(stardata->model.time + dtlim), + t->logarithmic ? log10(stardata->model.time + dtlim) : (stardata->model.time + dtlim), Yesno(Times_are_equal(t->next, log10(stardata->model.time + dtlim))) ); - Limit_timestep(*dt,dtlim,star,DT_LIMIT_FIXED_TIMESTEP); + Limit_timestep(*dtm, + dtlim, + star, + DT_LIMIT_FIXED_TIMESTEP); } } } diff --git a/src/timestep/timestep_fixed_trigger.c b/src/timestep/timestep_fixed_trigger.c index 5b55e9af17e08d95a82f8528f4f2dd8a588e7a62..e4bb103b1a2a840429ddea8e9054cccfa17392c5 100644 --- a/src/timestep/timestep_fixed_trigger.c +++ b/src/timestep/timestep_fixed_trigger.c @@ -7,15 +7,15 @@ Boolean timestep_fixed_trigger(struct stardata_t * RESTRICT const stardata, const int i) { /* - * Check if fixed timestep i should be triggered. + * Check if fixed timestep i should be triggered. * Return TRUE if it should be, FALSE otherwise. * * If the timestep is disabled, return FALSE. - * + * * If we're beyond the end time, or before the start time, * this can never be true. * - * If we're at max_evolution_time and t->final is TRUE, then return TRUE. + * If we're at max_evolution_time and t->final is TRUE, then return TRUE. */ Boolean ret; struct binary_c_fixed_timestep_t * t = stardata->model.fixed_timesteps + i; @@ -30,10 +30,10 @@ Boolean timestep_fixed_trigger(struct stardata_t * RESTRICT const stardata, else { const double T = t->logarithmic ? log10(stardata->model.time) : stardata->model.time; - + if(!In_range(T,t->begin,t->end)) { - /* + /* * Out of time range of the trigger so cannot trigger */ ret = FALSE; @@ -50,7 +50,7 @@ Boolean timestep_fixed_trigger(struct stardata_t * RESTRICT const stardata, else { /* - * Check if the time equals, or is more than, the next + * Check if the time equals, or is more than, the next * trigger time */ ret = Boolean_(Times_more_or_equal(T,t->next)); diff --git a/src/timestep/timestep_hard_limits.c b/src/timestep/timestep_hard_limits.c index e1d249e992bcc65381d830f6adb646f2677e0390..cb70d55e09e88b9f9a9d5cfc51dc6392dfecda81 100644 --- a/src/timestep/timestep_hard_limits.c +++ b/src/timestep/timestep_hard_limits.c @@ -47,12 +47,11 @@ void timestep_hard_limits(Timestep_prototype_args) DT_LIMIT_MAXIMUM_TIMESTEP); } - Star_number k; - Nuclear_burning_Starloop(k) + if(NUCLEAR_BURNING(star->stellar_type)) { Limit_timestep(*dt, stardata->preferences->maximum_nuclear_burning_timestep, - &stardata->star[k], + star, DT_LIMIT_MAXIMUM_TIMESTEP); } @@ -74,8 +73,7 @@ void timestep_hard_limits(Timestep_prototype_args) /* * If there has been an event, force a small timestep */ - if(0 && - (star->SN_type != SN_NONE || + if((star->SN_type != SN_NONE || stardata->previous_stardata->star[star->starnum].SN_type != SN_NONE)) { Limit_timestep(*dt, @@ -109,16 +107,4 @@ void timestep_hard_limits(Timestep_prototype_args) star, DT_LIMIT_TIME_REMAINING); } - - /* - * Hard wired minimum : do not apply - * if the timestep is limited by a fixed timestep - */ - if(stardata->model.fixed_timestep_triggered == FALSE && - star->dtlimiter != DT_LIMIT_FIXED_TIMESTEP) - { - *dt = Max(*dt, - MINIMUM_STELLAR_TIMESTEP); - } - } diff --git a/src/timestep/timestep_limits.c b/src/timestep/timestep_limits.c index 3fa81b4e54ff627d8f8d891238271897487fb717..dee8310405e8525a9277f1f54c9357b8ed664fbf 100644 --- a/src/timestep/timestep_limits.c +++ b/src/timestep/timestep_limits.c @@ -648,8 +648,7 @@ void timestep_limits(Timestep_prototype_args) * if dt_zoomfac < 1, don't let the timestep be > * 1.2 * dt_zoomfac * (this or previous timestep) */ - if(0 && - Use_timestep(DT_LIMIT_ZOOMFAC) && + if(Use_timestep(DT_LIMIT_ZOOMFAC) && stardata->previous_stardata && stardata->model.dt_zoomfac - 1.0 < -TINY) { diff --git a/src/timestep/timestep_prototypes.h b/src/timestep/timestep_prototypes.h index 01db4b7c5f18c76b96b9b9c5a9048693f7fbc31b..e51867ce0387bf7a9cd095344c3ece7653f98737 100644 --- a/src/timestep/timestep_prototypes.h +++ b/src/timestep/timestep_prototypes.h @@ -23,7 +23,8 @@ void timestep_logging(Timestep_prototype_args); void timestep_modulation(Timestep_prototype_args); void timestep_hard_limits(Timestep_prototype_args); void timestep_RLOF(Timestep_prototype_args); - +void nonstellar_timestep(struct stardata_t * const stardata, + double * const dt); #ifdef DISCS double Pure_function timestep_disc(struct stardata_t * const stardata, @@ -31,7 +32,9 @@ double Pure_function timestep_disc(struct stardata_t * const stardata, #endif // DISCS void setup_fixed_timesteps(struct stardata_t * RESTRICT const stardata); -void timestep_fixed_timesteps(Timestep_prototype_args); +void timestep_fixed_timesteps(struct stardata_t * const stardata, + struct star_t * const star, + double * const dt); void timestep_increment_fixed_timesteps(struct stardata_t * RESTRICT const stardata); Boolean timestep_fixed_trigger(struct stardata_t * RESTRICT stardata, const int i);