From 9293abcbbcd38210b8fe21a4bb48367daba4ab80 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Fri, 20 May 2016 17:12:34 +0100
Subject: [PATCH] Added the infrastructure for a new 'fixdt' kick task.

---
 examples/plot_tasks.py     |  5 +++--
 examples/plot_tasks_MPI.py |  5 +++--
 src/engine.c               | 22 +++++++++++++++++-----
 src/runner.c               |  3 +++
 src/task.c                 |  9 +++++----
 src/task.h                 |  1 +
 6 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/examples/plot_tasks.py b/examples/plot_tasks.py
index c96d063e0b..dadc3b1977 100755
--- a/examples/plot_tasks.py
+++ b/examples/plot_tasks.py
@@ -59,8 +59,8 @@ pl.rcParams.update(PLOT_PARAMS)
 
 #  Tasks and subtypes. Indexed as in tasks.h.
 TASKTYPES = ["none", "sort", "self", "pair", "sub", "init", "ghost", "drift",
-             "kick", "send", "recv", "grav_pp", "grav_mm", "grav_up",
-             "grav_down", "grav_external", "part_sort", "gpart_sort",
+             "kick", "kick_fixdt", "send", "recv", "grav_pp", "grav_mm",
+             "grav_up", "grav_down", "grav_external", "part_sort", "gpart_sort",
              "split_cell", "rewait", "count"]
 
 TASKCOLOURS = {"none": "black",
@@ -72,6 +72,7 @@ TASKCOLOURS = {"none": "black",
                "ghost": "cyan",
                "drift": "maroon",
                "kick": "green",
+               "kick_fixdt": "green",
                "send": "yellow",
                "recv": "magenta",
                "grav_pp": "mediumorchid",
diff --git a/examples/plot_tasks_MPI.py b/examples/plot_tasks_MPI.py
index ae84b0177b..99b2f3db9a 100755
--- a/examples/plot_tasks_MPI.py
+++ b/examples/plot_tasks_MPI.py
@@ -65,8 +65,8 @@ pl.rcParams.update(PLOT_PARAMS)
 
 #  Tasks and subtypes. Indexed as in tasks.h.
 TASKTYPES = ["none", "sort", "self", "pair", "sub", "init", "ghost", "drift",
-             "kick", "send", "recv", "grav_pp", "grav_mm", "grav_up",
-             "grav_down", "grav_external", "part_sort", "gpart_sort",
+             "kick", "kick_fixdt", "send", "recv", "grav_pp", "grav_mm",
+             "grav_up", "grav_down", "grav_external", "part_sort", "gpart_sort",
              "split_cell", "rewait", "count"]
 
 TASKCOLOURS = {"none": "black",
@@ -78,6 +78,7 @@ TASKCOLOURS = {"none": "black",
                "ghost": "cyan",
                "drift": "maroon",
                "kick": "green",
+               "kick_fixdt": "green",
                "send": "yellow",
                "recv": "magenta",
                "grav_pp": "mediumorchid",
diff --git a/src/engine.c b/src/engine.c
index 76243b1e48..799b5d4024 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -112,6 +112,7 @@ void engine_make_hierarchical_tasks(struct engine *e, struct cell *c,
   const int is_with_external_gravity =
       (e->policy & engine_policy_external_gravity) ==
       engine_policy_external_gravity;
+  const int is_fixdt = (e->policy & engine_policy_fixdt) == engine_policy_fixdt;
 
   /* Am I the super-cell? */
   if (super == NULL && (c->count > 0 || c->gcount > 0)) {
@@ -130,9 +131,14 @@ void engine_make_hierarchical_tasks(struct engine *e, struct cell *c,
       c->drift = scheduler_addtask(s, task_type_drift, task_subtype_none, 0, 0,
                                    c, NULL, 0);
 
-      /* Add the kick task. */
-      c->kick = scheduler_addtask(s, task_type_kick, task_subtype_none, 0, 0, c,
-                                  NULL, 0);
+      /* Add the kick task that matches the policy. */
+      if (is_fixdt) {
+        c->kick = scheduler_addtask(s, task_type_kick_fixdt, task_subtype_none,
+                                    0, 0, c, NULL, 0);
+      } else {
+        c->kick = scheduler_addtask(s, task_type_kick, task_subtype_none, 0, 0,
+                                    c, NULL, 0);
+      }
 
       if (c->count > 0) {
 
@@ -2102,11 +2108,17 @@ void engine_step(struct engine *e) {
   /* Build the masks corresponding to the policy */
   unsigned int mask = 0, submask = 0;
 
-  /* We always have sort tasks and kick tasks */
+  /* We always have sort tasks and init tasks */
   mask |= 1 << task_type_sort;
-  mask |= 1 << task_type_kick;
   mask |= 1 << task_type_init;
 
+  /* Add the correct kick task */
+  if (e->policy & engine_policy_fixdt) {
+    mask |= 1 << task_type_kick_fixdt;
+  } else {
+    mask |= 1 << task_type_kick;
+  }
+
   /* Add the tasks corresponding to hydro operations to the masks */
   if (e->policy & engine_policy_hydro) {
 
diff --git a/src/runner.c b/src/runner.c
index 3349fa3513..7b9872bad3 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -1371,6 +1371,9 @@ void *runner_main(void *data) {
         case task_type_kick:
           runner_do_kick(r, ci, 1);
           break;
+        case task_type_kick_fixdt:
+          runner_do_kick(r, ci, 1);
+          break;
         case task_type_send:
           break;
         case task_type_recv:
diff --git a/src/task.c b/src/task.c
index 31c2bfcb34..31e33ebcac 100644
--- a/src/task.c
+++ b/src/task.c
@@ -47,10 +47,11 @@
 
 /* Task type names. */
 const char *taskID_names[task_type_count] = {
-    "none",          "sort",      "self",       "pair",       "sub",
-    "init",          "ghost",     "drift",      "kick",       "send",
-    "recv",          "grav_pp",   "grav_mm",    "grav_up",    "grav_down",
-    "grav_external", "part_sort", "gpart_sort", "split_cell", "rewait"};
+    "none",      "sort",          "self",      "pair",       "sub",
+    "init",      "ghost",         "drift",     "kick",       "kick_fixdt",
+    "send",      "recv",          "grav_pp",   "grav_mm",    "grav_up",
+    "grav_down", "grav_external", "part_sort", "gpart_sort", "split_cell",
+    "rewait"};
 
 const char *subtaskID_names[task_type_count] = {"none",  "density",
                                                 "force", "grav"};
diff --git a/src/task.h b/src/task.h
index 25cc886f4b..c4632b4808 100644
--- a/src/task.h
+++ b/src/task.h
@@ -42,6 +42,7 @@ enum task_types {
   task_type_ghost,
   task_type_drift,
   task_type_kick,
+  task_type_kick_fixdt,
   task_type_send,
   task_type_recv,
   task_type_grav_pp,
-- 
GitLab