diff --git a/src/active.h b/src/active.h index 17adfd07d2bfe0519f0b432217d5253de13c4b78..f0aba74df440e9538634bfe6a848d9ee9bcd1674 100644 --- a/src/active.h +++ b/src/active.h @@ -28,6 +28,34 @@ #include "engine.h" #include "part.h" +/** + * @brief Check that a cell been drifted to the current time. + * + * Only used for debugging. Calls error() if the cell has not + * been drifted. Does nothing if SWIFT_DEBUG_CHECKS is not defined. + * + * @param c The #cell. + * @param e The #engine containing information about the current time. + */ +__attribute__((always_inline)) INLINE static void cell_is_drifted( + const struct cell *c, const struct engine *e) { + +#ifdef SWIFT_DEBUG_CHECKS + if (c->ti_old > e->ti_current) + error( + "Cell has been drifted too far forward in time! c->ti_old=%d " + "e->ti_current=%d", + c->ti_old, e->ti_current); + + if (c->ti_old != e->ti_current) { + error( + "Cell has not been drifted to the current time c->ti_old=%d, " + "e->ti_current=%d", + c->ti_old, e->ti_current); + } +#endif +} + /** * @brief Does a cell contain any active particle ? * diff --git a/src/runner_doiact.h b/src/runner_doiact.h index c067d3bc9a576ee9c7dfb6e910eb1aa01012f755..f4183c8024c0539379031248f1d190726065b34d 100644 --- a/src/runner_doiact.h +++ b/src/runner_doiact.h @@ -721,6 +721,11 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj) { /* Anything to do here? */ if (!cell_is_active(ci, e) && !cell_is_active(cj, e)) return; +#ifdef SWIFT_DEBUG_CHECKS + cell_is_drifted(ci, e); + cell_is_drifted(cj, e); +#endif + /* Get the sort ID. */ double shift[3] = {0.0, 0.0, 0.0}; const int sid = space_getsid(e->s, &ci, &cj, shift); @@ -913,6 +918,11 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj) { /* Anything to do here? */ if (!cell_is_active(ci, e) && !cell_is_active(cj, e)) return; +#ifdef SWIFT_DEBUG_CHECKS + cell_is_drifted(ci, e); + cell_is_drifted(cj, e); +#endif + /* Get the shift ID. */ double shift[3] = {0.0, 0.0, 0.0}; const int sid = space_getsid(e->s, &ci, &cj, shift); @@ -1303,6 +1313,10 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { if (!cell_is_active(c, e)) return; +#ifdef SWIFT_DEBUG_CHECKS + cell_is_drifted(ci, e); +#endif + struct part *restrict parts = c->parts; const int count = c->count; @@ -1534,6 +1548,10 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { if (!cell_is_active(c, e)) return; +#ifdef SWIFT_DEBUG_CHECKS + cell_is_drifted(ci, e); +#endif + struct part *restrict parts = c->parts; const int count = c->count;