From 7fac9be5aa7aa38079aa4e297f906215488d3dab Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Sun, 26 Aug 2018 13:45:16 +0100
Subject: [PATCH] Only copy the multipole information that is required and not
 the full gravity information.

---
 src/cell.c      | 36 ++++++++++++++++++++++++++++++++----
 src/cell.h      | 14 +++++++++++++-
 src/multipole.h |  6 +++---
 3 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index 2919839d50..7a50e80000 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -178,8 +178,6 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc,
 #ifdef WITH_MPI
 
   /* Start by packing the data of the current cell. */
-  if(with_gravity)
-    pc->multipole = *(c->multipole);
   pc->h_max = c->h_max;
   pc->ti_hydro_end_min = c->ti_hydro_end_min;
   pc->ti_hydro_end_max = c->ti_hydro_end_max;
@@ -192,6 +190,22 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc,
   pc->gcount = c->gcount;
   pc->scount = c->scount;
 
+  /* Copy the Multipole related information */
+  if(with_gravity) {
+    const struct gravity_tensors *mp = c->multipole;
+
+    pc->m_pole = mp->m_pole;
+    pc->CoM[0] = mp->CoM[0];
+    pc->CoM[1] = mp->CoM[1];
+    pc->CoM[2] = mp->CoM[2];
+    pc->CoM_rebuild[0] = mp->CoM_rebuild[0];
+    pc->CoM_rebuild[1] = mp->CoM_rebuild[1];
+    pc->CoM_rebuild[2] = mp->CoM_rebuild[2];
+    pc->r_max = mp->r_max;
+    pc->r_max_rebuild = mp->r_max_rebuild;
+  }
+
+
 #ifdef SWIFT_DEBUG_CHECKS
   pc->cellID = c->cellID;
 #endif
@@ -267,8 +281,6 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c,
 #ifdef WITH_MPI
 
   /* Unpack the current pcell. */
-  if(with_gravity)
-    *(c->multipole) = pc->multipole;
   c->h_max = pc->h_max;
   c->ti_hydro_end_min = pc->ti_hydro_end_min;
   c->ti_hydro_end_max = pc->ti_hydro_end_max;
@@ -284,6 +296,22 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c,
   c->cellID = pc->cellID;
 #endif
 
+  /* Copy the Multipole related information */
+  if(with_gravity) {
+
+    struct gravity_tensors *mp = c->multipole;
+
+    mp->m_pole = pc->m_pole;
+    mp->CoM[0] = pc->CoM[0];
+    mp->CoM[1] = pc->CoM[1];
+    mp->CoM[2] = pc->CoM[2];
+    mp->CoM_rebuild[0] = pc->CoM_rebuild[0];
+    mp->CoM_rebuild[1] = pc->CoM_rebuild[1];
+    mp->CoM_rebuild[2] = pc->CoM_rebuild[2];
+    mp->r_max = pc->r_max;
+    mp->r_max_rebuild = pc->r_max_rebuild;
+  }
+    
   /* Number of new cells created. */
   int count = 1;
 
diff --git a/src/cell.h b/src/cell.h
index c209f8d99b..8e53bb185e 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -78,7 +78,19 @@ struct link {
 struct pcell {
 
   /*! This cell's gravity-related tensors */
-  struct gravity_tensors multipole;
+  struct multipole m_pole;
+  
+  /*! Centre of mass. */
+  double CoM[3];
+
+  /*! Centre of mass at rebuild time. */
+  double CoM_rebuild[3];
+
+  /*! Upper limit of the CoM<->gpart distance. */
+  double r_max;
+
+  /*! Upper limit of the CoM<->gpart distance at last rebuild. */
+  double r_max_rebuild;
 
   /*! Relative indices of the cell's progeny. */
   int progeny[8];
diff --git a/src/multipole.h b/src/multipole.h
index c05aa36890..2ada835e32 100644
--- a/src/multipole.h
+++ b/src/multipole.h
@@ -186,12 +186,12 @@ struct gravity_tensors {
     /*! The actual content */
     struct {
 
-      /*! Multipole mass */
-      struct multipole m_pole;
-
       /*! Field tensor for the potential */
       struct grav_tensor pot;
 
+      /*! Multipole mass */
+      struct multipole m_pole;
+
       /*! Centre of mass of the matter dsitribution */
       double CoM[3];
 
-- 
GitLab