diff --git a/src/cosmology.c b/src/cosmology.c index 053f94da9bfd3e94d212c0418adb29ac880c6695..e09a63316d369fd8482980de903aec8e3f3913a1 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 b0b993afb217c595e8e3932a5e8ed9a30eefe6e7..008849312febebd21fb451a645e8e55df647d220 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 ec0ff1e954e5cb333d8a5e1767a15e5b54a9100d..395f980ff27d0b5c9f0b4fa7be9ee9eaf94528aa 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);