Commit 21f48d7e authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Correctly update the counters when adding a spart to the global array. Handle...

Correctly update the counters when adding a spart to the global array. Handle the case where we run out of free slots.
parent a72b92dd
......@@ -3725,7 +3725,7 @@ void cell_recursively_shift_sparts(struct cell *c,
c->stars.parts++;
}
struct spart *cell_add_spart(const struct engine *e, struct cell *const c) {
struct spart *cell_add_spart(struct engine *e, struct cell *const c) {
if (c->nodeID != engine_rank) error("Adding spart on a foreign node");
......@@ -3748,8 +3748,11 @@ struct spart *cell_add_spart(const struct engine *e, struct cell *const c) {
}
/* Are there any extra particles left? */
if (top->stars.count == top->stars.count_total)
error("We ran out of star particles!");
if (top->stars.count == top->stars.count_total) {
message("We ran out of star particles!");
atomic_inc(&e->forcerebuild);
return NULL;
}
/* Number of particles to shift in order to get a free space. */
const int n_copy = &top->stars.parts[top->stars.count] - c->stars.parts;
......@@ -3798,10 +3801,12 @@ struct spart *cell_add_spart(const struct engine *e, struct cell *const c) {
sp->time_bin = e->min_active_bin;
#ifdef SWIFT_DEBUG_CHECKS
/* Specify it was drifted to this point */
sp->ti_drift = e->ti_current;
#endif
e->s->nr_extra_sparts--;
/* Register that we used one of the free slots. */
atomic_dec(&e->s->nr_extra_sparts);
return sp;
}
......
......@@ -667,7 +667,7 @@ void cell_set_super_mapper(void *map_data, int num_elements, void *extra_data);
void cell_check_spart_pos(const struct cell *c,
const struct spart *global_sparts);
int cell_has_tasks(struct cell *c);
struct spart *cell_add_spart(const struct engine *e, struct cell *c);
struct spart *cell_add_spart(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,
......
......@@ -492,7 +492,7 @@ void runner_do_cooling(struct runner *r, struct cell *c, int timer) {
*/
void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
const struct engine *e = r->e;
struct engine *e = r->e;
const struct cosmology *cosmo = e->cosmology;
const int count = c->hydro.count;
struct part *restrict parts = c->hydro.parts;
......@@ -526,12 +526,15 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
message("c->cellID=%d Removing particle id=%lld rho=%e", c->cellID,
p->id, rho);
/* Destroy the gas particle and get it's gpart friend */
struct gpart *gp = cell_convert_part_to_gpart(e, c, p, xp);
/* Create a fresh (empty) spart */
struct spart *sp = cell_add_spart(e, c);
/* Did we run out of free spart slots? */
if (sp == NULL) continue;
/* Destroy the gas particle and get it's gpart friend */
struct gpart *gp = cell_convert_part_to_gpart(e, c, p, xp);
/* Assign the ID back */
sp->id = gp->id_or_neg_offset;
gp->type = swift_type_stars;
......@@ -566,13 +569,6 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
}
}
if (c->super == c) {
#ifdef SWIFT_DEBUG_CHECKS
/* Check that everything went OK */
cell_check_spart_pos(c, e->s->sparts);
#endif
}
if (timer) TIMER_TOC(timer_do_star_formation);
}
......
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