From ec81caee83e1faa5490f6136d2e9a72959e6df84 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Sat, 6 Apr 2019 14:04:49 +0100 Subject: [PATCH] When running star formation and feedback (not yet over MPI), make sure the star sorts are correctly updated once a star has been formed. --- src/runner.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++--- src/runner.h | 2 ++ 2 files changed, 96 insertions(+), 4 deletions(-) diff --git a/src/runner.c b/src/runner.c index 5ad8749a1a..d645770f2b 100644 --- a/src/runner.c +++ b/src/runner.c @@ -668,13 +668,11 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { /* If we formed any stars, the star sorts are now invalid. We need to * re-compute them. */ - if (with_feedback && (c == c->hydro.super) && + if (with_feedback && (c == c->top) && (current_stars_count != c->stars.count)) { - error("MATTHIEU needs to think a bit more here!"); - cell_clear_stars_sort_flags(c); - runner_do_stars_sort(r, c, 0x1FFF, /*cleanup=*/0, /*timer=*/0); + runner_do_all_stars_sort(r, c); } if (timer) TIMER_TOC(timer_do_star_formation); @@ -805,6 +803,10 @@ void runner_do_hydro_sort(struct runner *r, struct cell *c, int flags, TIMER_TIC; +#ifdef SWIFT_DEBUG_CHECKS + if (c->hydro.super == NULL) error("Task called above the super level!!!"); +#endif + /* We need to do the local sorts plus whatever was requested further up. */ flags |= c->hydro.do_sort; if (cleanup) { @@ -1023,6 +1025,10 @@ void runner_do_stars_sort(struct runner *r, struct cell *c, int flags, TIMER_TIC; +#ifdef SWIFT_DEBUG_CHECKS + if (c->hydro.super == NULL) error("Task called above the super level!!!"); +#endif + /* We need to do the local sorts plus whatever was requested further up. */ flags |= c->stars.do_sort; if (cleanup) { @@ -1214,6 +1220,90 @@ void runner_do_stars_sort(struct runner *r, struct cell *c, int flags, if (clock) TIMER_TOC(timer_do_stars_sort); } +/** + * @brief Recurse into a cell until reaching the super level and call + * the hydro sorting function there. + * + * This function must be called at or above the super level! + * + * This function will sort the particles in all 13 directions. + * + * @param r the #runner. + * @param c the #cell. + */ +void runner_do_all_hydro_sort(struct runner *r, struct cell *c) { + +#ifdef SWIFT_DEBUG_CHECKS + if (c->nodeID != engine_rank) error("Function called on a foreign cell!"); +#endif + + /* Shall we sort at this level? */ + if (c->hydro.super == c) { + + /* Sort everything */ + runner_do_hydro_sort(r, c, 0x1FFF, /*cleanup=*/0, /*timer=*/0); + + } else { + +#ifdef SWIFT_DEBUG_CHECKS + if (c->hydro.super != NULL) error("Function called below the super level!"); +#endif + + /* Ok, then, let's try lower */ + if (c->split) { + for (int k = 0; k < 8; ++k) { + if (c->progeny[k] != NULL) runner_do_all_hydro_sort(r, c->progeny[k]); + } + } else { +#ifdef SWIFT_DEBUG_CHECKS + error("Reached a leaf without encountering a hydro super cell!"); +#endif + } + } +} + +/** + * @brief Recurse into a cell until reaching the super level and call + * the star sorting function there. + * + * This function must be called at or above the super level! + * + * This function will sort the particles in all 13 directions. + * + * @param r the #runner. + * @param c the #cell. + */ +void runner_do_all_stars_sort(struct runner *r, struct cell *c) { + +#ifdef SWIFT_DEBUG_CHECKS + if (c->nodeID != engine_rank) error("Function called on a foreign cell!"); +#endif + + /* Shall we sort at this level? */ + if (c->hydro.super == c) { + + /* Sort everything */ + runner_do_stars_sort(r, c, 0x1FFF, /*cleanup=*/0, /*timer=*/0); + + } else { + +#ifdef SWIFT_DEBUG_CHECKS + if (c->hydro.super != NULL) error("Function called below the super level!"); +#endif + + /* Ok, then, let's try lower */ + if (c->split) { + for (int k = 0; k < 8; ++k) { + if (c->progeny[k] != NULL) runner_do_all_stars_sort(r, c->progeny[k]); + } + } else { +#ifdef SWIFT_DEBUG_CHECKS + error("Reached a leaf without encountering a hydro super cell!"); +#endif + } + } +} + /** * @brief Initialize the multipoles before the gravity calculation. * diff --git a/src/runner.h b/src/runner.h index b15dd001d9..fa32befc4f 100644 --- a/src/runner.h +++ b/src/runner.h @@ -73,6 +73,8 @@ void runner_do_hydro_sort(struct runner *r, struct cell *c, int flag, int cleanup, int clock); void runner_do_stars_sort(struct runner *r, struct cell *c, int flag, int cleanup, int clock); +void runner_do_all_hydro_sort(struct runner *r, struct cell *c); +void runner_do_all_stars_sort(struct runner *r, struct cell *c); void runner_do_drift_part(struct runner *r, struct cell *c, int timer); void runner_do_drift_gpart(struct runner *r, struct cell *c, int timer); void runner_do_drift_spart(struct runner *r, struct cell *c, int timer); -- GitLab