diff --git a/src/black_holes/Default/black_holes_io.h b/src/black_holes/Default/black_holes_io.h index e193f550bfd100077c33abdf6bdfcedb74d829da..f751596abef7418b86b1e9ae8d8740bbe64cbfe5 100644 --- a/src/black_holes/Default/black_holes_io.h +++ b/src/black_holes/Default/black_holes_io.h @@ -65,15 +65,15 @@ INLINE static void black_holes_write_particles(const struct bpart *bparts, /* List what we want to write */ list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, - bparts, x); - list[1] = - io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, bparts, v); - list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, bparts, mass); + 1.f, bparts, x, ""); + list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, 1.f, + bparts, v, ""); + list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, 0.f, + bparts, mass, ""); list[3] = io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, - bparts, id); + 0.f, bparts, id, ""); list[4] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - bparts, h); + 1.f, bparts, h, ""); #ifdef DEBUG_INTERACTIONS_BLACK_HOLES diff --git a/src/common_io.h b/src/common_io.h index c93414d1ffca8f7ead7a1ff29d387967f82a9cb2..03437d1a38a09e59e6abd4b9ca762f181ffc3731 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -27,7 +27,8 @@ #include "part_type.h" #include "units.h" -#define FIELD_BUFFER_SIZE 200 +#define FIELD_BUFFER_SIZE 64 +#define DESCRIPTION_BUFFER_SIZE 256 #define PARTICLE_GROUP_BUFFER_SIZE 50 #define FILENAME_BUFFER_SIZE 150 #define IO_BUFFER_ALIGNMENT 1024 diff --git a/src/gravity/Default/gravity_io.h b/src/gravity/Default/gravity_io.h index 2e443e8fdc2479f3f2feff30281dccad9a7b6519..edd0f60bc38ce86f385d759c2075db330e823d1c 100644 --- a/src/gravity/Default/gravity_io.h +++ b/src/gravity/Default/gravity_io.h @@ -111,12 +111,13 @@ INLINE static void darkmatter_write_particles(const struct gpart* gparts, "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, gparts, convert_gpart_pos); list[1] = io_make_output_field_convert_gpart( "Velocities", FLOAT, 3, UNIT_CONV_SPEED, gparts, convert_gpart_vel); - list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, gparts, mass); - list[3] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, gparts, id_or_neg_offset); - list[4] = io_make_output_field("GroupIDs", INT, 1, UNIT_CONV_NO_UNITS, gparts, - group_id); + list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, 0.f, + gparts, mass, ""); + list[3] = + io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, 0.f, + gparts, id_or_neg_offset, ""); + list[4] = io_make_output_field("GroupIDs", INT, 1, UNIT_CONV_NO_UNITS, 0.f, gparts, + group_id, ""); } #endif /* SWIFT_DEFAULT_GRAVITY_IO_H */ diff --git a/src/hydro/Minimal/hydro_io.h b/src/hydro/Minimal/hydro_io.h index c6e36e32d6176c6968e70c7ba689b6651a2d1c18..d3dcbaf1d4c8558da4c99fa8a2d5eadd1da31e20 100644 --- a/src/hydro/Minimal/hydro_io.h +++ b/src/hydro/Minimal/hydro_io.h @@ -165,16 +165,20 @@ INLINE static void hydro_write_particles(const struct part* parts, convert_part_pos); list[1] = io_make_output_field_convert_part( "Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, xparts, convert_part_vel); - list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass); - list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - parts, h); - list[4] = io_make_output_field("InternalEnergy", FLOAT, 1, - UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u); - list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id); + list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, 0.f, parts, + mass, "Masses of the particles"); + list[3] = io_make_output_field( + "SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, 1.f, parts, h, + "Smoothing lengths (FWHM of the kernel) of the particles"); + list[4] = io_make_output_field( + "InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, + 3. * hydro_gamma_minus_one, parts, u, "Thermal energy per unit mass."); + list[5] = + io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, 0.f, + parts, id, "Unique ID of the particles"); list[6] = - io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho); + io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, -3.f, parts, + rho, "Physical mass density of the particles"); list[7] = io_make_output_field_convert_part("Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, xparts, convert_S); diff --git a/src/io_properties.h b/src/io_properties.h index 0c2fb52f53a6dda649ea05e30355c25c638be762..739063059da449eada937138aa94fda5473e3c81 100644 --- a/src/io_properties.h +++ b/src/io_properties.h @@ -24,8 +24,8 @@ /* Local includes. */ #include "common_io.h" +#include "error.h" #include "inline.h" -#include "part.h" /* Standard includes. */ #include <string.h> @@ -79,6 +79,9 @@ struct io_props { /* Name */ char name[FIELD_BUFFER_SIZE]; + /* Description of the variable to write to the field's meta-data */ + char description[DESCRIPTION_BUFFER_SIZE]; + /* Type of the field */ enum IO_DATA_TYPE type; @@ -91,6 +94,9 @@ struct io_props { /* Units of the quantity */ enum unit_conversion_factor units; + /* Scale-factor exponent to apply for unit conversion to physical */ + float scale_factor_exponent; + /* Pointer to the field of the first particle in the array */ char* field; @@ -196,9 +202,10 @@ INLINE static struct io_props io_make_input_field_( /** * @brief Constructs an #io_props from its parameters */ -#define io_make_output_field(name, type, dim, units, part, field) \ - io_make_output_field_(name, type, dim, units, (char*)(&(part[0]).field), \ - sizeof(part[0])) +#define io_make_output_field(name, type, dim, units, a_exponent, part, field, \ + desc) \ + io_make_output_field_(name, type, dim, units, a_exponent, \ + (char*)(&(part[0]).field), sizeof(part[0]), desc) /** * @brief Construct an #io_props from its parameters @@ -214,13 +221,21 @@ INLINE static struct io_props io_make_input_field_( */ INLINE static struct io_props io_make_output_field_( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, - enum unit_conversion_factor units, char* field, size_t partSize) { + enum unit_conversion_factor units, float a_exponent, char* field, + size_t partSize, const char description[DESCRIPTION_BUFFER_SIZE]) { + struct io_props r; strcpy(r.name, name); + if (strlen(description) == 0) { + sprintf(r.description, "No description given"); + } else { + strcpy(r.description, description); + } r.type = type; r.dimension = dimension; r.importance = UNUSED; r.units = units; + r.scale_factor_exponent = a_exponent; r.field = field; r.partSize = partSize; r.parts = NULL; diff --git a/src/single_io.c b/src/single_io.c index afce1e1e6ebb6a8101ccfa109efd8df9e10fbd33..c5ac8ff0cafef650726aad9cc745659efb9beb69 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -327,14 +327,13 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName, units_cgs_conversion_string(buffer, snapshot_units, props.units); float baseUnitsExp[5]; units_get_base_unit_exponents_array(baseUnitsExp, props.units); - const float a_factor_exp = units_a_factor(snapshot_units, props.units); io_write_attribute_f(h_data, "U_M exponent", baseUnitsExp[UNIT_MASS]); io_write_attribute_f(h_data, "U_L exponent", baseUnitsExp[UNIT_LENGTH]); io_write_attribute_f(h_data, "U_t exponent", baseUnitsExp[UNIT_TIME]); io_write_attribute_f(h_data, "U_I exponent", baseUnitsExp[UNIT_CURRENT]); io_write_attribute_f(h_data, "U_T exponent", baseUnitsExp[UNIT_TEMPERATURE]); io_write_attribute_f(h_data, "h-scale exponent", 0); - io_write_attribute_f(h_data, "a-scale exponent", a_factor_exp); + io_write_attribute_f(h_data, "a-scale exponent", props.scale_factor_exponent); io_write_attribute_s(h_data, "Expression for physical CGS units", buffer); /* Write the actual number this conversion factor corresponds to */ @@ -347,7 +346,13 @@ void writeArray(const struct engine* e, hid_t grp, char* fileName, io_write_attribute_d( h_data, "Conversion factor to phyical CGS (including cosmological corrections)", - factor * pow(e->cosmology->a, a_factor_exp)); + factor * pow(e->cosmology->a, props.scale_factor_exponent)); + + if (strlen(props.description) != 0) { + + /* Write the full description */ + io_write_attribute_s(h_data, "Description", props.description); + } /* Free and close everything */ swift_free("writebuff", temp); diff --git a/src/stars/Default/stars_io.h b/src/stars/Default/stars_io.h index 5ff57549b9d0db37d6929c1e9fbb8da8372d7e6c..6bb0741ba67b366d6008a10b6b2d5e019365656e 100644 --- a/src/stars/Default/stars_io.h +++ b/src/stars/Default/stars_io.h @@ -65,15 +65,15 @@ INLINE static void stars_write_particles(const struct spart *sparts, /* List what we want to write */ list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, - sparts, x); - list[1] = - io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, sparts, v); - list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, sparts, mass); + 1.f, sparts, x, ""); + list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, 1.f, + sparts, v, ""); + list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, 0.f, + sparts, mass, ""); list[3] = io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, - sparts, id); + 0.f, sparts, id, ""); list[4] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - sparts, h); + 1.f, sparts, h, ""); #ifdef DEBUG_INTERACTIONS_STARS diff --git a/src/velociraptor_io.h b/src/velociraptor_io.h index d535e54815139e243b9a3bc40ec8dd4de2af1ac1..366c9f501445c0586b5aca46ce66ffea816f3f68 100644 --- a/src/velociraptor_io.h +++ b/src/velociraptor_io.h @@ -71,7 +71,7 @@ __attribute__((always_inline)) INLINE static int velociraptor_write_gparts( const struct velociraptor_gpart_data* group_data, struct io_props* list) { list[0] = io_make_output_field("GroupID", LONGLONG, 1, UNIT_CONV_NO_UNITS, - group_data, groupID); + 0.f, group_data, groupID, ""); return 1; }