diff --git a/src/debug.c b/src/debug.c index 196c2f7e49afa827f8d80539cdeb3a975cbf31fc..5be0370f64f2c21e6b28c40cc9802520087ae07f 100644 --- a/src/debug.c +++ b/src/debug.c @@ -193,6 +193,59 @@ int checkSpacehmax(struct space *s) { return 0; } +/** + * @brief Check if the h_max and dx_max values of a cell's hierarchy are + * consistent with the particles. Report verbosely if not. + * + * @param c the top cell of the hierarchy. + * @param depth the recursion depth for use in messages. Set to 0 initially. + * @result 1 or 0 + */ +int checkCellhdxmax(const struct cell *c, int *depth) { + + *depth = *depth + 1; + + float h_max = 0.0f; + float dx_max = 0.0f; + if (!c->split) { + const size_t nr_parts = c->count; + struct part *parts = c->parts; + for (size_t k = 0; k < nr_parts; k++) { + h_max = (h_max > parts[k].h) ? h_max : parts[k].h; + } + } else { + for (int k = 0; k < 8; k++) + if (c->progeny[k] != NULL) { + struct cell *cp = c->progeny[k]; + checkCellhdxmax(cp, depth); + dx_max = max(dx_max, cp->dx_max); + h_max = max(h_max, cp->h_max); + } + } + + /* Check. */ + int result = 1; + if (c->h_max != h_max) { + message("%d Inconsistent h_max: cell %f != parts %f", *depth, c->h_max, h_max); + message("location: %f %f %f", c->loc[0], c->loc[1], c->loc[2]); + result = 0; + } + if (c->dx_max != dx_max) { + message("%d Inconsistent dx_max: %f != %f", *depth, c->dx_max, dx_max); + message("location: %f %f %f", c->loc[0], c->loc[1], c->loc[2]); + result = 0; + } + + /* Check rebuild criterion. */ + if (h_max > c->dmin) { + message("%d Inconsistent c->dmin: %f > %f", *depth, h_max, c->dmin); + message("location: %f %f %f", c->loc[0], c->loc[1], c->loc[2]); + result = 0; + } + + return result; +} + #ifdef HAVE_METIS /** diff --git a/src/debug.h b/src/debug.h index d75ce91f1ea23221626f32e11472f713e9731789..7422a6f7f9815490966f08415e0312876ce0123f 100644 --- a/src/debug.h +++ b/src/debug.h @@ -32,6 +32,7 @@ void printParticle_single(const struct part *p, const struct xpart *xp); void printgParticle_single(struct gpart *gp); int checkSpacehmax(struct space *s); +int checkCellhdxmax(const struct cell *c, int *depth); #ifdef HAVE_METIS #include "metis.h" diff --git a/src/space.c b/src/space.c index 18f0e21e87b22715e6318be5dfbc3c0cc9a2cc12..5f7e3522eef8c398faba1aee4b03c49ab94232b1 100644 --- a/src/space.c +++ b/src/space.c @@ -346,7 +346,6 @@ void space_regrid(struct space *s, int verbose) { if (verbose) message("set cell dimensions to [ %i %i %i ].", cdim[0], cdim[1], cdim[2]); - fflush(stdout); #ifdef WITH_MPI if (oldnodeIDs != NULL) { @@ -1563,6 +1562,15 @@ void space_split_mapper(void *map_data, int num_cells, void *extra_data) { else c->owner = 0; /* Ok, there is really nothing on this rank... */ } + +#ifdef SWIFT_DEBUG_CHECKS + /* All cells and particles should have consistent h_max values. */ + for (int ind = 0; ind < num_cells; ind++) { + int depth = 0; + if (!checkCellhdxmax(&cells_top[ind], &depth)) + message(" at cell depth %d", depth); + } +#endif } /**