From 761b9d157206ff009a06c24f94199e5b02d3f4e1 Mon Sep 17 00:00:00 2001
From: James Willis <james.s.willis@durham.ac.uk>
Date: Fri, 2 Mar 2018 16:22:23 +0800
Subject: [PATCH] Call VELOCIraptor from the engine instead of main.

---
 examples/main.c | 20 --------------------
 src/engine.c    |  9 +++++++++
 2 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/examples/main.c b/examples/main.c
index 226d8d5983..6244a7bb61 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -51,22 +51,6 @@
 /* Global profiler. */
 struct profiler prof;
 
-void InitVelociraptor();
-void InvokeVelociraptor(const int num_gravity_parts, struct gpart *gravity_parts);
-
-void init_velociraptor() {
-
-    InitVelociraptor();
-}
-
-void call_velociraptor(struct engine *e) {
-
-    struct gpart *gparts = e->s->gparts;
-    const int nr_gparts = e->s->nr_gparts;
-
-    InvokeVelociraptor(nr_gparts, gparts);
-}
-
 /**
  * @brief Help messages for the command line parameters.
  */
@@ -135,8 +119,6 @@ void print_help_message() {
  */
 int main(int argc, char *argv[]) {
 
-  init_velociraptor();
-
   struct clocks_time tic, toc;
   struct engine e;
 
@@ -879,8 +861,6 @@ int main(int argc, char *argv[]) {
     /* Take a step. */
     engine_step(&e);
 
-    if (e.step%250 == 0) call_velociraptor(&e);
-
     /* Print the timers. */
     if (with_verbose_timers) timers_print(e.step);
 
diff --git a/src/engine.c b/src/engine.c
index b64aeb42eb..9cfd6d3a84 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -76,6 +76,7 @@
 #include "tools.h"
 #include "units.h"
 #include "version.h"
+#include "velociraptor_interface.h"
 
 /* Particle cache size. */
 #define CACHE_SIZE 512
@@ -4499,6 +4500,11 @@ void engine_step(struct engine *e) {
     e->step_props |= engine_step_prop_statistics;
   }
 
+  /* Invoke VELOCIraptor every 250 timesteps. */
+  if (e->step%250 == 0) {
+    invoke_velociraptor(e);
+  }
+
   /* Now apply all the collected time step updates and particle counts. */
   collectgroup1_apply(&e->collect_group1, e);
 
@@ -5245,6 +5251,9 @@ void engine_init(
   e->timeBase = (e->timeEnd - e->timeBegin) / max_nr_timesteps;
   e->timeBase_inv = 1.0 / e->timeBase;
   e->ti_current = 0;
+
+  /* Initialise VELOCIraptor. */
+  init_velociraptor(e);
 }
 
 /**
-- 
GitLab