From 01f622a8f70573dbafd04b5d818ba97f1b194dfb Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Tue, 27 Feb 2018 17:01:53 +0000
Subject: [PATCH] Added cosmological conversion factor for the time-step size.

---
 src/cosmology.c | 5 +++++
 src/cosmology.h | 3 +++
 src/timestep.h  | 8 ++++----
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/cosmology.c b/src/cosmology.c
index 053f94da9b..e09a63316d 100644
--- a/src/cosmology.c
+++ b/src/cosmology.c
@@ -167,6 +167,9 @@ void cosmology_update(struct cosmology *c, integertime_t ti_current) {
   /* Expansion rate */
   c->a_dot = c->H * c->a;
 
+  /* Time-step conversion factor */
+  c->time_step_factor = c->H;
+
   /* Time */
   c->time = cosmology_get_time_since_big_bang(c, a);
   c->lookback_time = c->universe_age_at_present_day - c->time;
@@ -464,6 +467,8 @@ void cosmology_init_no_cosmo(struct cosmology *c) {
   c->a_factor_hydro_accel = 1.;
   c->a_factor_grav_accel = 1.;
 
+  c->time_step_factor = 1.;
+
   c->a_dot = 0.;
   c->time = 0.;
   c->universe_age_at_present_day = 0.;
diff --git a/src/cosmology.h b/src/cosmology.h
index b0b993afb2..008849312f 100644
--- a/src/cosmology.h
+++ b/src/cosmology.h
@@ -62,6 +62,9 @@ struct cosmology {
   /*! Hubble constant at the current redshift (in internal units) */
   double H;
 
+  /*! Conversion factor from internal time-step size to cosmological step */
+  double time_step_factor;
+
   /*! Expansion rate at the current redshift (in internal units) */
   double a_dot;
 
diff --git a/src/timestep.h b/src/timestep.h
index ec0ff1e954..395f980ff2 100644
--- a/src/timestep.h
+++ b/src/timestep.h
@@ -84,8 +84,8 @@ __attribute__((always_inline)) INLINE static integertime_t get_gpart_timestep(
   /* Take the minimum of all */
   float new_dt = min(new_dt_self, new_dt_ext);
 
-  /* Apply cosmology correction (H==1 if non-cosmological) */
-  new_dt *= e->cosmology->H;
+  /* Apply cosmology correction */
+  new_dt *= e->cosmology->time_step_factor;
 
   /* Limit timestep within the allowed range */
   new_dt = min(new_dt, e->dt_max);
@@ -149,7 +149,7 @@ __attribute__((always_inline)) INLINE static integertime_t get_part_timestep(
   new_dt = min(new_dt, dt_h_change);
 
   /* Apply cosmology correction (H==1 if non-cosmological) */
-  new_dt *= e->cosmology->H;
+  new_dt *= e->cosmology->time_step_factor;
 
   /* Limit timestep within the allowed range */
   new_dt = min(new_dt, e->dt_max);
@@ -192,7 +192,7 @@ __attribute__((always_inline)) INLINE static integertime_t get_spart_timestep(
   float new_dt = min3(new_dt_star, new_dt_self, new_dt_ext);
 
   /* Apply cosmology correction (H==1 if non-cosmological) */
-  new_dt *= e->cosmology->H;
+  new_dt *= e->cosmology->time_step_factor;
 
   /* Limit timestep within the allowed range */
   new_dt = min(new_dt, e->dt_max);
-- 
GitLab