diff --git a/src/engine.c b/src/engine.c index c4c266dea43eaba9f7480f5ef46f3e6fec0fcfd6..af6150852e273fbc4dff66574a311f3e6b4f7a7f 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5421,6 +5421,9 @@ void engine_init(struct engine *e, struct space *s, e->snapshot_output_count = 0; e->dt_min = parser_get_param_double(params, "TimeIntegration:dt_min"); e->dt_max = parser_get_param_double(params, "TimeIntegration:dt_max"); + e->dt_max_RMS_displacement = FLT_MAX; + e->max_RMS_displacement_factor = + parser_get_param_double(params, "TimeIntegration:max_RMS_factor"); e->a_first_statistics = parser_get_opt_param_double(params, "Statistics:scale_factor_first", 0.1); e->time_first_statistics = diff --git a/src/engine.h b/src/engine.h index 6edb89fd3e36d33ec5cc4439bd875d25febb89e1..e137595390d1ba75f0d318485f950780a57927a2 100644 --- a/src/engine.h +++ b/src/engine.h @@ -125,6 +125,12 @@ struct engine { /* The minimum and maximum allowed dt */ double dt_min, dt_max; + /* Maximum time-step allowed by the RMS condition in cosmology runs. */ + double dt_max_RMS_displacement; + + /* Dimensionless factor for the RMS time-step condition. */ + double max_RMS_displacement_factor; + /* Time of the simulation beginning */ double time_begin; diff --git a/src/timestep.h b/src/timestep.h index a2ecfd2eb4a5309f7378e5ff25fa8d4b43271e9b..958a4c4c1c23d5a5332cf7e4eb7d56f84b0c2077 100644 --- a/src/timestep.h +++ b/src/timestep.h @@ -84,6 +84,9 @@ __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 the maximal displacement constraint (FLT_MAX if non-cosmological)*/ + new_dt = min(new_dt, e->dt_max_RMS_displacement); + /* Apply cosmology correction (This is 1 if non-cosmological) */ new_dt *= e->cosmology->time_step_factor; @@ -140,7 +143,7 @@ __attribute__((always_inline)) INLINE static integertime_t get_part_timestep( /* Final time-step is minimum of hydro and gravity */ float new_dt = min3(new_dt_hydro, new_dt_cooling, new_dt_grav); - /* Limit change in h */ + /* Limit change in smoothing length */ const float dt_h_change = (p->force.h_dt != 0.0f) ? fabsf(e->hydro_properties->log_max_h_change * p->h / p->force.h_dt) @@ -148,6 +151,9 @@ __attribute__((always_inline)) INLINE static integertime_t get_part_timestep( new_dt = min(new_dt, dt_h_change); + /* Apply the maximal displacement constraint (FLT_MAX if non-cosmological)*/ + new_dt = min(new_dt, e->dt_max_RMS_displacement); + /* Apply cosmology correction (This is 1 if non-cosmological) */ new_dt *= e->cosmology->time_step_factor; @@ -191,6 +197,9 @@ __attribute__((always_inline)) INLINE static integertime_t get_spart_timestep( /* Take the minimum of all */ float new_dt = min3(new_dt_star, new_dt_self, new_dt_ext); + /* Apply the maximal displacement constraint (FLT_MAX if non-cosmological)*/ + new_dt = min(new_dt, e->dt_max_RMS_displacement); + /* Apply cosmology correction (This is 1 if non-cosmological) */ new_dt *= e->cosmology->time_step_factor;