diff --git a/src/cell.c b/src/cell.c index 864d3f8e64bdc255842a239178626da286e216ff..6839fc765ee41d14fa32ce8dd54c7518b35b8a35 100644 --- a/src/cell.c +++ b/src/cell.c @@ -3648,15 +3648,16 @@ void cell_check_timesteps(struct cell *c) { #endif } -void cell_check_spart_pos(const struct cell* c, const struct spart *global_sparts) { +void cell_check_spart_pos(const struct cell *c, + const struct spart *global_sparts) { #ifdef SWIFT_DEBUG_CHECKS /* Recurse */ if (c->split) { - for(int k = 0; k < 8; ++k) + for (int k = 0; k < 8; ++k) if (c->progeny[k] != NULL) - cell_check_spart_pos(c->progeny[k], global_sparts); + cell_check_spart_pos(c->progeny[k], global_sparts); } struct spart *sparts = c->stars.parts; @@ -3664,55 +3665,61 @@ void cell_check_spart_pos(const struct cell* c, const struct spart *global_spart for (int i = 0; i < count; ++i) { const struct spart *sp = &sparts[i]; - if( (sp->x[0] < c->loc[0] / space_stretch) || - (sp->x[1] < c->loc[1]/ space_stretch) || - (sp->x[2] < c->loc[2]/ space_stretch) || - (sp->x[0] >= (c->loc[0] + c->width[0])* space_stretch) || - (sp->x[1] >= (c->loc[1] + c->width[1])* space_stretch) || - (sp->x[2] >= (c->loc[2] + c->width[2]) * space_stretch)) + if ((sp->x[0] < c->loc[0] / space_stretch) || + (sp->x[1] < c->loc[1] / space_stretch) || + (sp->x[2] < c->loc[2] / space_stretch) || + (sp->x[0] >= (c->loc[0] + c->width[0]) * space_stretch) || + (sp->x[1] >= (c->loc[1] + c->width[1]) * space_stretch) || + (sp->x[2] >= (c->loc[2] + c->width[2]) * space_stretch)) error("spart not in its cell!"); - if(sp->time_bin != time_bin_not_created && sp->time_bin != time_bin_inhibited) { - + if (sp->time_bin != time_bin_not_created && + sp->time_bin != time_bin_inhibited) { + const struct gpart *gp = sp->gpart; - if(gp == NULL && sp->time_bin != time_bin_not_created) error("Unlinked spart!"); - - if(&global_sparts[-gp->id_or_neg_offset] != sp) - error("Incorrectly linked spart!"); + if (gp == NULL && sp->time_bin != time_bin_not_created) + error("Unlinked spart!"); + + if (&global_sparts[-gp->id_or_neg_offset] != sp) + error("Incorrectly linked spart!"); } } - + #else error("Calling a degugging function outside debugging mode."); #endif - } /** - * @brief Recursively update the pointer and counter for #spart after the addition of a new particle. + * @brief Recursively update the pointer and counter for #spart after the + * addition of a new particle. * * @param c The cell we are working on. - * @param progeny_list The list of the progeny index at each level for the leaf-cell where the particle was added. - * @param main_branch Are we in a cell directly above the leaf where the new particle was added? + * @param progeny_list The list of the progeny index at each level for the + * leaf-cell where the particle was added. + * @param main_branch Are we in a cell directly above the leaf where the new + * particle was added? */ -void cell_recursively_shift_sparts(struct cell *c, const int progeny_list[space_cell_maxdepth], - const int main_branch) { +void cell_recursively_shift_sparts(struct cell *c, + const int progeny_list[space_cell_maxdepth], + const int main_branch) { if (c->split) { /* No need to recurse in progenies located before the insestion point */ const int first_progeny = main_branch ? progeny_list[(int)c->depth] : 0; - - for(int k = first_progeny; k < 8; ++k) { - if(c->progeny[k] != NULL) - cell_recursively_shift_sparts(c->progeny[k], progeny_list, - main_branch && (k == first_progeny)); + for (int k = first_progeny; k < 8; ++k) { + + if (c->progeny[k] != NULL) + cell_recursively_shift_sparts(c->progeny[k], progeny_list, + main_branch && (k == first_progeny)); } } - /* When directly above the leaf with the new particle: increase the particle count */ + /* When directly above the leaf with the new particle: increase the particle + * count */ /* When after the leaf with the new particle: shift by one position */ - if(main_branch) + if (main_branch) c->stars.count++; else c->stars.parts++; @@ -3721,48 +3728,49 @@ void cell_recursively_shift_sparts(struct cell *c, const int progeny_list[space_ void cell_add_spart(const struct engine *e, struct cell *const c) { if (c->nodeID != engine_rank) error("Adding spart on a foreign node"); - + /* Progeny number at each level */ int progeny[space_cell_maxdepth] = {0}; #ifdef SWIFT_DEBUG_CHECKS - for(int i = 0; i < space_cell_maxdepth; ++i) - progeny[i] = -1; + for (int i = 0; i < space_cell_maxdepth; ++i) progeny[i] = -1; #endif - + /* Get the top-level this leaf cell is in and compute the progeny indices at each level */ struct cell *top = c; while (top->parent != NULL) { - for(int k = 0; k < 8; ++k) { - if(top->parent->progeny[k] == top) { - progeny[(int)top->parent->depth] = k; + for (int k = 0; k < 8; ++k) { + if (top->parent->progeny[k] == top) { + progeny[(int)top->parent->depth] = k; } } top = top->parent; } - + message("top->cellID=%d", top->cellID); - message("depth=%d progenies=[%d %d %d %d %d %d %d %d]", c->depth, - progeny[0], progeny[1], progeny[2], progeny[3], progeny[4], progeny[5], progeny[6], progeny[7]); - + message("depth=%d progenies=[%d %d %d %d %d %d %d %d]", c->depth, progeny[0], + progeny[1], progeny[2], progeny[3], progeny[4], progeny[5], + progeny[6], progeny[7]); + #ifdef SWIFT_DEBUG_CHECKS if (top->depth != 0) error("Cell-linking issue"); #endif - + /* Are there any extra particles left? */ if (top->stars.count == top->stars.count_total) error("We ran out of star particles!"); - + /* Number of particles to shift in order to get a free space. */ const int n_copy = &top->stars.parts[top->stars.count] - c->stars.parts; - message("top->count=%d c->count=%d n_copy=%d", top->stars.count, c->stars.count, n_copy); - - if(n_copy > 0) { - + message("top->count=%d c->count=%d n_copy=%d", top->stars.count, + c->stars.count, n_copy); + + if (n_copy > 0) { + struct spart *temp = NULL; - if (posix_memalign((void**)&temp, spart_align, - n_copy * sizeof(struct spart)) != 0) + if (posix_memalign((void **)&temp, spart_align, + n_copy * sizeof(struct spart)) != 0) error("Impossible to allocate temp buffer"); /* Shift all the spart ahead of the current empty position by 1 */ @@ -3771,32 +3779,33 @@ void cell_add_spart(const struct engine *e, struct cell *const c) { free(temp); /* Update the gpart->spart links (shift by 1) */ - for(int i = 0; i < n_copy; ++i) { - if(c->stars.parts[i+1].gpart != NULL) { - c->stars.parts[i+1].gpart->id_or_neg_offset--; + for (int i = 0; i < n_copy; ++i) { + if (c->stars.parts[i + 1].gpart != NULL) { + c->stars.parts[i + 1].gpart->id_or_neg_offset--; } else { #ifdef SWIFT_DEBUG_CHECKS - // MATTHIEU - if(c->stars.parts[i+1].time_bin != time_bin_not_created) - error("Incorrectly linked spart!"); + // MATTHIEU + if (c->stars.parts[i + 1].time_bin != time_bin_not_created) + error("Incorrectly linked spart!"); #endif } - } + } } - /* Recursively shift all the stars to get a free spot at the start of the current cell*/ - cell_recursively_shift_sparts(top, progeny, /* main_branch=*/ 1); - + /* Recursively shift all the stars to get a free spot at the start of the + * current cell*/ + cell_recursively_shift_sparts(top, progeny, /* main_branch=*/1); + /* We now have an empty spart as the first particle in that cell */ struct spart *sp = &c->stars.parts[0]; bzero(sp, sizeof(struct spart)); - + /* Give it a decent position */ sp->x[0] = c->loc[0] + 0.5 * c->width[0]; sp->x[1] = c->loc[1] + 0.5 * c->width[1]; sp->x[2] = c->loc[2] + 0.5 * c->width[2]; sp->time_bin = time_bin_not_created; - + #ifdef SWIFT_DEBUG_CHECKS sp->ti_drift = e->ti_current; #endif @@ -3901,8 +3910,8 @@ void cell_remove_spart(const struct engine *e, struct cell *c, * * @return Pointer to the gpart the part has become. */ -struct gpart* cell_convert_part_to_gpart(const struct engine *e, struct cell *c, - struct part *p, struct xpart *xp) { +struct gpart *cell_convert_part_to_gpart(const struct engine *e, struct cell *c, + struct part *p, struct xpart *xp) { /* Quick cross-checks */ if (c->nodeID != e->nodeID) @@ -3943,8 +3952,8 @@ struct gpart* cell_convert_part_to_gpart(const struct engine *e, struct cell *c, * * @return Pointer to the gpart the spart has become. */ -struct gpart* cell_convert_spart_to_gpart(const struct engine *e, struct cell *c, - struct spart *sp) { +struct gpart *cell_convert_spart_to_gpart(const struct engine *e, + struct cell *c, struct spart *sp) { /* Quick cross-check */ if (c->nodeID != e->nodeID) diff --git a/src/cell.h b/src/cell.h index a78aeb5bec507d1b19ab2580acaf853f98bd9995..4177082ee0ac3489596d6f70c15d067ca979bdc9 100644 --- a/src/cell.h +++ b/src/cell.h @@ -672,10 +672,10 @@ void cell_remove_gpart(const struct engine *e, struct cell *c, struct gpart *gp); void cell_remove_spart(const struct engine *e, struct cell *c, struct spart *sp); -struct gpart* cell_convert_part_to_gpart(const struct engine *e, struct cell *c, - struct part *p, struct xpart *xp); -struct gpart* cell_convert_spart_to_gpart(const struct engine *e, struct cell *c, - struct spart *sp); +struct gpart *cell_convert_part_to_gpart(const struct engine *e, struct cell *c, + struct part *p, struct xpart *xp); +struct gpart *cell_convert_spart_to_gpart(const struct engine *e, + struct cell *c, struct spart *sp); void cell_reorder_extra_parts(struct cell *c, const ptrdiff_t parts_offset); void cell_reorder_extra_gparts(struct cell *c, struct part *parts, struct spart *sparts); diff --git a/src/runner.c b/src/runner.c index 7a7914660904aece932cf2bcb6aa4d93bc5cde6c..5f4738bb575d2206dd424e1701edf182e7e51eff 100644 --- a/src/runner.c +++ b/src/runner.c @@ -523,7 +523,8 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { // MATTHIEU: Temporary star-formation law // Do not use this at home. if (rho > 1.7e7 && e->step > 2) { - message("c->cellID=%d Removing particle id=%lld rho=%e", c->cellID, p->id, rho); + message("c->cellID=%d Removing particle id=%lld rho=%e", c->cellID, + p->id, rho); cell_convert_part_to_gpart(e, c, p, xp); cell_add_spart(e, c); }