From c66f6f88264d27fc8e234a53ed2fb5ba2ca53b67 Mon Sep 17 00:00:00 2001
From: Pedro Gonnet <gonnet@google.com>
Date: Fri, 19 Apr 2019 00:31:56 +0200
Subject: [PATCH] replace c->hydro.do_sub_limiter with
 cell_flag_do_hydro_sub_limiter. also use uint16_t for the sort masks.

---
 src/cell.c   |  9 +++++----
 src/cell.h   | 20 +++++++++-----------
 src/runner.c | 10 +++++-----
 src/space.c  |  2 --
 4 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index eed219e0c9..8c25b17f99 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -2138,8 +2138,8 @@ void cell_clear_drift_flags(struct cell *c, void *data) {
  * @brief Clear the limiter flags on the given cell.
  */
 void cell_clear_limiter_flags(struct cell *c, void *data) {
-  cell_clear_flag(c, cell_flag_do_hydro_limiter);
-  c->hydro.do_sub_limiter = 0;
+  cell_clear_flag(c,
+                  cell_flag_do_hydro_limiter & cell_flag_do_hydro_sub_limiter);
 }
 
 /**
@@ -2310,11 +2310,12 @@ void cell_activate_limiter(struct cell *c, struct scheduler *s) {
     scheduler_activate(s, c->timestep_limiter);
   } else {
     for (struct cell *parent = c->parent;
-         parent != NULL && !parent->hydro.do_sub_limiter;
+         parent != NULL &&
+         !cell_get_flag(parent, cell_flag_do_hydro_sub_limiter);
          parent = parent->parent) {
 
       /* Mark this cell for limiting */
-      parent->hydro.do_sub_limiter = 1;
+      cell_set_flag(parent, cell_flag_do_hydro_sub_limiter);
 
       if (parent == c->super) {
 #ifdef SWIFT_DEBUG_CHECKS
diff --git a/src/cell.h b/src/cell.h
index de624e204d..b31a229dcc 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -28,6 +28,7 @@
 
 /* Includes. */
 #include <stddef.h>
+#include <stdint.h>
 
 /* Local includes. */
 #include "align.h"
@@ -374,16 +375,13 @@ struct cell {
     int hold;
 
     /*! Bit mask of sort directions that will be needed in the next timestep. */
-    unsigned int requires_sorts;
+    uint16_t requires_sorts;
 
     /*! Bit mask of sorts that need to be computed for this cell. */
-    unsigned int do_sort;
+    uint16_t do_sort;
 
     /*! Bit-mask indicating the sorted directions */
-    unsigned int sorted;
-
-    /*! Do any of this cell's sub-cells need to be limited? */
-    char do_sub_limiter;
+    uint16_t sorted;
 
 #ifdef SWIFT_DEBUG_CHECKS
 
@@ -552,18 +550,18 @@ struct cell {
     /*! Values of dx_max_sort before the drifts, used for sub-cell tasks. */
     float dx_max_sort_old;
 
-    /*! Bit mask of sort directions that will be needed in the next timestep. */
-    unsigned int requires_sorts;
-
     /*! Pointer for the sorted indices. */
     struct entry *sort[13];
     struct entry *sortptr;
 
+    /*! Bit mask of sort directions that will be needed in the next timestep. */
+    uint16_t requires_sorts;
+
     /*! Bit-mask indicating the sorted directions */
-    unsigned int sorted;
+    uint16_t sorted;
 
     /*! Bit mask of sorts that need to be computed for this cell. */
-    unsigned int do_sort;
+    uint16_t do_sort;
 
     /*! Do any of this cell's sub-cells need to be sorted? */
     char do_sub_sort;
diff --git a/src/runner.c b/src/runner.c
index 113aa4753a..b9c6f15192 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -2871,13 +2871,13 @@ void runner_do_limiter(struct runner *r, struct cell *c, int force, int timer) {
   if (c->hydro.count == 0) {
 
     /* Clear the limiter flags. */
-    cell_clear_flag(c, cell_flag_do_hydro_limiter);
-    c->hydro.do_sub_limiter = 0;
+    cell_clear_flag(
+        c, cell_flag_do_hydro_limiter & cell_flag_do_hydro_sub_limiter);
     return;
   }
 
   /* Loop over the progeny ? */
-  if (c->split && (force || c->hydro.do_sub_limiter)) {
+  if (c->split && (force || cell_get_flag(c, cell_flag_do_hydro_sub_limiter))) {
     for (int k = 0; k < 8; k++) {
       if (c->progeny[k] != NULL) {
         struct cell *restrict cp = c->progeny[k];
@@ -2967,8 +2967,8 @@ void runner_do_limiter(struct runner *r, struct cell *c, int force, int timer) {
   }
 
   /* Clear the limiter flags. */
-  cell_clear_flag(c, cell_flag_do_hydro_limiter);
-  c->hydro.do_sub_limiter = 0;
+  cell_clear_flag(c,
+                  cell_flag_do_hydro_limiter & cell_flag_do_hydro_sub_limiter);
 
   if (timer) TIMER_TOC(timer_do_limiter);
 }
diff --git a/src/space.c b/src/space.c
index c31d2dfbd4..5dfbab9acd 100644
--- a/src/space.c
+++ b/src/space.c
@@ -262,7 +262,6 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements,
     c->grav.do_sub_drift = 0;
     c->stars.do_sub_drift = 0;
     c->black_holes.do_sub_drift = 0;
-    c->hydro.do_sub_limiter = 0;
     c->hydro.ti_end_min = -1;
     c->hydro.ti_end_max = -1;
     c->grav.ti_end_min = -1;
@@ -3326,7 +3325,6 @@ void space_split_recursive(struct space *s, struct cell *c,
       cp->flags = 0;
       cp->stars.do_sub_drift = 0;
       cp->black_holes.do_sub_drift = 0;
-      cp->hydro.do_sub_limiter = 0;
 #ifdef WITH_MPI
       cp->mpi.tag = -1;
 #endif  // WITH_MPI
-- 
GitLab