diff --git a/src/cell.c b/src/cell.c index 51f2cef0522c10d48b0f61afba087b99160838d4..62384b948dbcbb13bd9865da06d9e3b702376e19 100644 --- a/src/cell.c +++ b/src/cell.c @@ -3291,8 +3291,8 @@ void cell_remove_spart(const struct engine *e, struct cell *c, * @param p The #part to remove. * @param xp The extended data of the particle to remove. */ -void cell_convert_part_to_dark_matter(const struct engine *e, struct cell *c, - struct part *p, struct xpart *xp) { +void cell_convert_part_to_gpart(const struct engine *e, struct cell *c, + struct part *p, struct xpart *xp) { /* Quick cross-check */ if (c->nodeID != e->nodeID) @@ -3309,6 +3309,34 @@ void cell_convert_part_to_dark_matter(const struct engine *e, struct cell *c, } } +/** + * @brief "Remove" a spart particle from the calculation and convert its gpart + * friend to a dark matter particle. + * + * The particle is inhibited and will officially be removed at the next rebuild. + * + * @param e The #engine running on this node. + * @param c The #cell from which to remove the particle. + * @param sp The #spart to remove. + */ +void cell_convert_spart_to_gpart(const struct engine *e, struct cell *c, + struct spart *sp) { + + /* Quick cross-check */ + if (c->nodeID != e->nodeID) + error("Can't remove a particle in a foreign cell."); + + /* Mark the particle as inhibited */ + sp->time_bin = time_bin_inhibited; + + if (sp->gpart) { + sp->gpart->type = swift_type_dark_matter; + sp->gpart->id_or_neg_offset = sp->id; + } else { + error("Trying to convert part without gpart friend to dark matter!"); + } +} + /** * @brief Can we use the MM interactions fo a given pair of cells? * diff --git a/src/cell.h b/src/cell.h index 670c4b777a36bae8e6e2814cc1f0f86b787d1196..559504b798b3686151346590ac684a5b3a1955c2 100644 --- a/src/cell.h +++ b/src/cell.h @@ -622,6 +622,10 @@ void cell_remove_gpart(const struct engine *e, struct cell *c, struct gpart *gp); void cell_remove_spart(const struct engine *e, struct cell *c, struct spart *sp); +void cell_convert_part_to_gpart(const struct engine *e, struct cell *c, + struct part *p, struct xpart *xp); +void cell_convert_spart_to_gpart(const struct engine *e, struct cell *c, + struct spart *sp); int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, const struct engine *e, const struct space *s); int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct cell *cj, diff --git a/src/runner.c b/src/runner.c index bc6bc4f738129ee2dcf7bf12b11b22029ef76f19..f471b51eae9deab3d5609eafa8f7d093a13ce552 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2052,7 +2052,7 @@ void runner_do_end_force(struct runner *r, struct cell *c, int timer) { if (p->rho > 1.5e7 && e->step > 2) { message("Removing particle id=%lld rho=%e", p->id, p->rho); - cell_remove_part(e, c, p, xp); + cell_convert_part_to_gpart(e, c, p, xp); } } }