From 1ea0323df656ecfc0b1732ed26a95edc7c0d34b0 Mon Sep 17 00:00:00 2001 From: loikki <loic.hausammann@protonmail.ch> Date: Tue, 7 Apr 2020 12:34:08 +0200 Subject: [PATCH] GEAR: implement named columns --- src/chemistry/EAGLE/chemistry_io.h | 4 +++- src/chemistry/GEAR/chemistry_io.h | 24 +++++++++++++++++++++++- src/chemistry/QLA/chemistry_io.h | 4 +++- src/chemistry/none/chemistry_io.h | 6 ++++-- src/feedback/GEAR/feedback.h | 8 -------- src/parallel_io.c | 2 +- src/serial_io.c | 2 +- src/single_io.c | 2 +- 8 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/chemistry/EAGLE/chemistry_io.h b/src/chemistry/EAGLE/chemistry_io.h index abd517d49f..b0b3253204 100644 --- a/src/chemistry/EAGLE/chemistry_io.h +++ b/src/chemistry/EAGLE/chemistry_io.h @@ -280,8 +280,10 @@ INLINE static int chemistry_write_bparticles(const struct bpart* bparts, * @brief Writes the current model of SPH to the file * @param h_grp The HDF5 group in which to write * @param h_grp_columns The HDF5 group containing named columns + * @param e The #engine. */ -INLINE static void chemistry_write_flavour(hid_t h_grp, hid_t h_grp_columns) { +INLINE static void chemistry_write_flavour(hid_t h_grp, hid_t h_grp_columns, + const struct engine *e) { /* Write the chemistry model */ io_write_attribute_s(h_grp, "Chemistry Model", "EAGLE"); diff --git a/src/chemistry/GEAR/chemistry_io.h b/src/chemistry/GEAR/chemistry_io.h index e8f3989c56..59c1f79fd8 100644 --- a/src/chemistry/GEAR/chemistry_io.h +++ b/src/chemistry/GEAR/chemistry_io.h @@ -21,6 +21,7 @@ #include "chemistry_struct.h" #include "error.h" +#include "feedback.h" #include "io_properties.h" #include "parser.h" #include "part.h" @@ -113,12 +114,33 @@ INLINE static int chemistry_write_bparticles(const struct bpart* bparts, * @brief Writes the current model of SPH to the file * @param h_grp The HDF5 group in which to write * @param h_grp_columns The HDF5 group containing named columns + * @param e The #engine. */ -INLINE static void chemistry_write_flavour(hid_t h_grp, hid_t h_grp_columns) { +INLINE static void chemistry_write_flavour(hid_t h_grp, hid_t h_grp_columns, + const struct engine *e) { io_write_attribute_s(h_grp, "Chemistry Model", "GEAR"); io_write_attribute_d(h_grp, "Chemistry element count", GEAR_CHEMISTRY_ELEMENT_COUNT); +#ifdef FEEDBACK_GEAR + const char *element_names = e->feedback_props->stellar_model.elements_name; + + /* Add to the named columns */ + hsize_t dims[1] = {GEAR_CHEMISTRY_ELEMENT_COUNT}; + hid_t type = H5Tcopy(H5T_C_S1); + H5Tset_size(type, GEAR_LABELS_SIZE); + hid_t space = H5Screate_simple(1, dims, NULL); + hid_t dset = H5Dcreate(h_grp_columns, "ElementAbundances", type, space, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, element_names); + H5Dclose(dset); + dset = H5Dcreate(h_grp_columns, "SmoothedElementAbundances", type, space, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, element_names); + H5Dclose(dset); + + H5Tclose(type); +#endif } #endif diff --git a/src/chemistry/QLA/chemistry_io.h b/src/chemistry/QLA/chemistry_io.h index 7d9d44d244..8d964ab799 100644 --- a/src/chemistry/QLA/chemistry_io.h +++ b/src/chemistry/QLA/chemistry_io.h @@ -95,8 +95,10 @@ INLINE static int chemistry_write_bparticles(const struct bpart* bparts, * @brief Writes the current model of chemistry to the file * @param h_grp The HDF5 group in which to write * @param h_grp_columns The HDF5 group containing named columns + * @param e The #engine. */ -INLINE static void chemistry_write_flavour(hid_t h_grp, hid_t h_grp_columns) { +INLINE static void chemistry_write_flavour(hid_t h_grp, hid_t h_grp_columns, + const struct engine *e) { io_write_attribute_s(h_grp, "Chemistry Model", "Quick Lyman-alpha (constant primordial)"); diff --git a/src/chemistry/none/chemistry_io.h b/src/chemistry/none/chemistry_io.h index 0aed6d4ff2..7dae211043 100644 --- a/src/chemistry/none/chemistry_io.h +++ b/src/chemistry/none/chemistry_io.h @@ -95,8 +95,10 @@ INLINE static int chemistry_write_bparticles(const struct bpart* bparts, * @brief Writes the current model of chemistry to the file * @param h_grp The HDF5 group in which to write * @param h_grp_columns The HDF5 group containing named columns - */ -INLINE static void chemistry_write_flavour(hid_t h_grp, hid_t h_grp_columns) { + * @param e The #engine. +0 */ +INLINE static void chemistry_write_flavour(hid_t h_grp, hid_t h_grp_columns, + const struct engine *e) { io_write_attribute_s(h_grp, "Chemistry Model", "None"); } diff --git a/src/feedback/GEAR/feedback.h b/src/feedback/GEAR/feedback.h index 92ac870180..c4b26b29e7 100644 --- a/src/feedback/GEAR/feedback.h +++ b/src/feedback/GEAR/feedback.h @@ -74,14 +74,6 @@ INLINE static void feedback_write_flavour(struct feedback_props* feedback, hid_t h_grp) { io_write_attribute_s(h_grp, "Feedback Model", "GEAR"); - - for (int i = 0; i < GEAR_CHEMISTRY_ELEMENT_COUNT; i++) { - char buffer[20]; - sprintf(buffer, "Element %d", (int)i); - io_write_attribute_s( - h_grp, buffer, - stellar_evolution_get_element_name(&feedback->stellar_model, i)); - } }; #endif /* SWIFT_FEEDBACK_GEAR_H */ diff --git a/src/parallel_io.c b/src/parallel_io.c index e5567f3521..e0dda38de9 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1179,7 +1179,7 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6], if (h_grp_columns < 0) error("Error while creating named columns group"); entropy_floor_write_flavour(h_grp); cooling_write_flavour(h_grp, h_grp_columns, e->cooling_func); - chemistry_write_flavour(h_grp, h_grp_columns); + chemistry_write_flavour(h_grp, h_grp_columns, e); tracers_write_flavour(h_grp); feedback_write_flavour(e->feedback_props, h_grp); H5Gclose(h_grp_columns); diff --git a/src/serial_io.c b/src/serial_io.c index 0e66d22e55..b411b2bace 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1044,7 +1044,7 @@ void write_output_serial(struct engine* e, const char* baseName, if (h_grp_columns < 0) error("Error while creating named columns group"); entropy_floor_write_flavour(h_grp); cooling_write_flavour(h_grp, h_grp_columns, e->cooling_func); - chemistry_write_flavour(h_grp, h_grp_columns); + chemistry_write_flavour(h_grp, h_grp_columns, e); tracers_write_flavour(h_grp); feedback_write_flavour(e->feedback_props, h_grp); H5Gclose(h_grp_columns); diff --git a/src/single_io.c b/src/single_io.c index ce123fd8ae..63bd94aa2c 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -889,7 +889,7 @@ void write_output_single(struct engine* e, const char* baseName, if (h_grp_columns < 0) error("Error while creating named columns group"); entropy_floor_write_flavour(h_grp); cooling_write_flavour(h_grp, h_grp_columns, e->cooling_func); - chemistry_write_flavour(h_grp, h_grp_columns); + chemistry_write_flavour(h_grp, h_grp_columns, e); tracers_write_flavour(h_grp); feedback_write_flavour(e->feedback_props, h_grp); H5Gclose(h_grp_columns); -- GitLab