Skip to content
Snippets Groups Projects
Commit e6a7f8be authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Update the unit tests using the cosmology module for the new function signature.

parent c9d3801e
Branches
Tags
1 merge request!979Cosmological integration
...@@ -106,7 +106,7 @@ void output_list_read_file(struct output_list *outputlist, const char *filename, ...@@ -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 (type == OUTPUT_LIST_REDSHIFT) *time = 1. / (1. + *time);
if (cosmo && type == OUTPUT_LIST_AGE) if (cosmo && type == OUTPUT_LIST_AGE)
*time = cosmology_get_scale_factor(cosmo, *time); *time = cosmology_get_scale_factor_from_time(cosmo, *time);
/* Update size */ /* Update size */
ind += 1; ind += 1;
......
...@@ -20,11 +20,15 @@ ...@@ -20,11 +20,15 @@
/* Some standard headers. */ /* Some standard headers. */
#include "../config.h" #include "../config.h"
/* Some standard headers */
#include <fenv.h>
#include <math.h>
/* Includes. */ /* Includes. */
#include "swift.h" #include "swift.h"
#define N_CHECK 20 #define N_CHECK 200
#define TOLERANCE 1e-7 #define TOLERANCE 1e-6
void test_params_init(struct swift_params *params) { void test_params_init(struct swift_params *params) {
parser_init("", params); parser_init("", params);
...@@ -32,12 +36,21 @@ void test_params_init(struct swift_params *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_lambda:0.6910");
parser_set_param(params, "Cosmology:Omega_b:0.0486"); parser_set_param(params, "Cosmology:Omega_b:0.0486");
parser_set_param(params, "Cosmology:h:0.6774"); 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"); parser_set_param(params, "Cosmology:a_end:1.0");
} }
int main(int argc, char *argv[]) { 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..."); message("Initialization...");
/* pseudo initialization of params */ /* pseudo initialization of params */
...@@ -60,14 +73,15 @@ int main(int argc, char *argv[]) { ...@@ -60,14 +73,15 @@ int main(int argc, char *argv[]) {
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.); 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); double time = cosmology_get_time_since_big_bang(&cosmo, a);
tmp = cosmology_get_scale_factor(&cosmo, tmp); double my_a = cosmology_get_scale_factor_from_time(&cosmo, time);
/* check accuracy */ /* check accuracy */
tmp = (tmp - a) / a; double rel_err = (my_a - a) / a;
message("Accuracy of %g at a=%g", tmp, a); message("Accuracy of %g at a=%g", rel_err, a);
assert(fabs(tmp) < TOLERANCE); assert(fabs(rel_err) < TOLERANCE);
} }
message("Everything seems fine with cosmology."); message("Everything seems fine with cosmology.");
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
******************************************************************************/ ******************************************************************************/
#include "../config.h" #include "../config.h"
/* Some standard headers */
#include <fenv.h>
#include <math.h>
/* Includes. */ /* Includes. */
#include "swift.h" #include "swift.h"
...@@ -86,7 +90,8 @@ void test_cosmo(struct engine *e, char *name, int with_assert) { ...@@ -86,7 +90,8 @@ void test_cosmo(struct engine *e, char *name, int with_assert) {
double output_time = 0; double output_time = 0;
/* Test Time */ /* 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->ti_current = 0;
e->policy = engine_policy_cosmology; e->policy = engine_policy_cosmology;
...@@ -115,6 +120,16 @@ void test_cosmo(struct engine *e, char *name, int with_assert) { ...@@ -115,6 +120,16 @@ void test_cosmo(struct engine *e, char *name, int with_assert) {
}; };
int main(int argc, char *argv[]) { 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. */ /* Create a structure to read file into. */
struct swift_params params; struct swift_params params;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment