From 856d5eb34de68378cc9560de51a1933f851f2eec Mon Sep 17 00:00:00 2001
From: James Willis <james.s.willis@durham.ac.uk>
Date: Wed, 27 Jun 2018 14:14:25 +0100
Subject: [PATCH] Created fof_init() that sets the linking length. Calculate
 the linking length in the main now.

---
 examples/main.c |  3 +++
 src/engine.c    | 11 -----------
 src/fof.c       | 10 ++++++++++
 src/fof.h       |  1 +
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/examples/main.c b/examples/main.c
index 0af9cc2160..2a3e9e95c6 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -890,6 +890,9 @@ int main(int argc, char *argv[]) {
     if (with_structure_finding)
       engine_policies |= engine_policy_structure_finding;
 
+    /* Initialise the FOF parameters. */
+    fof_init(&s, N_total[0], N_total[1]);
+      
     /* Initialize the engine with the space and policies. */
     if (myrank == 0) clocks_gettime(&tic);
     engine_init(&e, &s, params, N_total[0], N_total[1], N_total[2],
diff --git a/src/engine.c b/src/engine.c
index bd1b25af59..6063612597 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -4606,19 +4606,8 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
 
   message("Performing Friends Of Friends search.");
 
-  /* Calculate the particle linking length based upon the mean inter-particle
-   * spacing. */
-  const int total_nr_dmparts = e->total_nr_gparts - e->total_nr_parts;
-  const double l_x = 0.2 * (s->dim[0] / cbrt(total_nr_dmparts));
-  s->l_x2 = l_x * l_x;
 
   ticks tic = getticks();
-  //fof_search_serial(s);
-  message("Serial FOF search took: %.3f %s.",
-          clocks_from_ticks(getticks() - tic), clocks_getunit());
-
-  tic = getticks();
-  //fof_search_tree_serial(s);
   fof_search_tree(s);
   message("Serial tree FOF search took: %.3f %s.",
           clocks_from_ticks(getticks() - tic), clocks_getunit());
diff --git a/src/fof.c b/src/fof.c
index 0d029752ee..9324fad2b5 100644
--- a/src/fof.c
+++ b/src/fof.c
@@ -27,6 +27,16 @@
 #include "threadpool.h"
 #include "engine.h"
 
+/* Initialises parameters for the FOF search. */
+void fof_init(struct space *s, long long Ngas, long long Ngparts) {
+
+  /* Calculate the particle linking length based upon the mean inter-particle
+   * spacing of the DM particles. */
+  const int total_nr_dmparts = Ngparts - Ngas;
+  const double l_x = 0.2 * (s->dim[0] / cbrt(total_nr_dmparts));
+  s->l_x2 = l_x * l_x;
+}
+
 /* Finds the root ID of the group a particle exists in. */
 __attribute__((always_inline)) INLINE static int fof_find(const int i,
                                                           int *group_id) {
diff --git a/src/fof.h b/src/fof.h
index 658ef1c0b0..5e8809c298 100644
--- a/src/fof.h
+++ b/src/fof.h
@@ -28,6 +28,7 @@
 #include "space.h"
 
 /* Function prototypes. */
+void fof_init(struct space *s, long long Ngas, long long Ngparts);
 void fof_search_serial(struct space *s);
 void fof_search_cell(struct space *s, struct cell *c);
 void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj);
-- 
GitLab