From 6cea41bdb98c6ea81a2054cf24a222182e07f3cd Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Thu, 18 Jan 2018 14:26:15 +0100 Subject: [PATCH] Add a function that returns the name of a specific chemistry element. Use that function to print the names in the snapshot header. --- src/chemistry/EAGLE/chemistry.h | 13 +++++++++++++ src/chemistry/EAGLE/chemistry_io.h | 12 +++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/chemistry/EAGLE/chemistry.h b/src/chemistry/EAGLE/chemistry.h index 8553f50041..d268486631 100644 --- a/src/chemistry/EAGLE/chemistry.h +++ b/src/chemistry/EAGLE/chemistry.h @@ -37,6 +37,19 @@ #include "physical_constants.h" #include "units.h" +/** + * @brief Return a string containing the name of a given #chemistry_element. + */ +__attribute__((always_inline)) INLINE static const char* +chemistry_get_element_name(enum chemistry_element elem) { + + static const char* chemistry_element_names[chemistry_element_count] = { + "Hydrogen", "Helium", "Carbon", "Nitrogen", "Oxygen", + "Neon", "Magnesium", "Silicium", "Iron"}; + + return chemistry_element_names[elem]; +} + /** * @brief Sets the chemistry properties of the (x-)particles to a valid start * state. diff --git a/src/chemistry/EAGLE/chemistry_io.h b/src/chemistry/EAGLE/chemistry_io.h index b05eb0dbe9..70c62a1bbd 100644 --- a/src/chemistry/EAGLE/chemistry_io.h +++ b/src/chemistry/EAGLE/chemistry_io.h @@ -19,6 +19,7 @@ #ifndef SWIFT_CHEMISTRY_IO_EAGLE_H #define SWIFT_CHEMISTRY_IO_EAGLE_H +#include "chemistry.h" #include "io_properties.h" /** @@ -98,9 +99,14 @@ int chemistry_write_particles(const struct part* parts, struct io_props* list) { * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -void chemistry_write_flavour(hid_t h_grpsph) { - - io_write_attribute_s(h_grpsph, "Chemistry Model", "EAGLE"); +void chemistry_write_flavour(hid_t h_grp) { + + io_write_attribute_s(h_grp, "Chemistry Model", "EAGLE"); + for (int elem = 0; elem < chemistry_element_count; ++elem) { + char buffer[20]; + sprintf(buffer, "Element %d", elem); + io_write_attribute_s(h_grp, buffer, chemistry_get_element_name(elem)); + } } #endif /* SWIFT_CHEMISTRY_IO_EAGLE_H */ -- GitLab