From 537d66cc06db92bc44ce77164e4a04908b84b56b Mon Sep 17 00:00:00 2001
From: loikki <loic.hausammann@protonmail.ch>
Date: Mon, 25 Mar 2019 08:34:18 +0100
Subject: [PATCH] h_max: use existing recursion

---
 src/cell.c   | 42 ------------------------------------------
 src/cell.h   |  2 --
 src/runner.c | 23 +++++++++++++++++++----
 3 files changed, 19 insertions(+), 48 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index 5228704102..c7c10bcf66 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -4999,45 +4999,3 @@ int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct cell *cj,
   return gravity_M2L_accept(multi_i->r_max_rebuild, multi_j->r_max_rebuild,
                             theta_crit2, r2);
 }
-
-
-/**
- * @brief Updates the hydro h_max in all the cell above.
- *
- * This function is used when h_max is updated in the ghost.
- *
- * @param c The #cell to update.
- * @param h_max The new h_max.
- */
-void cell_update_hydro_h_max(struct cell *c, double h_max) {
-
-  /* Check if new h_max is larger */
-  if (h_max > c->hydro.h_max) {
-    c->hydro.h_max = h_max;
-
-    /* Update parents */
-    if (c->parent != NULL)
-      cell_update_hydro_h_max(c->parent, h_max);
-  }
-}
-
-
-/**
- * @brief Updates the stars h_max in all the cell above.
- *
- * This function is used when h_max is updated in the ghost.
- *
- * @param c The #cell to update.
- * @param h_max The new h_max.
- */
-void cell_update_stars_h_max(struct cell *c, double h_max) {
-
-  /* Check if new h_max is larger */
-  if (h_max > c->stars.h_max) {
-    c->stars.h_max = h_max;
-
-    /* Update parents */
-    if (c->parent != NULL)
-      cell_update_stars_h_max(c->parent, h_max);
-  }
-}
diff --git a/src/cell.h b/src/cell.h
index 42b74dae36..e76657349e 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -799,8 +799,6 @@ int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj,
                          const struct engine *e, const struct space *s);
 int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct cell *cj,
                                  const struct engine *e, const struct space *s);
-void cell_update_hydro_h_max(struct cell *c, double h_max);
-void cell_update_stars_h_max(struct cell *c, double h_max);
 
 /**
  * @brief Compute the square of the minimal distance between any two points in
diff --git a/src/runner.c b/src/runner.c
index 1a63b440f9..6edb34414d 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -154,7 +154,13 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) {
   /* Recurse? */
   if (c->split) {
     for (int k = 0; k < 8; k++)
-      if (c->progeny[k] != NULL) runner_do_stars_ghost(r, c->progeny[k], 0);
+      if (c->progeny[k] != NULL) {
+	runner_do_stars_ghost(r, c->progeny[k], 0);
+
+	/* update h_max */
+	if (c->progeny[k]->stars.h_max > c->stars.h_max)
+	  c->stars.h_max = c->progeny[k]->stars.h_max;
+      }
   } else {
 
     /* Init the list of active particles that have to be updated. */
@@ -418,7 +424,9 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) {
     free(h_0);
   }
 
-  cell_update_stars_h_max(c, h_max);
+  /* update h_max */
+  if (h_max > c->stars.h_max)
+    c->stars.h_max = h_max;
 
   if (timer) TIMER_TOC(timer_dostars_ghost);
 }
@@ -1365,7 +1373,12 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) {
   /* Recurse? */
   if (c->split) {
     for (int k = 0; k < 8; k++)
-      if (c->progeny[k] != NULL) runner_do_ghost(r, c->progeny[k], 0);
+      if (c->progeny[k] != NULL) {
+	runner_do_ghost(r, c->progeny[k], 0);
+	/* update h_max */
+	if (c->progeny[k]->hydro.h_max > c->hydro.h_max)
+	  c->hydro.h_max = c->progeny[k]->hydro.h_max;
+      }
   } else {
 
     /* Init the list of active particles that have to be updated and their
@@ -1726,7 +1739,9 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) {
     free(h_0);
   }
 
-  cell_update_hydro_h_max(c, h_max);
+  /* Update h_max */
+  if (h_max > c->hydro.h_max)
+    c->hydro.h_max = h_max;
 
   if (timer) TIMER_TOC(timer_do_ghost);
 }
-- 
GitLab