Skip to content

Commit

Permalink
Test comoving distance functions in testCosmology
Browse files Browse the repository at this point in the history
  • Loading branch information
jchelly committed Jan 11, 2023
1 parent 22112d6 commit 36bdad8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/testCosmology.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) {
struct cosmology cosmo;
cosmology_init(&params, &us, &phys_const, &cosmo);

message("Start checking computation...");
message("Start checking time since big bang computation...");

for (int i = 0; i < N_CHECK; i++) {
double a = 0.1 + 0.9 * i / (N_CHECK - 1.);
Expand All @@ -70,6 +70,20 @@ int main(int argc, char *argv[]) {
assert(fabs(tmp) < TOLERANCE);
}

message("Start checking comoving distance computation...");

for (int i = 0; i < N_CHECK; i++) {
double a = 0.1 + 0.9 * i / (N_CHECK - 1.);
/* Compute a(comoving_distance(a)) and check if same results */
double tmp = cosmology_get_comoving_distance(&cosmo, a);
tmp = cosmology_scale_factor_at_comoving_distance(&cosmo, tmp);

/* check accuracy */
tmp = (tmp - a) / a;
message("Accuracy of %g at a=%g", tmp, a);
assert(fabs(tmp) < TOLERANCE);
}

message("Everything seems fine with cosmology.");

cosmology_clean(&cosmo);
Expand Down

0 comments on commit 36bdad8

Please sign in to comment.