diff --git a/src/runner.c b/src/runner.c index 835a184d33c0143c116e9a6a9270320cc1eb63a5..be6b2681867d5d67a65f01556f2000840a8625e2 100644 --- a/src/runner.c +++ b/src/runner.c @@ -209,7 +209,8 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) { /* Skip if h is already h_max and we don't have enough neighbours */ if ((sp->h >= stars_h_max) && (f < 0.f)) { - stars_reset_acceleration(sp); + stars_reset_feedback(sp); + /* Ok, we are done with this particle */ continue; } @@ -260,7 +261,7 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) { } /* We now have a particle whose smoothing length has converged */ - stars_reset_acceleration(sp); + stars_reset_feedback(sp); /* Compute the stellar evolution */ stars_evolve_spart(sp, stars_properties, cosmo); diff --git a/src/stars/Default/stars.h b/src/stars/Default/stars.h index 4684c2c38e12d90fd0aa5d926319795ff5ff5afa..093079adc35d443967b92538f8e1090dfb82f86c 100644 --- a/src/stars/Default/stars.h +++ b/src/stars/Default/stars.h @@ -100,6 +100,7 @@ __attribute__((always_inline)) INLINE static void stars_reset_predicted_values( */ __attribute__((always_inline)) INLINE static void stars_end_feedback( struct spart* sp) { + sp->feedback.h_dt *= sp->h * hydro_dimension_inv; } @@ -174,7 +175,7 @@ __attribute__((always_inline)) INLINE static void stars_evolve_spart( * * @param p The particle to act upon */ -__attribute__((always_inline)) INLINE static void stars_reset_acceleration( +__attribute__((always_inline)) INLINE static void stars_reset_feedback( struct spart* restrict p) { /* Reset time derivative */ @@ -186,4 +187,5 @@ __attribute__((always_inline)) INLINE static void stars_reset_acceleration( p->num_ngb_force = 0; #endif } + #endif /* SWIFT_DEFAULT_STARS_H */ diff --git a/src/stars/Default/stars_part.h b/src/stars/Default/stars_part.h index 0d163b2283442a287386b336c421dffa645fde50..3e99d73834d475dbd59f1035a24215df389c06a7 100644 --- a/src/stars/Default/stars_part.h +++ b/src/stars/Default/stars_part.h @@ -61,6 +61,7 @@ struct spart { timebin_t time_bin; struct { + /* Number of neighbours. */ float wcount; @@ -69,18 +70,19 @@ struct spart { } density; - /*! Tracer structure */ - struct tracers_xpart_data tracers_data; - - /*! Chemistry structure */ - struct chemistry_part_data chemistry_data; - struct { + /* Change in smoothing length over time. */ float h_dt; } feedback; + /*! Tracer structure */ + struct tracers_xpart_data tracers_data; + + /*! Chemistry structure */ + struct chemistry_part_data chemistry_data; + #ifdef SWIFT_DEBUG_CHECKS /* Time of the last drift */ diff --git a/src/stars/EAGLE/stars.h b/src/stars/EAGLE/stars.h index 4acfef360cedf8993702d27a748a364288052410..a1817fe4947043d18312e7180ac02d3c68529f9d 100644 --- a/src/stars/EAGLE/stars.h +++ b/src/stars/EAGLE/stars.h @@ -66,6 +66,25 @@ __attribute__((always_inline)) INLINE static void stars_init_spart( sp->density.wcount_dh = 0.f; } +/** + * @brief Predict additional particle fields forward in time when drifting + * + * @param p The particle + * @param dt_drift The drift time-step for positions. + */ +__attribute__((always_inline)) INLINE static void stars_predict_extra( + struct spart* restrict sp, float dt_drift) { + + const float h_inv = 1.f / sp->h; + + /* Predict smoothing length */ + const float w1 = sp->feedback.h_dt * h_inv * dt_drift; + if (fabsf(w1) < 0.2f) + sp->h *= approx_expf(w1); /* 4th order expansion of exp(w) */ + else + sp->h *= expf(w1); +} + /** * @brief Sets the values to be predicted in the drifts to their values at a * kick time @@ -82,8 +101,11 @@ __attribute__((always_inline)) INLINE static void stars_reset_predicted_values( * * @param sp The particle to act upon */ -__attribute__((always_inline)) INLINE static void stars_end_force( - struct spart* sp) {} +__attribute__((always_inline)) INLINE static void stars_end_feedback( + struct spart* sp) { + + sp->feedback.h_dt *= sp->h * hydro_dimension_inv; +} /** * @brief Kick the additional variables @@ -148,4 +170,25 @@ __attribute__((always_inline)) INLINE static void stars_evolve_spart( struct spart* restrict sp, const struct stars_props* stars_properties, const struct cosmology* cosmo) {} +/** + * @brief Reset acceleration fields of a particle + * + * This is the equivalent of hydro_reset_acceleration. + * We do not compute the acceleration on star, therefore no need to use it. + * + * @param p The particle to act upon + */ +__attribute__((always_inline)) INLINE static void stars_reset_feedback( + struct spart* restrict p) { + + /* Reset time derivative */ + p->feedback.h_dt = 0.f; + +#ifdef DEBUG_INTERACTIONS_STARS + for (int i = 0; i < MAX_NUM_OF_NEIGHBOURS_STARS; ++i) + p->ids_ngbs_force[i] = -1; + p->num_ngb_force = 0; +#endif +} + #endif /* SWIFT_EAGLE_STARS_H */ diff --git a/src/stars/EAGLE/stars_part.h b/src/stars/EAGLE/stars_part.h index a18a55e959078201ada3c7589db92e5b4946ad25..02ba397660302a06748b3db9c4b3371332c0478a 100644 --- a/src/stars/EAGLE/stars_part.h +++ b/src/stars/EAGLE/stars_part.h @@ -65,6 +65,7 @@ struct spart { timebin_t time_bin; struct { + /* Number of neighbours. */ float wcount; @@ -73,8 +74,16 @@ struct spart { } density; + struct { + + /* Change in smoothing length over time. */ + float h_dt; + + } feedback; + /*! Union for the birth time and birht scale factor */ union { + /*! Birth time */ float birth_time;