diff --git a/src/cell.c b/src/cell.c index eecf824002add311610e2ed5f3e137329de3abc9..d4a31db62f6c186b1413dd13a70a8765c7383c0f 100644 --- a/src/cell.c +++ b/src/cell.c @@ -5323,6 +5323,9 @@ void cell_remove_part(const struct engine *e, struct cell *c, struct part *p, if (c->nodeID != e->nodeID) error("Can't remove a particle in a foreign cell."); + /* Don't remove a particle twice */ + if (p->time_bin == time_bin_inhibited) return; + /* Mark the particle as inhibited */ p->time_bin = time_bin_inhibited; @@ -5357,6 +5360,10 @@ void cell_remove_part(const struct engine *e, struct cell *c, struct part *p, void cell_remove_gpart(const struct engine *e, struct cell *c, struct gpart *gp) { + /* Quick cross-check */ + if (c->nodeID != e->nodeID) + error("Can't remove a particle in a foreign cell."); + /* Don't remove a particle twice */ if (gp->time_bin == time_bin_inhibited) return; @@ -5388,6 +5395,9 @@ void cell_remove_spart(const struct engine *e, struct cell *c, if (c->nodeID != e->nodeID) error("Can't remove a particle in a foreign cell."); + /* Don't remove a particle twice */ + if (sp->time_bin == time_bin_inhibited) return; + /* Mark the particle as inhibited and stand-alone */ sp->time_bin = time_bin_inhibited; if (sp->gpart) { @@ -5421,6 +5431,9 @@ void cell_remove_bpart(const struct engine *e, struct cell *c, if (c->nodeID != e->nodeID) error("Can't remove a particle in a foreign cell."); + /* Don't remove a particle twice */ + if (bp->time_bin == time_bin_inhibited) return; + /* Mark the particle as inhibited and stand-alone */ bp->time_bin = time_bin_inhibited; if (bp->gpart) {