From 2df4bac80223c8468d75110391f1c74c02a96664 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Thu, 1 Mar 2018 11:20:10 +0100
Subject: [PATCH] Print the engine policy to the snapshots.

---
 src/common_io.c   | 22 ++++++++++++++++++++--
 src/common_io.h   |  1 +
 src/engine.c      | 18 +++++++++---------
 src/parallel_io.c |  3 +++
 src/serial_io.c   |  3 +++
 src/single_io.c   |  3 +++
 6 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/src/common_io.c b/src/common_io.c
index 53ca5cc4b7..6732681739 100644
--- a/src/common_io.c
+++ b/src/common_io.c
@@ -375,9 +375,8 @@ void io_write_unit_system(hid_t h_file, const struct unit_system* us,
  * @param h_file The (opened) HDF5 file in which to write
  */
 void io_write_code_description(hid_t h_file) {
-  hid_t h_grpcode = 0;
 
-  h_grpcode = H5Gcreate1(h_file, "/Code", 0);
+  const hid_t h_grpcode = H5Gcreate1(h_file, "/Code", 0);
   if (h_grpcode < 0) error("Error while creating code group");
 
   io_write_attribute_s(h_grpcode, "Code", "SWIFT");
@@ -409,6 +408,25 @@ void io_write_code_description(hid_t h_file) {
   H5Gclose(h_grpcode);
 }
 
+/**
+ * @brief Write the #engine policy to the file.
+ * @param h_file File to write to.
+ * @param e The #engine to read the policy from.
+ */
+void io_write_engine_policy(hid_t h_file, const struct engine* e) {
+
+  const hid_t h_grp = H5Gcreate1(h_file, "/Policy", 0);
+  if (h_grp < 0) error("Error while creating policy group");
+
+  for (int i = 1; i <= engine_maxpolicy; ++i)
+    if (e->policy & (1 << i))
+      io_write_attribute_i(h_grp, engine_policy_names[i + 1], 1);
+    else
+      io_write_attribute_i(h_grp, engine_policy_names[i + 1], 0);
+
+  H5Gclose(h_grp);
+}
+
 #endif /* HAVE_HDF5 */
 
 /**
diff --git a/src/common_io.h b/src/common_io.h
index c317238160..49358d8a37 100644
--- a/src/common_io.h
+++ b/src/common_io.h
@@ -73,6 +73,7 @@ void io_write_attribute_l(hid_t grp, const char* name, long data);
 void io_write_attribute_s(hid_t grp, const char* name, const char* str);
 
 void io_write_code_description(hid_t h_file);
+void io_write_engine_policy(hid_t h_file, const struct engine* e);
 
 void io_read_unit_system(hid_t h_file, struct unit_system* us, int mpi_rank);
 void io_write_unit_system(hid_t h_grp, const struct unit_system* us,
diff --git a/src/engine.c b/src/engine.c
index c48510b657..df55ac42ce 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -87,15 +87,15 @@ const char *engine_policy_names[] = {"none",
                                      "steal",
                                      "keep",
                                      "block",
-                                     "cpu_tight",
+                                     "cpu tight",
                                      "mpi",
-                                     "numa_affinity",
+                                     "numa affinity",
                                      "hydro",
-                                     "self_gravity",
-                                     "external_gravity",
-                                     "cosmology_integration",
-                                     "drift_all",
-                                     "reconstruct_mpoles",
+                                     "self gravity",
+                                     "external gravity",
+                                     "cosmological integration",
+                                     "drift everything",
+                                     "reconstruct multi-poles",
                                      "cooling",
                                      "sourceterms",
                                      "stars"};
@@ -5759,7 +5759,7 @@ void engine_print_policy(struct engine *e) {
     printf("[0000] %s engine_policy: engine policies are [ ",
            clocks_get_timesincestart());
     for (int k = 0; k <= engine_maxpolicy; k++)
-      if (e->policy & (1 << k)) printf(" %s ", engine_policy_names[k + 1]);
+      if (e->policy & (1 << k)) printf(" '%s' ", engine_policy_names[k + 1]);
     printf(" ]\n");
     fflush(stdout);
   }
@@ -5767,7 +5767,7 @@ void engine_print_policy(struct engine *e) {
   printf("%s engine_policy: engine policies are [ ",
          clocks_get_timesincestart());
   for (int k = 0; k <= engine_maxpolicy; k++)
-    if (e->policy & (1 << k)) printf(" %s ", engine_policy_names[k + 1]);
+    if (e->policy & (1 << k)) printf(" '%s' ", engine_policy_names[k + 1]);
   printf(" ]\n");
   fflush(stdout);
 #endif
diff --git a/src/parallel_io.c b/src/parallel_io.c
index 315c187e65..e6e1dfd703 100644
--- a/src/parallel_io.c
+++ b/src/parallel_io.c
@@ -899,6 +899,9 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6],
   /* Print the code version */
   io_write_code_description(h_file);
 
+  /* Print the run's policy */
+  io_write_engine_policy(h_file, e);
+
   /* Print the SPH parameters */
   if (e->policy & engine_policy_hydro) {
     h_grp = H5Gcreate(h_file, "/HydroScheme", H5P_DEFAULT, H5P_DEFAULT,
diff --git a/src/serial_io.c b/src/serial_io.c
index 047c3d3f88..6747b345db 100644
--- a/src/serial_io.c
+++ b/src/serial_io.c
@@ -807,6 +807,9 @@ void write_output_serial(struct engine* e, const char* baseName,
     /* Print the code version */
     io_write_code_description(h_file);
 
+    /* Print the run's policy */
+    io_write_engine_policy(h_file, e);
+
     /* Print the SPH parameters */
     if (e->policy & engine_policy_hydro) {
       h_grp = H5Gcreate(h_file, "/HydroScheme", H5P_DEFAULT, H5P_DEFAULT,
diff --git a/src/single_io.c b/src/single_io.c
index 4ba85c2b1b..862851378d 100644
--- a/src/single_io.c
+++ b/src/single_io.c
@@ -659,6 +659,9 @@ void write_output_single(struct engine* e, const char* baseName,
   /* Print the code version */
   io_write_code_description(h_file);
 
+  /* Print the run's policy */
+  io_write_engine_policy(h_file, e);
+
   /* Print the SPH parameters */
   if (e->policy & engine_policy_hydro) {
     h_grp = H5Gcreate(h_file, "/HydroScheme", H5P_DEFAULT, H5P_DEFAULT,
-- 
GitLab