Commit bcb9b2e8 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Added comoving and physical potential calculation functions for gparts.

parent 978b272e
......@@ -48,16 +48,29 @@ __attribute__((always_inline)) INLINE static float gravity_get_softening(
}
/**
* @brief Returns the potential of a particle
* @brief Returns the comoving potential of a particle
*
* @param gp The particle of interest
*/
__attribute__((always_inline)) INLINE static float gravity_get_potential(
const struct gpart* restrict gp) {
__attribute__((always_inline)) INLINE static float
gravity_get_comoving_potential(const struct gpart* restrict gp) {
return gp->potential;
}
/**
* @brief Returns the physical potential of a particle
*
* @param gp The particle of interest.
* @param cosmo The cosmological model.
*/
__attribute__((always_inline)) INLINE static float
gravity_get_physical_potential(const struct gpart* restrict gp,
const struct cosmology* cosmo) {
return gp->potential * cosmo->a_inv;
}
/**
* @brief Computes the gravity time-step of a given particle due to self-gravity
*
......
......@@ -191,7 +191,7 @@ void stats_collect_part_mapper(void *map_data, int nr_parts, void *extra_data) {
stats.E_int += m * u_inter;
stats.E_rad += cooling_get_radiated_energy(xp);
if (gp != NULL) {
stats.E_pot_self += m * gravity_get_potential(gp) * a_inv;
stats.E_pot_self += m * gravity_get_physical_potential(gp, cosmo);
stats.E_pot_ext += m * external_gravity_get_potential_energy(
time, potential, phys_const, gp);
}
......@@ -292,7 +292,7 @@ void stats_collect_gpart_mapper(void *map_data, int nr_gparts,
/* Collect energies. */
stats.E_kin += 0.5f * m * (v[0] * v[0] + v[1] * v[1] + v[2] * v[2]) *
a_inv2; /* 1/2 m a^2 \dot{r}^2 */
stats.E_pot_self += m * gravity_get_potential(gp) * a_inv;
stats.E_pot_self += m * gravity_get_physical_potential(gp, cosmo);
stats.E_pot_ext += m * external_gravity_get_potential_energy(
time, potential, phys_const, gp);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment