diff --git a/src/cell.c b/src/cell.c index 54bb5bd2c361faa39dbdceb1ed974f0cffedc3df..332750cd26337286af3249d00d06f918a7d70151 100644 --- a/src/cell.c +++ b/src/cell.c @@ -3327,7 +3327,7 @@ void cell_activate_subcell_grav_tasks(struct cell *ci, struct cell *cj, if (lock_unlock(&cj->grav.mlock) != 0) error("Impossible to unlock m-pole"); /* Can we use multipoles ? */ - if (cell_can_use_pair_mm(ci, cj, e, sp, /*use_rebuild_sizes=*/0)) { + if (cell_can_use_pair_mm(ci, cj, e, sp, /*use_rebuild_data=*/0)) { /* Ok, no need to drift anything */ return; } @@ -6381,12 +6381,12 @@ void cell_reorder_extra_gparts(struct cell *c, struct part *parts, * @param cj The second #cell. * @param e The #engine. * @param s The #space. - * @param use_rebuild_sizes Are we considering the sizes at the last tree-build - * (1) or current sizes (0)? + * @param use_rebuild_data Are we considering the data at the last tree-build + * (1) or current data (0)? */ int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, const struct engine *e, const struct space *s, - const int use_rebuild_sizes) { + const int use_rebuild_data) { const struct gravity_props *props = e->gravity_properties; const int periodic = s->periodic; @@ -6396,10 +6396,18 @@ int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, const struct gravity_tensors *const multi_i = ci->grav.multipole; const struct gravity_tensors *const multi_j = cj->grav.multipole; + double dx, dy, dz; + /* Get the distance between the CoMs */ - double dx = multi_i->CoM[0] - multi_j->CoM[0]; - double dy = multi_i->CoM[1] - multi_j->CoM[1]; - double dz = multi_i->CoM[2] - multi_j->CoM[2]; + if (use_rebuild_data) { + dx = multi_i->CoM_rebuild[0] - multi_j->CoM_rebuild[0]; + dy = multi_i->CoM_rebuild[1] - multi_j->CoM_rebuild[1]; + dz = multi_i->CoM_rebuild[2] - multi_j->CoM_rebuild[2]; + } else { + dx = multi_i->CoM[0] - multi_j->CoM[0]; + dy = multi_i->CoM[1] - multi_j->CoM[1]; + dz = multi_i->CoM[2] - multi_j->CoM[2]; + } /* Apply BC */ if (periodic) { @@ -6410,5 +6418,5 @@ int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, const double r2 = dx * dx + dy * dy + dz * dz; return gravity_M2L_accept_symmetric(props, multi_i, multi_j, r2, - use_rebuild_sizes); + use_rebuild_data); } diff --git a/src/cell.h b/src/cell.h index 3dac9514767ddefed485f5e6017c3ed008769e94..b7677a53234970106f60a7236608415bcc1dd54b 100644 --- a/src/cell.h +++ b/src/cell.h @@ -960,7 +960,7 @@ void cell_reorder_extra_gparts(struct cell *c, struct part *parts, void cell_reorder_extra_sparts(struct cell *c, const ptrdiff_t sparts_offset); int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, const struct engine *e, const struct space *s, - const int use_rebuild_sizes); + const int use_rebuild_data); /** * @brief Compute the square of the minimal distance between any two points in diff --git a/src/engine_maketasks.c b/src/engine_maketasks.c index 6bfba81c77b5af12c72a59fa34533dcf6db3e4d0..e34ca2f909288cf0ffc654edc762d4bacae685e3 100644 --- a/src/engine_maketasks.c +++ b/src/engine_maketasks.c @@ -1381,7 +1381,7 @@ void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, if (periodic && min_radius2 > max_distance2) continue; /* Are the cells too close for a MM interaction ? */ - if (!cell_can_use_pair_mm(ci, cj, e, s, /*use_rebuild_sizes=*/1)) { + if (!cell_can_use_pair_mm(ci, cj, e, s, /*use_rebuild_data=*/1)) { /* Ok, we need to add a direct pair calculation */ scheduler_addtask(sched, task_type_pair, task_subtype_grav, 0, 0, diff --git a/src/scheduler.c b/src/scheduler.c index 6ef6722802f9d6b392c8c2dbe96ce4a8a7af97de..7a76ab2faabbb2c582c057cadad4708d98feb7e1 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -873,7 +873,7 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { if (cj->progeny[j] != NULL) { /* Can we use a M-M interaction here? */ if (cell_can_use_pair_mm(ci->progeny[i], cj->progeny[j], e, - sp, /*use_rebuild_sizes=*/1)) { + sp, /*use_rebuild_data=*/1)) { /* Flag this pair as being treated by the M-M task. * We use the 64 bits in the task->flags field to store