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

Add a flag to verify that a synchronized particle gets its time-step recomputed.

parent 614914ca
......@@ -878,6 +878,10 @@ __attribute__((always_inline)) INLINE static void hydro_first_init_part(
xp->a_grav[2] = 0.f;
xp->u_full = p->u;
#ifdef SWIFT_DEBUG_CHECKS
p->synchronized = 0;
#endif
hydro_reset_acceleration(p);
hydro_init_part(p, NULL);
}
......
......@@ -194,6 +194,9 @@ struct part {
/* Time of the last kick */
integertime_t ti_kick;
/* Has the particle been synchronised back on the timeline this step? */
char synchronized;
#endif
} SWIFT_STRUCT_ALIGN;
......
......@@ -620,6 +620,10 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) {
with_cosmology, e->cosmology,
e->hydro_properties, e->cooling_func, e->time);
#ifdef SWIFT_DEBUG_CHECKS
p->synchronized = 0;
#endif
/* Number of updated particles */
updated++;
if (p->gpart != NULL) g_updated++;
......@@ -646,6 +650,10 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) {
else { /* part is inactive */
#ifdef SWIFT_DEBUG_CHECKS
if (p->synchronized) p->synchronized = 2;
#endif
if (!part_is_inhibited(p, e)) {
const integertime_t ti_end =
......
......@@ -5295,6 +5295,8 @@ void space_check_limiter_mapper(void *map_data, int nr_parts,
if (parts[k].wakeup == time_bin_awake)
error("Particle still woken up! id=%lld", parts[k].id);
if (parts[k].synchronized != 0) error("Synchronized particle not treated!");
if (parts[k].gpart != NULL)
if (parts[k].time_bin != parts[k].gpart->time_bin)
error("Gpart not on the same time-bin as part");
......
......@@ -24,24 +24,28 @@
#include "kick.h"
INLINE static void timestep_sync_part(struct part *p, struct xpart *xp, const struct engine *e,
const struct cosmology *cosmo) {
INLINE static void timestep_sync_part(struct part *p, struct xpart *xp,
const struct engine *e,
const struct cosmology *cosmo) {
const int with_cosmology = (e->policy & engine_policy_cosmology);
const integertime_t ti_current = e->ti_current;
const timebin_t max_active_bin = e->max_active_bin;
const timebin_t min_active_bin = e->min_active_bin;
const double time_base = e->time_base;
/* This particle is already active. Nothing to do here... */
if (p->time_bin <= max_active_bin) return;
message("Synchronizing particle %lld", p->id);
/* We want to make the particle finish it's time-step now. */
/* Start by recovering the start and end point of the particle's time-step. */
const integertime_t old_ti_beg = get_integer_time_begin(ti_current, p->time_bin);
const integertime_t old_ti_end = get_integer_time_end(ti_current, p->time_bin);
const integertime_t old_ti_beg =
get_integer_time_begin(ti_current, p->time_bin);
const integertime_t old_ti_end =
get_integer_time_end(ti_current, p->time_bin);
/* Old time-step length on the time-line */
const integertime_t old_dti = old_ti_end - old_ti_beg;
......@@ -70,8 +74,7 @@ INLINE static void timestep_sync_part(struct part *p, struct xpart *xp, const st
if (new_dti > old_dti) error("New time-step larger than old one");
#endif
double dt_kick_grav = 0., dt_kick_hydro = 0., dt_kick_therm = 0.,
double dt_kick_grav = 0., dt_kick_hydro = 0., dt_kick_therm = 0.,
dt_kick_corr = 0.;
/* Now we need to reverse the kick1... (the dt are negative here) */
......@@ -95,21 +98,21 @@ INLINE static void timestep_sync_part(struct part *p, struct xpart *xp, const st
e->cosmology, e->hydro_properties, e->entropy_floor,
old_ti_beg + old_dti / 2, old_ti_beg);
/* ...and apply the new one (dt is positiive) */
/* ...and apply the new one (dt is positiive) */
if (with_cosmology) {
dt_kick_hydro = cosmology_get_hydro_kick_factor(cosmo, new_ti_beg,
new_ti_beg + new_dti );
dt_kick_grav = cosmology_get_grav_kick_factor(cosmo, new_ti_beg,
new_ti_beg + new_dti );
new_ti_beg + new_dti);
dt_kick_grav =
cosmology_get_grav_kick_factor(cosmo, new_ti_beg, new_ti_beg + new_dti);
dt_kick_therm = cosmology_get_therm_kick_factor(cosmo, new_ti_beg,
new_ti_beg + new_dti );
dt_kick_corr = cosmology_get_corr_kick_factor(cosmo, new_ti_beg,
new_ti_beg + new_dti );
new_ti_beg + new_dti);
dt_kick_corr =
cosmology_get_corr_kick_factor(cosmo, new_ti_beg, new_ti_beg + new_dti);
} else {
dt_kick_hydro = (new_dti ) * time_base;
dt_kick_grav = (new_dti ) * time_base;
dt_kick_therm = (new_dti ) * time_base;
dt_kick_corr = (new_dti ) * time_base;
dt_kick_hydro = (new_dti)*time_base;
dt_kick_grav = (new_dti)*time_base;
dt_kick_therm = (new_dti)*time_base;
dt_kick_corr = (new_dti)*time_base;
}
kick_part(p, xp, dt_kick_hydro, dt_kick_grav, dt_kick_therm, dt_kick_corr,
......@@ -117,12 +120,16 @@ INLINE static void timestep_sync_part(struct part *p, struct xpart *xp, const st
new_ti_beg + new_dti);
#ifdef SWIFT_DEBUG_CHECKS
if (p->ti_kick != ti_current) error("Particle has not been synchronized correctly.");
if (p->ti_kick != ti_current)
error("Particle has not been synchronized correctly.");
p->synchronized = 1;
#endif
p->time_bin = min_active_bin;
p->wakeup = time_bin_not_awake;
/* The particle is now ready to compute its new time-step size and for the next kick */
/* The particle is now ready to compute its new time-step size and for the
* next kick */
}
#endif /* SWIFT_TIMESTEP_SYNC_H */
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