Commit 20e2cd54 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Add a description and a scale-factor exponent to each individual array written to the snapshots.

parent 14e71980
......@@ -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
......
......@@ -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
......
......@@ -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 */
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment