diff --git a/src/active.h b/src/active.h index 4631536d9a613fad9413d6ce038972d33863fe04..9cbc7ade0052194c0c15eebadaf7a7a3dbb4cf04 100644 --- a/src/active.h +++ b/src/active.h @@ -25,6 +25,7 @@ /* Local includes. */ #include "cell.h" #include "engine.h" +#include "feedback.h" #include "part.h" #include "timeline.h" @@ -246,6 +247,26 @@ __attribute__((always_inline)) INLINE static int cell_is_active_sinks( return (c->sinks.ti_end_min == e->ti_current); } +/** + * @brief Does a cell contain any s-particle finishing their time-step now ? + * + * This also considers additional physics modules interacting with stars. + * + * @param c The #cell. + * @param e The #engine containing information about the current time. + * @return 1 if the #cell contains at least an active particle, 0 otherwise. + */ +__attribute__((always_inline)) INLINE static int cell_need_activating_stars( + const struct cell *c, const struct engine *e, const int with_star_formation, + const int with_star_formation_sink) { + + return cell_is_active_stars(c, e) || + (feedback_use_newborn_stars && with_star_formation && + cell_is_active_hydro(c, e)) || + (with_star_formation_sink && + (cell_is_active_sinks(c, e) || cell_is_active_hydro(c, e))); +} + /** * @brief Does a cell contain any b-particle finishing their time-step now ? * diff --git a/src/cell_unskip.c b/src/cell_unskip.c index 9ca4db50c19501e5acf4922010a13a5be5ad3dfb..78e0e2817ceb56e19eb989bd78960e7041b1eef6 100644 --- a/src/cell_unskip.c +++ b/src/cell_unskip.c @@ -263,6 +263,7 @@ void cell_activate_super_spart_drifts(struct cell *c, struct scheduler *s) { if (c == c->hydro.super) { cell_activate_drift_spart(c, s); + cell_set_flag(c, cell_flag_do_stars_drift); } else { if (c->split) { for (int k = 0; k < 8; ++k) { @@ -822,11 +823,8 @@ void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj, /* Self interaction? */ if (cj == NULL) { - const int ci_active = - cell_is_active_stars(ci, e) || - (with_star_formation && cell_is_active_hydro(ci, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(ci, e) || cell_is_active_sinks(ci, e))); + const int ci_active = cell_need_activating_stars(ci, e, with_star_formation, + with_star_formation_sink); /* Do anything? */ if (!ci_active || ci->hydro.count == 0 || @@ -864,16 +862,10 @@ void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj, double shift[3]; const int sid = space_getsid(s->space, &ci, &cj, shift); - const int ci_active = - cell_is_active_stars(ci, e) || - (with_star_formation && cell_is_active_hydro(ci, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(ci, e) || cell_is_active_sinks(ci, e))); - const int cj_active = - cell_is_active_stars(cj, e) || - (with_star_formation && cell_is_active_hydro(cj, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(cj, e) || cell_is_active_sinks(cj, e))); + const int ci_active = cell_need_activating_stars(ci, e, with_star_formation, + with_star_formation_sink); + const int cj_active = cell_need_activating_stars(cj, e, with_star_formation, + with_star_formation_sink); /* Should we even bother? */ if (!ci_active && !cj_active) return; @@ -1818,6 +1810,7 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) { if (c->top->hydro.star_formation != NULL) { cell_activate_star_formation_tasks(c->top, s, with_feedback); + cell_activate_super_spart_drifts(c->top, s); } if (c->top->hydro.star_formation_sink != NULL) { cell_activate_star_formation_sink_tasks(c->top, s, with_feedback); @@ -2003,10 +1996,8 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s, int rebuild = 0; if (c->stars.drift != NULL) { - if (cell_is_active_stars(c, e) || - (with_star_formation && cell_is_active_hydro(c, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(c, e) || cell_is_active_sinks(c, e)))) { + if (cell_need_activating_stars(c, e, with_star_formation, + with_star_formation_sink)) { cell_activate_drift_spart(c, s); } @@ -2025,18 +2016,12 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s, const int cj_nodeID = nodeID; #endif - const int ci_active = - cell_is_active_stars(ci, e) || - (with_star_formation && cell_is_active_hydro(ci, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(ci, e) || cell_is_active_sinks(ci, e))); + const int ci_active = cell_need_activating_stars(ci, e, with_star_formation, + with_star_formation_sink); const int cj_active = - (cj != NULL) && - (cell_is_active_stars(cj, e) || - (with_star_formation && cell_is_active_hydro(cj, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(cj, e) || cell_is_active_sinks(cj, e)))); + (cj != NULL) && cell_need_activating_stars(cj, e, with_star_formation, + with_star_formation_sink); /* Activate the drifts */ if (t->type == task_type_self && ci_active) { @@ -2216,12 +2201,12 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s, const int cj_nodeID = nodeID; #endif - const int ci_active = cell_is_active_stars(ci, e) || - (with_star_formation && cell_is_active_hydro(ci, e)); + const int ci_active = cell_need_activating_stars(ci, e, with_star_formation, + with_star_formation_sink); const int cj_active = - (cj != NULL) && (cell_is_active_stars(cj, e) || - (with_star_formation && cell_is_active_hydro(cj, e))); + (cj != NULL) && cell_need_activating_stars(cj, e, with_star_formation, + with_star_formation_sink); #ifdef SWIFT_DEBUG_CHECKS if (with_star_formation_sink) { @@ -2286,12 +2271,12 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s, } #endif - const int ci_active = cell_is_active_stars(ci, e) || - (with_star_formation && cell_is_active_hydro(ci, e)); + const int ci_active = cell_need_activating_stars(ci, e, with_star_formation, + with_star_formation_sink); const int cj_active = - (cj != NULL) && (cell_is_active_stars(cj, e) || - (with_star_formation && cell_is_active_hydro(cj, e))); + (cj != NULL) && cell_need_activating_stars(cj, e, with_star_formation, + with_star_formation_sink); if (t->type == task_type_self && ci_active) { scheduler_activate(s, t); @@ -2332,18 +2317,12 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s, const int cj_nodeID = nodeID; #endif - const int ci_active = - cell_is_active_stars(ci, e) || - (with_star_formation && cell_is_active_hydro(ci, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(ci, e) || cell_is_active_sinks(ci, e))); + const int ci_active = cell_need_activating_stars(ci, e, with_star_formation, + with_star_formation_sink); const int cj_active = - (cj != NULL) && - (cell_is_active_stars(cj, e) || - (with_star_formation && cell_is_active_hydro(cj, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(cj, e) || cell_is_active_sinks(cj, e)))); + (cj != NULL) && cell_need_activating_stars(cj, e, with_star_formation, + with_star_formation_sink); if (t->type == task_type_self && ci_active) { scheduler_activate(s, t); @@ -2373,10 +2352,8 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s, /* Unskip all the other task types. */ if (c->nodeID == nodeID) { - if (cell_is_active_stars(c, e) || - (with_star_formation && cell_is_active_hydro(c, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(c, e) || cell_is_active_sinks(c, e)))) { + if (cell_need_activating_stars(c, e, with_star_formation, + with_star_formation_sink)) { if (c->stars.density_ghost != NULL) scheduler_activate(s, c->stars.density_ghost); diff --git a/src/engine_marktasks.c b/src/engine_marktasks.c index 30a25a40b88f233de0523aab8eec3c2c112b7e84..da930c85c5ceef2b5ddad7434f288744f975b836 100644 --- a/src/engine_marktasks.c +++ b/src/engine_marktasks.c @@ -101,9 +101,8 @@ void engine_marktasks_mapper(void *map_data, int num_elements, const int ci_active_black_holes = cell_is_active_black_holes(ci, e); const int ci_active_sinks = cell_is_active_sinks(ci, e) || ci_active_hydro; - const int ci_active_stars = cell_is_active_stars(ci, e) || - (with_star_formation && ci_active_hydro) || - (with_star_formation_sink && ci_active_sinks); + const int ci_active_stars = cell_need_activating_stars( + ci, e, with_star_formation, with_star_formation_sink); const int ci_active_rt = with_rt && rt_should_do_unskip_cell(ci, e); /* Activate the hydro drift */ @@ -404,14 +403,10 @@ void engine_marktasks_mapper(void *map_data, int num_elements, const int cj_active_sinks = cell_is_active_sinks(cj, e) || cj_active_hydro; - const int ci_active_stars = - cell_is_active_stars(ci, e) || - (with_star_formation && ci_active_hydro) || - (with_star_formation_sink && (ci_active_hydro || ci_active_sinks)); - const int cj_active_stars = - cell_is_active_stars(cj, e) || - (with_star_formation && cj_active_hydro) || - (with_star_formation_sink && (cj_active_hydro || cj_active_sinks)); + const int ci_active_stars = cell_need_activating_stars( + ci, e, with_star_formation, with_star_formation_sink); + const int cj_active_stars = cell_need_activating_stars( + cj, e, with_star_formation, with_star_formation_sink); const int ci_active_rt = with_rt && rt_should_iact_cell_pair(ci, cj, e); const int cj_active_rt = with_rt && rt_should_iact_cell_pair(cj, ci, e); @@ -1318,19 +1313,15 @@ void engine_marktasks_mapper(void *map_data, int num_elements, t_type == task_type_stars_prep_ghost1 || t_type == task_type_hydro_prep_ghost1 || t_type == task_type_stars_prep_ghost2) { - if (cell_is_active_stars(t->ci, e) || - (with_star_formation && cell_is_active_hydro(t->ci, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(t->ci, e) || cell_is_active_sinks(t->ci, e)))) + if (cell_need_activating_stars(t->ci, e, with_star_formation, + with_star_formation_sink)) scheduler_activate(s, t); } /* Feedback implicit tasks? */ else if (t_type == task_type_stars_in || t_type == task_type_stars_out) { - if (cell_is_active_stars(t->ci, e) || - (with_star_formation && cell_is_active_hydro(t->ci, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(t->ci, e) || cell_is_active_sinks(t->ci, e)))) + if (cell_need_activating_stars(t->ci, e, with_star_formation, + with_star_formation_sink)) scheduler_activate(s, t); } diff --git a/src/engine_unskip.c b/src/engine_unskip.c index fa39ea4b2f2e81723fe7c4c8f6ea2787ccd3d72d..37b4e224b29a14f008ed5b8e66f582701955abff 100644 --- a/src/engine_unskip.c +++ b/src/engine_unskip.c @@ -125,11 +125,8 @@ static void engine_do_unskip_stars(struct cell *c, struct engine *e, /* Ignore empty cells. */ if (!non_empty) return; - const int ci_active = - cell_is_active_stars(c, e) || - (with_star_formation && cell_is_active_hydro(c, e)) || - (with_star_formation_sink && - (cell_is_active_hydro(c, e) || cell_is_active_sinks(c, e))); + const int ci_active = cell_need_activating_stars(c, e, with_star_formation, + with_star_formation_sink); /* Skip inactive cells. */ if (!ci_active) return; diff --git a/src/feedback.h b/src/feedback.h index 7d9f7cb127cb164e7c133e235b183695f308e445..49fe7816e525c4b51a8a6af6f4909f4913ba45a4 100644 --- a/src/feedback.h +++ b/src/feedback.h @@ -26,16 +26,20 @@ #if defined(FEEDBACK_NONE) #include "./feedback/none/feedback.h" #include "./feedback/none/feedback_iact.h" +#define feedback_use_newborn_stars 0 #elif defined(FEEDBACK_EAGLE_THERMAL) #include "./feedback/EAGLE_thermal/feedback.h" #include "./feedback/EAGLE_thermal/feedback_iact.h" +#define feedback_use_newborn_stars 0 #elif defined(FEEDBACK_EAGLE_KINETIC) #include "./feedback/EAGLE_kinetic/feedback.h" #include "./feedback/EAGLE_kinetic/feedback_iact.h" +#define feedback_use_newborn_stars 0 #define EXTRA_STAR_LOOPS #elif defined(FEEDBACK_GEAR) #include "./feedback/GEAR/feedback.h" #include "./feedback/GEAR/feedback_iact.h" +#define feedback_use_newborn_stars 1 #else #error "Invalid choice of feedback model" #endif