From 317c515e1fa9350c68e4fc02eb310cef333adebb Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Tue, 5 May 2020 17:13:03 +0200
Subject: [PATCH] Pass the 'periodic' argument to the MACs

---
 src/cell.c               |  2 +-
 src/gravity_cache.h      |  6 +++---
 src/multipole_accept.h   | 13 ++++++++-----
 src/runner_doiact_grav.c |  5 +++--
 4 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index 332750cd26..d0235f7026 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -6418,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_data);
+                                      use_rebuild_data, periodic);
 }
diff --git a/src/gravity_cache.h b/src/gravity_cache.h
index a1cc3b3b25..8063647911 100644
--- a/src/gravity_cache.h
+++ b/src/gravity_cache.h
@@ -255,8 +255,8 @@ INLINE static void gravity_cache_populate(
     const float r2 = dx * dx + dy * dy + dz * dz;
 
     /* Check whether we can use the multipole instead of P-P */
-    use_mpole[i] = allow_mpole &&
-                   gravity_M2P_accept(grav_props, &gparts[i], multipole, r2);
+    use_mpole[i] = allow_mpole && gravity_M2P_accept(grav_props, &gparts[i],
+                                                     multipole, r2, periodic);
   }
 
 #ifdef SWIFT_DEBUG_CHECKS
@@ -430,7 +430,7 @@ INLINE static void gravity_cache_populate_all_mpole(
     }
     const float r2 = dx * dx + dy * dy + dz * dz;
 
-    if (!gravity_M2P_accept(grav_props, &gparts[i], multipole, r2))
+    if (!gravity_M2P_accept(grav_props, &gparts[i], multipole, r2, periodic))
       error("Using m-pole where the test fails");
 #endif
   }
diff --git a/src/multipole_accept.h b/src/multipole_accept.h
index 5bafa6d175..4cdee61318 100644
--- a/src/multipole_accept.h
+++ b/src/multipole_accept.h
@@ -43,11 +43,12 @@
  * @param r2 The square of the distance between the centres of mass of A and B.
  * @param use_rebuild_sizes Are we considering the sizes at the last tree-build
  * (1) or current sizes (0)?
+ * @param periodic Are we using periodic BCs?
  */
 __attribute__((nonnull, pure)) INLINE static int gravity_M2L_accept(
     const struct gravity_props *props, const struct gravity_tensors *restrict A,
     const struct gravity_tensors *restrict B, const float r2,
-    const int use_rebuild_sizes) {
+    const int use_rebuild_sizes, const int periodic) {
 
   /* Order of the expansion */
   const int p = SELF_GRAVITY_MULTIPOLE_ORDER;
@@ -144,14 +145,15 @@ __attribute__((nonnull, pure)) INLINE static int gravity_M2L_accept(
  * @param r2 The square of the distance between the centres of mass of A and B.
  * @param use_rebuild_sizes Are we considering the sizes at the last tree-build
  * (1) or current sizes (0)?
+ * @param periodic Are we using periodic BCs?
  */
 __attribute__((nonnull, pure)) INLINE static int gravity_M2L_accept_symmetric(
     const struct gravity_props *props, const struct gravity_tensors *restrict A,
     const struct gravity_tensors *restrict B, const float r2,
-    const int use_rebuild_sizes) {
+    const int use_rebuild_sizes, const int periodic) {
 
-  return gravity_M2L_accept(props, A, B, r2, use_rebuild_sizes) &&
-         gravity_M2L_accept(props, B, A, r2, use_rebuild_sizes);
+  return gravity_M2L_accept(props, A, B, r2, use_rebuild_sizes, periodic) &&
+         gravity_M2L_accept(props, B, A, r2, use_rebuild_sizes, periodic);
 }
 
 /**
@@ -164,10 +166,11 @@ __attribute__((nonnull, pure)) INLINE static int gravity_M2L_accept_symmetric(
  * @param pa The particle we want to compute forces for (sink)
  * @param B The gravity tensors that act as a source.
  * @param r2 The square of the distance between pa and the centres of mass of B.
+ * @param periodic Are we using periodic BCs?
  */
 __attribute__((nonnull, pure)) INLINE static int gravity_M2P_accept(
     const struct gravity_props *props, const struct gpart *pa,
-    const struct gravity_tensors *B, const float r2) {
+    const struct gravity_tensors *B, const float r2, const int periodic) {
 
   /* Order of the expansion */
   const int p = SELF_GRAVITY_MULTIPOLE_ORDER;
diff --git a/src/runner_doiact_grav.c b/src/runner_doiact_grav.c
index 5a2f18f18f..8c5824012b 100644
--- a/src/runner_doiact_grav.c
+++ b/src/runner_doiact_grav.c
@@ -1678,7 +1678,7 @@ void runner_dopair_recursive_grav(struct runner *r, struct cell *ci,
 
   /* Can we use M-M interactions ? */
   if (gravity_M2L_accept_symmetric(e->gravity_properties, multi_i, multi_j, r2,
-                                   /* use_rebuild_sizes=*/0)) {
+                                   /* use_rebuild_sizes=*/0, periodic)) {
 
     /* Go M-M */
     runner_dopair_grav_mm(r, ci, cj);
@@ -1906,7 +1906,8 @@ void runner_do_grav_long_range(struct runner *r, struct cell *ci,
 
     /* Are we in charge of this cell pair? */
     if (gravity_M2L_accept_symmetric(e->gravity_properties, multi_top, multi_j,
-                                     r2_rebuild, /*use_rebuild_sizes=*/1)) {
+                                     r2_rebuild, /*use_rebuild_sizes=*/1,
+                                     periodic)) {
 
       /* Call the PM interaction fucntion on the active sub-cells of ci */
       runner_dopair_grav_mm_nonsym(r, ci, cj);
-- 
GitLab