diff --git a/src/cell.c b/src/cell.c index 96e4e03b1332023a86dc2c966fb25b50478bc1e5..c6da651985c51b0cb05c302a39815d4f9368e891 100644 --- a/src/cell.c +++ b/src/cell.c @@ -5253,7 +5253,8 @@ void cell_clear_hydro_sort_flags(struct cell *c, const int clear_unused_flags) { /** * @brief Recursively checks that all particles in a cell have a time-step */ -void cell_check_timesteps(struct cell *c) { +void cell_check_timesteps(const struct cell *c, const integertime_t ti_current, + const timebin_t max_bin) { #ifdef SWIFT_DEBUG_CHECKS if (c->hydro.ti_end_min == 0 && c->grav.ti_end_min == 0 && @@ -5263,13 +5264,57 @@ void cell_check_timesteps(struct cell *c) { if (c->split) { for (int k = 0; k < 8; ++k) - if (c->progeny[k] != NULL) cell_check_timesteps(c->progeny[k]); + if (c->progeny[k] != NULL) + cell_check_timesteps(c->progeny[k], ti_current, max_bin); } else { if (c->nodeID == engine_rank) for (int i = 0; i < c->hydro.count; ++i) if (c->hydro.parts[i].time_bin == 0) error("Particle without assigned time-bin"); } + + /* Other checks not relevent when starting-up */ + if (ti_current == 0) return; + + integertime_t ti_end_min = max_nr_timesteps; + integertime_t ti_end_max = 0; + integertime_t ti_beg_max = 0; + + for (int i = 0; i < c->hydro.count; ++i) { + + const struct part *p = &c->hydro.parts[i]; + if (p->time_bin == time_bin_inhibited) continue; + if (p->time_bin == time_bin_not_created) continue; + + integertime_t ti_end, ti_beg; + + if (p->time_bin <= max_bin) { + integertime_t time_step = get_integer_timestep(p->time_bin); + ti_end = get_integer_time_end(ti_current, p->time_bin) + time_step; + ti_beg = get_integer_time_begin(ti_current + 1, p->time_bin); + } else { + ti_end = get_integer_time_end(ti_current, p->time_bin); + ti_beg = get_integer_time_begin(ti_current + 1, p->time_bin); + } + + ti_end_min = min(ti_end, ti_end_min); + ti_end_max = max(ti_end, ti_end_max); + ti_beg_max = max(ti_beg, ti_beg_max); + } + + if (ti_end_min != c->hydro.ti_end_min) + error( + "Non-matching ti_end_min. Cell=%lld true=%lld ti_current=%lld depth=%d", + c->hydro.ti_end_min, ti_end_min, ti_current, c->depth); + if (ti_end_max != c->hydro.ti_end_max) + error( + "Non-matching ti_end_max. Cell=%lld true=%lld ti_current=%lld depth=%d", + c->hydro.ti_end_max, ti_end_max, ti_current, c->depth); + if (ti_beg_max != c->hydro.ti_beg_max) + error( + "Non-matching ti_beg_max. Cell=%lld true=%lld ti_current=%lld depth=%d", + c->hydro.ti_beg_max, ti_beg_max, ti_current, c->depth); + #else error("Calling debugging code without debugging flag activated."); #endif diff --git a/src/cell.h b/src/cell.h index abaced2b9d6143ec66e1a9f92112da35998bf8f6..df6949643b35455e55125474acfc9dfc5c13b3fc 100644 --- a/src/cell.h +++ b/src/cell.h @@ -885,7 +885,8 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force); void cell_drift_bpart(struct cell *c, const struct engine *e, int force); void cell_drift_multipole(struct cell *c, const struct engine *e); void cell_drift_all_multipoles(struct cell *c, const struct engine *e); -void cell_check_timesteps(struct cell *c); +void cell_check_timesteps(const struct cell *c, const integertime_t ti_current, + const timebin_t max_bin); void cell_store_pre_drift_values(struct cell *c); void cell_set_star_resort_flag(struct cell *c); void cell_activate_star_formation_tasks(struct cell *c, struct scheduler *s, diff --git a/src/engine.c b/src/engine.c index 5bbc0711658b94ee8f87acd22a05a6138ce3876c..672acd33a49e02d57239ece37403d8a653aefd72 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2341,6 +2341,9 @@ void engine_step(struct engine *e) { e->b_updates_since_rebuild += e->collect_group1.b_updated; #ifdef SWIFT_DEBUG_CHECKS + /* Verify that all cells have correct time-step information */ + space_check_timesteps(e->s); + if (e->ti_end_min == e->ti_current && e->ti_end_min < max_nr_timesteps) error("Obtained a time-step of size 0"); #endif diff --git a/src/space.c b/src/space.c index 64eef6864d361a3a41b3563103d8953749795dde..06fb52992c68f7766fd09c4df93536f14fb3f0c0 100644 --- a/src/space.c +++ b/src/space.c @@ -3609,11 +3609,21 @@ void space_split_recursive(struct space *s, struct cell *c, c->split = 0; maxdepth = c->depth; - timebin_t hydro_time_bin_min = num_time_bins, hydro_time_bin_max = 0; - timebin_t gravity_time_bin_min = num_time_bins, gravity_time_bin_max = 0; - timebin_t stars_time_bin_min = num_time_bins, stars_time_bin_max = 0; - timebin_t black_holes_time_bin_min = num_time_bins, - black_holes_time_bin_max = 0; + ti_hydro_end_min = max_nr_timesteps; + ti_hydro_end_max = 0; + ti_hydro_beg_max = 0; + + ti_gravity_end_min = max_nr_timesteps; + ti_gravity_end_max = 0; + ti_gravity_beg_max = 0; + + ti_stars_end_min = max_nr_timesteps; + ti_stars_end_max = 0; + ti_stars_beg_max = 0; + + ti_black_holes_end_min = max_nr_timesteps; + ti_black_holes_end_max = 0; + ti_black_holes_beg_max = 0; /* parts: Get dt_min/dt_max and h_max. */ for (int k = 0; k < count; k++) { @@ -3623,9 +3633,18 @@ void space_split_recursive(struct space *s, struct cell *c, if (parts[k].time_bin == time_bin_inhibited) error("Inhibited particle present in space_split()"); #endif - hydro_time_bin_min = min(hydro_time_bin_min, parts[k].time_bin); - hydro_time_bin_max = max(hydro_time_bin_max, parts[k].time_bin); + + /* When does this particle's time-step start and end? */ + const timebin_t time_bin = parts[k].time_bin; + const integertime_t ti_end = get_integer_time_end(ti_current, time_bin); + const integertime_t ti_beg = get_integer_time_begin(ti_current, time_bin); + + ti_hydro_end_min = min(ti_hydro_end_min, ti_end); + ti_hydro_end_max = max(ti_hydro_end_max, ti_end); + ti_hydro_beg_max = max(ti_hydro_beg_max, ti_beg); + h_max = max(h_max, parts[k].h); + /* Collect SFR from the particles after rebuilt */ star_formation_logger_log_inactive_part(&parts[k], &xparts[k], &c->stars.sfh); @@ -3646,8 +3665,15 @@ void space_split_recursive(struct space *s, struct cell *c, if (gparts[k].time_bin == time_bin_inhibited) error("Inhibited g-particle present in space_split()"); #endif - gravity_time_bin_min = min(gravity_time_bin_min, gparts[k].time_bin); - gravity_time_bin_max = max(gravity_time_bin_max, gparts[k].time_bin); + + /* When does this particle's time-step start and end? */ + const timebin_t time_bin = gparts[k].time_bin; + const integertime_t ti_end = get_integer_time_end(ti_current, time_bin); + const integertime_t ti_beg = get_integer_time_begin(ti_current, time_bin); + + ti_gravity_end_min = min(ti_gravity_end_min, ti_end); + ti_gravity_end_max = max(ti_gravity_end_max, ti_end); + ti_gravity_beg_max = max(ti_gravity_beg_max, ti_beg); } /* sparts: Get dt_min/dt_max */ @@ -3658,8 +3684,16 @@ void space_split_recursive(struct space *s, struct cell *c, if (sparts[k].time_bin == time_bin_inhibited) error("Inhibited s-particle present in space_split()"); #endif - stars_time_bin_min = min(stars_time_bin_min, sparts[k].time_bin); - stars_time_bin_max = max(stars_time_bin_max, sparts[k].time_bin); + + /* When does this particle's time-step start and end? */ + const timebin_t time_bin = sparts[k].time_bin; + const integertime_t ti_end = get_integer_time_end(ti_current, time_bin); + const integertime_t ti_beg = get_integer_time_begin(ti_current, time_bin); + + ti_stars_end_min = min(ti_stars_end_min, ti_end); + ti_stars_end_max = max(ti_stars_end_max, ti_end); + ti_stars_beg_max = max(ti_stars_beg_max, ti_beg); + stars_h_max = max(stars_h_max, sparts[k].h); /* Reset x_diff */ @@ -3676,10 +3710,16 @@ void space_split_recursive(struct space *s, struct cell *c, if (bparts[k].time_bin == time_bin_inhibited) error("Inhibited b-particle present in space_split()"); #endif - black_holes_time_bin_min = - min(black_holes_time_bin_min, bparts[k].time_bin); - black_holes_time_bin_max = - max(black_holes_time_bin_max, bparts[k].time_bin); + + /* When does this particle's time-step start and end? */ + const timebin_t time_bin = bparts[k].time_bin; + const integertime_t ti_end = get_integer_time_end(ti_current, time_bin); + const integertime_t ti_beg = get_integer_time_begin(ti_current, time_bin); + + ti_black_holes_end_min = min(ti_black_holes_end_min, ti_end); + ti_black_holes_end_max = max(ti_black_holes_end_max, ti_end); + ti_black_holes_beg_max = max(ti_black_holes_beg_max, ti_beg); + black_holes_h_max = max(black_holes_h_max, bparts[k].h); /* Reset x_diff */ @@ -3688,26 +3728,6 @@ void space_split_recursive(struct space *s, struct cell *c, bparts[k].x_diff[2] = 0.f; } - /* Convert into integer times */ - ti_hydro_end_min = get_integer_time_end(ti_current, hydro_time_bin_min); - ti_hydro_end_max = get_integer_time_end(ti_current, hydro_time_bin_max); - ti_hydro_beg_max = - get_integer_time_begin(ti_current + 1, hydro_time_bin_max); - ti_gravity_end_min = get_integer_time_end(ti_current, gravity_time_bin_min); - ti_gravity_end_max = get_integer_time_end(ti_current, gravity_time_bin_max); - ti_gravity_beg_max = - get_integer_time_begin(ti_current + 1, gravity_time_bin_max); - ti_stars_end_min = get_integer_time_end(ti_current, stars_time_bin_min); - ti_stars_end_max = get_integer_time_end(ti_current, stars_time_bin_max); - ti_stars_beg_max = - get_integer_time_begin(ti_current + 1, stars_time_bin_max); - ti_black_holes_end_min = - get_integer_time_end(ti_current, black_holes_time_bin_min); - ti_black_holes_end_max = - get_integer_time_end(ti_current, black_holes_time_bin_max); - ti_black_holes_beg_max = - get_integer_time_begin(ti_current + 1, black_holes_time_bin_max); - /* Construct the multipole and the centre of mass*/ if (s->with_self_gravity) { if (gcount > 0) { @@ -5437,10 +5457,13 @@ void space_check_top_multipoles_drift_point(struct space *s, * * @param s The #space to check. */ -void space_check_timesteps(struct space *s) { +void space_check_timesteps(const struct space *s) { #ifdef SWIFT_DEBUG_CHECKS for (int i = 0; i < s->nr_cells; ++i) { - cell_check_timesteps(&s->cells_top[i]); + if (s->cells_top[i].nodeID == engine_rank) { + cell_check_timesteps(&s->cells_top[i], s->e->ti_current, + s->e->max_active_bin); + } } #else error("Calling debugging code without debugging flag activated."); diff --git a/src/space.h b/src/space.h index 94f51fcbe17bc3ff89a72891aeb90223e9007d8d..5ce9a3429939edec57def1e551d7db09bedcbcf5 100644 --- a/src/space.h +++ b/src/space.h @@ -365,7 +365,7 @@ void space_check_drift_point(struct space *s, integertime_t ti_drift, int multipole); void space_check_top_multipoles_drift_point(struct space *s, integertime_t ti_drift); -void space_check_timesteps(struct space *s); +void space_check_timesteps(const struct space *s); void space_check_limiter(struct space *s); void space_check_swallow(struct space *s); void space_check_sort_flags(struct space *s);