diff --git a/src/cosmology.c b/src/cosmology.c index a443529c7a92fc01ddee4c975a29837d5efd1faa..538b118700a914c77dbbd036ba317a339e127ab2 100644 --- a/src/cosmology.c +++ b/src/cosmology.c @@ -679,6 +679,9 @@ double cosmology_get_a_from_z(const struct cosmology *c, double redshift) { /** * @brief Compute scale factor from time since big bang. * + * WARNING: This method has a low accuracy at high redshift. + * The relative error is around 1e-3 (testCosmology.c is measuring it). + * * @param c The current #cosmology. * @param t time since the big bang * @return The scale factor. diff --git a/tests/testCosmology.c b/tests/testCosmology.c index 31c7aea64bb8597a240c420a21845c861654494a..f24b920df7027071df9613b701bb8bef03354208 100644 --- a/tests/testCosmology.c +++ b/tests/testCosmology.c @@ -23,7 +23,7 @@ /* Includes. */ #include "swift.h" -#define N_CHECK 10 +#define N_CHECK 20 #define TOLERANCE 1e-3 void test_params_init(struct swift_params *params) { @@ -58,17 +58,15 @@ int main(int argc, char *argv[]) { message("Start checking computation..."); - double a[N_CHECK] = {0.1, 0.2, 0.3, 0.4, 0.5, - 0.6, 0.7, 0.8, 0.9, 1.0}; - 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[i]); + double tmp = cosmology_get_time_since_big_bang(&cosmo, a); tmp = cosmology_get_scale_factor(&cosmo, tmp); /* check accuracy */ - tmp = (tmp - a[i]) / a[i]; - message("Accuracy of %f at a=%f", tmp, a[i]); + tmp = (tmp - a) / a; + message("Accuracy of %g at a=%g", tmp, a); assert(fabs(tmp) < TOLERANCE); }