From d51be2e62878882a580927035e274fa14413255c Mon Sep 17 00:00:00 2001 From: Robert Izzard <r.izzard@surrey.ac.uk> Date: Sat, 7 Aug 2021 11:54:21 +0100 Subject: [PATCH] add function to test if we're running under Valgrind, and if we are and haven't built with -Dvalgrind=true, bail rewritten the old Fryer BH mass routines, also to include the Startrack prescription update ubuntu installer script (work in progress for Python wrapper) --- meson.build | 1 + src/debug/debug_prototypes.h | 4 + src/debug/test_for_valgrind.c | 53 +++++ src/main.c | 6 +- src/massive/COCoreToProtoMassDelayed.c | 27 --- src/massive/COCoreToProtoMassRapid.c | 11 +- src/massive/Fryer2012.c | 234 +++++++++++++++++++++++ src/massive/baryonicRemnantMassGeneral.c | 26 --- src/massive/massive_prototypes.h | 44 +++-- src/setup/cmd_line_args_list.h | 2 +- src/setup/version.c | 1 + src/supernovae/bh_prescriptions.def | 4 +- src/supernovae/ns_bh_mass.c | 206 +++++++++----------- src/supernovae/set_kick_velocity.c | 13 +- src/zfuncs/fallbackDelayed.c | 55 ------ src/zfuncs/fallbackRapid.c | 57 ------ src/zfuncs/massFallbackGeneral.c | 29 --- tbse | 1 + ubuntu_install_binary_c.sh | 59 +++--- 19 files changed, 461 insertions(+), 372 deletions(-) create mode 100644 src/debug/test_for_valgrind.c delete mode 100644 src/massive/COCoreToProtoMassDelayed.c create mode 100644 src/massive/Fryer2012.c delete mode 100644 src/massive/baryonicRemnantMassGeneral.c delete mode 100644 src/zfuncs/fallbackDelayed.c delete mode 100644 src/zfuncs/fallbackRapid.c delete mode 100644 src/zfuncs/massFallbackGeneral.c diff --git a/meson.build b/meson.build index 3f20baf8d..c65bc8784 100644 --- a/meson.build +++ b/meson.build @@ -411,6 +411,7 @@ if get_option('valgrind') == true 'avx512ifma', 'avx512vbmi', ] + cflags += [ '-DVALGRIND' ] foreach cflag : _instruction_sets __cflag = '-mno-' + cflag if compiler.has_argument( __cflag ) diff --git a/src/debug/debug_prototypes.h b/src/debug/debug_prototypes.h index ca98ed5a0..e9cad65b8 100644 --- a/src/debug/debug_prototypes.h +++ b/src/debug/debug_prototypes.h @@ -29,4 +29,8 @@ void diff_stardata(struct stardata_t * const stardata MAYBE_UNUSED); #include "libbacktrace_prototypes.h" #endif +#ifndef VALGRIND +void test_for_valgrind(void); +#endif + #endif // DEBUG_PROTOTYPES_H diff --git a/src/debug/test_for_valgrind.c b/src/debug/test_for_valgrind.c new file mode 100644 index 000000000..fda156b5a --- /dev/null +++ b/src/debug/test_for_valgrind.c @@ -0,0 +1,53 @@ +#include "binary_c.h" +No_empty_translation_unit_warning; + + +#ifndef VALGRIND + +#undef exit + +#ifdef __HAVE_VALGRIND__ +#include "valgrind/valgrind.h" +#endif//__HAVE_VALGRIND__ + +void test_for_valgrind(void) +{ + /* + * Test for whether we are running undef Valgrind. + * + * If we are, and we haven't built binary_c using + * "meson -Dvalgrind=true" (or similar) stop running + * because we are likely to crash. + */ + Boolean running_under_valgrind = FALSE; + +#ifdef __HAVE_VALGRIND__ + /* + * If we have valgrind development files installed, + * use the RUNNING_ON_VALGRIND macro to do the detection. + */ + if(RUNNING_ON_VALGRIND) running_under_valgrind = TRUE; +#endif//__HAVE_VALGRIND__ + + /* + * Fallback: test LD_PRELOAD + */ + char * ld_preload = getenv("LD_PRELOAD"); + if(ld_preload && + ( + strstr(ld_preload, "/valgrind/") != NULL + || + strstr(ld_preload, "/vgpreload") != NULL) + ) + { + running_under_valgrind = TRUE; + } + + + if(running_under_valgrind == TRUE) + { + printf("You are trying to run binary_c through valgrind without building with valgrind support. On some architectures this will fail, so please configure binary_c with something like\n\nmeson -Dvalgrind=true builddir\n\nand rebuild.\n"); + exit(1); + } +} +#endif // VALGRIND diff --git a/src/main.c b/src/main.c index 27f4f0f35..acd9f0491 100644 --- a/src/main.c +++ b/src/main.c @@ -36,7 +36,6 @@ static void vector_tests(void); // will be removed! int main (int argc, char ** argv) { - /* * This is binary_c's entry point when called on the * command line. @@ -45,6 +44,10 @@ int main (int argc, * options, make a stardata, then call binary_c main * with the stardata. */ +#ifndef VALGRIND + test_for_valgrind(); +#endif + #ifdef ALTSTACK char * altstack = setup_segfaults(); #endif @@ -86,7 +89,6 @@ static int binary_c_main(int argc, * * First, do the main memory allocations and build the store */ - main_allocations(&stardata, NULL, &preferences, diff --git a/src/massive/COCoreToProtoMassDelayed.c b/src/massive/COCoreToProtoMassDelayed.c deleted file mode 100644 index 0aa7c7aa7..000000000 --- a/src/massive/COCoreToProtoMassDelayed.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "../binary_c.h" -No_empty_translation_unit_warning; - - -double Constant_function COCoreToProtoMassDelayed(const double COCoreMass) -{ - /* - Equation 18 in Fryer et al 2012 - - Parameters - ----------- - COCoreMass : double - Mass of the CO core in Msol - - Returns - -------- - Mproto : double - Mass of the Fe/Ni proto core in Msol - - -- Simon Stevenson - */ - return - COCoreMass < 3.5 ? 1.2 : - COCoreMass < 6.0 ? 1.3 : - COCoreMass < 11.0 ? 1.4 : - 1.6; -} diff --git a/src/massive/COCoreToProtoMassRapid.c b/src/massive/COCoreToProtoMassRapid.c index e31dd4f02..2744b6202 100644 --- a/src/massive/COCoreToProtoMassRapid.c +++ b/src/massive/COCoreToProtoMassRapid.c @@ -4,19 +4,19 @@ No_empty_translation_unit_warning; double Constant_function COCoreToProtoMassRapid(const double COCoreMass) { - /* +/* Equation 10 in Fryer et al 2012 - + Parameters ------------ COCoreMass : double Carbon Oxygen (CO) core mass in Msol - + Returns -------- Mproto : double Mass of Fe/Ni proto core in Msol - + -- Simon Stevenson */ if(COCoreMass < 4.82) @@ -34,6 +34,5 @@ double Constant_function COCoreToProtoMassRapid(const double COCoreMass) else { return 0.37 * COCoreMass - 0.07; - } + } } - diff --git a/src/massive/Fryer2012.c b/src/massive/Fryer2012.c new file mode 100644 index 000000000..397611431 --- /dev/null +++ b/src/massive/Fryer2012.c @@ -0,0 +1,234 @@ +#include "../binary_c.h" +No_empty_translation_unit_warning; + +/* + * Fryer et al. (ApJ 749,91 2012) functions + * + * https://iopscience.iop.org/article/10.1088/0004-637X/749/1/91/pdf + * + * The notation in here follows the paper, and I while + * have written a few comments, you should check the paper + * for details. + * + * Startrack algorithm: Eqs 10-14 + * Rapid algorithm: Eqs 15-17 + * Delayed algorithm: Eqs 18-20 + */ + +/* + * Startrack algorithm + */ +double Constant_function Fryer2012_Eq10(const double Mc_CO) +{ + /* + * Final Fe/Ni core mass, M_proto, based on + * Hurley et al. (2000) and Timmes et al. (1996) + */ + return + Mc_CO < 4.82 ? 1.50 : + Mc_CO < 6.31 ? 2.11 : + Mc_CO < 6.75 ? (0.69 * Mc_CO - 2.26) : + (0.37 * Mc_CO - 0.07); +} + +double Constant_function Fryer2012_Eq11(const double M, + const double Mc_CO, + const double M_proto) +{ + /* + * Fallback mass, M_fb, as a function of core mass. + */ + const double M_fb = + Mc_CO < 5.0 ? 0.0 : + ( + (M - M_proto) * + ( + Mc_CO < 7.6 ? (0.378 * Mc_CO - 1.889) : + 1.0 + ) + ); + return Limit_range(M_fb,0.0,M - M_proto); +} + +double Constant_function Fryer2012_Eq12(const double M_proto, + const double M_fb) +{ + /* + * Remnant baryonic mass + */ + return M_proto + M_fb; +} + +double Constant_function Fryer2012_Eq13(const double M_remnant_baryonic) +{ + /* + * Remnant gravitational mass of neutron stars + */ + return M_remnant_baryonic - 0.075 * Pow2(M_remnant_baryonic); +} + +double Constant_function Fryer2012_Eq14(const double M_remnant) +{ + /* + * Remnant gravitational mass of black holes + */ + return M_remnant * 0.9; +} + +double Constant_function Fryer2012_remnant_gravitational_mass(const struct stardata_t * const stardata, + const double M_remnant_baryonic) +{ + /* + * Wrapper for Eqs. 13,14 to act based on stellar type + */ + return + M_remnant_baryonic < stardata->preferences->max_neutron_star_mass ? + Fryer2012_Eq13(M_remnant_baryonic): /* NS */ + Fryer2012_Eq14(M_remnant_baryonic); /* BH */ +} + +/* + * Rapid algorithm + */ +double Constant_function Fryer2012_Eq15(const double Mc_CO MAYBE_UNUSED) +{ + /* + * Proto-compact object mass + */ + return 1.0; +} + +double Constant_function Fryer2012_Eq16(const double M, + const double Mc_CO, + const double M_proto) +{ + /* + * Fallback mass, M_fb + */ + + /* this is in the Fryer paper */ +//#define Eq16_a1 (0.25 - (1.275/M - M_proto)) + /* but it probably should be this, as in Spera+2015 */ +#define Eq16_a1 (0.25 - (1.275/(M - M_proto))) + +#define Eq16_b1 (-11.0 * Eq16_a1 + 1.0) + const double M_fb = + Mc_CO < 2.5 ? 0.2 : + Mc_CO < 6.0 ? (0.286 * Mc_CO - 0.514) : + ( + (M - M_proto) * ( + Mc_CO < 7.0 ? 1.0 : + Mc_CO < 11.0 ? (Eq16_a1 * Mc_CO + Eq16_b1) : + 1.0 + ) + ); + return Limit_range(M_fb,0.0,M - M_proto); +} + +double Constant_function Fryer2012_Eq17(const double M_proto, + const double M_fb) +{ + /* + * Remnant baryonic mass + */ + return M_proto + M_fb; +} + + +/* + * Delayed algorithm + */ +double Constant_function Fryer2012_Eq18(const double Mc_CO) +{ + /* + * M_proto + */ + return + Mc_CO < 3.5 ? 1.2 : + Mc_CO < 6.0 ? 1.3 : + Mc_CO < 11.0 ? 1.4 : + 1.6; +} + +double Constant_function Fryer2012_Eq19(const double M, + const double Mc_CO, + const double M_proto) +{ + +/* this is in the paper */ +//#define Eq19_a2 (0.133 - (0.093/M - M_proto)) + +/* but it probably should be this */ +#define Eq19_a2 (0.133 - (0.093/(M - M_proto))) + +#define Eq19_b2 (-11.0*Eq19_a2 + 1.0) + const double M_fb = + Mc_CO < 2.5 ? 0.2 : + Mc_CO < 3.5 ? (0.5 * Mc_CO - 1.05) : + ( + (M - M_proto) * + ( + Mc_CO < 11.0 ? (Eq19_a2 * Mc_CO + Eq19_b2) : + 1.0 + ) + ); + return Limit_range(M_fb, 0.0, M - M_proto); +} + +double Constant_function Fryer2012_Eq20(const double M_proto, + const double M_fb) +{ + /* + * Remnant baryonic mass + */ + return M_proto + M_fb; +} + +/* + * Wrapper functions + * + * Use these to select based on which of the three prescriptions + * you wish to use. + */ +double Fryer2012_M_fb(struct stardata_t * const stardata, + const double M, + const double Mc_CO, + const double M_proto) +{ + return + stardata->preferences->BH_prescription==BH_FRYER12_DELAYED ? + Fryer2012_Eq19(M,Mc_CO,M_proto) : + stardata->preferences->BH_prescription==BH_FRYER12_RAPID ? + Fryer2012_Eq16(M,Mc_CO,M_proto) : + stardata->preferences->BH_prescription==BH_FRYER12_STARTRACK ? + Fryer2012_Eq11(M,Mc_CO,M_proto) : + 0.0; +} + +double Fryer2012_M_proto(struct stardata_t * const stardata, + const double Mc_CO) +{ + return + stardata->preferences->BH_prescription==BH_FRYER12_DELAYED ? + Fryer2012_Eq18(Mc_CO) : + stardata->preferences->BH_prescription==BH_FRYER12_RAPID ? + Fryer2012_Eq15(Mc_CO) : + stardata->preferences->BH_prescription==BH_FRYER12_STARTRACK ? + Fryer2012_Eq10(Mc_CO) : + 0.0; +} + +double Fryer2012_f_fb(struct stardata_t * const stardata, + const double M, + const double Mc_CO) +{ + /* + * Fallback fraction + */ + const double M_proto = + Fryer2012_M_proto(stardata,Mc_CO); + const double M_fb = + Fryer2012_M_fb(stardata,M,Mc_CO,M_proto); + + return Limit_range(M_fb / (M - M_proto), 0.0, 1.0); +} diff --git a/src/massive/baryonicRemnantMassGeneral.c b/src/massive/baryonicRemnantMassGeneral.c deleted file mode 100644 index 92517375a..000000000 --- a/src/massive/baryonicRemnantMassGeneral.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "../binary_c.h" -No_empty_translation_unit_warning; - - -double Constant_function baryonicRemnantMassGeneral(const double Mproto, - const double Mfb) -{ - /* - Equation 12 in Fryer et al 2012 - - Parameters - ----------- - Mproto : double - Mass of proto compact object in Msol - Mfb : double - Mass falling back onto proto compact object Mfb = fb*(MpreSN - Mproto) - - Returns - -------- - Mremnant, baryonic : double - Baryonic mass of remnant - - -- Simon Stevenson - */ - return Mproto + Mfb; //Mfb = fb*(MpreSN - Mproto); -} diff --git a/src/massive/massive_prototypes.h b/src/massive/massive_prototypes.h index 90bd3608d..9df82b610 100644 --- a/src/massive/massive_prototypes.h +++ b/src/massive/massive_prototypes.h @@ -3,19 +3,37 @@ #define MASSIVE_PROTOTYPES_H +double Constant_function Fryer2012_Eq10(const double Mc_CO); +double Constant_function Fryer2012_Eq11(const double M, + const double Mc_CO, + const double M_proto); +double Constant_function Fryer2012_Eq12(const double M_proto, + const double M_fb); +double Constant_function Fryer2012_Eq13(const double M_remnant_baryonic); +double Constant_function Fryer2012_Eq14(const double M_remnant); +double Constant_function Fryer2012_Eq15(const double Mc_CO MAYBE_UNUSED); +double Constant_function Fryer2012_Eq16(const double M, + const double Mc_CO, + const double M_proto); +double Constant_function Fryer2012_Eq17(const double M_proto, + const double M_fb); +double Constant_function Fryer2012_Eq18(const double Mc_CO); +double Constant_function Fryer2012_Eq19(const double M, + const double Mc_CO, + const double M_proto); +double Constant_function Fryer2012_Eq20(const double M_proto, + const double M_fb); +double Constant_function Fryer2012_remnant_gravitational_mass(const struct stardata_t * const stardata, + const double M_baryon); -double Constant_function fallbackDelayed(const double MpreSN, - const double Mproto, - const double COCoreMass); -double Constant_function fallbackRapid(const double MpreSN, - const double Mproto, - const double COCoreMass); -double Constant_function COCoreToProtoMassRapid(const double COCoreMass); -double Constant_function COCoreToProtoMassDelayed(const double COCoreMass); -double Constant_function massFallbackGeneral(const double MpreSN, - const double Mproto, - const double fb); -double Constant_function baryonicRemnantMassGeneral(const double Mproto, - const double Mfb); +double Fryer2012_M_fb(struct stardata_t * const stardata, + const double M, + const double Mc_CO, + const double M_proto); +double Fryer2012_M_proto(struct stardata_t * const stardata, + const double Mc_CO); +double Fryer2012_f_fb(struct stardata_t * const stardata, + const double M, + const double Mc_CO); #endif // MASSIVE_PROTOTYPES_H diff --git a/src/setup/cmd_line_args_list.h b/src/setup/cmd_line_args_list.h index 06baf892d..c87f76a44 100644 --- a/src/setup/cmd_line_args_list.h +++ b/src/setup/cmd_line_args_list.h @@ -1453,7 +1453,7 @@ BATCHMODE_ARGS { ARG_SECTION_STARS, "BH_prescription", - "Black hole mass prescrition: relates the mass of a newly formed black hole to its progenitor's (CO) core mass. 0=Hurley et al 2000/2002, 1=Belczynski (early 2000s).", + "Black hole mass prescrition: relates the mass of a newly formed black hole to its progenitor's (CO) core mass. BH_HURLEY2002 = 0 = Hurley et al 2000/2002, BH_BELCZYNSKI = 1 = Belczynski (early 2000s), BH_SPERA2015 = Spera+ 2015, BH_FRYER12_DELAYED = 3 = Fryer et al. (2012) delayed prescription, BH_FRYER12_RAPID = 4 = Fryer et al. (2012) rapid prescription, BH_FRYER12_STARTRACK = 5 = Fryer et al. (2012) startrack prescription.", ARG_INTEGER , WTTS_USE_DEFAULT, Var(stardata->preferences->BH_prescription), diff --git a/src/setup/version.c b/src/setup/version.c index acd05b5ae..5fde50671 100644 --- a/src/setup/version.c +++ b/src/setup/version.c @@ -1272,6 +1272,7 @@ void version(struct stardata_t * RESTRICT const stardata) Show_int_macro(MAX_EXIT_STATEMENT_PRINT_SIZE); #endif Macrotest(FLUSH_LOG); + Macrotest(VALGRIND); Macrotest(__HAVE_VALGRIND__); Macrotest(__HAVE_LIBGSL__); Macrotest(__HAVE_LIBBFD__); diff --git a/src/supernovae/bh_prescriptions.def b/src/supernovae/bh_prescriptions.def index cf0d88ccc..0a3b63830 100644 --- a/src/supernovae/bh_prescriptions.def +++ b/src/supernovae/bh_prescriptions.def @@ -7,7 +7,7 @@ X( BELCZYNSKI ) \ X( SPERA2015 ) \ X( FRYER12_DELAYED ) \ - X( FRYER12_RAPID ) - + X( FRYER12_RAPID ) \ + X( FRYER12_STARTRACK ) #endif // BH_PRESCRIPTIONS_DEF diff --git a/src/supernovae/ns_bh_mass.c b/src/supernovae/ns_bh_mass.c index 6e25039c3..a91088e24 100644 --- a/src/supernovae/ns_bh_mass.c +++ b/src/supernovae/ns_bh_mass.c @@ -1,23 +1,25 @@ #include "../binary_c.h" No_empty_translation_unit_warning; - - -double Pure_function ns_bh_mass(const double m, - const double mc_CO, +double Pure_function ns_bh_mass(const double M, + const double Mc_CO, struct stardata_t * RESTRICT const stardata, const struct star_t * RESTRICT const star) { /* * Function to evaluate the NS/BH remnant mass given - * total mass m and CO Core mass mc_CO + * total mass, M, and CO Core mass, Mc_CO. + * + * Note that, where we have the choice, we return the + * gravitational mass because this is the mass that goes + * into orbital calculations. */ - double mbh; + double M_remnant; /* * If we are a TPAGB star, assume the core collapses to * a NS in an electron capture supernova. This should - * only happen in unusual circumstances, or as an STPAGB star. + * only happen in unusual circumstances or as an STPAGB star. */ if(star->stellar_type==TPAGB) return star->core_mass[CORE_He]; @@ -26,37 +28,21 @@ double Pure_function ns_bh_mass(const double m, /* * Chris' NS/BH formula as in Hurley+ 2000, 2002 */ - mbh = 1.170 + 0.090*mc_CO; + M_remnant = 1.170 + 0.090 * Mc_CO; } else if(stardata->preferences->BH_prescription==BH_BELCZYNSKI) { /* * Use NS/BH mass given by Belczynski et al. 2002, ApJ, 572, 407. */ - // First set mcx - double mcx; - if(mc_CO<2.5) - { - mcx = 0.1617670*mc_CO + 1.0670550; - } - else - { - mcx = 0.3141540*mc_CO + 0.6860880; - } - // Then set the remnant mass - if(mc_CO<=5.0) - { - mbh = mcx; - } - else if(mc_CO<7.60) - { - mbh = mcx + (mc_CO - 5.0)*(m - mcx)/2.60; - } - else - { - mbh = m; - } - //printf("Mc_CO=%g, Mcx=%g, Mbh=%g\n", mc_CO, mcx, mbh); + const double Mc_x = + Mc_CO < 2.5 ? (0.1617670 * Mc_CO + 1.0670550): + (0.3141540 * Mc_CO + 0.6860880); + + M_remnant = + Mc_CO <= 5.0 ? Mc_x : + Mc_CO < 7.60 ? (Mc_x + (Mc_CO - 5.0) * (M - Mc_x) / 2.60) : + M; } else if(stardata->preferences->BH_prescription==BH_SPERA2015) { @@ -72,21 +58,21 @@ double Pure_function ns_bh_mass(const double m, if(stardata->common.metallicity<=5e-4) { /* Z < 5e-4 */ - p = -2.333 + 0.1559 * mc_CO + 0.2700 * mc_CO * mc_CO; // Eq. C2 - if(mc_CO <= 5.0) + p = -2.333 + 0.1559 * Mc_CO + 0.2700 * Mc_CO * Mc_CO; // Eq. C2 + if(Mc_CO <= 5.0) { - mbh = Max(p,1.27); // Eq. C1 MCO < 5 + M_remnant = Max(p,1.27); // Eq. C1 MCO < 5 } - else if(mc_CO < 10.0) + else if(Mc_CO < 10.0) { - mbh = p; // Eq. C1 5 < MCO < 10 + M_remnant = p; // Eq. C1 5 < MCO < 10 } else { - double mZ = -6.476e2 * stardata->common.metallicity + 1.911; // Eq. C3 - double qZ = 2.300e3 * stardata->common.metallicity + 11.67; // Eq. C3 - double f = mZ * mc_CO + qZ; // Eq. C2 - mbh = Min(p,f); // Eq. C1 MCO > 10 + const double mZ = -6.476e2 * stardata->common.metallicity + 1.911; // Eq. C3 + const double qZ = 2.300e3 * stardata->common.metallicity + 11.67; // Eq. C3 + const double f = mZ * Mc_CO + qZ; // Eq. C2 + M_remnant = Min(p,f); // Eq. C1 MCO > 10 } } else @@ -115,15 +101,14 @@ double Pure_function ns_bh_mass(const double m, } /* Eq. C5 */ - const double h = A1 + (A2 - A1) / (1.0 + exp10( (L - mc_CO) * eta)); - - if(mc_CO <= 5.0) + const double h = A1 + (A2 - A1) / (1.0 + exp10( (L - Mc_CO) * eta)); + if(Mc_CO <= 5.0) { - mbh = Max(h,1.27); // Eq. C4 MCO < 5 + M_remnant = Max(h,1.27); // Eq. C4 MCO < 5 } - else if(mc_CO < 10.0) + else if(Mc_CO < 10.0) { - mbh = h; // Eq. C4 5 < MCO < 10 + M_remnant = h; // Eq. C4 5 < MCO < 10 } else { @@ -148,92 +133,79 @@ double Pure_function ns_bh_mass(const double m, qZ = 2.300e3 * stardata->common.metallicity + 11.67; } - const double f = mZ * mc_CO + qZ; // Eq. C5 - mbh = Max(h,f); // Eq. C4 MCO > 10 + const double f = mZ * Mc_CO + qZ; // Eq. C5 + M_remnant = Max(h,f); // Eq. C4 MCO > 10 } } /* BH mass cannot exceed the total stellar mass */ - mbh = Min(m, mbh); + M_remnant = Min(M, M_remnant); } - else if(stardata->preferences->BH_prescription==BH_FRYER12_RAPID) + else if(stardata->preferences->BH_prescription==BH_FRYER12_STARTRACK) { - /* - Function to put together the various functions above based on users choice of SN engine. - - Parameters - ----------- - MpreSN : double - Pre-supernova total mass of the star in Msol - COCoreMass : double - CO Core mass at time of the SN in Msol - fallbackFraction : double - Fraction of mass [0,1] falling back onto proto compact object - engine : int - Which supernova engine to use - - Returns - -------- - Mrem : double - Remnant mass in Msol - - -- Simon Stevenson - */ - - - double Mproto = 0.0; - double fb = 0.0; - double Mfb = 0.0; - double Mrem_grav MAYBE_UNUSED = 0.0; - - // Calculate Mproto - Mproto = COCoreToProtoMassRapid(mc_CO); - - // Calculate fb, Mfb - fb = fallbackRapid(m, Mproto, mc_CO); - - Mfb = massFallbackGeneral(m, Mproto, fb); - - // Calculate Mremnant, baryonic - mbh = baryonicRemnantMassGeneral(Mproto, Mfb); - - //MATHIEU_WARNING:DEBUG - //printf("fb=%e Mfb=%e\n",fb,Mfb); + * Fryer et al. (ApJ 749,91 2012) startrack prescription + */ + const double M_proto = Fryer2012_Eq10(Mc_CO); + const double M_fallback = Fryer2012_Eq11(M,Mc_CO,M_proto); + const double M_BH_baryonic = Fryer2012_Eq12(M_proto,M_fallback); + M_remnant = Fryer2012_remnant_gravitational_mass(stardata,M_BH_baryonic); + Dprint("Fryer startrack Mc_CO %g M %g -> M_proto %g, M_fallback %g, M_BH_baryonic %g -> M_remn-ant(grav) = %g\n", + Mc_CO, + M, + M_proto, + M_fallback, + M_BH_baryonic, + M_remnant); + } + else if(stardata->preferences->BH_prescription==BH_FRYER12_RAPID) + { /* - Mrem_grav = gravitationalRemnantMassGeneral(mbh); - mbh = Mrem_grav - */ + * Fryer et al. (ApJ 749,91 2012) rapid prescription + */ + const double M_proto = Fryer2012_Eq15(Mc_CO); + const double M_fallback = Fryer2012_Eq16(M,Mc_CO,M_proto); + const double M_BH_baryonic = Fryer2012_Eq17(M_proto,M_fallback); + M_remnant = Fryer2012_remnant_gravitational_mass(stardata,M_BH_baryonic); + Dprint("Fryer rapid Mc_CO %g M %g -> M_proto %g, M_fallback %g, M_BH_baryonic %g -> M_remn-ant(grav) = %g\n", + Mc_CO, + M, + M_proto, + M_fallback, + M_BH_baryonic, + M_remnant); } else if(stardata->preferences->BH_prescription==BH_FRYER12_DELAYED) { - double Mproto = 0.0; - double fb = 0.0; - double Mfb = 0.0; - double Mrem_bary MAYBE_UNUSED = 0.0; - - // Calculate Mproto - Mproto = COCoreToProtoMassDelayed(mc_CO); - - // Calculate fb, Mfb - fb = fallbackDelayed(m, Mproto, mc_CO); - - Mfb = massFallbackGeneral(m, Mproto, fb); - - // Calculate Mremnant, baryonic, Mremnant, gravitational - mbh = baryonicRemnantMassGeneral(Mproto, Mfb); - - /* Mrem_grav = gravitationalRemnantMassGeneral(mbh); */ - //MATHIEU_WARNING:DEBUG - //printf("fb=%e Mfb=%e\n",fb,Mfb); + /* + * Fryer et al. (ApJ 749,91 2012) delayed prescription + */ + const double M_proto = Fryer2012_Eq18(Mc_CO); + const double M_fallback = Fryer2012_Eq19(M,Mc_CO,M_proto); + const double M_BH_baryonic = Fryer2012_Eq20(M_proto,M_fallback); + M_remnant = Fryer2012_remnant_gravitational_mass(stardata,M_BH_baryonic); + Dprint("Fryer delayed Mc_CO %g M %g -> M_proto %g, M_fallback %g, M_BH_baryonic %g -> M_remn-ant(grav) = %g\n", + Mc_CO, + M, + M_proto, + M_fallback, + M_BH_baryonic, + M_remnant); } else { // no prescription! - mbh=0; + M_remnant=0; } - Dprint("BH_MASS M = %g MCO = %g Z = %g -> MBH = %g\n",m,mc_CO,stardata->common.metallicity,mbh); + /* + * Make sure non-physical solutions cannot happen + */ + Clamp(M_remnant, + 0.0, + M); + + Dprint("NS/BH mass from M = %g, MCO = %g, Z = %g -> M_remn-ant = %g\n",M,Mc_CO,stardata->common.metallicity,M_remnant); - return(mbh); + return M_remnant; } diff --git a/src/supernovae/set_kick_velocity.c b/src/supernovae/set_kick_velocity.c index d0c19106d..23b8724f8 100644 --- a/src/supernovae/set_kick_velocity.c +++ b/src/supernovae/set_kick_velocity.c @@ -64,15 +64,12 @@ void set_kick_velocity(struct stardata_t * const stardata, * fallback (Mathieu Renzo 2016) */ if(stardata->preferences->BH_prescription==BH_FRYER12_DELAYED || - stardata->preferences->BH_prescription==BH_FRYER12_RAPID) + stardata->preferences->BH_prescription==BH_FRYER12_RAPID || + stardata->preferences->BH_prescription==BH_FRYER12_STARTRACK) { - double Mproto = stardata->preferences->BH_prescription==BH_FRYER12_DELAYED ? - COCoreToProtoMassDelayed(pre_explosion_star->core_mass[CORE_CO]) : - 1.0; // was COCoreToProtoMassRapid(pre_explosion_star->core_mass[CORE_CO]); - double fb = - stardata->preferences->BH_prescription==BH_FRYER12_DELAYED ? - fallbackDelayed(pre_explosion_star->mass, Mproto, pre_explosion_star->core_mass[CORE_CO]) : - fallbackRapid(pre_explosion_star->mass, Mproto, pre_explosion_star->core_mass[CORE_CO]); + const double fb = Fryer2012_f_fb(stardata, + pre_explosion_star->mass, + pre_explosion_star->core_mass[CORE_CO]); vk *= 1.0 - fb; /* diff --git a/src/zfuncs/fallbackDelayed.c b/src/zfuncs/fallbackDelayed.c deleted file mode 100644 index c988f7907..000000000 --- a/src/zfuncs/fallbackDelayed.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "../binary_c.h" -No_empty_translation_unit_warning; - - - -double Constant_function fallbackDelayed(const double MpreSN, - const double Mproto, - const double COCoreMass) -{ - /* - Calculate fallback using the delayed prescription - - Equation 19 of Fryer et al 2012 - - Parameters - ----------- - MpreSN : double - Pre supernova stellar mass in Msol - Mproto : double - Fe/Ni proto compact object mass in Msol - COCoreMass : double - Pre supernova CO core mass in Msol - - Returns - -------- - fb : double, must be in the range 0 to 1 - Fallback - - -- Simon Stevenson - */ - double fb; - if(COCoreMass < 2.5) - { - fb = 0.2/(MpreSN - Mproto); - } - else if(COCoreMass < 3.5) - { - fb = (0.5 * COCoreMass - 1.05)/(MpreSN - Mproto); - } - else if(COCoreMass < 11.0) - { - double a2 = 0.133 - (0.093)/(MpreSN - Mproto); - double b2 = -11.0 * a2 + 1.0; - fb = a2 * COCoreMass + b2; - } - else - { - fb = 1.0; - } - - Clamp(fb,0.0,1.0); - - return fb; -} - diff --git a/src/zfuncs/fallbackRapid.c b/src/zfuncs/fallbackRapid.c deleted file mode 100644 index 4a9b7aa36..000000000 --- a/src/zfuncs/fallbackRapid.c +++ /dev/null @@ -1,57 +0,0 @@ -#include "../binary_c.h" -No_empty_translation_unit_warning; - - -double Constant_function fallbackRapid(const double MpreSN, - const double Mproto, - const double COCoreMass) -{ - /* - Calculate fallback using the rapid prescription - - Equations 15 & 16 from Fryer et al 2012 - - Parameters - ----------- - MpreSN : double - Pre supernova stellar mass in Msol - Mproto : double - Fe/Ni proto compact object mass in Msol - COCoreMass : double - Pre supernova CO core mass in Msol - - Returns - --------- - fb : double - Fraction of mass falling back onto proto object - - -- Simon Stevenson - */ - - double fb; - if(COCoreMass < 2.5) - { - fb = 0.2/(MpreSN - Mproto); - } - else if(COCoreMass < 6.0) - { - fb = (0.286 * COCoreMass - 0.514)/(MpreSN - Mproto); - } - else if(COCoreMass < 7.0) - { - fb = 1.0; - } - else if(COCoreMass < 11.0) - { - double a1 = 0.25 - (1.275/(MpreSN - Mproto)); - double b1 = -11.0 * a1 + 1.0; - fb = a1 * COCoreMass + b1; - } - else - { - fb = 1.0; - } - - Clamp(fb,0.0,1.0); - return fb; -} diff --git a/src/zfuncs/massFallbackGeneral.c b/src/zfuncs/massFallbackGeneral.c deleted file mode 100644 index d043ff94e..000000000 --- a/src/zfuncs/massFallbackGeneral.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "../binary_c.h" -No_empty_translation_unit_warning; - - -double Constant_function massFallbackGeneral(const double MpreSN, - const double Mproto, - const double fb) -{ - /* - Equation 11 in Fryer et al 2012 - - Parameters - ----------- - MpreSN : double - Pre supernova stellar mass in Msol - COCoreMass : double - Pre supernova Carbon Oxygen (CO) core mass in Msol - fb : double - Fallback [0,1] - - Returns - -------- - Mfb : double - Mass falling back onto proto object - - -- Simon Stevenson - */ - return fb * (MpreSN - Mproto); -} diff --git a/tbse b/tbse index a1a315da5..7db2d0b41 100755 --- a/tbse +++ b/tbse @@ -1194,6 +1194,7 @@ MASS_ACCRETION_FOR_ELD=-1 # BH_SPERA2015 = 2: Spera+ 2015 # BH_FRYER12_DELAYED = 3: Fryer 2012 (delayed) # BH_FRYER12_RAPID = 4: Fryer 2012 (rapid) +# BH_FRYER12_STARTRACK = 5: Fryer 2012 (startrack) BH_PRESCRIPTION=BH_FRYER12_DELAYED # Type Ia supernovae diff --git a/ubuntu_install_binary_c.sh b/ubuntu_install_binary_c.sh index 6aaf74ae4..c0f393ebf 100755 --- a/ubuntu_install_binary_c.sh +++ b/ubuntu_install_binary_c.sh @@ -91,8 +91,8 @@ function setup_bash echo 'export LD_LIBRARY_PATH=$HOME/lib:$BINARY_C:$BINARY_C/src' >> $BASHRC # do this only once! echo 'export PATH=.:$HOME/bin:$HOME/.local/bin:$PATH' >> $BASHRC # do this only once! - # psb, psbb, git functions etc. and completion of binary_c arguments - printf '%s' ' + # psb, psbb, git functions etc. and completion of binary_c arguments + printf '%s' ' # source perlbrewbinary_c source $HOME/perl5/perlbrew/etc/bashrc @@ -166,7 +166,7 @@ export GSL_DIR=`gsl-config --prefix` export PATH=$HOME/bin:$HOME/.local/bin:$PATH if [ -f $HOME/perl5/perlbrew/etc/bashrc ]; then - source $HOME/perl5/perlbrew/etc/bashrc + source $HOME/perl5/perlbrew/etc/bashrc fi } @@ -183,7 +183,7 @@ function install_from_surrey_git cd $PACKAGE-master/ if [ -d builddir ]; then - rm -r builddir + rm -r builddir fi meson --prefix=$HOME --buildtype=release builddir ninja -C builddir install @@ -194,8 +194,8 @@ function install_binary_c_from_zip # download and install binary_c if [ -d $BINARY_C ]; then - echo "Directory $BINARY_C already exists: please remove any old binary_c installation before installing a new one" - exit + echo "Directory $BINARY_C already exists: please remove any old binary_c installation before installing a new one" + exit fi cd /tmp # work from /tmp $WGET https://$GITLAB/binary_c/-/archive/master/binary_c-master.zip -O binary_c-master.zip @@ -267,23 +267,23 @@ function install_perl if [ "$CURRENT_PERL" == "$LATEST_PERL" ]; then - echo "You already have the latest Perl" + echo "You already have the latest Perl" else - NEWER_PERL=`echo -e "$CURRENT_PERL\n$LATEST_PERL" | sort -Vr | head -1` - if [ "$NEWER_PERL" == "$LATEST_PERL" ]; - then - echo "Installing $LATEST_PERL" - perlbrew -v install $LATEST_PERL --thread --multi --64bitall --notest -Dusethreads -Duselargefiles -Dcccdlflags=-fPIC -Dpager=/usr/bin/sensible-pager -Doptimize="-O3 -mtune=generic" -Duseshrplib -j $NTHREADS - # clean the build - echo "Cleaning perlbrew/build" - rm -rf $HOME/perl5/perlbrew/build 2>/dev/null - else - echo "No newer Perl has been found : sticking with $CURRENT_PERL" + NEWER_PERL=`echo -e "$CURRENT_PERL\n$LATEST_PERL" | sort -Vr | head -1` + if [ "$NEWER_PERL" == "$LATEST_PERL" ]; + then + echo "Installing $LATEST_PERL" + perlbrew -v install $LATEST_PERL --thread --multi --64bitall --notest -Dusethreads -Duselargefiles -Dcccdlflags=-fPIC -Dpager=/usr/bin/sensible-pager -Doptimize="-O3 -mtune=generic" -Duseshrplib -j $NTHREADS + # clean the build + echo "Cleaning perlbrew/build" + rm -rf $HOME/perl5/perlbrew/build 2>/dev/null + else + echo "No newer Perl has been found : sticking with $CURRENT_PERL" fi - echo "Source perlbrew" - source ~/perl5/perlbrew/etc/bashrc 2>&1 || true - echo "Switch to use $LATEST_PERL" - perlbrew switch $LATEST_PERL + echo "Source perlbrew" + source ~/perl5/perlbrew/etc/bashrc 2>&1 || true + echo "Switch to use $LATEST_PERL" + perlbrew switch $LATEST_PERL fi source ~/perl5/perlbrew/etc/bashrc 2>&1 || true @@ -296,7 +296,8 @@ function install_binary_c_python # install the binary_c Python module export LIBRARY_PATH=$LD_LIBRARY_PATH pip3 install -U pip setuptools - pip3 install git+https://$GITLAB/binary_c-python.git + # pip3 install git+https://$GITLAB/binary_c-python.git + pip3 install git+https://gitlab.eps.surrey.ac.uk/ri0005/binary_c-python.git@development_version/2.1.7 } function update_packages @@ -312,7 +313,7 @@ function update_packages # install required packages sudo apt-get install bash zip gcc-10 libgcc-10-dev gdb valgrind gawk python3.9 pipenv kcachegrind meson ninja-build emacs perl libgsl-dev global libbsd-dev binutils-dev libiberty-dev libjemalloc-dev zlib1g-dev unzip wget curl git sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1 -# sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2 2>/dev/null + # sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2 2>/dev/null echo "You should normally choose Python 3.9" sudo update-alternatives --config python # >>> choose python3.9 <<< sudo apt-get clean @@ -388,12 +389,12 @@ done # install binary_c echo "Install binary_c from ... ?" select s in "git (https)" "git (ssh, keys must be set up)" "git (zip, no version control)" "No"; - do case $s in - "git (https)" ) install_binary_c_from_git_https; break;; - "git (ssh, keys must be set up)" ) install_binary_c_from_git_ssh; break;; - "git (zip, no version control)" ) install_binary_c_from_zip; break;; - "No" ) break;; - esac +do case $s in + "git (https)" ) install_binary_c_from_git_https; break;; + "git (ssh, keys must be set up)" ) install_binary_c_from_git_ssh; break;; + "git (zip, no version control)" ) install_binary_c_from_zip; break;; + "No" ) break;; + esac done # install binary_c's perl modules -- GitLab