diff --git a/src/cell.c b/src/cell.c index c3422f99ee3d9bd7598712bc5b0a1752902e82c5..24b3ea14d3a96ca5f268621bb180be70a92cdaae 100644 --- a/src/cell.c +++ b/src/cell.c @@ -5466,6 +5466,43 @@ void cell_check_sort_flags(const struct cell *c) { #endif } +/** + * @brief Checks that a cell and all its progenies have cleared their drift + * flags. + * + * Should only be used for debugging purposes. + * + * @param c The #cell to check. + */ +void cell_check_drift_flags(const struct cell *c) { + +#ifdef SWIFT_DEBUG_CHECKS + const int do_hydro_drift = cell_get_flag(c, cell_flag_do_hydro_drift); + const int do_hydro_sub_drift = cell_get_flag(c, cell_flag_do_hydro_sub_drift); + const int do_stars_sub_drift = cell_get_flag(c, cell_flag_do_stars_sub_drift); + + if (do_hydro_drift) + error("cell %d has a hydro drift flag set. Node=%d depth=%d maxdepth=%d", + c->cellID, c->nodeID, c->depth, c->maxdepth); + + if (do_hydro_sub_drift) + error( + "cell %d has a hydro sub_drift flag set. Node=%d depth=%d maxdepth=%d", + c->cellID, c->nodeID, c->depth, c->maxdepth); + + if (do_stars_sub_drift) + error( + "cell %d has a stars sub_drift flag set. Node=%d depth=%d maxdepth=%d", + c->cellID, c->nodeID, c->depth, c->maxdepth); + + if (c->split) { + for (int k = 0; k < 8; ++k) { + if (c->progeny[k] != NULL) cell_check_drift_flags(c->progeny[k]); + } + } +#endif +} + /** * @brief Recursively update the pointer and counter for #spart after the * addition of a new particle. diff --git a/src/cell.h b/src/cell.h index 7dd7459218d8bcc9b62ca82727a90bd1a8f7493c..4e53221afa101dcaf497fef8da15546315907b22 100644 --- a/src/cell.h +++ b/src/cell.h @@ -932,6 +932,7 @@ void cell_set_super_mapper(void *map_data, int num_elements, void *extra_data); void cell_check_spart_pos(const struct cell *c, const struct spart *global_sparts); void cell_check_sort_flags(const struct cell *c); +void cell_check_drift_flags(const struct cell *c); void cell_clear_stars_sort_flags(struct cell *c, const int unused_flags); void cell_clear_hydro_sort_flags(struct cell *c, const int unused_flags); int cell_has_tasks(struct cell *c); diff --git a/src/engine.c b/src/engine.c index ae82c8e03d5d25ee71bfe2b2b1411ee4f7af2cb1..12b5fa6ce97a739dbb07850a6f02dd908db86114 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1814,6 +1814,7 @@ void engine_rebuild(struct engine *e, const int repartitioned, cell_check_foreign_multipole(&e->s->cells_top[e->s->local_cells_top[k]]); } + space_check_drift_flags(e->s); space_check_sort_flags(e->s); #endif @@ -2704,6 +2705,7 @@ void engine_step(struct engine *e) { #ifdef SWIFT_DEBUG_CHECKS /* Make sure all woken-up particles have been processed */ space_check_limiter(e->s); + space_check_drift_flags(e->s); space_check_sort_flags(e->s); space_check_swallow(e->s); #endif diff --git a/src/space.c b/src/space.c index 781e86019fa49d0f3b340869d8b1333a39d6cfab..b125de7d33eba0c4ccc0d15b552d7e98bb1b0662 100644 --- a/src/space.c +++ b/src/space.c @@ -5737,6 +5737,41 @@ void space_check_sort_flags(struct space *s) { #endif } +void space_check_drift_flags_mapper(void *map_data, int nr_cells, + void *extra_data) { + +#ifdef SWIFT_DEBUG_CHECKS + + const struct space *s = (struct space *)extra_data; + int *local_cells_top = map_data; + + for (int ind = 0; ind < nr_cells; ++ind) { + const struct cell *c = &s->cells_top[local_cells_top[ind]]; + + cell_check_drift_flags(c); + } + +#endif +} + +/** + * @brief Checks that all cells have cleared their drift flags. + * + * Should only be used for debugging purposes. + * + * @param s The #space to check. + */ +void space_check_drift_flags(struct space *s) { +#ifdef SWIFT_DEBUG_CHECKS + + threadpool_map(&s->e->threadpool, space_check_drift_flags_mapper, + s->local_cells_with_tasks_top, s->nr_local_cells_with_tasks, + sizeof(int), 1, s); +#else + error("Calling debugging code without debugging flag activated."); +#endif +} + /** * @brief Resets all the individual cell task counters to 0. * diff --git a/src/space.h b/src/space.h index b7ba589482d8bd0a464cc6d3cc01076e1f4d2442..73ee71f2af9d29ef3c99375bfaba31bd12a49eb9 100644 --- a/src/space.h +++ b/src/space.h @@ -374,6 +374,7 @@ void space_check_timesteps(const struct space *s); void space_check_limiter(struct space *s); void space_check_swallow(struct space *s); void space_check_sort_flags(struct space *s); +void space_check_drift_flags(struct space *s); void space_replicate(struct space *s, int replicate, int verbose); void space_generate_gas(struct space *s, const struct cosmology *cosmo, const int periodic, const int with_DM_background,