Commit 6e9c2e08 authored by Matthieu Schaller's avatar Matthieu Schaller

Added a debugging check to verify that the drift flags have been reset

parent c413c53e
......@@ -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.
......
......@@ -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);
......
......@@ -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
......
......@@ -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.
*
......
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment