diff --git a/src/hydro/Default/hydro.h b/src/hydro/Default/hydro.h index 31f0c4172099479abff9e1ed19487130a0a8938b..890380b23ac1496854dc5359f9249993c166d2c3 100644 --- a/src/hydro/Default/hydro.h +++ b/src/hydro/Default/hydro.h @@ -97,6 +97,23 @@ __attribute__((always_inline)) INLINE static float hydro_get_mass( return p->mass; } +/** + * @brief Returns the velocities drifted to the current time of a particle. + * + * @param p The particle of interest + * @param xp The extended data of the particle. + * @param dt The time since the last kick. + * @param v (return) The velocities at the current time. + */ +__attribute__((always_inline)) INLINE static void hydro_get_drifted_velocities( + const struct part *restrict p, const struct xpart *xp, float dt, + float v[3]) { + + v[0] = xp->v_full[0] + p->a_hydro[0] * dt; + v[1] = xp->v_full[1] + p->a_hydro[1] * dt; + v[2] = xp->v_full[2] + p->a_hydro[2] * dt; +} + /** * @brief Returns the time derivative of internal energy of a particle * diff --git a/src/hydro/Gadget2/hydro.h b/src/hydro/Gadget2/hydro.h index fdd0795cfcb084cd470403095b63d29b8f55c158..f3c33bc7a00bc649d5e6a2d5b75bc04022359f72 100644 --- a/src/hydro/Gadget2/hydro.h +++ b/src/hydro/Gadget2/hydro.h @@ -106,6 +106,23 @@ __attribute__((always_inline)) INLINE static float hydro_get_mass( return p->mass; } +/** + * @brief Returns the velocities drifted to the current time of a particle. + * + * @param p The particle of interest + * @param xp The extended data of the particle. + * @param dt The time since the last kick. + * @param v (return) The velocities at the current time. + */ +__attribute__((always_inline)) INLINE static void hydro_get_drifted_velocities( + const struct part *restrict p, const struct xpart *xp, float dt, + float v[3]) { + + v[0] = xp->v_full[0] + p->a_hydro[0] * dt; + v[1] = xp->v_full[1] + p->a_hydro[1] * dt; + v[2] = xp->v_full[2] + p->a_hydro[2] * dt; +} + /** * @brief Returns the time derivative of internal energy of a particle * diff --git a/src/hydro/Gizmo/hydro.h b/src/hydro/Gizmo/hydro.h index 3b22d46da956dedccc307a5ce1e32235870bccaa..920556114a8ecb07571b052a7421e70143897059 100644 --- a/src/hydro/Gizmo/hydro.h +++ b/src/hydro/Gizmo/hydro.h @@ -754,6 +754,18 @@ __attribute__((always_inline)) INLINE static float hydro_get_mass( return p->conserved.mass; } +/** + * @brief Returns the velocities drifted to the current time of a particle. + * + * @param p The particle of interest + * @param xp The extended data of the particle. + * @param dt The time since the last kick. + * @param v (return) The velocities at the current time. + */ +__attribute__((always_inline)) INLINE static void hydro_get_drifted_velocities( + const struct part* restrict p, const struct xpart* xp, float dt, + float v[3]) {} + /** * @brief Returns the density of a particle * diff --git a/src/hydro/Minimal/hydro.h b/src/hydro/Minimal/hydro.h index 905412040cbb8ac9666e555d88cad9bc56de13ab..935b5d96843c5ed13b167ad1152c96b5ced647bd 100644 --- a/src/hydro/Minimal/hydro.h +++ b/src/hydro/Minimal/hydro.h @@ -116,6 +116,23 @@ __attribute__((always_inline)) INLINE static float hydro_get_mass( return p->mass; } +/** + * @brief Returns the velocities drifted to the current time of a particle. + * + * @param p The particle of interest + * @param xp The extended data of the particle. + * @param dt The time since the last kick. + * @param v (return) The velocities at the current time. + */ +__attribute__((always_inline)) INLINE static void hydro_get_drifted_velocities( + const struct part *restrict p, const struct xpart *xp, float dt, + float v[3]) { + + v[0] = xp->v_full[0] + p->a_hydro[0] * dt; + v[1] = xp->v_full[1] + p->a_hydro[1] * dt; + v[2] = xp->v_full[2] + p->a_hydro[2] * dt; +} + /** * @brief Returns the time derivative of internal energy of a particle * diff --git a/src/hydro/PressureEntropy/hydro.h b/src/hydro/PressureEntropy/hydro.h index 080b796b21d7f3b48191cd375574ae1de6d11d1a..2c10e4fde8865c5afa228fbb92a79dfa5aa55a87 100644 --- a/src/hydro/PressureEntropy/hydro.h +++ b/src/hydro/PressureEntropy/hydro.h @@ -106,6 +106,23 @@ __attribute__((always_inline)) INLINE static float hydro_get_mass( return p->mass; } +/** + * @brief Returns the velocities drifted to the current time of a particle. + * + * @param p The particle of interest + * @param xp The extended data of the particle. + * @param dt The time since the last kick. + * @param v (return) The velocities at the current time. + */ +__attribute__((always_inline)) INLINE static void hydro_get_drifted_velocities( + const struct part *restrict p, const struct xpart *xp, float dt, + float v[3]) { + + v[0] = xp->v_full[0] + p->a_hydro[0] * dt; + v[1] = xp->v_full[1] + p->a_hydro[1] * dt; + v[2] = xp->v_full[2] + p->a_hydro[2] * dt; +} + /** * @brief Returns the time derivative of internal energy of a particle * diff --git a/src/hydro/Shadowswift/hydro.h b/src/hydro/Shadowswift/hydro.h index eb9938a341f1e6273f8ea03264bdda6dc69832e6..e4ea0d971cd89862d3ea6b99f0b04930666a154a 100644 --- a/src/hydro/Shadowswift/hydro.h +++ b/src/hydro/Shadowswift/hydro.h @@ -544,6 +544,18 @@ __attribute__((always_inline)) INLINE static float hydro_get_mass( return p->conserved.mass; } +/** + * @brief Returns the velocities drifted to the current time of a particle. + * + * @param p The particle of interest + * @param xp The extended data of the particle. + * @param dt The time since the last kick. + * @param v (return) The velocities at the current time. + */ +__attribute__((always_inline)) INLINE static void hydro_get_drifted_velocities( + const struct part* restrict p, const struct xpart* xp, float dt, + float v[3]) {} + /** * @brief Returns the density of a particle * diff --git a/src/statistics.c b/src/statistics.c index d50143b9ebf6fbbfa2715c2382c7e3eacbf13eda..f3604a2417159abab59f84e66130449a9203e362 100644 --- a/src/statistics.c +++ b/src/statistics.c @@ -135,22 +135,11 @@ void stats_collect_part_mapper(void *map_data, int nr_parts, void *extra_data) { const integertime_t ti_end = get_integer_time_end(ti_current, p->time_bin); const float dt = (ti_current - ((ti_begin + ti_end) / 2)) * timeBase; - /* Get the total acceleration */ - float a_tot[3] = {p->a_hydro[0], p->a_hydro[1], p->a_hydro[2]}; - if (gp != NULL) { - a_tot[0] += gp->a_grav[0]; - a_tot[1] += gp->a_grav[1]; - a_tot[2] += gp->a_grav[2]; - } - - /* Extrapolate velocities to current time */ - const float v[3] = {xp->v_full[0] + a_tot[0] * dt, - xp->v_full[1] + a_tot[1] * dt, - xp->v_full[2] + a_tot[2] * dt}; - - const float m = hydro_get_mass(p); + float v[3]; + hydro_get_drifted_velocities(p, xp, dt, v); const double x[3] = {p->x[0], p->x[1], p->x[2]}; - const float rho = hydro_get_density(p); + const float m = hydro_get_mass(p); + const float entropy = hydro_get_entropy(p); const float u_int = hydro_get_internal_energy(p); /* Collect mass */ @@ -182,7 +171,7 @@ void stats_collect_part_mapper(void *map_data, int nr_parts, void *extra_data) { } /* Collect entropy */ - stats.entropy += m * gas_entropy_from_internal_energy(rho, u_int); + stats.entropy += m * entropy; } /* Now write back to memory */