From 96167fb9969eb51e5c4861cb92d265ea4bb40a9e Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Tue, 25 Jun 2019 09:52:46 +0100 Subject: [PATCH] Update the gpart mass when synchronizing when the star or BH mass changes. --- src/part.c | 34 ++++++++++++++++++++++++++++++++++ src/space.c | 8 +++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/part.c b/src/part.c index 9394ab314b..7d967caad1 100644 --- a/src/part.c +++ b/src/part.c @@ -30,6 +30,7 @@ /* Local headers */ #include "error.h" +#include "hydro.h" #include "part.h" /** @@ -210,6 +211,13 @@ void part_verify_links(struct part *parts, struct gpart *gparts, part->x[1], part->x[2], gparts[k].x[0] - part->x[0], gparts[k].x[1] - part->x[1], gparts[k].x[2] - part->x[2]); + /* Check that the particles have the same mass */ + if (gparts[k].mass != hydro_get_mass(part)) + error( + "Linked particles do not have the same mass!\n" + "gp->m=%e p->m=%e", + gparts[k].mass, hydro_get_mass(part)); + /* Check that the particles are at the same time */ if (gparts[k].time_bin != part->time_bin) error("Linked particles are not at the same time !"); @@ -237,6 +245,13 @@ void part_verify_links(struct part *parts, struct gpart *gparts, spart->x[1], spart->x[2], gparts[k].x[0] - spart->x[0], gparts[k].x[1] - spart->x[1], gparts[k].x[2] - spart->x[2]); + /* Check that the particles have the same mass */ + if (gparts[k].mass != spart->mass) + error( + "Linked particles do not have the same mass!\n" + "gp->m=%e sp->m=%e", + gparts[k].mass, spart->mass); + /* Check that the particles are at the same time */ if (gparts[k].time_bin != spart->time_bin) error("Linked particles are not at the same time !"); @@ -264,6 +279,13 @@ void part_verify_links(struct part *parts, struct gpart *gparts, bpart->x[1], bpart->x[2], gparts[k].x[0] - bpart->x[0], gparts[k].x[1] - bpart->x[1], gparts[k].x[2] - bpart->x[2]); + /* Check that the particles have the same mass */ + if (gparts[k].mass != bpart->mass) + error( + "Linked particles do not have the same mass!\n" + "gp->m=%e sp->m=%e", + gparts[k].mass, bpart->mass); + /* Check that the particles are at the same time */ if (gparts[k].time_bin != bpart->time_bin) error("Linked particles are not at the same time !"); @@ -287,6 +309,10 @@ void part_verify_links(struct part *parts, struct gpart *gparts, parts[k].x[2] != parts[k].gpart->x[2]) error("Linked particles are not at the same position !"); + /* Check that the particles have the same mass */ + if (hydro_get_mass(&parts[k]) != parts[k].gpart->mass) + error("Linked particles do not have the same mass!\n"); + /* Check that the particles are at the same time */ if (parts[k].time_bin != parts[k].gpart->time_bin) error("Linked particles are not at the same time !"); @@ -309,6 +335,10 @@ void part_verify_links(struct part *parts, struct gpart *gparts, sparts[k].x[2] != sparts[k].gpart->x[2]) error("Linked particles are not at the same position !"); + /* Check that the particles have the same mass */ + if (sparts[k].mass != sparts[k].gpart->mass) + error("Linked particles do not have the same mass!\n"); + /* Check that the particles are at the same time */ if (sparts[k].time_bin != sparts[k].gpart->time_bin) error("Linked particles are not at the same time !"); @@ -332,6 +362,10 @@ void part_verify_links(struct part *parts, struct gpart *gparts, bparts[k].x[2] != bparts[k].gpart->x[2]) error("Linked particles are not at the same position !"); + /* Check that the particles have the same mass */ + if (bparts[k].mass != bparts[k].gpart->mass) + error("Linked particles do not have the same mass!\n"); + /* Check that the particles are at the same time */ if (bparts[k].time_bin != bparts[k].gpart->time_bin) error("Linked particles are not at the same time !"); diff --git a/src/space.c b/src/space.c index 488672eb0b..8b76b2d7ee 100644 --- a/src/space.c +++ b/src/space.c @@ -3934,7 +3934,7 @@ void space_synchronize_particle_positions_mapper(void *map_data, int nr_gparts, for (int k = 0; k < nr_gparts; k++) { /* Get the particle */ - const struct gpart *restrict gp = &gparts[k]; + struct gpart *restrict gp = &gparts[k]; if (gp->type == swift_type_dark_matter) continue; @@ -3953,6 +3953,8 @@ void space_synchronize_particle_positions_mapper(void *map_data, int nr_gparts, xp->v_full[0] = gp->v_full[0]; xp->v_full[1] = gp->v_full[1]; xp->v_full[2] = gp->v_full[2]; + + gp->mass = p->mass; } else if (gp->type == swift_type_stars) { @@ -3964,6 +3966,8 @@ void space_synchronize_particle_positions_mapper(void *map_data, int nr_gparts, sp->x[0] = gp->x[0]; sp->x[1] = gp->x[1]; sp->x[2] = gp->x[2]; + + gp->mass = sp->mass; } else if (gp->type == swift_type_black_hole) { @@ -3975,6 +3979,8 @@ void space_synchronize_particle_positions_mapper(void *map_data, int nr_gparts, bp->x[0] = gp->x[0]; bp->x[1] = gp->x[1]; bp->x[2] = gp->x[2]; + + gp->mass = bp->mass; } } } -- GitLab