From 632f3418f9ad75b19cd40d5e902feda6f744dee7 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Thu, 14 Feb 2019 10:39:11 +0100
Subject: [PATCH] Add a (temporary) optional parameter to the YAML file to
 impose a smoothing length value to all stars.

---
 src/space.c | 14 ++++++++++++++
 src/space.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/src/space.c b/src/space.c
index c368f2c220..ac6c08a3a5 100644
--- a/src/space.c
+++ b/src/space.c
@@ -3512,6 +3512,8 @@ void space_first_init_sparts_mapper(void *restrict map_data, int count,
   const ptrdiff_t delta = sp - s->sparts;
 #endif
 
+  const float initial_h = s->initial_spart_h;
+
   const int with_feedback = (e->policy & engine_policy_feedback);
 
   const struct cosmology *cosmo = e->cosmology;
@@ -3524,6 +3526,11 @@ void space_first_init_sparts_mapper(void *restrict map_data, int count,
     sp[k].v[1] *= a_factor_vel;
     sp[k].v[2] *= a_factor_vel;
 
+    /* Imposed smoothing length from parameter file */
+    if (initial_h != -1.f) {
+      sp[k].h = initial_h;
+    }
+
 #ifdef HYDRO_DIMENSION_2D
     sp[k].x[2] = 0.f;
     sp[k].v[2] = 0.f;
@@ -3849,6 +3856,13 @@ void space_init(struct space *s, struct swift_params *params,
     for (size_t k = 0; k < Npart; k++) parts[k].h *= scaling;
   }
 
+  /* Read in imposed star smoothing length */
+  s->initial_spart_h = parser_get_opt_param_float(
+	params, "InitialConditions:stars_smoothing_length", -1.f);
+  if (s->initial_spart_h != -1.f) {
+    message("Imposing a star smoothing length of %e", s->initial_spart_h);
+  }
+
   /* Apply shift */
   double shift[3] = {0.0, 0.0, 0.0};
   parser_get_opt_param_double_array(params, "InitialConditions:shift", 3,
diff --git a/src/space.h b/src/space.h
index 564a1d0992..fe47a2b8b9 100644
--- a/src/space.h
+++ b/src/space.h
@@ -224,6 +224,9 @@ struct space {
   /*! Sum of the norm of the velocity of all the #spart */
   float sum_spart_vel_norm;
 
+  /*! Initial value of the smoothing length read from the parameter file */
+  float initial_spart_h;
+
   /*! General-purpose lock for this space. */
   swift_lock_type lock;
 
-- 
GitLab