Commit c6fcd48a authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Add check that cell h_max and dx_max make sense

parent 19dae51a
...@@ -193,6 +193,59 @@ int checkSpacehmax(struct space *s) { ...@@ -193,6 +193,59 @@ int checkSpacehmax(struct space *s) {
return 0; 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 #ifdef HAVE_METIS
/** /**
......
...@@ -32,6 +32,7 @@ void printParticle_single(const struct part *p, const struct xpart *xp); ...@@ -32,6 +32,7 @@ void printParticle_single(const struct part *p, const struct xpart *xp);
void printgParticle_single(struct gpart *gp); void printgParticle_single(struct gpart *gp);
int checkSpacehmax(struct space *s); int checkSpacehmax(struct space *s);
int checkCellhdxmax(const struct cell *c, int *depth);
#ifdef HAVE_METIS #ifdef HAVE_METIS
#include "metis.h" #include "metis.h"
......
...@@ -346,7 +346,6 @@ void space_regrid(struct space *s, int verbose) { ...@@ -346,7 +346,6 @@ void space_regrid(struct space *s, int verbose) {
if (verbose) if (verbose)
message("set cell dimensions to [ %i %i %i ].", cdim[0], cdim[1], message("set cell dimensions to [ %i %i %i ].", cdim[0], cdim[1],
cdim[2]); cdim[2]);
fflush(stdout);
#ifdef WITH_MPI #ifdef WITH_MPI
if (oldnodeIDs != NULL) { if (oldnodeIDs != NULL) {
...@@ -1563,6 +1562,15 @@ void space_split_mapper(void *map_data, int num_cells, void *extra_data) { ...@@ -1563,6 +1562,15 @@ void space_split_mapper(void *map_data, int num_cells, void *extra_data) {
else else
c->owner = 0; /* Ok, there is really nothing on this rank... */ 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
} }
/** /**
......
Supports Markdown
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