From 825558a773f0010c52c3e90a6a3cbedb2d8177a1 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Sun, 13 May 2018 13:30:40 +0200
Subject: [PATCH] Prevent the use of 0 or negative smoothing-scale for the
 gravity mesh forces.

---
 src/gravity_properties.c | 3 +++
 src/runner_doiact_fft.c  | 1 +
 tests/fft_params.yml     | 2 +-
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/gravity_properties.c b/src/gravity_properties.c
index 79be11a8ba..928765cc14 100644
--- a/src/gravity_properties.c
+++ b/src/gravity_properties.c
@@ -48,6 +48,9 @@ void gravity_props_init(struct gravity_props *p,
   p->r_cut_min = parser_get_opt_param_float(params, "Gravity:r_cut_min",
                                             gravity_props_default_r_cut_min);
 
+  if (p->a_smooth <= 0.)
+    error("The mesh smoothing scale 'a_smooth' must be > 0.");
+
   /* Time integration */
   p->eta = parser_get_param_float(params, "Gravity:eta");
 
diff --git a/src/runner_doiact_fft.c b/src/runner_doiact_fft.c
index 97283542f4..9bcf69feda 100644
--- a/src/runner_doiact_fft.c
+++ b/src/runner_doiact_fft.c
@@ -454,6 +454,7 @@ void runner_do_grav_fft(struct runner* r, int timer) {
   TIMER_TIC;
 
   if (cdim[0] != cdim[1] || cdim[0] != cdim[2]) error("Non-square mesh");
+  if (a_smooth <= 0.) error("Invalid value of a_smooth");
 
   /* Some useful constants */
   const int N = cdim[0];
diff --git a/tests/fft_params.yml b/tests/fft_params.yml
index 6938e36581..ff32d83d48 100644
--- a/tests/fft_params.yml
+++ b/tests/fft_params.yml
@@ -7,5 +7,5 @@ Gravity:
   theta:                  0.7        # Opening angle (Multipole acceptance criterion)
   comoving_softening:     0.00001    # Comoving softening length (in internal units).
   max_physical_softening: 0.00001    # Physical softening length (in internal units).
-  a_smooth:               0.
+  a_smooth:               0.00001
   r_cut:                  0.
-- 
GitLab