Skip to content
Snippets Groups Projects
Commit 91486ab0 authored by Izzard, Robert Dr (Maths & Physics)'s avatar Izzard, Robert Dr (Maths & Physics)
Browse files

some code cleanup:

double2bin : test return value of writes in case of failure

clean up preroche slowdown (some macros were wrong)

update and debug unit tests
parent 2f423221
No related branches found
No related tags found
No related merge requests found
......@@ -9,8 +9,9 @@ int main()
double p;
while(fscanf(stdin,"%lf",&p)!=EOF)
{
fwrite(&p,sizeof(double),1,stdout);
if(!fwrite(&p,sizeof(double),1,stdout)) return 1;
}
fflush(stdout);
return 0;
}
......@@ -23,6 +23,8 @@
#define UNDEF -666.6
#define UNDEF_STARS UNDEF,UNDEF
#define UNIT_TEST_PREFIX \
"BINARY_C_UNIT_TEST"
......@@ -55,14 +57,12 @@
"vwind2", \
"stellar_timestep1", \
"stellar_timestep2", \
"NTP1", \
"NTP2", \
"tm1", \
"tm2", \
"tn1", \
"tn2", \
"dt1", \
"dt2", \
"NTP1", \
"NTP2", \
"dt", \
"dtm", \
"Jorb", \
......@@ -147,7 +147,7 @@
#define UNIT_TEST_HEADER_FORMAT \
"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s"
"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s"
#define UNIT_TEST_FORMAT \
"%g %g %g %g %g %d %d %d %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
......@@ -177,7 +177,8 @@
/*
* No nucsyn, set to undefined
*/
#define UNIT_TESTS_NUCSYN UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF
#define UNIT_TESTS_NUCSYN UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS
#endif
#define UNIT_TEST_time stardata->model.time
......@@ -186,6 +187,7 @@
STARS(mass), \
STARS(core_mass), \
STARS(stellar_type), \
stardata->model.sgl, \
STARS(radius), \
STARS(roche_radius), \
STARS(age), \
......@@ -206,25 +208,25 @@
stardata->common.eccentricity, \
Jdot_orbit(stardata), \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_GRAVITATIONAL_RADIATION], \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_WIND_LOSS], \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_WIND_GAIN], \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_RLOF_LOSS], \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_RLOF_GAIN], \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_CBDISC], \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_TIDES], \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_NONCONSERVATIVE_LOSS], \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_NOVA], \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_ARTIFICIAL], \
edot_orbit(stardata), \
stardata->model.derivative[DERIVATIVE_ORBIT_ECCENTRICITY_GRAVITATIONAL_RADIATION], \
stardata->model.derivative[DERIVATIVE_ORBIT_ECCENTRICITY_TIDES], \
stardata->model.derivative[DERIVATIVE_ORBIT_ECCENTRICITY_WINDS], \
UNDEF, \
stardata->model.derivative[DERIVATIVE_ORBIT_ECCENTRICITY_CBDISC], \
STARS(derivative[DERIVATIVE_STELLAR_MASS_WIND_LOSS]), \
STARS(derivative[DERIVATIVE_STELLAR_MASS_WIND_GAIN]), \
STARS(derivative[DERIVATIVE_STELLAR_MASS_RLOF_LOSS]), \
STARS(derivative[DERIVATIVE_STELLAR_MASS_RLOF_GAIN]), \
UNDEF, \
STARS(derivative[DERIVATIVE_STELLAR_MASS_NOVA]), \
STARS(derivative[DERIVATIVE_STELLAR_MASS_NONCONSERVATIVE_LOSS]), \
STARS(derivative[DERIVATIVE_STELLAR_MASS_CBDISC_GAIN]), \
STARS(derivative[DERIVATIVE_STELLAR_MASS_DECRETION_DISC]), \
......@@ -243,6 +245,7 @@
666.0
/* V 2.0pre27 */
#elif BINARY_C_MAJOR_VERSION >= 2 && \
BINARY_C_MINOR_VERSION >= 0 && \
......@@ -268,7 +271,7 @@
/*
* No nucsyn, set to undefined
*/
#define UNIT_TESTS_NUCSYN UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF,UNDEF
#define UNIT_TESTS_NUCSYN UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS,UNDEF_STARS
#endif
#define UNIT_TEST_time stardata->model.time
......@@ -277,6 +280,7 @@
STARS(mass), \
STARS(core_mass), \
STARS(stellar_type), \
stardata->model.sgl, \
STARS(radius), \
STARS(roche_radius), \
STARS(age), \
......@@ -297,37 +301,37 @@
stardata->common.eccentricity, \
Jdot_orbit(stardata), \
stardata->model.derivative[DERIVATIVE_ORBIT_ANGMOM_GRAVITATIONAL_RADIATION], \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
edot_orbit(stardata), \
stardata->model.derivative[DERIVATIVE_ORBIT_ECCENTRICITY_GRAVITATIONAL_RADIATION], \
stardata->model.derivative[DERIVATIVE_ORBIT_ECCENTRICITY_TIDES], \
stardata->model.derivative[DERIVATIVE_ORBIT_ECCENTRICITY_WINDS], \
UNDEF, \
UNDEF, \
STARS(derivative[DERIVATIVE_STELLAR_MASS_WIND_LOSS]), \
STARS(derivative[DERIVATIVE_STELLAR_MASS_WIND_GAIN]), \
STARS(derivative[DERIVATIVE_STELLAR_MASS_RLOF_LOSS]), \
STARS(derivative[DERIVATIVE_STELLAR_MASS_RLOF_GAIN]), \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF_STARS, \
UNDEF_STARS, \
UNDEF_STARS, \
UNDEF_STARS, \
UNDEF_STARS, \
STARS(derivative[DERIVATIVE_STELLAR_ANGMOM_WIND_LOSS]), \
STARS(derivative[DERIVATIVE_STELLAR_ANGMOM_WIND_GAIN]), \
STARS(derivative[DERIVATIVE_STELLAR_ANGMOM_RLOF_LOSS]), \
STARS(derivative[DERIVATIVE_STELLAR_ANGMOM_RLOF_GAIN]), \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF, \
UNDEF_STARS, \
UNDEF_STARS, \
UNDEF_STARS, \
UNDEF_STARS, \
STARS(derivative[DERIVATIVE_STELLAR_ANGMOM_TIDE]), \
STARS(derivative[DERIVATIVE_STELLAR_ANGMOM_MAGNETIC_BRAKING]), \
UNIT_TESTS_NUCSYN, \
......@@ -348,6 +352,7 @@
* Newer binary_c uses PRINTF for output, but if this
* is not defined instead use printf
*/
#undef PRINTF
#ifndef PRINTF
#define PRINTF printf
#endif
......
......@@ -536,10 +536,11 @@
* Enable these to reduce the timestep when R approaches R_lobe (roche_radius)
* on the EAGB and/or TPAGB
*/
//#define SLOW_DOWN_PREROCHE_HG
//#define SLOW_DOWN_PREROCHE_EAGB
//#define SLOW_DOWN_PREROCHE_TPAGB
//#define SLOW_DOWN_PREROCHE_MS
#define SLOW_DOWN_PREROCHE_MS
#define SLOW_DOWN_PREROCHE_HG
#define SLOW_DOWN_PREROCHE_EAGB
#define SLOW_DOWN_PREROCHE_TPAGB
/*
* Perhaps reduce the timestep when the star is rotating
......@@ -651,7 +652,7 @@
/*
* The fraction of matter retained in a nova explosion
*/
#define EPSNOV_DEFAULT 1e-3
#define NOVA_RETENTION_FRACTION_DEFAULT 1e-3
/*
* Define TIME_RESOLVE_NOVAE to time-resolve novae to within
......@@ -840,11 +841,9 @@
/*
* defaults:
* RLOF_OVERFLOW_THRESHOLD 1.0
* RLOF_STABILITY_FACTOR 0.9999
* RLOF_STABILITY_FACTOR 1.0
*/
#define RLOF_OVERFLOW_THRESHOLD 1.0
//#define RLOF_STABILITY_FACTOR 0.99999
//#define RLOF_STABILITY_FACTOR 0.99
#define RLOF_STABILITY_FACTOR 1.0
/*
......
......@@ -600,7 +600,7 @@
/*
* Enable unit testing
*/
#define UNIT_TESTS
//#define UNIT_TESTS
#endif //CODE_OPTIONS_H
......@@ -68,7 +68,7 @@ void reset_preferences(struct preferences_t * RESTRICT preferences)
#endif//NUCSYN
// initialize other free parameters
preferences->nova_retention_fraction=EPSNOV_DEFAULT;
preferences->nova_retention_fraction=NOVA_RETENTION_FRACTION_DEFAULT;
preferences->accretion_limit_eddington_multiplier=ACCRETION_LIMIT_EDDINGTON_MULTIPLIER_DEFAULT;
preferences->accretion_limit_thermal_multiplier=ACCRETION_LIMIT_THERMAL_MULTIPLIER_DEFAULT;
preferences->accretion_limit_dynamical_multiplier=ACCRETION_LIMIT_DYNAMICAL_MULTIPLIER_DEFAULT;
......
......@@ -404,8 +404,8 @@ void version(struct stardata_t * RESTRICT stardata)
PRINTF("MIN_SEP_FOR_CLOSE_ANG_MOM_LOSS1 %g\n",MIN_SEP_FOR_CLOSE_ANG_MOM_LOSS1);
PRINTF("MIN_SEP_FOR_CLOSE_ANG_MOM_LOSS2 %g\n",MIN_SEP_FOR_CLOSE_ANG_MOM_LOSS2);
PRINTF("MIN_SEP_FOR_CLOSE_ANG_MOM_LOSS %g\n",MIN_SEP_FOR_CLOSE_ANG_MOM_LOSS);
PRINTF("EPSNOV_DEFAULT (fraction of matter retained in a nova explosion) default=%g\n",
EPSNOV_DEFAULT);
PRINTF("NOVA_RETENTION_FRACTION_DEFAULT (fraction of matter retained in a nova explosion) default=%g\n",
NOVA_RETENTION_FRACTION_DEFAULT);
PRINTF("Accretion rate limit defaults: NOVAE_UPPER_LIMIT=%g SOFT_XRAY_UPPER_LIMIT=%g\n",
ACCRETION_RATE_NOVAE_UPPER_LIMIT_DEFAULT,
......
......@@ -204,7 +204,8 @@ void stellar_structure_BSE(struct new_stellar_structure_t * s,
* When stars merge their MS lifetimes are a bit off
* sometimes because the mass has increased.
* Compensate for this by putting a merged HG
* at the beginning of the HG.
* at the beginning of the HG: evolution on the HG
* will, in any case, be fast.
*/
if(s->age - s->tm < TINY &&
s->stellar_type > 1)
......
......@@ -114,11 +114,13 @@ double monte_carlo_kick(struct star_t * exploder,
/* logging */
Append_logstring(LOG_SN_AND_KICK,
"%s %s (%d %d) -> kick %d(%g) vk=%g vr=%g omega=%g phi=%g -> vn=%g ; ",
"%s %s (SN type %d %d, pre-explosion M=%g Mc=%g) -> kick %d(%g) vk=%g vr=%g omega=%g phi=%g -> vn=%g ; ",
exploder->SN_type==SN_WDKICK ? "WD kick" : "SN kick",
strings[exploder->SN_type],
exploder->SN_type,
pre_explosion_star->SN_type,
pre_explosion_star->mass,
pre_explosion_star->core_mass,
kick_distribution,
kick_dispersion,
kick_system->kick_speed,
......
......@@ -17,12 +17,6 @@ void timestep_EAGB(Timestep_prototype_args)
HRDIAG_DT_NEGATIVE_CHECK;
#endif // HRDIAG
/*
* RGI : I am not sure what tn has to do with calculating
* the time remaining in this phase of evolution. Indeed,
* sometimes using the MIN of tn and the time at the first
* pulse leads to problems.
*/
//*time_remaining = MIN(tn,tscls[T_TPAGB_FIRST_PULSE]) - age;
*time_remaining = tscls[T_TPAGB_FIRST_PULSE] - age;
......@@ -30,12 +24,12 @@ void timestep_EAGB(Timestep_prototype_args)
* Slow down as we approach RLOF, we want to make this
* as accurate as possible.
*/
#if (defined(SLOW_DOWN_PREROCHE_EAGB)&& !defined(RLOF_REDUCE_TIMESTEP))
#if defined SLOW_DOWN_PREROCHE_EAGB && !defined RLOF_REDUCE_TIMESTEP
double rr=star->radius / star->roche_radius;
rr=1.0-rr;
rr=MIN(1.0,rr);
rr=MAX(0.1,rr);
double newdt = *dt * rr;
Limit_timestep(*dt,newdt,star,DT_LIMIT_PREROCHE_EAGB);
Limit_timestep(*dt,newdt,star,DT_LIMIT_EAGB_PREROCHE);
#endif // SLOW_DOWN_PREROCHE_EAGB
}
......@@ -60,12 +60,13 @@ void timestep_TPAGB(Timestep_prototype_args)
Set_timestep(*dt,tip,star,DT_LIMIT_TPAGB_NUCSYN_INTERPULSE);
}
#if (defined(SLOW_DOWN_PREROCHE_TPAGB)&& !defined(RLOF_REDUCE_TIMESTEP))
#if defined SLOW_DOWN_PREROCHE_TPAGB && !defined RLOF_REDUCE_TIMESTEP
/*
* Slow down as we approach RLOF, we want to make this
* as accurate as possible.
*/
{
double tip=star->interpulse_period*stardata->preferences->dtfac*0.9999;
double rr=star->radius / star->roche_radius;
rr=1.0-rr;
rr=MIN(1.0,rr);
......
......@@ -281,7 +281,9 @@ E2_PRESCRIPTION=1
############################
#
# Method for calculting the Roche-lobe overflow rate:
# 0=H02, 1=Adaptive (for radiative stars), 2=Ritter (broken),
# 0=H02
# 1=Adaptive (really only good for radiative stars)
# 2=Ritter (probably broken),
# 3=Claeys etal 2014 variant on H02
RLOF_METHOD=3
......@@ -951,7 +953,7 @@ YIELDS_DT=100
#NONCONSERVATIVE_ANGMOM_GAMMA=-2
#TPAGBWIND=1
#ELD_ACC_MASS=1000.0
#NOVA_RETENTION_FACTOR=0.1
#NOVA_RETENTION_FRACTION=0.1
#AGB_CORE_ALGORITHM=1
#AGB_3DUP_ALGORITHM=2
#REIMERS_ETA=0.5
......
......@@ -15,6 +15,7 @@ use 5.16.0;
#
my $valgrind = ''; # valgrind or ''
my $nice = "nice";
my $repeat = 1;
my $q = robqueue->new(
nthreads=>rob_misc::ncpus(),
......@@ -42,8 +43,7 @@ sub runsystem
}
else
{
my $r = `tbse $valgrind --repeat $repeat --random_systems 1 --log_filename /tmp/c_log-$n.dat 2>\&1 | tail -1000`;
my $r = `$nice tbse $valgrind --repeat $repeat --random_systems 1 --log_filename /tmp/c_log-$n.dat 2>\&1 | tail -1000`;
my $status = $?;
my $args = ($r=~/(--M_1.*)/g)[$valgrind ? 1 : 1];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment