From 9a02eab9fd0c225b03a4e6e38d49a8434cf9e3ef Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Sat, 17 Feb 2018 20:00:56 +0100 Subject: [PATCH] Add a function to set the cosmological factors to valid values when running a non-cosmological case. --- examples/main.c | 5 ++++- src/cosmology.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/cosmology.h | 5 +++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/examples/main.c b/examples/main.c index aee457723c..b9f1426a75 100644 --- a/examples/main.c +++ b/examples/main.c @@ -601,7 +601,10 @@ int main(int argc, char *argv[]) { /* Initialise the cosmology */ struct cosmology cosmo; - if (with_cosmology) cosmology_init(params, &us, &prog_const, &cosmo); + if (with_cosmology) + cosmology_init(params, &us, &prog_const, &cosmo); + else + cosmology_init_no_cosmo(params, &us, &prog_const, &cosmo); if (with_cosmology) cosmology_print(&cosmo); /* Initialise the hydro properties */ diff --git a/src/cosmology.c b/src/cosmology.c index 8ee3fe82f2..3a65ffc0f9 100644 --- a/src/cosmology.c +++ b/src/cosmology.c @@ -421,6 +421,51 @@ void cosmology_init(const struct swift_params *params, cosmology_init_tables(c); } +/** + * @brief Initialise the #cosmology for non-cosmological time-integration + * + * Essentially sets all constants to 1. + * + * @param params The parsed values. + * @param us The current internal system of units. + * @param phys_const The physical constants in the current system of units. + * @param c The #cosmology to initialise. + */ +void cosmology_init_no_cosmo(const struct swift_params *params, + const struct unit_system *us, + const struct phys_const *phys_const, + struct cosmology *c) { + + c->Omega_m = 0.; + c->Omega_r = 0.; + c->Omega_k = 0.; + c->Omega_lambda = 0.; + c->Omega_b = 0.; + c->w_0 = 0.; + c->w_a = 0.; + c->h = 0.; + c->w = 0.; + + c->a_begin = 1.; + c->a_end = 1.; + c->log_a_begin = 0.; + c->log_a_end = 0.; + + c->H = 1.; + c->a = 1.; + c->a_inv = 1.; + c->a_dot = 0.; + c->time = 0.; + c->universe_age_at_present_day = 0.; + + /* Initialise the interpolation tables */ + c->drift_fac_interp_table = NULL; + c->grav_kick_fac_interp_table = NULL; + c->hydro_kick_fac_interp_table = NULL; + c->time_interp_table = NULL; + c->time_interp_table_offset = 0.; +} + /** * @brief Computes the cosmology factor that enters the drift operator. * diff --git a/src/cosmology.h b/src/cosmology.h index 2611a1ea96..62f57275f3 100644 --- a/src/cosmology.h +++ b/src/cosmology.h @@ -146,6 +146,11 @@ void cosmology_init(const struct swift_params *params, const struct unit_system *us, const struct phys_const *phys_const, struct cosmology *c); +void cosmology_init_no_cosmo(const struct swift_params *params, + const struct unit_system *us, + const struct phys_const *phys_const, + struct cosmology *c); + void cosmology_print(const struct cosmology *c); void cosmology_clean(struct cosmology *c); -- GitLab