From 04f4a2f5c61bdd6000e3d9c85c764242dfd3f18a Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Wed, 13 Jul 2016 16:14:30 +0100
Subject: [PATCH] Be verbose about the choices made in the snapshots

---
 src/hydro/Default/hydro_io.h |  3 ---
 src/hydro/Gadget2/hydro_io.h |  3 ---
 src/hydro/Minimal/hydro_io.h |  3 ---
 src/hydro_properties.c       | 19 +++++++++++++++++++
 src/hydro_properties.h       |  8 ++++++++
 src/parallel_io.c            |  5 ++++-
 src/serial_io.c              |  5 ++++-
 src/single_io.c              |  5 ++++-
 8 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/src/hydro/Default/hydro_io.h b/src/hydro/Default/hydro_io.h
index fb1f7af922..31990de2e0 100644
--- a/src/hydro/Default/hydro_io.h
+++ b/src/hydro/Default/hydro_io.h
@@ -102,9 +102,6 @@ __attribute__((always_inline)) INLINE static void hydro_write_particles(
  */
 void writeSPHflavour(hid_t h_grpsph) {
 
-  /* Kernel function description */
-  writeAttribute_s(h_grpsph, "Kernel", kernel_name);
-
   /* Viscosity and thermal conduction */
   writeAttribute_s(h_grpsph, "Thermal Conductivity Model",
                    "Price (2008) without switch");
diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h
index f7ee04cbba..9cbdef6dd1 100644
--- a/src/hydro/Gadget2/hydro_io.h
+++ b/src/hydro/Gadget2/hydro_io.h
@@ -102,9 +102,6 @@ __attribute__((always_inline)) INLINE static void hydro_write_particles(
  */
 void writeSPHflavour(hid_t h_grpsph) {
 
-  /* Kernel function description */
-  writeAttribute_s(h_grpsph, "Kernel", kernel_name);
-
   /* Viscosity and thermal conduction */
   writeAttribute_s(h_grpsph, "Thermal Conductivity Model",
                    "(No treatment) Legacy Gadget-2 as in Springel (2005)");
diff --git a/src/hydro/Minimal/hydro_io.h b/src/hydro/Minimal/hydro_io.h
index d5e52e18ef..40b9a4b0e6 100644
--- a/src/hydro/Minimal/hydro_io.h
+++ b/src/hydro/Minimal/hydro_io.h
@@ -102,9 +102,6 @@ __attribute__((always_inline)) INLINE static void hydro_write_particles(
  */
 void writeSPHflavour(hid_t h_grpsph) {
 
-  /* Kernel function description */
-  writeAttribute_s(h_grpsph, "Kernel", kernel_name);
-
   /* Viscosity and thermal conduction */
   /* Nothing in this minimal model... */
   writeAttribute_s(h_grpsph, "Thermal Conductivity Model", "No model");
diff --git a/src/hydro_properties.c b/src/hydro_properties.c
index 45106d1a86..756b9958b7 100644
--- a/src/hydro_properties.c
+++ b/src/hydro_properties.c
@@ -25,6 +25,7 @@
 #include <math.h>
 
 /* Local headers. */
+#include "common_io.h"
 #include "error.h"
 #include "gamma.h"
 #include "hydro.h"
@@ -70,3 +71,21 @@ void hydro_props_print(const struct hydro_props *p) {
     message("Maximal iterations in ghost task set to %d (default is %d)",
             p->max_smoothing_iterations, hydro_props_default_max_iterations);
 }
+
+#if defined(HAVE_HDF5)
+void hydro_props_print_snapshot(hid_t h_grpsph, const struct hydro_props *p) {
+
+  writeAttribute_f(h_grpsph, "Adiabatic index", hydro_gamma);
+  writeAttribute_s(h_grpsph, "Scheme", SPH_IMPLEMENTATION);
+  writeAttribute_s(h_grpsph, "Kernel function", kernel_name);
+  writeAttribute_f(h_grpsph, "Kernel target N_ngb", p->target_neighbours);
+  writeAttribute_f(h_grpsph, "Kernel delta N_ngb", p->delta_neighbours);
+  writeAttribute_f(h_grpsph, "Kernel eta", p->eta_neighbours);
+  writeAttribute_f(h_grpsph, "CFL parameter", p->CFL_condition);
+  writeAttribute_f(h_grpsph, "Volume log(max(delta h))", p->log_max_h_change);
+  writeAttribute_f(h_grpsph, "Volume max change time-step",
+                   powf(expf(p->log_max_h_change), 3.f));
+  writeAttribute_f(h_grpsph, "Max ghost iterations",
+                   p->max_smoothing_iterations);
+}
+#endif
diff --git a/src/hydro_properties.h b/src/hydro_properties.h
index c84252a1dc..6b151e2d03 100644
--- a/src/hydro_properties.h
+++ b/src/hydro_properties.h
@@ -23,6 +23,10 @@
 /* Config parameters. */
 #include "../config.h"
 
+#if defined(HAVE_HDF5)
+#include <hdf5.h>
+#endif
+
 /* Local includes. */
 #include "const.h"
 #include "parser.h"
@@ -53,4 +57,8 @@ struct hydro_props {
 void hydro_props_print(const struct hydro_props *p);
 void hydro_props_init(struct hydro_props *p, const struct swift_params *params);
 
+#if defined(HAVE_HDF5)
+void hydro_props_print_snapshot(hid_t h_grpsph, const struct hydro_props *p);
+#endif
+
 #endif /* SWIFT_HYDRO_PROPERTIES */
diff --git a/src/parallel_io.c b/src/parallel_io.c
index 1411b85b9b..0720c7cbd3 100644
--- a/src/parallel_io.c
+++ b/src/parallel_io.c
@@ -39,6 +39,7 @@
 #include "common_io.h"
 #include "engine.h"
 #include "error.h"
+#include "hydro_properties.h"
 #include "kernel_hydro.h"
 #include "part.h"
 #include "units.h"
@@ -639,8 +640,10 @@ void write_output_parallel(struct engine* e, const char* baseName,
   writeCodeDescription(h_file);
 
   /* Print the SPH parameters */
-  h_grp = H5Gcreate(h_file, "/SPH", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+  h_grp =
+      H5Gcreate(h_file, "/HydroScheme", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
   if (h_grp < 0) error("Error while creating SPH group");
+  hydro_props_print_snapshot(h_grp, e->hydro_properties);
   writeSPHflavour(h_grp);
   H5Gclose(h_grp);
 
diff --git a/src/serial_io.c b/src/serial_io.c
index fac3c1b006..7c7afd1a27 100644
--- a/src/serial_io.c
+++ b/src/serial_io.c
@@ -39,6 +39,7 @@
 #include "common_io.h"
 #include "engine.h"
 #include "error.h"
+#include "hydro_properties.h"
 #include "kernel_hydro.h"
 #include "part.h"
 #include "units.h"
@@ -714,8 +715,10 @@ void write_output_serial(struct engine* e, const char* baseName,
     writeCodeDescription(h_file);
 
     /* Print the SPH parameters */
-    h_grp = H5Gcreate(h_file, "/SPH", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+    h_grp = H5Gcreate(h_file, "/HydroScheme", H5P_DEFAULT, H5P_DEFAULT,
+                      H5P_DEFAULT);
     if (h_grp < 0) error("Error while creating SPH group");
+    hydro_props_print_snapshot(h_grp, e->hydro_properties);
     writeSPHflavour(h_grp);
     H5Gclose(h_grp);
 
diff --git a/src/single_io.c b/src/single_io.c
index 329ec72532..ff437ef137 100644
--- a/src/single_io.c
+++ b/src/single_io.c
@@ -38,6 +38,7 @@
 #include "common_io.h"
 #include "engine.h"
 #include "error.h"
+#include "hydro_properties.h"
 #include "kernel_hydro.h"
 #include "part.h"
 #include "units.h"
@@ -564,8 +565,10 @@ void write_output_single(struct engine* e, const char* baseName,
   writeCodeDescription(h_file);
 
   /* Print the SPH parameters */
-  h_grp = H5Gcreate(h_file, "/SPH", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+  h_grp =
+      H5Gcreate(h_file, "/HydroScheme", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
   if (h_grp < 0) error("Error while creating SPH group");
+  hydro_props_print_snapshot(h_grp, e->hydro_properties);
   writeSPHflavour(h_grp);
   H5Gclose(h_grp);
 
-- 
GitLab