Skip to content
Snippets Groups Projects
Commit 3a43c49c authored by lhausamm's avatar lhausamm Committed by Loic Hausammann
Browse files

Change output testCosmology and add warning message about accuracy in cosmology.c

parent 867f606a
No related branches found
No related tags found
1 merge request!560Output time from a file
...@@ -679,6 +679,9 @@ double cosmology_get_a_from_z(const struct cosmology *c, double redshift) { ...@@ -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. * @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 c The current #cosmology.
* @param t time since the big bang * @param t time since the big bang
* @return The scale factor. * @return The scale factor.
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* Includes. */ /* Includes. */
#include "swift.h" #include "swift.h"
#define N_CHECK 10 #define N_CHECK 20
#define TOLERANCE 1e-3 #define TOLERANCE 1e-3
void test_params_init(struct swift_params *params) { void test_params_init(struct swift_params *params) {
...@@ -58,17 +58,15 @@ int main(int argc, char *argv[]) { ...@@ -58,17 +58,15 @@ int main(int argc, char *argv[]) {
message("Start checking computation..."); 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++) { 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 */ /* 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); tmp = cosmology_get_scale_factor(&cosmo, tmp);
/* check accuracy */ /* check accuracy */
tmp = (tmp - a[i]) / a[i]; tmp = (tmp - a) / a;
message("Accuracy of %f at a=%f", tmp, a[i]); message("Accuracy of %g at a=%g", tmp, a);
assert(fabs(tmp) < TOLERANCE); assert(fabs(tmp) < TOLERANCE);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment