From c8671f27934024abe1af2c17f263344e9e3736f5 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Sat, 15 Dec 2018 19:41:13 +0100
Subject: [PATCH] Add --temperature runtime flag to activate the calculation of
 temperature without the cooling task.

---
 README                                      | 13 +++++++----
 README.md                                   | 13 +++++++----
 doc/RTD/source/CommandLineOptions/index.rst | 13 +++++++----
 examples/main.c                             | 26 +++++++++++++--------
 src/cooling/EAGLE/cooling.c                 |  2 +-
 src/engine.c                                |  7 ++++--
 src/engine.h                                | 13 ++++++-----
 7 files changed, 53 insertions(+), 34 deletions(-)

diff --git a/README b/README
index 5b0b5f3ebf..272188b3f7 100644
--- a/README
+++ b/README
@@ -21,21 +21,24 @@ Parameters:
     -h, --help                        show this help message and exit
 
   Simulation options:
-    -b, --feedback                    Run with stars feedback
+  
+    -b, --feedback                    Run with stars feedback.
     -c, --cosmology                   Run with cosmological time integration.
-    -C, --cooling                     Run with cooling
+    --temperature                     Run with temperature calculation.
+    -C, --cooling                     Run with cooling (also switches on --with-temperature).
     -D, --drift-all                   Always drift all particles even the ones
                                       far from active particles. This emulates
                                       Gadget-[23] and GIZMO's default behaviours.
-    -F, --star-formation	      Run with star formation
+    -F, --star-formation	      Run with star formation.
     -g, --external-gravity            Run with an external gravitational potential.
     -G, --self-gravity                Run with self-gravity.
     -M, --multipole-reconstruction    Reconstruct the multipoles every time-step.
     -s, --hydro                       Run with hydrodynamics.
-    -S, --stars                       Run with stars
-    -x, --velociraptor                Run with structure finding
+    -S, --stars                       Run with stars.
+    -x, --velociraptor                Run with structure finding.
 
   Control options:
+  
     -a, --pin                         Pin runners using processor affinity.
     -d, --dry-run                     Dry run. Read the parameter file, allocates
                                       memory but does not read the particles
diff --git a/README.md b/README.md
index 92925017d9..7a3c1287c7 100644
--- a/README.md
+++ b/README.md
@@ -69,21 +69,24 @@ Parameters:
     -h, --help                        show this help message and exit
 
   Simulation options:
-    -b, --feedback                    Run with stars feedback
+  
+    -b, --feedback                    Run with stars feedback.
     -c, --cosmology                   Run with cosmological time integration.
-    -C, --cooling                     Run with cooling
+    --temperature                     Run with temperature calculation.
+    -C, --cooling                     Run with cooling (also switches on --with-temperature).
     -D, --drift-all                   Always drift all particles even the ones
                                       far from active particles. This emulates
                                       Gadget-[23] and GIZMO's default behaviours.
-    -F, --star-formation	      Run with star formation
+    -F, --star-formation	      Run with star formation.
     -g, --external-gravity            Run with an external gravitational potential.
     -G, --self-gravity                Run with self-gravity.
     -M, --multipole-reconstruction    Reconstruct the multipoles every time-step.
     -s, --hydro                       Run with hydrodynamics.
-    -S, --stars                       Run with stars
-    -x, --velociraptor                Run with structure finding
+    -S, --stars                       Run with stars.
+    -x, --velociraptor                Run with structure finding.
 
   Control options:
+  
     -a, --pin                         Pin runners using processor affinity.
     -d, --dry-run                     Dry run. Read the parameter file, allocates
                                       memory but does not read the particles
diff --git a/doc/RTD/source/CommandLineOptions/index.rst b/doc/RTD/source/CommandLineOptions/index.rst
index de969730be..bd58f031e6 100644
--- a/doc/RTD/source/CommandLineOptions/index.rst
+++ b/doc/RTD/source/CommandLineOptions/index.rst
@@ -16,21 +16,24 @@ can be found by typing ``./swift -h``::
     -h, --help                        show this help message and exit
 
   Simulation options:
-    -b, --feedback                    Run with stars feedback
+
+    -b, --feedback                    Run with stars feedback.
     -c, --cosmology                   Run with cosmological time integration.
-    -C, --cooling                     Run with cooling
+    --temperature                     Run with temperature calculation. 
+    -C, --cooling                     Run with cooling (also switches on --with-temperature).
     -D, --drift-all                   Always drift all particles even the ones
                                       far from active particles. This emulates
                                       Gadget-[23] and GIZMO's default behaviours.
-    -F, --star-formation	      Run with star formation
+    -F, --star-formation	      Run with star formation.
     -g, --external-gravity            Run with an external gravitational potential.
     -G, --self-gravity                Run with self-gravity.
     -M, --multipole-reconstruction    Reconstruct the multipoles every time-step.
     -s, --hydro                       Run with hydrodynamics.
-    -S, --stars                       Run with stars
-    -x, --velociraptor                Run with structure finding
+    -S, --stars                       Run with stars.
+    -x, --velociraptor                Run with structure finding.
 
   Control options:
+
     -a, --pin                         Pin runners using processor affinity.
     -d, --dry-run                     Dry run. Read the parameter file, allocates
                                       memory but does not read the particles
diff --git a/examples/main.c b/examples/main.c
index e3dd46a6ea..db8d8f0d41 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -146,6 +146,7 @@ int main(int argc, char *argv[]) {
   int restart = 0;
   int with_cosmology = 0;
   int with_external_gravity = 0;
+  int with_temperature = 0;
   int with_cooling = 0;
   int with_self_gravity = 0;
   int with_hydro = 0;
@@ -173,20 +174,23 @@ int main(int argc, char *argv[]) {
   struct argparse_option options[] = {
       OPT_HELP(),
 
-      OPT_GROUP("  Simulation options:"),
-      OPT_BOOLEAN('b', "feedback", &with_feedback, "Run with stars feedback",
+      OPT_GROUP("  Simulation options:\n"),
+      OPT_BOOLEAN('b', "feedback", &with_feedback, "Run with stars feedback.",
                   NULL, 0, 0),
       OPT_BOOLEAN('c', "cosmology", &with_cosmology,
                   "Run with cosmological time integration.", NULL, 0, 0),
-      OPT_BOOLEAN('C', "cooling", &with_cooling, "Run with cooling", NULL, 0,
-                  0),
+      OPT_BOOLEAN(0, "temperature", &with_temperature,
+                  "Run with temperature calculation.", NULL, 0, 0),
+      OPT_BOOLEAN('C', "cooling", &with_cooling,
+                  "Run with cooling (also switches on --with-temperature).",
+                  NULL, 0, 0),
       OPT_BOOLEAN('D', "drift-all", &with_drift_all,
                   "Always drift all particles even the ones far from active "
                   "particles. This emulates Gadget-[23] and GIZMO's default "
                   "behaviours.",
                   NULL, 0, 0),
       OPT_BOOLEAN('F', "star-formation", &with_star_formation,
-                  "Run with star formation", NULL, 0, 0),
+                  "Run with star formation.", NULL, 0, 0),
       OPT_BOOLEAN('g', "external-gravity", &with_external_gravity,
                   "Run with an external gravitational potential.", NULL, 0, 0),
       OPT_BOOLEAN('G', "self-gravity", &with_self_gravity,
@@ -195,11 +199,11 @@ int main(int argc, char *argv[]) {
                   "Reconstruct the multipoles every time-step.", NULL, 0, 0),
       OPT_BOOLEAN('s', "hydro", &with_hydro, "Run with hydrodynamics.", NULL, 0,
                   0),
-      OPT_BOOLEAN('S', "stars", &with_stars, "Run with stars", NULL, 0, 0),
+      OPT_BOOLEAN('S', "stars", &with_stars, "Run with stars.", NULL, 0, 0),
       OPT_BOOLEAN('x', "velociraptor", &with_structure_finding,
-                  "Run with structure finding", NULL, 0, 0),
+                  "Run with structure finding.", NULL, 0, 0),
 
-      OPT_GROUP("  Control options:"),
+      OPT_GROUP("  Control options:\n"),
       OPT_BOOLEAN('a', "pin", &with_aff,
                   "Pin runners using processor affinity.", NULL, 0, 0),
       OPT_BOOLEAN('d', "dry-run", &dry_run,
@@ -854,7 +858,8 @@ int main(int argc, char *argv[]) {
 
     /* Initialise the cooling function properties */
     bzero(&cooling_func, sizeof(struct cooling_function_data));
-    if (with_cooling) cooling_init(params, &us, &prog_const, &cooling_func);
+    if (with_cooling || with_temperature)
+      cooling_init(params, &us, &prog_const, &cooling_func);
     if (myrank == 0) cooling_print(&cooling_func);
 
     /* Initialise the chemistry */
@@ -872,6 +877,7 @@ int main(int argc, char *argv[]) {
     if (with_external_gravity)
       engine_policies |= engine_policy_external_gravity;
     if (with_cosmology) engine_policies |= engine_policy_cosmology;
+    if (with_temperature) engine_policies |= engine_policy_temperature;
     if (with_cooling) engine_policies |= engine_policy_cooling;
     if (with_stars) engine_policies |= engine_policy_stars;
     if (with_star_formation) engine_policies |= engine_policy_star_formation;
@@ -1209,7 +1215,7 @@ int main(int argc, char *argv[]) {
   if (with_verbose_timers) timers_close_file();
   if (with_cosmology) cosmology_clean(e.cosmology);
   if (with_self_gravity) pm_mesh_clean(e.mesh);
-  if (with_cooling) cooling_clean(&cooling_func);
+  if (with_cooling || with_temperature) cooling_clean(&cooling_func);
   engine_clean(&e);
   free(params);
 
diff --git a/src/cooling/EAGLE/cooling.c b/src/cooling/EAGLE/cooling.c
index 062dee011f..b94d60ff43 100644
--- a/src/cooling/EAGLE/cooling.c
+++ b/src/cooling/EAGLE/cooling.c
@@ -671,7 +671,7 @@ float cooling_get_temperature(
   if (cooling->Redshifts == NULL)
     error(
         "Cooling function has not been initialised. Did you forget the "
-        "--cooling runtime flag?");
+        "--temperature runtime flag?");
 #endif
 
   /* Get physical internal energy */
diff --git a/src/engine.c b/src/engine.c
index 841a92638b..ce9153e8c8 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -108,6 +108,7 @@ const char *engine_policy_names[] = {"none",
                                      "cosmological integration",
                                      "drift everything",
                                      "reconstruct multi-poles",
+                                     "temperature",
                                      "cooling",
                                      "stars",
                                      "structure finding",
@@ -2717,7 +2718,8 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
   space_init_sparts(s, e->verbose);
 
   /* Update the cooling function */
-  if (e->policy & engine_policy_cooling)
+  if ((e->policy & engine_policy_cooling) ||
+      (e->policy & engine_policy_temperature))
     cooling_update(e->cosmology, e->cooling_func, /*restart_flag=*/0);
 
 #ifdef WITH_LOGGER
@@ -2973,7 +2975,8 @@ void engine_step(struct engine *e) {
   }
 
   /* Update the cooling function */
-  if (e->policy & engine_policy_cooling)
+  if ((e->policy & engine_policy_cooling) ||
+      (e->policy & engine_policy_temperature))
     cooling_update(e->cosmology, e->cooling_func, /*restart_flag=*/0);
 
   /*****************************************************/
diff --git a/src/engine.h b/src/engine.h
index d7d916c1bc..fea874435c 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -69,13 +69,14 @@ enum engine_policy {
   engine_policy_cosmology = (1 << 10),
   engine_policy_drift_all = (1 << 11),
   engine_policy_reconstruct_mpoles = (1 << 12),
-  engine_policy_cooling = (1 << 13),
-  engine_policy_stars = (1 << 14),
-  engine_policy_structure_finding = (1 << 15),
-  engine_policy_star_formation = (1 << 16),
-  engine_policy_feedback = (1 << 17)
+  engine_policy_temperature = (1 << 13),
+  engine_policy_cooling = (1 << 14),
+  engine_policy_stars = (1 << 15),
+  engine_policy_structure_finding = (1 << 16),
+  engine_policy_star_formation = (1 << 17),
+  engine_policy_feedback = (1 << 18)
 };
-#define engine_maxpolicy 18
+#define engine_maxpolicy 19
 extern const char *engine_policy_names[engine_maxpolicy + 1];
 
 /**
-- 
GitLab