diff --git a/src/runner.c b/src/runner.c index 2b509b3557ebc78c84c763e73dc8f85428a11690..c1ac634eb752798005d551994a9306e3075052bc 100644 --- a/src/runner.c +++ b/src/runner.c @@ -282,7 +282,52 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) { ((sp->h <= stars_h_min) && (f > 0.f))) { stars_reset_feedback(sp); - feedback_reset_feedback(sp, feedback_props); + + /* Only do feedback if stars have a reasonable birth time */ + if (feedback_do_feedback(sp)) { + + const integertime_t ti_step = get_integer_timestep(sp->time_bin); + const integertime_t ti_begin = + get_integer_time_begin(e->ti_current - 1, sp->time_bin); + + /* Get particle time-step */ + double dt; + if (with_cosmology) { + dt = cosmology_get_delta_time(e->cosmology, ti_begin, + ti_begin + ti_step); + } else { + dt = get_timestep(sp->time_bin, e->time_base); + } + + /* Calculate age of the star at current time */ + double star_age_end_of_step; + if (with_cosmology) { + star_age_end_of_step = + cosmology_get_delta_time_from_scale_factors( + cosmo, (double)sp->birth_scale_factor, cosmo->a); + } else { + star_age_end_of_step = (float)e->time - sp->birth_time; + } + + /* Has this star been around for a while ? */ + if (star_age_end_of_step > 0.) { + + /* Age of the star at the start of the step */ + const double star_age_beg_of_step = + max(star_age_end_of_step - dt, 0.); + + /* Compute the stellar evolution */ + feedback_evolve_spart(sp, feedback_props, cosmo, us, + star_age_beg_of_step, dt); + } else { + + /* Reset the feedback fields of the star particle */ + feedback_reset_feedback(sp, feedback_props); + } + } else { + + feedback_reset_feedback(sp, feedback_props); + } /* Ok, we are done with this particle */ continue;