diff --git a/src/cell.c b/src/cell.c index 819b039d1485a1d1b0bac14fbf3e1dfa16e5ae46..4bc9ca251ac72819cc3b96079a8e42ad30772c67 100644 --- a/src/cell.c +++ b/src/cell.c @@ -967,6 +967,7 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset, /* Store the counts and offsets. */ for (int k = 0; k < 8; k++) { c->progeny[k]->hydro.count = bucket_count[k]; + c->progeny[k]->hydro.count_total = c->progeny[k]->hydro.count; c->progeny[k]->hydro.parts = &c->hydro.parts[bucket_offset[k]]; c->progeny[k]->hydro.xparts = &c->hydro.xparts[bucket_offset[k]]; } @@ -1084,6 +1085,7 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset, /* Store the counts and offsets. */ for (int k = 0; k < 8; k++) { c->progeny[k]->stars.count = bucket_count[k]; + c->progeny[k]->stars.count_total = c->progeny[k]->stars.count; c->progeny[k]->stars.parts = &c->stars.parts[bucket_offset[k]]; } @@ -1146,6 +1148,7 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset, /* Store the counts and offsets. */ for (int k = 0; k < 8; k++) { c->progeny[k]->grav.count = bucket_count[k]; + c->progeny[k]->grav.count_total = c->progeny[k]->grav.count; c->progeny[k]->grav.parts = &c->grav.parts[bucket_offset[k]]; } } @@ -3645,7 +3648,22 @@ void cell_check_timesteps(struct cell *c) { #endif } -void cell_add_spart(const struct engine *e, struct cell *c) {} +void cell_add_spart(const struct engine *e, struct cell *c) { + + if (c->nodeID != engine_rank) error("Adding spart on a foreign node"); + + /* Get the top-level this leaf cell is in */ + struct cell *top = c; + while (top->parent != NULL) top = top->parent; + +#ifdef SWIFT_DEBUG_CHECKS + if (top->depth != 0) error("Cell-linking issue"); +#endif + + /* Are there any extra particles left? */ + if (top->stars.count == top->stars.count_total) + error("We ran out of star particles!"); +} /** * @brief "Remove" a gas particle from the calculation. diff --git a/src/cell.h b/src/cell.h index 1f9dc110f28394e20f0cef693584af85e4a45f2c..f3fc61308c518d59a1febc7abbdd536ea3829ab8 100644 --- a/src/cell.h +++ b/src/cell.h @@ -312,6 +312,9 @@ struct cell { /*! Nr of #part in this cell. */ int count; + /*! Nr of #part this cell can hold after addition of new #part. */ + int count_total; + /*! Number of #part updated in this cell. */ int updated; @@ -339,7 +342,7 @@ struct cell { /*! Do any of this cell's sub-cells need to be sorted? */ char do_sub_sort; - #ifdef SWIFT_DEBUG_CHECKS +#ifdef SWIFT_DEBUG_CHECKS /*! Last (integer) time the cell's sort arrays were updated. */ integertime_t ti_sort; @@ -416,6 +419,9 @@ struct cell { /*! Nr of #gpart in this cell. */ int count; + /*! Nr of #gpart this cell can hold after addition of new #gpart. */ + int count_total; + /*! Number of #gpart updated in this cell. */ int updated; @@ -659,6 +665,7 @@ void cell_activate_sorts(struct cell *c, int sid, struct scheduler *s); void cell_clear_drift_flags(struct cell *c, void *data); void cell_set_super_mapper(void *map_data, int num_elements, void *extra_data); int cell_has_tasks(struct cell *c); +void cell_add_spart(const struct engine *e, struct cell *c); void cell_remove_part(const struct engine *e, struct cell *c, struct part *p, struct xpart *xp); void cell_remove_gpart(const struct engine *e, struct cell *c, diff --git a/src/runner.c b/src/runner.c index 0026d833b98ec9f07bdec7f13d3d5bccf6a4b1e8..4d891063bcf8fe815387673cbd95c510d4f2bcd8 100644 --- a/src/runner.c +++ b/src/runner.c @@ -525,6 +525,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { if (rho > 1.5e7 && e->step > 2) { message("Removing particle id=%lld rho=%e", p->id, rho); cell_convert_part_to_gpart(e, c, p, xp); + cell_add_spart(e, c); } } } diff --git a/src/space.c b/src/space.c index 3b3d1927fcb43a25d8e3d9a75eb303d5f0e54bd5..323e9d3a01cbe393b42b7bac90ea4ecb11fe6b18 100644 --- a/src/space.c +++ b/src/space.c @@ -194,12 +194,15 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->stars.dx_max_part = 0.f; c->hydro.sorted = 0; c->hydro.count = 0; + c->hydro.count_total = 0; c->hydro.updated = 0; c->hydro.inhibited = 0; c->grav.count = 0; + c->grav.count_total = 0; c->grav.updated = 0; c->grav.inhibited = 0; c->stars.count = 0; + c->stars.count_total = 0; c->stars.updated = 0; c->stars.inhibited = 0; c->grav.init = NULL; @@ -1522,10 +1525,15 @@ void space_rebuild(struct space *s, int repartitioned, int verbose) { c->hydro.xparts = xfinger; c->grav.parts = gfinger; c->stars.parts = sfinger; - finger = &finger[c->hydro.count + space_extra_parts]; - xfinger = &xfinger[c->hydro.count + space_extra_parts]; - gfinger = &gfinger[c->grav.count + space_extra_gparts]; - sfinger = &sfinger[c->stars.count + space_extra_sparts]; + + c->hydro.count_total = c->hydro.count + space_extra_parts; + c->grav.count_total = c->grav.count + space_extra_gparts; + c->stars.count_total = c->stars.count + space_extra_sparts; + + finger = &finger[c->hydro.count_total]; + xfinger = &xfinger[c->hydro.count_total]; + gfinger = &gfinger[c->grav.count_total]; + sfinger = &sfinger[c->stars.count_total]; /* Add this cell to the list of local cells */ s->local_cells_top[s->nr_local_cells] = k; @@ -2616,6 +2624,9 @@ void space_split_recursive(struct space *s, struct cell *c, cp->hydro.count = 0; cp->grav.count = 0; cp->stars.count = 0; + cp->hydro.count_total = 0; + cp->grav.count_total = 0; + cp->stars.count_total = 0; cp->hydro.ti_old_part = c->hydro.ti_old_part; cp->grav.ti_old_part = c->grav.ti_old_part; cp->grav.ti_old_multipole = c->grav.ti_old_multipole; @@ -2821,6 +2832,8 @@ void space_split_recursive(struct space *s, struct cell *c, /* parts: Get dt_min/dt_max and h_max. */ for (int k = 0; k < count; k++) { #ifdef SWIFT_DEBUG_CHECKS + if (parts[k].time_bin == time_bin_not_created) + error("Extra particle present in space_split()"); if (parts[k].time_bin == time_bin_inhibited) error("Inhibited particle present in space_split()"); #endif @@ -2839,6 +2852,8 @@ void space_split_recursive(struct space *s, struct cell *c, /* gparts: Get dt_min/dt_max. */ for (int k = 0; k < gcount; k++) { #ifdef SWIFT_DEBUG_CHECKS + if (gparts[k].time_bin == time_bin_not_created) + error("Extra g-particle present in space_split()"); if (gparts[k].time_bin == time_bin_inhibited) error("Inhibited g-particle present in space_split()"); #endif @@ -2849,6 +2864,8 @@ void space_split_recursive(struct space *s, struct cell *c, /* sparts: Get dt_min/dt_max */ for (int k = 0; k < scount; k++) { #ifdef SWIFT_DEBUG_CHECKS + if (sparts[k].time_bin == time_bin_not_created) + error("Extra s-particle present in space_split()"); if (sparts[k].time_bin == time_bin_inhibited) error("Inhibited s-particle present in space_split()"); #endif diff --git a/src/space.h b/src/space.h index 65a1f4fb90239725a71be709246f653675495642..c06ae26e1a84c9522fb0b0d2a099059d4dfd71b2 100644 --- a/src/space.h +++ b/src/space.h @@ -44,8 +44,8 @@ struct cosmology; #define space_cellallocchunk 1000 #define space_splitsize_default 400 #define space_maxsize_default 8000000 -#define space_extra_parts_default 10 -#define space_extra_gparts_default 30 +#define space_extra_parts_default 0 +#define space_extra_gparts_default 0 #define space_extra_sparts_default 20 #define space_expected_max_nr_strays_default 100 #define space_subsize_pair_hydro_default 256000000 diff --git a/src/task.c b/src/task.c index 6bc29730eddec091590687867fc5dd72bbb129ec..52c62c67f16bea15d98a7d90893c63d0a60cea79 100644 --- a/src/task.c +++ b/src/task.c @@ -384,6 +384,7 @@ void task_unlock(struct task *t) { cell_unlocktree(ci); cell_sunlocktree(ci); cell_gunlocktree(ci); + break; default: break;