Commit a26f42b5 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Update the black_holes_struct.h file to contain a structure for the BHs and...

Update the black_holes_struct.h file to contain a structure for the BHs and added functions to manipulate the structure.
parent df9e7d53
......@@ -36,7 +36,7 @@ struct black_holes_bpart_data {};
* @param p_data The #part's #black_holes_part_data structure.
*/
__attribute__((always_inline)) INLINE static void
black_holes_mark_as_not_swallowed(struct black_holes_part_data* p_data) {
black_holes_mark_part_as_not_swallowed(struct black_holes_part_data* p_data) {
/* Nothing to do here: No swallowing in the default model */
}
......@@ -47,8 +47,8 @@ black_holes_mark_as_not_swallowed(struct black_holes_part_data* p_data) {
*
* @param p_data The #part's #black_holes_part_data structure.
*/
__attribute__((always_inline)) INLINE static void black_holes_mark_as_swallowed(
struct black_holes_part_data* p_data) {
__attribute__((always_inline)) INLINE static void
black_holes_mark_part_as_swallowed(struct black_holes_part_data* p_data) {
/* Nothing to do here: No swallowing in the default model */
}
......@@ -59,7 +59,43 @@ __attribute__((always_inline)) INLINE static void black_holes_mark_as_swallowed(
* @param p_data The #part's #black_holes_part_data structure.
*/
__attribute__((always_inline)) INLINE static long long
black_holes_get_swallow_id(struct black_holes_part_data* p_data) {
black_holes_get_part_swallow_id(struct black_holes_part_data* p_data) {
/* Return a non-existing ID */
return -1;
}
/**
* @brief Update a given #bpart's BH data field to mark the particle has
* not yet been swallowed.
*
* @param p_data The #bpart's #black_holes_bpart_data structure.
*/
__attribute__((always_inline)) INLINE static void
black_holes_mark_bpart_as_not_swallowed(struct black_holes_bpart_data* p_data) {
/* Nothing to do here: No merging in the default model */
}
/**
* @brief Update a given #bpart's BH data field to mark the particle has
* having been been swallowed.
*
* @param p_data The #bpart's #black_holes_bpart_data structure.
*/
__attribute__((always_inline)) INLINE static void
black_holes_mark_bpart_as_merged(struct black_holes_part_data* p_data) {
/* Nothing to do here: No merging in the default model */
}
/**
* @brief Return the ID of the BH that should swallow this #bpart.
*
* @param p_data The #bpart's #black_holes_bpart_data structure.
*/
__attribute__((always_inline)) INLINE static long long
black_holes_get_bpart_swallow_id(struct black_holes_bpart_data* p_data) {
/* Return a non-existing ID */
return -1;
......
......@@ -44,7 +44,7 @@ struct black_holes_bpart_data {
* @param p_data The #part's #black_holes_part_data structure.
*/
__attribute__((always_inline)) INLINE static void
black_holes_mark_as_not_swallowed(struct black_holes_part_data* p_data) {
black_holes_mark_part_as_not_swallowed(struct black_holes_part_data* p_data) {
p_data->swallow_id = -1;
}
......@@ -55,8 +55,8 @@ black_holes_mark_as_not_swallowed(struct black_holes_part_data* p_data) {
*
* @param p_data The #part's #black_holes_part_data structure.
*/
__attribute__((always_inline)) INLINE static void black_holes_mark_as_swallowed(
struct black_holes_part_data* p_data) {
__attribute__((always_inline)) INLINE static void
black_holes_mark_part_as_swallowed(struct black_holes_part_data* p_data) {
p_data->swallow_id = -2;
}
......@@ -67,7 +67,42 @@ __attribute__((always_inline)) INLINE static void black_holes_mark_as_swallowed(
* @param p_data The #part's #black_holes_part_data structure.
*/
__attribute__((always_inline)) INLINE static long long
black_holes_get_swallow_id(struct black_holes_part_data* p_data) {
black_holes_get_part_swallow_id(struct black_holes_part_data* p_data) {
return p_data->swallow_id;
}
/**
* @brief Update a given #bpart's BH data field to mark the particle has
* not yet been swallowed.
*
* @param p_data The #bpart's #black_holes_bpart_data structure.
*/
__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;
}
/**
* @brief Update a given #bpart's BH data field to mark the particle has
* having been been swallowed.
*
* @param p_data The #bpart's #black_holes_bpart_data structure.
*/
__attribute__((always_inline)) INLINE static void
black_holes_mark_bpart_as_merged(struct black_holes_part_data* p_data) {
p_data->swallow_id = -2;
}
/**
* @brief Return the ID of the BH that should swallow this #bpart.
*
* @param p_data The #bpart's #black_holes_bpart_data structure.
*/
__attribute__((always_inline)) INLINE static long long
black_holes_get_bpart_swallow_id(struct black_holes_bpart_data* p_data) {
return p_data->swallow_id;
}
......
......@@ -4371,7 +4371,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) {
cell_h_max = max(cell_h_max, p->h);
/* Mark the particle has not being swallowed */
black_holes_mark_as_not_swallowed(&p->black_holes_data);
black_holes_mark_part_as_not_swallowed(&p->black_holes_data);
/* Get ready for a density calculation */
if (part_is_active(p, e)) {
......@@ -4816,6 +4816,9 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) {
/* Maximal smoothing length */
cell_h_max = max(cell_h_max, bp->h);
/* Mark the particle has not being swallowed */
black_holes_mark_bpart_as_not_swallowed(&bp->merger_data);
/* Get ready for a density calculation */
if (bpart_is_active(bp, e)) {
black_holes_init_bpart(bp);
......
......@@ -3778,7 +3778,7 @@ void runner_do_swallow(struct runner *r, struct cell *c, int timer) {
/* Get the ID of the black holes that will swallow this part */
const long long swallow_id =
black_holes_get_swallow_id(&p->black_holes_data);
black_holes_get_part_swallow_id(&p->black_holes_data);
/* Has this particle been flagged for swallowing? */
if (swallow_id >= 0) {
......@@ -3827,7 +3827,7 @@ void runner_do_swallow(struct runner *r, struct cell *c, int timer) {
}
/* In any case, prevent the particle from being re-swallowed */
black_holes_mark_as_swallowed(&p->black_holes_data);
black_holes_mark_part_as_swallowed(&p->black_holes_data);
found = 1;
break;
......
......@@ -4081,7 +4081,7 @@ void space_first_init_parts_mapper(void *restrict map_data, int count,
cool_func);
/* And the black hole markers */
black_holes_mark_as_not_swallowed(&p[k].black_holes_data);
black_holes_mark_part_as_not_swallowed(&p[k].black_holes_data);
#ifdef SWIFT_DEBUG_CHECKS
/* Check part->gpart->part linkeage. */
......@@ -4309,6 +4309,9 @@ void space_first_init_bparts_mapper(void *restrict map_data, int count,
black_holes_first_init_bpart(&bp[k], props);
/* And the black hole merger markers */
black_holes_mark_bpart_as_not_swallowed(&bp[k].merger_data);
#ifdef SWIFT_DEBUG_CHECKS
if (bp[k].gpart && bp[k].gpart->id_or_neg_offset != -(k + delta))
error("Invalid gpart -> bpart link");
......@@ -5215,8 +5218,8 @@ void space_check_limiter(struct space *s) {
/**
* @brief #threadpool mapper function for the swallow debugging check
*/
void space_check_swallow_mapper(void *map_data, int nr_parts,
void *extra_data) {
void space_check_part_swallow_mapper(void *map_data, int nr_parts,
void *extra_data) {
#ifdef SWIFT_DEBUG_CHECKS
/* Unpack the data */
struct part *restrict parts = (struct part *)map_data;
......@@ -5227,7 +5230,7 @@ void space_check_swallow_mapper(void *map_data, int nr_parts,
if (parts[k].time_bin == time_bin_inhibited) continue;
const long long swallow_id =
black_holes_get_swallow_id(&parts[k].black_holes_data);
black_holes_get_part_swallow_id(&parts[k].black_holes_data);
if (swallow_id != -1)
error("Particle has not been swallowed! id=%lld", parts[k].id);
......@@ -5237,6 +5240,31 @@ void space_check_swallow_mapper(void *map_data, int nr_parts,
#endif
}
/**
* @brief #threadpool mapper function for the swallow debugging check
*/
void space_check_bpart_swallow_mapper(void *map_data, int nr_bparts,
void *extra_data) {
#ifdef SWIFT_DEBUG_CHECKS
/* Unpack the data */
struct bpart *restrict bparts = (struct bpart *)map_data;
/* Verify that all particles have been swallowed or are untouched */
for (int k = 0; k < nr_bparts; k++) {
if (bparts[k].time_bin == time_bin_inhibited) continue;
const long long swallow_id =
black_holes_get_bpart_swallow_id(&bparts[k].merger_data);
if (swallow_id != -1)
error("BH particle has not been swallowed! id=%lld", bparts[k].id);
}
#else
error("Calling debugging code without debugging flag activated.");
#endif
}
/**
* @brief Checks that all particles have their swallow flag in a "no swallow"
* state.
......@@ -5248,8 +5276,11 @@ void space_check_swallow_mapper(void *map_data, int nr_parts,
void space_check_swallow(struct space *s) {
#ifdef SWIFT_DEBUG_CHECKS
threadpool_map(&s->e->threadpool, space_check_swallow_mapper, s->parts,
s->nr_parts, sizeof(struct part), 1000, NULL);
threadpool_map(&s->e->threadpool, space_check_part_swallow_mapper, s->parts,
s->nr_parts, sizeof(struct part), 0, NULL);
threadpool_map(&s->e->threadpool, space_check_bpart_swallow_mapper, s->bparts,
s->nr_bparts, sizeof(struct bpart), 0, NULL);
#else
error("Calling debugging code without debugging flag activated.");
#endif
......
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