diff --git a/src/hydro/Gadget2/hydro.h b/src/hydro/Gadget2/hydro.h index 77c4b5dd61b7ff9b84242df61f503fb42b472952..8cad1c62ad669b9c0dc5bbe333985c1e20b882af 100644 --- a/src/hydro/Gadget2/hydro.h +++ b/src/hydro/Gadget2/hydro.h @@ -306,10 +306,11 @@ hydro_get_physical_internal_energy_dt(const struct part *restrict p, * We assume a constant density for the conversion to entropy. * * @param p The particle of interest. - * @param du_dt The new time derivative of the internal energy. + * @param du_dt The new time derivative of the comoving internal energy. */ __attribute__((always_inline)) INLINE static void -hydro_set_comoving_internal_energy_dt(struct part *restrict p, float du_dt) { +hydro_set_comoving_internal_energy_dt(struct part *restrict p, + const float du_dt) { p->entropy_dt = gas_entropy_from_internal_energy(p->rho, du_dt); } @@ -321,15 +322,29 @@ hydro_set_comoving_internal_energy_dt(struct part *restrict p, float du_dt) { * * @param p The particle of interest. * @param cosmo Cosmology data structure - * @param du_dt The time derivative of the internal energy. + * @param du_dt The time derivative of the physical internal energy. */ __attribute__((always_inline)) INLINE static void hydro_set_physical_internal_energy_dt(struct part *restrict p, const struct cosmology *restrict cosmo, - float du_dt) { + const float du_dt) { p->entropy_dt = gas_entropy_from_internal_energy(p->rho * cosmo->a3_inv, du_dt); } +/** + * @brief Sets the physical entropy of a particle + * + * @param p The particle of interest. + * @param cosmo Cosmology data structure + * @param s The physical entropy + */ +__attribute__((always_inline)) INLINE static void hydro_set_physical_entropy( + struct part *p, struct xpart *xp, const struct cosmology *cosmo, + const float entropy) { + + /* Note there is no conversion from physical to comoving entropy */ + xp->entropy_full = entropy; +} /** * @brief Computes the hydro time-step of a given particle diff --git a/src/kick.h b/src/kick.h index e85c9de40d2084304bde108e6f5fa9c776fd3e8f..4cd0cee56750c96ce1f1d2be66148d68e69f055e 100644 --- a/src/kick.h +++ b/src/kick.h @@ -79,6 +79,7 @@ __attribute__((always_inline)) INLINE static void kick_part( struct part *restrict p, struct xpart *restrict xp, double dt_kick_hydro, double dt_kick_grav, double dt_kick_therm, double dt_kick_corr, const struct cosmology *cosmo, const struct hydro_props *hydro_props, + const struct entropy_floor_properties *entropy_floor_props, integertime_t ti_start, integertime_t ti_end) { #ifdef SWIFT_DEBUG_CHECKS @@ -114,6 +115,13 @@ __attribute__((always_inline)) INLINE static void kick_part( hydro_kick_extra(p, xp, dt_kick_therm, dt_kick_grav, dt_kick_hydro, dt_kick_corr, cosmo, hydro_props); if (p->gpart != NULL) gravity_kick_extra(p->gpart, dt_kick_grav); + + /* Verify that the particle is not below the entropy floor */ + const float floor = entropy_floor(p, cosmo, entropy_floor_props); + if (hydro_get_physical_entropy(p, xp, cosmo) < floor) { + hydro_set_physical_entropy(p, xp, cosmo, floor); + hydro_set_physical_internal_energy_dt(p, cosmo, 0.f); + } } /** diff --git a/src/runner.c b/src/runner.c index 83ae4b72bb3a3380e634f89e8da9507b55f60074..69f7577a7a3a33b73a6492ba52abfea7e874614e 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1679,6 +1679,7 @@ void runner_do_kick1(struct runner *r, struct cell *c, int timer) { const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; const struct hydro_props *hydro_props = e->hydro_properties; + const struct entropy_floor_properties *entropy_floor = e->entropy_floor; const int with_cosmology = (e->policy & engine_policy_cosmology); struct part *restrict parts = c->hydro.parts; struct xpart *restrict xparts = c->hydro.xparts; @@ -1746,7 +1747,7 @@ void runner_do_kick1(struct runner *r, struct cell *c, int timer) { /* do the kick */ kick_part(p, xp, dt_kick_hydro, dt_kick_grav, dt_kick_therm, - dt_kick_corr, cosmo, hydro_props, ti_begin, + dt_kick_corr, cosmo, hydro_props, entropy_floor, ti_begin, ti_begin + ti_step / 2); /* Update the accelerations to be used in the drift for hydro */ @@ -1853,6 +1854,7 @@ void runner_do_kick2(struct runner *r, struct cell *c, int timer) { const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; const struct hydro_props *hydro_props = e->hydro_properties; + const struct entropy_floor_properties *entropy_floor = e->entropy_floor; const int with_cosmology = (e->policy & engine_policy_cosmology); const int count = c->hydro.count; const int gcount = c->grav.count; @@ -1916,8 +1918,8 @@ void runner_do_kick2(struct runner *r, struct cell *c, int timer) { /* Finish the time-step with a second half-kick */ kick_part(p, xp, dt_kick_hydro, dt_kick_grav, dt_kick_therm, - dt_kick_corr, cosmo, hydro_props, ti_begin + ti_step / 2, - ti_begin + ti_step); + dt_kick_corr, cosmo, hydro_props, entropy_floor, + ti_begin + ti_step / 2, ti_begin + ti_step); #ifdef SWIFT_DEBUG_CHECKS /* Check that kick and the drift are synchronized */