diff --git a/src/cell.c b/src/cell.c index ba08fc1fd48a8be44a0aa628e5bcc47e3786bba9..96705bfa78a14687356161d9ef832922e7ea9f15 100644 --- a/src/cell.c +++ b/src/cell.c @@ -662,6 +662,35 @@ void cell_clean_links(struct cell *c, void *data) { c->nr_force = 0; } +/** + * @brief Checks whether the cells are direct neighbours ot not. Both cells have + * to be of the same size + * + * @param ci First #cell. + * @param cj Second #cell. + * + * @todo Deal with periodicity. + */ +int cell_are_neighbours(const struct cell *restrict ci, + const struct cell *restrict cj) { + +#ifdef SANITY_CHECKS + if (ci->h[0] != cj->h[0]) error("Cells of different size !"); +#endif + + /* Maximum allowed distance */ + const double min_dist = 1.2 * ci->h[0]; /* 1.2 accounts for rounding errors */ + + /* (Manhattan) Distance between the cells */ + for (int k = 0; k < 3; k++) { + const double center_i = ci->loc[k]; + const double center_j = cj->loc[k]; + if (fabsf(center_i - center_j) > min_dist) return 0; + } + + return 1; +} + /** * @brief Computes the multi-pole brutally and compare to the * recursively computed one. diff --git a/src/cell.h b/src/cell.h index 9095f6c700b79e683aeb32e3d9bf64f3634d014d..a71c82b67a8c8a0c14e5fbd1a2c332beda19a95b 100644 --- a/src/cell.h +++ b/src/cell.h @@ -188,6 +188,8 @@ void cell_init_parts(struct cell *c, void *data); void cell_init_gparts(struct cell *c, void *data); void cell_convert_hydro(struct cell *c, void *data); void cell_clean_links(struct cell *c, void *data); +int cell_are_neighbours(const struct cell *restrict ci, + const struct cell *restrict cj); void cell_check_multipole(struct cell *c, void *data); #endif /* SWIFT_CELL_H */ diff --git a/src/engine.c b/src/engine.c index bdb3ad395058ec171da3455c4a5ef1f38fb9b532..438ae251aec8cb17ea94abab4416a4ec5845d00b 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1078,35 +1078,6 @@ void engine_exchange_strays(struct engine *e, size_t offset_parts, #endif } -/** - * @brief Checks whether two cells are direct neighbours or not. - * - * @param ci First #cell. - * @param cj Second #cell. - * - * @return 1 if the cell are touching (by a face, edge or corner), 0 otherwise. - */ -__attribute__((always_inline)) INLINE static int are_neighbours( - const struct cell *restrict ci, const struct cell *restrict cj) { - -#ifdef SANITY_CHECKS - if (ci->h[0] != cj->h[0]) - error(" Cells of different size in distance calculation."); -#endif - - /* Maximum allowed distance */ - const double min_dist = 1.2 * ci->h[0]; /* 1.2 accounts for rounding errors */ - - /* (Manhattan) Distance between the cells */ - for (int k = 0; k < 3; k++) { - const double center_i = ci->loc[k]; - const double center_j = cj->loc[k]; - if (fabsf(center_i - center_j) > min_dist) return 0; - } - - return 1; -} - /** * @brief Constructs the top-level pair tasks for the short-range gravity * interactions. @@ -1149,7 +1120,7 @@ void engine_make_gravity_tasks(struct engine *e) { /* Is that neighbour local ? */ if (cj->nodeID != nodeID) continue; - if (are_neighbours(ci, cj)) + if (cell_are_neighbours(ci, cj)) scheduler_addtask(sched, task_type_pair, task_subtype_grav, 0, 0, ci, cj, 1); else diff --git a/src/runner_doiact_grav.h b/src/runner_doiact_grav.h index b8c820ea9f16155c3545beb7525dd8fa7b3a332b..2a9d126114290b97941f4428ce0aa4733f5d1d75 100644 --- a/src/runner_doiact_grav.h +++ b/src/runner_doiact_grav.h @@ -55,31 +55,6 @@ void runner_do_grav_up(struct runner *r, struct cell *c) { } } -/** - * @brief Checks whether the cells are direct neighbours ot not. Both cells have - * to be of the same size - * - * @param ci First #cell. - * @param cj Second #cell. - * - * @todo Deal with periodicity. - */ -__attribute__((always_inline)) INLINE static int are_neighbours( - const struct cell *restrict ci, const struct cell *restrict cj) { - - /* Maximum allowed distance */ - const double min_dist = 1.2 * ci->h[0]; /* 1.2 accounts for rounding errors */ - - /* (Manhattan) Distance between the cells */ - for (int k = 0; k < 3; k++) { - const double center_i = ci->loc[k]; - const double center_j = cj->loc[k]; - if (fabsf(center_i - center_j) > min_dist) return 0; - } - - return 1; -} - /** * @brief Computes the interaction of all the particles in a cell with the * multipole of another cell. @@ -354,7 +329,7 @@ static void runner_dopair_grav(struct runner *r, struct cell *ci, "itself."); /* Are the cells direct neighbours? */ - if (!are_neighbours(ci, cj)) + if (!cell_are_neighbours(ci, cj)) error( "Non-neighbouring cells ! ci->x=[%f %f %f] ci->h=%f cj->loc=[%f %f %f] " "cj->h=%f", @@ -394,7 +369,7 @@ static void runner_dopair_grav(struct runner *r, struct cell *ci, for (int k = 0; k < 8; k++) { if (cj->progeny[k] != NULL) { - if (are_neighbours(ci->progeny[j], cj->progeny[k])) { + if (cell_are_neighbours(ci->progeny[j], cj->progeny[k])) { /* Recurse */ runner_dopair_grav(r, ci->progeny[j], cj->progeny[k]); @@ -461,7 +436,8 @@ static void runner_dosub_grav(struct runner *r, struct cell *ci, } else { #ifdef SANITY_CHECKS - if (!are_neighbours(ci, cj)) error("Non-neighbouring cells in pair task !"); + if (!cell_are_neighbours(ci, cj)) + error("Non-neighbouring cells in pair task !"); #endif runner_dopair_grav(r, ci, cj); @@ -472,36 +448,35 @@ static void runner_do_grav_mm(struct runner *r, struct cell *ci, struct cell *cj) { #ifdef SANITY_CHECKS - if (are_neighbours(ci, cj)) { - + if (cell_are_neighbours(ci, cj)) { error("Non-neighbouring cells in mm task !"); - + } #endif #if ICHECK > 0 - for (int pid = 0; pid < ci->gcount; pid++) { + for (int pid = 0; pid < ci->gcount; pid++) { - /* Get a hold of the ith part in ci. */ - struct gpart *restrict gp = &ci->gparts[pid]; + /* Get a hold of the ith part in ci. */ + struct gpart *restrict gp = &ci->gparts[pid]; - if (gp->id == -ICHECK) - message("id=%lld loc=[ %f %f %f ] size= %f count= %d", gp->id, - cj->loc[0], cj->loc[1], cj->loc[2], cj->h[0], cj->gcount); - } + if (gp->id == -ICHECK) + message("id=%lld loc=[ %f %f %f ] size= %f count= %d", gp->id, cj->loc[0], + cj->loc[1], cj->loc[2], cj->h[0], cj->gcount); + } - for (int pid = 0; pid < cj->gcount; pid++) { + for (int pid = 0; pid < cj->gcount; pid++) { - /* Get a hold of the ith part in ci. */ - struct gpart *restrict gp = &cj->gparts[pid]; + /* Get a hold of the ith part in ci. */ + struct gpart *restrict gp = &cj->gparts[pid]; - if (gp->id == -ICHECK) - message("id=%lld loc=[ %f %f %f ] size= %f count= %d", gp->id, - ci->loc[0], ci->loc[1], ci->loc[2], ci->h[0], ci->gcount); - } + if (gp->id == -ICHECK) + message("id=%lld loc=[ %f %f %f ] size= %f count= %d", gp->id, ci->loc[0], + ci->loc[1], ci->loc[2], ci->h[0], ci->gcount); + } #endif - runner_dopair_grav_pm(r, ci, cj); - runner_dopair_grav_pm(r, cj, ci); - } + runner_dopair_grav_pm(r, ci, cj); + runner_dopair_grav_pm(r, cj, ci); +} #endif /* SWIFT_RUNNER_DOIACT_GRAV_H */ diff --git a/tests/testKernelGrav.c b/tests/testKernelGrav.c index 2adc6f703aec408ddd887239b6e8f828ea45b411..c05d15bcb4930f8430c4d4371620623e07605f34 100644 --- a/tests/testKernelGrav.c +++ b/tests/testKernelGrav.c @@ -30,6 +30,7 @@ * @brief The Gadget-2 gravity kernel function * * @param r The distance between particles + * @param h The cut-off distance of the kernel */ float gadget(float r, float h) { float fac;