diff --git a/src/cell.c b/src/cell.c index b9effc6e599643be9f57f6d339dd594e606d5b6a..435dc33c7c1a9c869cd6cee9047e58d6c4df3fe1 100644 --- a/src/cell.c +++ b/src/cell.c @@ -4834,17 +4834,48 @@ void cell_drift_multipole(struct cell *c, const struct engine *e) { * * @param c The #cell to clean. */ -void cell_clear_stars_sort_flags(struct cell *c) { +void cell_clear_stars_sort_flags(struct cell *c, const int clear_all) { + + /* Indicate that the cell is not sorted and cancel the pointer sorting arrays. + */ + if (clear_all) { + c->stars.requires_sorts = 0; + c->stars.do_sort = 0; + cell_clear_flag(c, cell_flag_do_stars_sub_sort); + } + c->stars.sorted = 0; + cell_free_stars_sorts(c); + /* Recurse if possible */ if (c->split) { for (int k = 0; k < 8; k++) - if (c->progeny[k] != NULL) cell_clear_stars_sort_flags(c->progeny[k]); + if (c->progeny[k] != NULL) cell_clear_stars_sort_flags(c->progeny[k], clear_all); } +} + +/** + * @brief Resets all the sorting properties for the hydro in a given cell + * hierarchy. + * + * @param c The #cell to clean. + */ +void cell_clear_hydro_sort_flags(struct cell *c, int clear_all) { /* Indicate that the cell is not sorted and cancel the pointer sorting arrays. */ - c->stars.sorted = 0; - cell_free_stars_sorts(c); + if (clear_all) { + c->hydro.do_sort = 0; + c->hydro.requires_sorts = 0; + cell_clear_flag(c, cell_flag_do_hydro_sub_sort); + } + c->hydro.sorted = 0; + cell_free_hydro_sorts(c); + + /* Recurse if possible */ + if (c->split) { + for (int k = 0; k < 8; k++) + if (c->progeny[k] != NULL) cell_clear_hydro_sort_flags(c->progeny[k], clear_all); + } } /** diff --git a/src/runner.c b/src/runner.c index 2ee3032522b6c27c66dba2afbdd4cc51e6c7652f..a39a6770258ad35e95ad4f45100416d86485c054 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1140,7 +1140,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { if (with_feedback && (c == c->top) && (current_stars_count != c->stars.count)) { - cell_clear_stars_sort_flags(c); + cell_clear_stars_sort_flags(c, 0); runner_do_all_stars_sort(r, c); } @@ -1250,21 +1250,6 @@ void runner_do_sort_ascending(struct entry *sort, int N) { RUNNER_CHECK_SORTS(hydro) RUNNER_CHECK_SORTS(stars) -void cell_clear_hydro_sort_flags2(struct cell *c) { - - c->hydro.do_sort = 0; - cell_clear_flag(c, cell_flag_do_hydro_sub_sort); - c->hydro.requires_sorts = 0; - cell_free_hydro_sorts(c); - - if(c->split) { - for(int k = 0; k < 8; ++k){ - if(c->progeny[k] != NULL) - cell_clear_hydro_sort_flags2(c->progeny[k]); - } - } -} - /** * @brief Sort the particles in the given cell along all cardinal directions. * @@ -1342,7 +1327,7 @@ void runner_do_hydro_sort(struct runner *r, struct cell *c, int flags, dx_max_sort_old = max(dx_max_sort_old, c->progeny[k]->hydro.dx_max_sort_old); } else { - cell_clear_hydro_sort_flags2(c->progeny[k]); + cell_clear_hydro_sort_flags(c->progeny[k], 1); } } } @@ -1492,22 +1477,6 @@ void runner_do_hydro_sort(struct runner *r, struct cell *c, int flags, if (clock) TIMER_TOC(timer_dosort); } -void cell_clear_stars_sort_flags2(struct cell *c) { - - c->stars.do_sort = 0; - cell_clear_flag(c, cell_flag_do_stars_sub_sort); - c->stars.requires_sorts = 0; - cell_free_stars_sorts(c); - - if(c->split) { - for(int k = 0; k < 8; ++k){ - if(c->progeny[k] != NULL) - cell_clear_stars_sort_flags2(c->progeny[k]); - } - } -} - - /** * @brief Sort the stars particles in the given cell along all cardinal * directions. @@ -1595,7 +1564,7 @@ void runner_do_stars_sort(struct runner *r, struct cell *c, int flags, dx_max_sort_old = max(dx_max_sort_old, c->progeny[k]->stars.dx_max_sort_old); } else { - cell_clear_stars_sort_flags2(c->progeny[k]); + cell_clear_stars_sort_flags(c->progeny[k], 1); } } } @@ -4285,7 +4254,7 @@ void *runner_main(void *data) { free(t->buff); } else if (t->subtype == task_subtype_sf_counts) { cell_unpack_sf_counts(ci, (struct pcell_sf *)t->buff); - cell_clear_stars_sort_flags(ci); + cell_clear_stars_sort_flags(ci, 0); free(t->buff); } else if (t->subtype == task_subtype_xv) { runner_do_recv_part(r, ci, 1, 1);