From dcb0fd7a7c2cae484f4b42396b251ab3d0012b54 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Wed, 24 Aug 2016 10:24:04 +0100 Subject: [PATCH] Style change in cell_is_drift_needed() and early abort in the drift when dt==0 --- src/cell.c | 10 ++++------ src/runner.c | 3 +++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cell.c b/src/cell.c index 094645ba50..dfbfe5fc00 100644 --- a/src/cell.c +++ b/src/cell.c @@ -829,12 +829,10 @@ int cell_is_drift_needed(struct cell *c, int ti_current) { if (l->t->type != task_type_pair && l->t->type != task_type_sub_pair) continue; - /* Left or right? */ - if (l->t->ci == c) { - if (l->t->cj->ti_end_min == ti_current) return 1; - } else if (l->t->cj == c) { - if (l->t->ci->ti_end_min == ti_current) return 1; - } + /* Does the other cell in the pair have an active particle ? */ + if ((l->t->ci == c) && (l->t->cj->ti_end_min == ti_current) || + (l->t->cj == c) && (l->t->ci->ti_end_min == ti_current)) + return 1; } /* No neighbouring cell has active particles. Drift not necessary */ diff --git a/src/runner.c b/src/runner.c index 57a6b9de70..87de99ba72 100644 --- a/src/runner.c +++ b/src/runner.c @@ -650,6 +650,9 @@ static void runner_do_drift(struct cell *c, struct engine *e) { /* Do we need to drift ? */ if (!e->drift_all && !cell_is_drift_needed(c, ti_current)) return; + /* Check that we are actually going to move forward. */ + if (ti_current == ti_old) return; + /* Drift from the last time the cell was drifted to the current time */ const double dt = (ti_current - ti_old) * timeBase; -- GitLab