Skip to content
Snippets Groups Projects
Commit 160e3ac9 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

In the BH loops, only abort the BH-gas loop if there is no gas and not also the BH-BH loop.

parent 1d8b665c
No related branches found
No related tags found
No related merge requests found
...@@ -105,7 +105,7 @@ void DOSELF1_BH(struct runner *r, struct cell *c, int timer) { ...@@ -105,7 +105,7 @@ void DOSELF1_BH(struct runner *r, struct cell *c, int timer) {
const struct cosmology *cosmo = e->cosmology; const struct cosmology *cosmo = e->cosmology;
/* Anything to do here? */ /* Anything to do here? */
if (c->hydro.count == 0 || c->black_holes.count == 0) return; if (c->black_holes.count == 0) return;
if (!cell_is_active_black_holes(c, e)) return; if (!cell_is_active_black_holes(c, e)) return;
const int bcount = c->black_holes.count; const int bcount = c->black_holes.count;
...@@ -114,52 +114,56 @@ void DOSELF1_BH(struct runner *r, struct cell *c, int timer) { ...@@ -114,52 +114,56 @@ void DOSELF1_BH(struct runner *r, struct cell *c, int timer) {
struct part *restrict parts = c->hydro.parts; struct part *restrict parts = c->hydro.parts;
struct xpart *restrict xparts = c->hydro.xparts; struct xpart *restrict xparts = c->hydro.xparts;
/* Loop over the bparts in ci. */ /* Do we actually have any gas neighbours? */
for (int bid = 0; bid < bcount; bid++) { if (c->hydro.count != 0) {
/* Get a hold of the ith bpart in ci. */ /* Loop over the bparts in ci. */
struct bpart *restrict bi = &bparts[bid]; for (int bid = 0; bid < bcount; bid++) {
/* Skip inactive particles */ /* Get a hold of the ith bpart in ci. */
if (!bpart_is_active(bi, e)) continue; struct bpart *restrict bi = &bparts[bid];
const float hi = bi->h; /* Skip inactive particles */
const float hig2 = hi * hi * kernel_gamma2; if (!bpart_is_active(bi, e)) continue;
const float bix[3] = {(float)(bi->x[0] - c->loc[0]),
(float)(bi->x[1] - c->loc[1]),
(float)(bi->x[2] - c->loc[2])};
/* Loop over the parts in cj. */ const float hi = bi->h;
for (int pjd = 0; pjd < count; pjd++) { const float hig2 = hi * hi * kernel_gamma2;
const float bix[3] = {(float)(bi->x[0] - c->loc[0]),
(float)(bi->x[1] - c->loc[1]),
(float)(bi->x[2] - c->loc[2])};
/* Get a pointer to the jth particle. */ /* Loop over the parts in cj. */
struct part *restrict pj = &parts[pjd]; for (int pjd = 0; pjd < count; pjd++) {
struct xpart *restrict xpj = &xparts[pjd];
const float hj = pj->h;
/* Early abort? */ /* Get a pointer to the jth particle. */
if (part_is_inhibited(pj, e)) continue; struct part *restrict pj = &parts[pjd];
struct xpart *restrict xpj = &xparts[pjd];
const float hj = pj->h;
/* Compute the pairwise distance. */ /* Early abort? */
const float pjx[3] = {(float)(pj->x[0] - c->loc[0]), if (part_is_inhibited(pj, e)) continue;
(float)(pj->x[1] - c->loc[1]),
(float)(pj->x[2] - c->loc[2])}; /* Compute the pairwise distance. */
float dx[3] = {bix[0] - pjx[0], bix[1] - pjx[1], bix[2] - pjx[2]}; const float pjx[3] = {(float)(pj->x[0] - c->loc[0]),
const float r2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2]; (float)(pj->x[1] - c->loc[1]),
(float)(pj->x[2] - c->loc[2])};
float dx[3] = {bix[0] - pjx[0], bix[1] - pjx[1], bix[2] - pjx[2]};
const float r2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
#ifdef SWIFT_DEBUG_CHECKS #ifdef SWIFT_DEBUG_CHECKS
/* Check that particles have been drifted to the current time */ /* Check that particles have been drifted to the current time */
if (bi->ti_drift != e->ti_current) if (bi->ti_drift != e->ti_current)
error("Particle bi not drifted to current time"); error("Particle bi not drifted to current time");
if (pj->ti_drift != e->ti_current) if (pj->ti_drift != e->ti_current)
error("Particle pj not drifted to current time"); error("Particle pj not drifted to current time");
#endif #endif
if (r2 < hig2) { if (r2 < hig2) {
IACT_BH_GAS(r2, dx, hi, hj, bi, pj, xpj, cosmo, ti_current); IACT_BH_GAS(r2, dx, hi, hj, bi, pj, xpj, cosmo, ti_current);
} }
} /* loop over the parts in ci. */ } /* loop over the parts in ci. */
} /* loop over the bparts in ci. */ } /* loop over the bparts in ci. */
} /* Do we have gas particles in the cell? */
/* When doing BH swallowing, we need a quick loop also over the BH /* When doing BH swallowing, we need a quick loop also over the BH
* neighbours */ * neighbours */
...@@ -243,7 +247,7 @@ void DO_NONSYM_PAIR1_BH_NAIVE(struct runner *r, struct cell *restrict ci, ...@@ -243,7 +247,7 @@ void DO_NONSYM_PAIR1_BH_NAIVE(struct runner *r, struct cell *restrict ci,
const struct cosmology *cosmo = e->cosmology; const struct cosmology *cosmo = e->cosmology;
/* Anything to do here? */ /* Anything to do here? */
if (cj->hydro.count == 0 || ci->black_holes.count == 0) return; if (ci->black_holes.count == 0) return;
if (!cell_is_active_black_holes(ci, e)) return; if (!cell_is_active_black_holes(ci, e)) return;
const int bcount_i = ci->black_holes.count; const int bcount_i = ci->black_holes.count;
...@@ -261,52 +265,56 @@ void DO_NONSYM_PAIR1_BH_NAIVE(struct runner *r, struct cell *restrict ci, ...@@ -261,52 +265,56 @@ void DO_NONSYM_PAIR1_BH_NAIVE(struct runner *r, struct cell *restrict ci,
shift[k] = -e->s->dim[k]; shift[k] = -e->s->dim[k];
} }
/* Loop over the bparts in ci. */ /* Do we actually have any gas neighbours? */
for (int bid = 0; bid < bcount_i; bid++) { if (cj->hydro.count != 0) {
/* Get a hold of the ith bpart in ci. */ /* Loop over the bparts in ci. */
struct bpart *restrict bi = &bparts_i[bid]; for (int bid = 0; bid < bcount_i; bid++) {
/* Skip inactive particles */ /* Get a hold of the ith bpart in ci. */
if (!bpart_is_active(bi, e)) continue; struct bpart *restrict bi = &bparts_i[bid];
const float hi = bi->h; /* Skip inactive particles */
const float hig2 = hi * hi * kernel_gamma2; if (!bpart_is_active(bi, e)) continue;
const float bix[3] = {(float)(bi->x[0] - (cj->loc[0] + shift[0])),
(float)(bi->x[1] - (cj->loc[1] + shift[1])),
(float)(bi->x[2] - (cj->loc[2] + shift[2]))};
/* Loop over the parts in cj. */ const float hi = bi->h;
for (int pjd = 0; pjd < count_j; pjd++) { const float hig2 = hi * hi * kernel_gamma2;
const float bix[3] = {(float)(bi->x[0] - (cj->loc[0] + shift[0])),
(float)(bi->x[1] - (cj->loc[1] + shift[1])),
(float)(bi->x[2] - (cj->loc[2] + shift[2]))};
/* Get a pointer to the jth particle. */ /* Loop over the parts in cj. */
struct part *restrict pj = &parts_j[pjd]; for (int pjd = 0; pjd < count_j; pjd++) {
struct xpart *restrict xpj = &xparts_j[pjd];
const float hj = pj->h;
/* Skip inhibited particles. */ /* Get a pointer to the jth particle. */
if (part_is_inhibited(pj, e)) continue; struct part *restrict pj = &parts_j[pjd];
struct xpart *restrict xpj = &xparts_j[pjd];
const float hj = pj->h;
/* Compute the pairwise distance. */ /* Skip inhibited particles. */
const float pjx[3] = {(float)(pj->x[0] - cj->loc[0]), if (part_is_inhibited(pj, e)) continue;
(float)(pj->x[1] - cj->loc[1]),
(float)(pj->x[2] - cj->loc[2])}; /* Compute the pairwise distance. */
float dx[3] = {bix[0] - pjx[0], bix[1] - pjx[1], bix[2] - pjx[2]}; const float pjx[3] = {(float)(pj->x[0] - cj->loc[0]),
const float r2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2]; (float)(pj->x[1] - cj->loc[1]),
(float)(pj->x[2] - cj->loc[2])};
float dx[3] = {bix[0] - pjx[0], bix[1] - pjx[1], bix[2] - pjx[2]};
const float r2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
#ifdef SWIFT_DEBUG_CHECKS #ifdef SWIFT_DEBUG_CHECKS
/* Check that particles have been drifted to the current time */ /* Check that particles have been drifted to the current time */
if (bi->ti_drift != e->ti_current) if (bi->ti_drift != e->ti_current)
error("Particle bi not drifted to current time"); error("Particle bi not drifted to current time");
if (pj->ti_drift != e->ti_current) if (pj->ti_drift != e->ti_current)
error("Particle pj not drifted to current time"); error("Particle pj not drifted to current time");
#endif #endif
if (r2 < hig2) { if (r2 < hig2) {
IACT_BH_GAS(r2, dx, hi, hj, bi, pj, xpj, cosmo, ti_current); IACT_BH_GAS(r2, dx, hi, hj, bi, pj, xpj, cosmo, ti_current);
} }
} /* loop over the parts in cj. */ } /* loop over the parts in cj. */
} /* loop over the bparts in ci. */ } /* loop over the bparts in ci. */
} /* Do we have gas particles in the cell? */
/* When doing BH swallowing, we need a quick loop also over the BH /* When doing BH swallowing, we need a quick loop also over the BH
* neighbours */ * neighbours */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment