From 65954cffbb093d57c96121d6ec88ef2ef42e86c9 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Tue, 2 Apr 2019 22:14:00 +0200
Subject: [PATCH] Add a function to correctly activate the star drift when
 activating the star formation.

---
 src/cell.c             | 26 ++++++++++++++++++++++++++
 src/cell.h             |  1 +
 src/engine_marktasks.c |  1 +
 3 files changed, 28 insertions(+)

diff --git a/src/cell.c b/src/cell.c
index 28cb5f3fab..48667900c2 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -1845,6 +1845,32 @@ void cell_clear_limiter_flags(struct cell *c, void *data) {
   c->hydro.do_sub_limiter = 0;
 }
 
+/**
+ * @brief Recurse down in a cell hierarchy until the hydro.super level is reached
+ * and activate the spart drift at that level.
+ *
+ * @param c The #cell to recurse into.
+ * @param s The #scheduler.
+ */
+void cell_activate_super_spart_drifts(struct cell *c, struct scheduler *s) {
+
+  if (c == c->hydro.super) {
+    cell_activate_drift_spart(c, s);
+  } else {
+    if (c->split) {
+      for (int k = 0; k < 8; ++k) {
+        if (c->progeny[k] != NULL) {
+          cell_activate_super_spart_drifts(c->progeny[k], s);
+        }
+      }
+    } else {
+#ifdef SWIFT_DEBUG_CHECKS
+      error("Reached a leaf cell without finding a hydro.super!!");
+#endif
+    }
+  }
+}
+
 /**
  * @brief Activate the #part drifts on the given cell.
  */
diff --git a/src/cell.h b/src/cell.h
index b0912d33f2..13adc8ae0b 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -774,6 +774,7 @@ void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj,
                                        struct scheduler *s);
 void cell_activate_subcell_external_grav_tasks(struct cell *ci,
                                                struct scheduler *s);
+void cell_activate_super_spart_drifts(struct cell *c, struct scheduler *s);
 void cell_activate_drift_part(struct cell *c, struct scheduler *s);
 void cell_activate_drift_gpart(struct cell *c, struct scheduler *s);
 void cell_activate_drift_spart(struct cell *c, struct scheduler *s);
diff --git a/src/engine_marktasks.c b/src/engine_marktasks.c
index e54465d0bf..9fffcdda42 100644
--- a/src/engine_marktasks.c
+++ b/src/engine_marktasks.c
@@ -665,6 +665,7 @@ 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_super_spart_drifts(t->ci, s);
       }
     }
   }
-- 
GitLab