diff --git a/src/outputlist.c b/src/outputlist.c index da841103d2ce35b849112d62ffd523f632cc457b..d49f0abd9872d3af2ae20c877afb6a2d6ddde120 100644 --- a/src/outputlist.c +++ b/src/outputlist.c @@ -106,7 +106,7 @@ void output_list_read_file(struct output_list *outputlist, const char *filename, if (type == OUTPUT_LIST_REDSHIFT) *time = 1. / (1. + *time); if (cosmo && type == OUTPUT_LIST_AGE) - *time = cosmology_get_scale_factor(cosmo, *time); + *time = cosmology_get_scale_factor_from_time(cosmo, *time); /* Update size */ ind += 1; diff --git a/tests/testCosmology.c b/tests/testCosmology.c index 05dc69b2a925b0e19a9bb4a20ac1003b4b30704b..a574773cf164d06eb07f56e4493b392e584caaa2 100644 --- a/tests/testCosmology.c +++ b/tests/testCosmology.c @@ -20,11 +20,15 @@ /* Some standard headers. */ #include "../config.h" +/* Some standard headers */ +#include <fenv.h> +#include <math.h> + /* Includes. */ #include "swift.h" -#define N_CHECK 20 -#define TOLERANCE 1e-7 +#define N_CHECK 200 +#define TOLERANCE 1e-6 void test_params_init(struct swift_params *params) { parser_init("", params); @@ -32,12 +36,21 @@ void test_params_init(struct swift_params *params) { parser_set_param(params, "Cosmology:Omega_lambda:0.6910"); parser_set_param(params, "Cosmology:Omega_b:0.0486"); parser_set_param(params, "Cosmology:h:0.6774"); - parser_set_param(params, "Cosmology:a_begin:0.1"); + parser_set_param(params, "Cosmology:a_begin:0.01"); parser_set_param(params, "Cosmology:a_end:1.0"); } int main(int argc, char *argv[]) { + /* Initialize CPU frequency, this also starts time. */ + unsigned long long cpufreq = 0; + clocks_set_cpufreq(cpufreq); + +/* Choke on FP-exceptions */ +#ifdef HAVE_FE_ENABLE_EXCEPT + feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); +#endif + message("Initialization..."); /* pseudo initialization of params */ @@ -60,14 +73,15 @@ int main(int argc, char *argv[]) { for (int i = 0; i < N_CHECK; i++) { double a = 0.1 + 0.9 * i / (N_CHECK - 1.); + /* Compute a(t(a)) and check if same results */ - double tmp = cosmology_get_time_since_big_bang(&cosmo, a); - tmp = cosmology_get_scale_factor(&cosmo, tmp); + double time = cosmology_get_time_since_big_bang(&cosmo, a); + double my_a = cosmology_get_scale_factor_from_time(&cosmo, time); /* check accuracy */ - tmp = (tmp - a) / a; - message("Accuracy of %g at a=%g", tmp, a); - assert(fabs(tmp) < TOLERANCE); + double rel_err = (my_a - a) / a; + message("Accuracy of %g at a=%g", rel_err, a); + assert(fabs(rel_err) < TOLERANCE); } message("Everything seems fine with cosmology."); diff --git a/tests/testOutputList.c b/tests/testOutputList.c index fd69ef91389758adf87aa48ab983a6cfbd6a89a9..dfb873b64e033142f8d1c8c21272202d7d27a034 100644 --- a/tests/testOutputList.c +++ b/tests/testOutputList.c @@ -19,6 +19,10 @@ ******************************************************************************/ #include "../config.h" +/* Some standard headers */ +#include <fenv.h> +#include <math.h> + /* Includes. */ #include "swift.h" @@ -86,7 +90,8 @@ void test_cosmo(struct engine *e, char *name, int with_assert) { double output_time = 0; /* Test Time */ - e->time_base = log(e->time_end / e->cosmology->a_begin) / max_nr_timesteps; + e->time_base = + log(e->cosmology->a_end / e->cosmology->a_begin) / max_nr_timesteps; e->ti_current = 0; e->policy = engine_policy_cosmology; @@ -115,6 +120,16 @@ void test_cosmo(struct engine *e, char *name, int with_assert) { }; int main(int argc, char *argv[]) { + + /* Initialize CPU frequency, this also starts time. */ + unsigned long long cpufreq = 0; + clocks_set_cpufreq(cpufreq); + +/* Choke on FP-exceptions */ +#ifdef HAVE_FE_ENABLE_EXCEPT + feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); +#endif + /* Create a structure to read file into. */ struct swift_params params;