From cbf521a57a9cb3157bc5a83156790bc3b6828b05 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Wed, 24 Apr 2019 17:50:50 +0200 Subject: [PATCH] In the feedback loops, skip the particles that are not doing feedback. --- src/feedback/EAGLE/feedback.h | 21 +++++++++++++++++++++ src/feedback/none/feedback.h | 15 +++++++++++++++ src/runner.c | 7 +++---- src/runner_doiact_stars.h | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/feedback/EAGLE/feedback.h b/src/feedback/EAGLE/feedback.h index 5fa32fc2fa..14f6821b06 100644 --- a/src/feedback/EAGLE/feedback.h +++ b/src/feedback/EAGLE/feedback.h @@ -44,6 +44,27 @@ __attribute__((always_inline)) INLINE static int feedback_do_feedback( return (sp->birth_time != -1.); } +/** + * @brief Should this particle be doing any feedback-related operation? + * + * @param sp The #spart. + * @param time The current simulation time (Non-cosmological runs). + * @param cosmo The cosmological model (cosmological runs). + * @param with_cosmology Are we doing a cosmological run? + */ +__attribute__((always_inline)) INLINE static int feedback_is_active( + const struct spart* sp, const float time, const struct cosmology* cosmo, + const int with_cosmology) { + + if (sp->birth_time == -1.) return 0; + + if (with_cosmology) { + return ((float)cosmo->a) > sp->birth_scale_factor; + } else { + return time > sp->birth_time; + } +} + /** * @brief Prepares a s-particle for its feedback interactions * diff --git a/src/feedback/none/feedback.h b/src/feedback/none/feedback.h index de37015a99..84a1cf36df 100644 --- a/src/feedback/none/feedback.h +++ b/src/feedback/none/feedback.h @@ -45,6 +45,21 @@ __attribute__((always_inline)) INLINE static int feedback_do_feedback( return 0; } +/** + * @brief Should this particle be doing any feedback-related operation? + * + * @param sp The #spart. + * @param time The current simulation time (Non-cosmological runs). + * @param cosmo The cosmological model (cosmological runs). + * @param with_cosmology Are we doing a cosmological run? + */ +__attribute__((always_inline)) INLINE static int feedback_is_active( + const struct spart* sp, const float time, const struct cosmology* cosmo, + const int with_cosmology) { + + return 0; +} + /** * @brief Prepares a star's feedback field before computing what * needs to be distributed. diff --git a/src/runner.c b/src/runner.c index 0a9b6c5780..e56b7f0513 100644 --- a/src/runner.c +++ b/src/runner.c @@ -185,7 +185,8 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) { if ((right = (float *)malloc(sizeof(float) * c->stars.count)) == NULL) error("Can't allocate memory for right."); for (int k = 0; k < c->stars.count; k++) - if (spart_is_active(&sparts[k], e)) { + if (spart_is_active(&sparts[k], e) && + feedback_is_active(&sparts[k], e->time, cosmo, with_cosmology)) { sid[scount] = k; h_0[scount] = sparts[k].h; left[scount] = 0.f; @@ -1608,14 +1609,12 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { const float h_init = h_0[i]; const float h_old = p->h; const float h_old_dim = pow_dimension(h_old); - // const float h_old_inv_dim = pow_dimension(1.f / h_old); const float h_old_dim_minus_one = pow_dimension_minus_one(h_old); float h_new; int has_no_neighbours = 0; - if (p->density.wcount == 0.f) { - // 1e-5 * kernel_root * h_old_inv_dim) { /* No neighbours case */ + if (p->density.wcount == 0.f) { /* No neighbours case */ /* Flag that there were no neighbours */ has_no_neighbours = 1; diff --git a/src/runner_doiact_stars.h b/src/runner_doiact_stars.h index 50cdad07a5..da279fcd01 100644 --- a/src/runner_doiact_stars.h +++ b/src/runner_doiact_stars.h @@ -102,6 +102,7 @@ void DOSELF1_STARS(struct runner *r, struct cell *c, int timer) { TIMER_TIC; const struct engine *e = r->e; + const int with_cosmology = e->policy & engine_policy_cosmology; const integertime_t ti_current = e->ti_current; const struct cosmology *cosmo = e->cosmology; @@ -124,8 +125,13 @@ void DOSELF1_STARS(struct runner *r, struct cell *c, int timer) { /* Get a hold of the ith spart in ci. */ struct spart *restrict si = &sparts[sid]; + + /* Skip inactive particles */ if (!spart_is_active(si, e)) continue; + /* Skip inactive particles */ + if (!feedback_is_active(si, e->time, cosmo, with_cosmology)) continue; + const float hi = si->h; const float hig2 = hi * hi * kernel_gamma2; const float six[3] = {(float)(si->x[0] - c->loc[0]), @@ -191,6 +197,7 @@ void DO_NONSYM_PAIR1_STARS_NAIVE(struct runner *r, struct cell *restrict ci, #endif const struct engine *e = r->e; + const int with_cosmology = e->policy & engine_policy_cosmology; const integertime_t ti_current = e->ti_current; const struct cosmology *cosmo = e->cosmology; @@ -222,8 +229,13 @@ void DO_NONSYM_PAIR1_STARS_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith spart in ci. */ struct spart *restrict si = &sparts_i[sid]; + + /* Skip inactive particles */ if (!spart_is_active(si, e)) continue; + /* Skip inactive particles */ + if (!feedback_is_active(si, e->time, cosmo, with_cosmology)) continue; + const float hi = si->h; const float hig2 = hi * hi * kernel_gamma2; const float six[3] = {(float)(si->x[0] - (cj->loc[0] + shift[0])), @@ -284,6 +296,7 @@ void DO_SYM_PAIR1_STARS(struct runner *r, struct cell *ci, struct cell *cj, TIMER_TIC; const struct engine *e = r->e; + const int with_cosmology = e->policy & engine_policy_cosmology; const integertime_t ti_current = e->ti_current; const struct cosmology *cosmo = e->cosmology; @@ -350,6 +363,9 @@ void DO_SYM_PAIR1_STARS(struct runner *r, struct cell *ci, struct cell *cj, /* Skip inactive particles */ if (!spart_is_active(spi, e)) continue; + /* Skip inactive particles */ + if (!feedback_is_active(spi, e->time, cosmo, with_cosmology)) continue; + /* Compute distance from the other cell. */ const double px[3] = {spi->x[0], spi->x[1], spi->x[2]}; float dist = px[0] * runner_shift[sid][0] + px[1] * runner_shift[sid][1] + @@ -475,6 +491,9 @@ void DO_SYM_PAIR1_STARS(struct runner *r, struct cell *ci, struct cell *cj, /* Skip inactive particles */ if (!spart_is_active(spj, e)) continue; + /* Skip inactive particles */ + if (!feedback_is_active(spj, e->time, cosmo, with_cosmology)) continue; + /* Compute distance from the other cell. */ const double px[3] = {spj->x[0], spj->x[1], spj->x[2]}; float dist = px[0] * runner_shift[sid][0] + px[1] * runner_shift[sid][1] + -- GitLab