From f391b698e00924e2a2db732759ee6bc924274368 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Tue, 2 Apr 2019 18:46:20 +0200
Subject: [PATCH] Correct set the top-pointer and activate the star formation
 task at the right level.

---
 src/cell.c             | 2 +-
 src/engine_marktasks.c | 1 -
 src/runner.c           | 2 ++
 src/space.c            | 2 ++
 4 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index fa6c972e7a..28cb5f3fab 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -3222,7 +3222,7 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) {
     if (c->hydro.cooling != NULL) scheduler_activate(s, c->hydro.cooling);
     if (c->logger != NULL) scheduler_activate(s, c->logger);
 
-    if (c->hydro.star_formation != NULL) {
+    if (c->top->hydro.star_formation != NULL) {
       scheduler_activate(s, c->top->hydro.star_formation);
       cell_activate_drift_spart(c, s);
     }
diff --git a/src/engine_marktasks.c b/src/engine_marktasks.c
index d2bd1719e2..e54465d0bf 100644
--- a/src/engine_marktasks.c
+++ b/src/engine_marktasks.c
@@ -665,7 +665,6 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
     else if (t_type == task_type_star_formation) {
       if (cell_is_active_hydro(t->ci, e)) {
         scheduler_activate(s, t);
-        // cell_activate_drift_spart(t->ci, s);
       }
     }
   }
diff --git a/src/runner.c b/src/runner.c
index 1a07da1069..01514f7bee 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -671,6 +671,8 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
   if (with_feedback && (c == c->hydro.super) &&
       (current_stars_count != c->stars.count)) {
 
+    error("MATTHIEU needs to think a bit more here!");
+
     cell_clear_stars_sort_flags(c);
     runner_do_stars_sort(r, c, 0x1FFF, /*cleanup=*/0, /*timer=*/0);
   }
diff --git a/src/space.c b/src/space.c
index 1dc7d5cbe6..9c4bbe7a4f 100644
--- a/src/space.c
+++ b/src/space.c
@@ -571,6 +571,7 @@ void space_regrid(struct space *s, int verbose) {
           c->hydro.count = 0;
           c->grav.count = 0;
           c->stars.count = 0;
+          c->top = c;
           c->super = c;
           c->hydro.super = c;
           c->grav.super = c;
@@ -2769,6 +2770,7 @@ void space_split_recursive(struct space *s, struct cell *c,
       cp->stars.dx_max_sort = 0.f;
       cp->nodeID = c->nodeID;
       cp->parent = c;
+      cp->top = c->top;
       cp->super = NULL;
       cp->hydro.super = NULL;
       cp->grav.super = NULL;
-- 
GitLab