diff --git a/src/cell.c b/src/cell.c index 2bb869f833ce021b0324b0afaa3669c9a1ee70a7..f5ada2c6dfab4b8793df9f40b63deaf2b7e9009a 100644 --- a/src/cell.c +++ b/src/cell.c @@ -1293,3 +1293,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 95067531f4fbd6ec1f1060f505f78a119575d882..8ccdbac32b366edcf0633a1b7c5f2df6747f4173 100644 --- a/src/cell.h +++ b/src/cell.h @@ -330,5 +330,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 38905c036d5920ae3b1479e0a817886dd2131da6..54e61a472250c99962d2028331ebe4010b301482 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2648,6 +2648,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 = -1; e->forcerebuild = 1; diff --git a/src/space.c b/src/space.c index 78b5e08ac27073f5b689f45ab0261845c9e38030..d760222504b846c0e553e6433ce4b417f6dfa775 100644 --- a/src/space.c +++ b/src/space.c @@ -2392,6 +2392,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 8f69a7a05ae89a0bb5bf30e06b9814d7b3024420..d4b2a753375d914f1bd08d884a8d41510f352792 100644 --- a/src/space.h +++ b/src/space.h @@ -201,6 +201,8 @@ void space_init_gparts(struct space *s); void space_init_sparts(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 */