From 3f0c1c31971a4051da9b690b8603a2250e944e3f Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Mon, 3 Jul 2017 18:11:18 +0100
Subject: [PATCH] repartitioning: make the trigger correctly with a value of 2,
 previously the minimum no. of steps was in fact 3

Also match sanity checks to same as documented allowed values for trigger
---
 src/engine.c    | 7 ++++---
 src/partition.c | 3 +++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/engine.c b/src/engine.c
index 827778100f..e82930d9d5 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -891,13 +891,14 @@ void engine_repartition_trigger(struct engine *e) {
   /* Do nothing if there have not been enough steps since the last
    * repartition, don't want to repeat this too often or immediately after
    * a repartition step. */
-  if (e->step - e->last_repartition > 2) {
+  if (e->step - e->last_repartition >= 2) {
 
     /* Old style if trigger is >1 or this is the second step (want an early
      * repartition following the initial repartition). */
     if (e->reparttype->trigger > 1 || e->step == 2) {
       if (e->reparttype->trigger > 1) {
-        if (e->step % (int)e->reparttype->trigger == 2) e->forcerepart = 1;
+        if ((e->step % (int)e->reparttype->trigger) == 0)
+          e->forcerepart = 1;
       } else {
         e->forcerepart = 1;
       }
@@ -4064,7 +4065,7 @@ void engine_init(struct engine *e, struct space *s,
   e->parameter_file = params;
 #ifdef WITH_MPI
   e->cputime_last_step = 0;
-  e->last_repartition = -1;
+  e->last_repartition = 0;
 #endif
   engine_rank = nodeID;
 
diff --git a/src/partition.c b/src/partition.c
index e0d7b289aa..1588aa2482 100644
--- a/src/partition.c
+++ b/src/partition.c
@@ -1070,6 +1070,9 @@ void partition_init(struct partition *partition,
       parser_get_opt_param_float(params, "DomainDecomposition:trigger", 0.05f);
   if (repartition->trigger <= 0)
     error("Invalid DomainDecomposition:trigger, must be greater than zero");
+  if (repartition->trigger < 2 && repartition->trigger >= 1)
+    error("Invalid DomainDecomposition:trigger, must be 2 or greater or less"
+          " than 1");
 
   /* Fraction of particles that should be updated before a repartition
    * based on CPU time is considered. */
-- 
GitLab