diff --git a/src/cell.c b/src/cell.c index 3e3a23e2ef59931945bf6eac7878e684bcb10e59..1de475b56fe958de00485de546f2d7c4f185afe4 100644 --- a/src/cell.c +++ b/src/cell.c @@ -1091,3 +1091,26 @@ void cell_drift(struct cell *c, const struct engine *e) { /* Update the time of the last drift */ c->ti_old = ti_current; } + +/** + * @brief Recursively checks that all particles in a cell have a time-step + */ +void cell_check_timesteps(struct cell *c) { +#ifdef SWIFT_DEBUG_CHECKS + + if(c->nodeID != engine_rank) return; + + if(c->ti_end_min == 0) error("Cell without assigned time-step"); + + if(c->split) { + for(int k=0; k<8; ++k) + if(c->progeny[k] != NULL) cell_check_timesteps(c->progeny[k]); + } else { + + for(int i=0; i<c->count; ++i) + if(c->parts[i].time_bin == 0) + error("Particle without assigned time-bin"); + + } +#endif +} diff --git a/src/cell.h b/src/cell.h index 355c56a07b03ab55efcfbda8a3ec4577b61665dc..599daff1066348148a35a779bb6011ab07b37ed8 100644 --- a/src/cell.h +++ b/src/cell.h @@ -306,5 +306,6 @@ int cell_is_drift_needed(struct cell *c, const struct engine *e); int cell_unskip_tasks(struct cell *c, struct scheduler *s); void cell_set_super(struct cell *c, struct cell *super); void cell_drift(struct cell *c, const struct engine *e); +void cell_check_timesteps(struct cell *c); #endif /* SWIFT_CELL_H */ diff --git a/src/engine.c b/src/engine.c index 5ca6ab413de1c1707ffee55dfca6e3247527e43b..4a417ee716ee39ef76bc11ecf0128d93e44f6064 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2665,6 +2665,10 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs) { clocks_gettime(&time2); +#ifdef SWIFT_DEBUG_CHECKS + space_check_timesteps(e->s); +#endif + /* Ready to go */ e->step = 0; e->forcerebuild = 1; diff --git a/src/space.c b/src/space.c index 08dd41cdea5bf598c2b17d47f35e6fc0221c2a06..22674e3cbef820c69d2bdc09a7e73bd04d249083 100644 --- a/src/space.c +++ b/src/space.c @@ -2007,6 +2007,19 @@ void space_check_drift_point(struct space *s, integertime_t ti_current) { space_map_cells_pre(s, 1, cell_check_drift_point, &ti_current); } +/** + * @brief Checks that all particles and local cells have a non-zero time-step. + */ +void space_check_timesteps(struct space *s) { +#ifdef SWIFT_DEBUG_CHECKS + + for (int i=0; i<s->nr_cells; ++i) { + cell_check_timesteps(&s->cells_top[i]); + } + +#endif +} + /** * @brief Frees up the memory allocated for this #space */ diff --git a/src/space.h b/src/space.h index e17b827e6f800a387d78a772d21c44093d0af1c9..acfa0c4c2b11c47795aace974db0ec07f530cd1e 100644 --- a/src/space.h +++ b/src/space.h @@ -186,6 +186,8 @@ void space_init_parts(struct space *s); void space_init_gparts(struct space *s); void space_link_cleanup(struct space *s); void space_check_drift_point(struct space *s, integertime_t ti_current); +void space_check_timesteps(struct space *s); void space_clean(struct space *s); + #endif /* SWIFT_SPACE_H */