diff --git a/src/black_holes/EAGLE/black_holes_iact.h b/src/black_holes/EAGLE/black_holes_iact.h index 0bfe2a51e8327dcb33e4d0f390cad530633094fd..bd3d8f0ce20a25f09c432c61a311593ba6656799 100644 --- a/src/black_holes/EAGLE/black_holes_iact.h +++ b/src/black_holes/EAGLE/black_holes_iact.h @@ -219,11 +219,12 @@ runner_iact_nonsym_bh_bh_swallow(const float r2, const float *dx, const float G = 43.; // MATTHIEU: Fix this!!! - /* The BH with the smaller ID will be merged onto the one with the larger ID - */ - if (bj->id < bi->id) { - - message("ID is smaller"); + /* The BH with the smaller mass will be merged onto the one with the + * larger mass. + * To avoid rounding issues, we additionally check for IDs if the BHs + * have the exact same mass. */ + if ((bj->subgrid_mass < bi->subgrid_mass) || + (bj->subgrid_mass == bi->subgrid_mass && bj->id < bi->id)) { /* Merge if gravitationally bound * Note that we use the kernel support here as the size and not just the @@ -234,11 +235,15 @@ runner_iact_nonsym_bh_bh_swallow(const float r2, const float *dx, /* This particle is swallowed by the BH with the largest ID of all the * candidates wanting to swallow it */ - if (bj->merger_data.swallow_id < bi->id) { + if ((bj->merger_data.swallow_mass < bi->subgrid_mass) || + (bj->merger_data.swallow_mass == bi->subgrid_mass && + bj->merger_data.swallow_id < bi->id)) { message("BH %lld wants to swallow BH particle %lld", bi->id, bj->id); bj->merger_data.swallow_id = bi->id; + bj->merger_data.swallow_mass = bi->subgrid_mass; + } else { message( diff --git a/src/black_holes/EAGLE/black_holes_struct.h b/src/black_holes/EAGLE/black_holes_struct.h index 96d9afd4d7d2d873ad3f412674ccf5ae1cc5e7ed..98f5380e9f32ced36bcf2e4e3f02eaeb89db7218 100644 --- a/src/black_holes/EAGLE/black_holes_struct.h +++ b/src/black_holes/EAGLE/black_holes_struct.h @@ -35,6 +35,9 @@ struct black_holes_bpart_data { /*! ID of the black-hole that will swallow this #bpart. */ long long swallow_id; + + /*! Mass of the black-hole that will swallow this #bpart. */ + float swallow_mass; }; /** @@ -82,6 +85,7 @@ __attribute__((always_inline)) INLINE static void black_holes_mark_bpart_as_not_swallowed(struct black_holes_bpart_data* p_data) { p_data->swallow_id = -1; + p_data->swallow_mass = 0.f; } /** @@ -94,6 +98,7 @@ __attribute__((always_inline)) INLINE static void black_holes_mark_bpart_as_merged(struct black_holes_bpart_data* p_data) { p_data->swallow_id = -2; + p_data->swallow_mass = -1.f; } /**