Commit 77e16d2f authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

When converting a part to a gpart also erase the pointer connection.

parent 98242ef5
......@@ -3234,6 +3234,9 @@ void cell_remove_part(const struct engine *e, struct cell *c, struct part *p,
/* Mark the particle as inhibited */
p->time_bin = time_bin_inhibited;
if (p->gpart) p->gpart->time_bin = time_bin_inhibited;
/* Un-link the part */
p->gpart = NULL;
}
/**
......@@ -3278,6 +3281,9 @@ void cell_remove_spart(const struct engine *e, struct cell *c,
/* Mark the particle as inhibited */
sp->time_bin = time_bin_inhibited;
if (sp->gpart) sp->gpart->time_bin = time_bin_inhibited;
/* Un-link the spart */
sp->gpart = NULL;
}
/**
......@@ -3294,19 +3300,29 @@ void cell_remove_spart(const struct engine *e, struct cell *c,
void cell_convert_part_to_gpart(const struct engine *e, struct cell *c,
struct part *p, struct xpart *xp) {
/* Quick cross-check */
/* Quick cross-checks */
if (c->nodeID != e->nodeID)
error("Can't remove a particle in a foreign cell.");
if (p->gpart == NULL)
error("Trying to convert part without gpart friend to dark matter!");
/* Get a handle */
struct gpart *gp = p->gpart;
/* Mark the particle as inhibited */
p->time_bin = time_bin_inhibited;
if (p->gpart) {
p->gpart->type = swift_type_dark_matter;
p->gpart->id_or_neg_offset = p->id;
} else {
error("Trying to convert part without gpart friend to dark matter!");
}
/* Un-link the part */
p->gpart = NULL;
/* Mark the gpart as dark matter */
gp->type = swift_type_dark_matter;
gp->id_or_neg_offset = p->id;
#ifdef SWIFT_DEBUG_CHECKS
gp->ti_kick = p->ti_kick;
#endif
}
/**
......@@ -3320,21 +3336,31 @@ void cell_convert_part_to_gpart(const struct engine *e, struct cell *c,
* @param sp The #spart to remove.
*/
void cell_convert_spart_to_gpart(const struct engine *e, struct cell *c,
struct spart *sp) {
struct spart *sp) {
/* Quick cross-check */
if (c->nodeID != e->nodeID)
error("Can't remove a particle in a foreign cell.");
if (sp->gpart == NULL)
error("Trying to convert spart without gpart friend to dark matter!");
/* Get a handle */
struct gpart *gp = sp->gpart;
/* 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!");
}
/* Un-link the spart */
sp->gpart = NULL;
/* Mark the gpart as dark matter */
gp->type = swift_type_dark_matter;
gp->id_or_neg_offset = sp->id;
#ifdef SWIFT_DEBUG_CHECKS
gp->ti_kick = sp->ti_kick;
#endif
}
/**
......
......@@ -625,7 +625,7 @@ void cell_remove_spart(const struct engine *e, struct cell *c,
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);
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,
......
......@@ -45,8 +45,8 @@ __attribute__((always_inline)) INLINE static void kick_gpart(
if (gp->ti_kick != ti_start)
error(
"g-particle has not been kicked to the current time gp->ti_kick=%lld, "
"ti_start=%lld, ti_end=%lld",
gp->ti_kick, ti_start, ti_end);
"ti_start=%lld, ti_end=%lld id=%lld",
gp->ti_kick, ti_start, ti_end, gp->id_or_neg_offset);
gp->ti_kick = ti_end;
#endif
......@@ -85,8 +85,8 @@ __attribute__((always_inline)) INLINE static void kick_part(
if (p->ti_kick != ti_start)
error(
"particle has not been kicked to the current time p->ti_kick=%lld, "
"ti_start=%lld, ti_end=%lld",
p->ti_kick, ti_start, ti_end);
"ti_start=%lld, ti_end=%lld id=%lld",
p->ti_kick, ti_start, ti_end, p->id);
p->ti_kick = ti_end;
#endif
......@@ -133,8 +133,8 @@ __attribute__((always_inline)) INLINE static void kick_spart(
if (sp->ti_kick != ti_start)
error(
"s-particle has not been kicked to the current time sp->ti_kick=%lld, "
"ti_start=%lld, ti_end=%lld",
sp->ti_kick, ti_start, ti_end);
"ti_start=%lld, ti_end=%lld id=%lld",
sp->ti_kick, ti_start, ti_end, sp->id);
sp->ti_kick = ti_end;
#endif
......
......@@ -2053,6 +2053,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_convert_part_to_gpart(e, c, p, xp);
// cell_remove_part(e,c,p,xp);
}
}
}
......
......@@ -609,26 +609,26 @@ void space_rebuild(struct space *s, int verbose) {
const int local_nodeID = s->e->nodeID;
/* Move non-local parts and inhibited parts to the end of the list. */
if (s->e->nr_nodes > 1 || count_inhibited_parts > 0) {
if (s->e->nr_nodes > 1 || count_inhibited_parts > 0) {
for (size_t k = 0; k < nr_parts; /* void */) {
if (ind[k] == -1 || cells_top[ind[k]].nodeID != local_nodeID) {
nr_parts -= 1;
/* Swap the particle */
memswap(&s->parts[k], &s->parts[nr_parts], sizeof(struct part));
/* Swap the link with the gpart */
if (s->parts[k].gpart != NULL) {
s->parts[k].gpart->id_or_neg_offset = -k;
}
if (s->parts[nr_parts].gpart != NULL) {
s->parts[nr_parts].gpart->id_or_neg_offset = -nr_parts;
}
/* Swap the xpart */
memswap(&s->xparts[k], &s->xparts[nr_parts], sizeof(struct xpart));
/* Swap the index */
memswap(&ind[k], &ind[nr_parts], sizeof(int));
nr_parts -= 1;
/* Swap the particle */
memswap(&s->parts[k], &s->parts[nr_parts], sizeof(struct part));
/* Swap the link with the gpart */
if (s->parts[k].gpart != NULL) {
s->parts[k].gpart->id_or_neg_offset = -k;
}
if (s->parts[nr_parts].gpart != NULL) {
s->parts[nr_parts].gpart->id_or_neg_offset = -nr_parts;
}
/* Swap the xpart */
memswap(&s->xparts[k], &s->xparts[nr_parts], sizeof(struct xpart));
/* Swap the index */
memswap(&ind[k], &ind[nr_parts], sizeof(int));
} else {
/* Increment when not exchanging otherwise we need to retest "k".*/
k++;
/* Increment when not exchanging otherwise we need to retest "k".*/
k++;
}
}
}
......@@ -652,24 +652,24 @@ void space_rebuild(struct space *s, int verbose) {
#endif /* SWIFT_DEBUG_CHECKS */
/* Move non-local sparts and inhibited sparts to the end of the list. */
if (s->e->nr_nodes > 1 || count_inhibited_sparts > 0) {
if (s->e->nr_nodes > 1 || count_inhibited_sparts > 0) {
for (size_t k = 0; k < nr_sparts; /* void */) {
if (sind[k] == -1 || cells_top[sind[k]].nodeID != local_nodeID) {
nr_sparts -= 1;
/* Swap the particle */
memswap(&s->sparts[k], &s->sparts[nr_sparts], sizeof(struct spart));
/* Swap the link with the gpart */
if (s->sparts[k].gpart != NULL) {
s->sparts[k].gpart->id_or_neg_offset = -k;
}
if (s->sparts[nr_sparts].gpart != NULL) {
s->sparts[nr_sparts].gpart->id_or_neg_offset = -nr_sparts;
}
/* Swap the index */
memswap(&sind[k], &sind[nr_sparts], sizeof(int));
nr_sparts -= 1;
/* Swap the particle */
memswap(&s->sparts[k], &s->sparts[nr_sparts], sizeof(struct spart));
/* Swap the link with the gpart */
if (s->sparts[k].gpart != NULL) {
s->sparts[k].gpart->id_or_neg_offset = -k;
}
if (s->sparts[nr_sparts].gpart != NULL) {
s->sparts[nr_sparts].gpart->id_or_neg_offset = -nr_sparts;
}
/* Swap the index */
memswap(&sind[k], &sind[nr_sparts], sizeof(int));
} else {
/* Increment when not exchanging otherwise we need to retest "k".*/
k++;
/* Increment when not exchanging otherwise we need to retest "k".*/
k++;
}
}
}
......@@ -693,30 +693,30 @@ void space_rebuild(struct space *s, int verbose) {
#endif /* SWIFT_DEBUG_CHECKS */
/* Move non-local gparts and inhibited parts to the end of the list. */
if (s->e->nr_nodes > 1 || count_inhibited_gparts > 0) {
if (s->e->nr_nodes > 1 || count_inhibited_gparts > 0) {
for (size_t k = 0; k < nr_gparts; /* void */) {
if (gind[k] == -1 || cells_top[gind[k]].nodeID != local_nodeID) {
nr_gparts -= 1;
/* Swap the particle */
memswap(&s->gparts[k], &s->gparts[nr_gparts], sizeof(struct gpart));
/* Swap the link with part/spart */
if (s->gparts[k].type == swift_type_gas) {
s->parts[-s->gparts[k].id_or_neg_offset].gpart = &s->gparts[k];
} else if (s->gparts[k].type == swift_type_stars) {
s->sparts[-s->gparts[k].id_or_neg_offset].gpart = &s->gparts[k];
}
if (s->gparts[nr_gparts].type == swift_type_gas) {
s->parts[-s->gparts[nr_gparts].id_or_neg_offset].gpart =
&s->gparts[nr_gparts];
} else if (s->gparts[nr_gparts].type == swift_type_stars) {
s->sparts[-s->gparts[nr_gparts].id_or_neg_offset].gpart =
&s->gparts[nr_gparts];
}
/* Swap the index */
memswap(&gind[k], &gind[nr_gparts], sizeof(int));
nr_gparts -= 1;
/* Swap the particle */
memswap(&s->gparts[k], &s->gparts[nr_gparts], sizeof(struct gpart));
/* Swap the link with part/spart */
if (s->gparts[k].type == swift_type_gas) {
s->parts[-s->gparts[k].id_or_neg_offset].gpart = &s->gparts[k];
} else if (s->gparts[k].type == swift_type_stars) {
s->sparts[-s->gparts[k].id_or_neg_offset].gpart = &s->gparts[k];
}
if (s->gparts[nr_gparts].type == swift_type_gas) {
s->parts[-s->gparts[nr_gparts].id_or_neg_offset].gpart =
&s->gparts[nr_gparts];
} else if (s->gparts[nr_gparts].type == swift_type_stars) {
s->sparts[-s->gparts[nr_gparts].id_or_neg_offset].gpart =
&s->gparts[nr_gparts];
}
/* Swap the index */
memswap(&gind[k], &gind[nr_gparts], sizeof(int));
} else {
/* Increment when not exchanging otherwise we need to retest "k".*/
k++;
/* Increment when not exchanging otherwise we need to retest "k".*/
k++;
}
}
}
......
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