From 53173af40c3f2ebc01894ada58be31df7d06d450 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Mon, 2 Apr 2018 14:16:02 +0200 Subject: [PATCH 01/39] Add selection of output fields --- examples/main.c | 31 ++++++++++++++++++++- src/engine.c | 1 + src/engine.h | 3 ++ src/gravity/Default/gravity_io.h | 10 +++---- src/hydro/Gadget2/hydro_io.h | 28 +++++++++---------- src/io_properties.h | 48 ++++++++++++++++++++++---------- src/parallel_io.c | 13 ++++++--- src/parser.c | 17 ++++++++--- src/parser.h | 1 + src/serial_io.c | 13 ++++++--- src/single_io.c | 12 ++++++-- src/stars/Default/star_io.h | 8 +++--- 12 files changed, 132 insertions(+), 53 deletions(-) diff --git a/examples/main.c b/examples/main.c index 692eb53de..18ae54d3f 100644 --- a/examples/main.c +++ b/examples/main.c @@ -198,11 +198,12 @@ int main(int argc, char *argv[]) { char *cmdparams[PARSER_MAX_NO_OF_PARAMS]; char paramFileName[200] = ""; char restart_file[200] = ""; + char outputFieldsFileName[200] = ""; unsigned long long cpufreq = 0; /* Parse the parameters */ int c; - while ((c = getopt(argc, argv, "acCdDef:FgGhMn:P:rsSt:Tv:y:Y:")) != -1) + while ((c = getopt(argc, argv, "acCdDef:FgGhMn:o:P:rsSt:Tv:y:Y:")) != -1) switch (c) { case 'a': #if defined(HAVE_SETAFFINITY) && defined(HAVE_LIBNUMA) @@ -259,6 +260,15 @@ int main(int argc, char *argv[]) { return 1; } break; + case 'o': + if (sscanf(optarg, "%s", outputFieldsFileName) != 1) { + if (myrank == 0) + { + printf("Error parsing output fields filename"); + print_help_message(); + } + } + break; case 'P': cmdparams[nparams] = optarg; nparams++; @@ -457,6 +467,25 @@ int main(int argc, char *argv[]) { MPI_Bcast(params, sizeof(struct swift_params), MPI_BYTE, 0, MPI_COMM_WORLD); #endif + /* Read output fields */ + struct swift_params *output_fields = + (struct swift_params *)malloc(sizeof(struct swift_params)); + if (output_fields == NULL) error("Error allocating memory for the output fields file."); + if (myrank == 0) { + message("Reading runtime output fields from file '%s'", outputFieldsFileName); + if (strcmp(outputFieldsFileName, "") != 0) + parser_read_file(outputFieldsFileName, output_fields); + else + parser_init(outputFieldsFileName, output_fields); + + /* And dump the parameters as used. */ + parser_write_params_to_file(output_fields, "used_output_fields.yml"); + } +#ifdef WITH_MPI + /* Broadcast the parameter file */ + MPI_Bcast(output_fields, sizeof(struct swift_params), MPI_BYTE, 0, MPI_COMM_WORLD); +#endif + /* Check that we can write the snapshots by testing if the output * directory exists and is searchable and writable. */ char basename[PARSER_MAX_LINE_SIZE]; diff --git a/src/engine.c b/src/engine.c index 9a7a7ede8..f62866456 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5484,6 +5484,7 @@ void engine_init(struct engine *e, struct space *s, e->chemistry = chemistry; e->sourceterms = sourceterms; e->parameter_file = params; + e->output_fields = output_fields; #ifdef WITH_MPI e->cputime_last_step = 0; e->last_repartition = 0; diff --git a/src/engine.h b/src/engine.h index 72f440b2e..e04a80e99 100644 --- a/src/engine.h +++ b/src/engine.h @@ -312,6 +312,9 @@ struct engine { /* The (parsed) parameter file */ const struct swift_params *parameter_file; + /* The (parsed) output fields */ + const struct swift_params *output_fields; + /* Temporary struct to hold a group of deferable properties (in MPI mode * these are reduced together, but may not be required just yet). */ struct collectgroup1 collect_group1; diff --git a/src/gravity/Default/gravity_io.h b/src/gravity/Default/gravity_io.h index 7b8ec2c8f..efe508e97 100644 --- a/src/gravity/Default/gravity_io.h +++ b/src/gravity/Default/gravity_io.h @@ -106,15 +106,15 @@ void darkmatter_write_particles(const struct gpart* gparts, /* List what we want to write */ list[0] = io_make_output_field_convert_gpart( - "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, gparts, convert_gpart_pos); + "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, gparts, convert_gpart_pos, 1); list[1] = io_make_output_field_convert_gpart( - "Velocities", FLOAT, 3, UNIT_CONV_SPEED, gparts, convert_gpart_vel); + "Velocities", FLOAT, 3, UNIT_CONV_SPEED, gparts, convert_gpart_vel, 1); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, gparts, mass); + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, gparts, mass, 1); list[3] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, gparts, id_or_neg_offset); + UNIT_CONV_NO_UNITS, gparts, id_or_neg_offset, 1); list[4] = io_make_output_field("Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, - gparts, potential); + gparts, potential, 1); } #endif /* SWIFT_DEFAULT_GRAVITY_IO_H */ diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h index b6e2c3223..9642d51cb 100644 --- a/src/hydro/Gadget2/hydro_io.h +++ b/src/hydro/Gadget2/hydro_io.h @@ -139,28 +139,28 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, /* List what we want to write */ list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, - convert_part_pos); + convert_part_pos, 1); list[1] = io_make_output_field_convert_part( - "Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, xparts, convert_part_vel); + "Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, xparts, convert_part_vel, 1); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass); + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass, 1); list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - parts, h); + parts, h, 1); list[4] = io_make_output_field( - "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy); + "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy, 1); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id); + UNIT_CONV_NO_UNITS, parts, id, 1); list[6] = - io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho); + io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho, 1); list[7] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - parts, xparts, convert_part_u); + parts, xparts, convert_part_u, 1); list[8] = io_make_output_field_convert_part( - "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_part_P); + "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_part_P, 1); list[9] = io_make_output_field_convert_part("Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, - xparts, convert_part_potential); + xparts, convert_part_potential, 1); #ifdef DEBUG_INTERACTIONS_SPH @@ -168,15 +168,15 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, *num_fields += 4; list[0] = io_make_output_field("Num_ngb_density", INT, 1, UNIT_CONV_NO_UNITS, - parts, num_ngb_density); + parts, num_ngb_density, 1); list[1] = io_make_output_field("Num_ngb_force", INT, 1, UNIT_CONV_NO_UNITS, - parts, num_ngb_force); + parts, num_ngb_force, 1); list[2] = io_make_output_field("Ids_ngb_density", LONGLONG, MAX_NUM_OF_NEIGHBOURS, - UNIT_CONV_NO_UNITS, parts, ids_ngbs_density); + UNIT_CONV_NO_UNITS, parts, ids_ngbs_density, 1); list[3] = io_make_output_field("Ids_ngb_force", LONGLONG, MAX_NUM_OF_NEIGHBOURS, - UNIT_CONV_NO_UNITS, parts, ids_ngbs_force); + UNIT_CONV_NO_UNITS, parts, ids_ngbs_force, 1); #endif } diff --git a/src/io_properties.h b/src/io_properties.h index 037d32338..49a4e0ecb 100644 --- a/src/io_properties.h +++ b/src/io_properties.h @@ -97,13 +97,17 @@ struct io_props { /* Conversion function for gpart */ conversion_func_gpart_float convert_gpart_f; conversion_func_gpart_double convert_gpart_d; + + /* default output behaviour + * 0 means not writing, 1 means writing */ + int default_output; }; /** * @brief Constructs an #io_props from its parameters */ #define io_make_input_field(name, type, dim, importance, units, part, field) \ - io_make_input_field_(name, type, dim, importance, units, \ + io_make_input_field_(name, type, dim, importance, units, \ (char*)(&(part[0]).field), sizeof(part[0])) /** @@ -139,6 +143,7 @@ INLINE static struct io_props io_make_input_field_( r.convert_part_d = NULL; r.convert_gpart_f = NULL; r.convert_gpart_d = NULL; + r.default_output = 0; return r; } @@ -146,9 +151,9 @@ 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) \ +#define io_make_output_field(name, type, dim, units, part, field, default_output) \ io_make_output_field_(name, type, dim, units, (char*)(&(part[0]).field), \ - sizeof(part[0])) + sizeof(part[0]), default_output) /** * @brief Construct an #io_props from its parameters @@ -159,12 +164,14 @@ INLINE static struct io_props io_make_input_field_( * @param units The units of the dataset * @param field Pointer to the field of the first particle * @param partSize The size in byte of the particle + * @param default_output Default output behaviour (0 -> not write, 1 -> write) * * Do not call this function directly. Use the macro defined above. */ 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, char* field, size_t partSize, + int default_output) { struct io_props r; strcpy(r.name, name); r.type = type; @@ -180,6 +187,7 @@ INLINE static struct io_props io_make_output_field_( r.convert_part_d = NULL; r.convert_gpart_f = NULL; r.convert_gpart_d = NULL; + r.default_output = default_output; return r; } @@ -188,9 +196,9 @@ INLINE static struct io_props io_make_output_field_( * @brief Constructs an #io_props (with conversion) from its parameters */ #define io_make_output_field_convert_part(name, type, dim, units, part, xpart, \ - convert) \ - io_make_output_field_convert_part_##type( \ - name, type, dim, units, sizeof(part[0]), part, xpart, convert) + convert, default_output) \ + io_make_output_field_convert_part_##type( \ + name, type, dim, units, sizeof(part[0]), part, xpart, convert, default_output) /** * @brief Construct an #io_props from its parameters @@ -203,6 +211,7 @@ INLINE static struct io_props io_make_output_field_( * @param parts The particle array * @param xparts The xparticle array * @param functionPtr The function used to convert a particle to a float + * @param default_output Default output behaviour (0 -> not write, 1 -> write) * * Do not call this function directly. Use the macro defined above. */ @@ -210,7 +219,8 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t partSize, const struct part* parts, const struct xpart* xparts, - conversion_func_part_float functionPtr) { + conversion_func_part_float functionPtr, + int default_output) { struct io_props r; strcpy(r.name, name); @@ -228,6 +238,7 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT( r.convert_part_d = NULL; r.convert_gpart_f = NULL; r.convert_gpart_d = NULL; + r.default_output = default_output; return r; } @@ -243,6 +254,7 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT( * @param parts The particle array * @param xparts The xparticle array * @param functionPtr The function used to convert a particle to a float + * @param default_output Default output behaviour (0 -> not write, 1 -> write) * * Do not call this function directly. Use the macro defined above. */ @@ -250,7 +262,7 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t partSize, const struct part* parts, const struct xpart* xparts, - conversion_func_part_double functionPtr) { + conversion_func_part_double functionPtr, int default_output) { struct io_props r; strcpy(r.name, name); @@ -268,6 +280,7 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE( r.convert_part_d = functionPtr; r.convert_gpart_f = NULL; r.convert_gpart_d = NULL; + r.default_output = default_output; return r; } @@ -276,9 +289,10 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE( * @brief Constructs an #io_props (with conversion) from its parameters */ #define io_make_output_field_convert_gpart(name, type, dim, units, gpart, \ - convert) \ - io_make_output_field_convert_gpart_##type(name, type, dim, units, \ - sizeof(gpart[0]), gpart, convert) + convert, default_output) \ + io_make_output_field_convert_gpart_##type(name, type, dim, units, \ + sizeof(gpart[0]), gpart, convert, \ + default_output) /** * @brief Construct an #io_props from its parameters @@ -290,13 +304,15 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE( * @param gpartSize The size in byte of the particle * @param gparts The particle array * @param functionPtr The function used to convert a g-particle to a float + * @param default_output Default output behaviour (0 -> not write, 1 -> write) * * Do not call this function directly. Use the macro defined above. */ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t gpartSize, - const struct gpart* gparts, conversion_func_gpart_float functionPtr) { + const struct gpart* gparts, conversion_func_gpart_float functionPtr, + int default_output) { struct io_props r; strcpy(r.name, name); @@ -314,6 +330,7 @@ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT( r.convert_part_d = NULL; r.convert_gpart_f = functionPtr; r.convert_gpart_d = NULL; + r.default_output = default_output; return r; } @@ -328,13 +345,15 @@ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT( * @param gpartSize The size in byte of the particle * @param gparts The particle array * @param functionPtr The function used to convert a g-particle to a float + * @param default_output Default output behaviour (0 -> not write, 1 -> write) * * Do not call this function directly. Use the macro defined above. */ INLINE static struct io_props io_make_output_field_convert_gpart_DOUBLE( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t gpartSize, - const struct gpart* gparts, conversion_func_gpart_double functionPtr) { + const struct gpart* gparts, conversion_func_gpart_double functionPtr, + int default_output) { struct io_props r; strcpy(r.name, name); @@ -352,6 +371,7 @@ INLINE static struct io_props io_make_output_field_convert_gpart_DOUBLE( r.convert_part_d = NULL; r.convert_gpart_f = NULL; r.convert_gpart_d = functionPtr; + r.default_output = default_output; return r; } diff --git a/src/parallel_io.c b/src/parallel_io.c index e09022516..e17def2aa 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1262,10 +1262,15 @@ void write_output_parallel(struct engine* e, const char* baseName, } /* Write everything */ - for (int i = 0; i < num_fields; ++i) - writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, - N_total[ptype], mpi_rank, offset[ptype], internal_units, - snapshot_units); + for (int i = 0; i < num_fields; ++i) { + char field[200] = "OutputFields:"; + strcat(field, list[i].name); + int should_write = parser_get_opt_param_int(output_fields, field, list[i].default_output); + if (should_write) + writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, + N_total[ptype], mpi_rank, offset[ptype], internal_units, + snapshot_units); + } /* Free temporary array */ if (dmparts) { diff --git a/src/parser.c b/src/parser.c index af9ef5fd6..581f3a0cf 100644 --- a/src/parser.c +++ b/src/parser.c @@ -57,12 +57,23 @@ static void find_duplicate_section(const struct swift_params *params, static int lineNumber = 0; /** - * @brief Reads an input file and stores each parameter in a structure. + * @brief Initialize the parser structure. * * @param file_name Name of file to be read * @param params Structure to be populated from file */ +void parser_init(const char *file_name, struct swift_params *params) { + params->paramCount = 0; + params->sectionCount = 0; + strcpy(params->fileName, file_name); +} +/** + * @brief Reads an input file and stores each parameter in a structure. + * + * @param file_name Name of file to be read + * @param params Structure to be populated from file + */ void parser_read_file(const char *file_name, struct swift_params *params) { /* Open file for reading */ FILE *file = fopen(file_name, "r"); @@ -71,9 +82,7 @@ void parser_read_file(const char *file_name, struct swift_params *params) { char line[PARSER_MAX_LINE_SIZE]; /* Initialise parameter count. */ - params->paramCount = 0; - params->sectionCount = 0; - strcpy(params->fileName, file_name); + parser_init(file_name, params); /* Check if parameter file exits. */ if (file == NULL) { diff --git a/src/parser.h b/src/parser.h index 58f4a53ea..dc4520b98 100644 --- a/src/parser.h +++ b/src/parser.h @@ -55,6 +55,7 @@ struct swift_params { }; /* Public API. */ +void parser_init(const char *file_name, struct swift_params *params); void parser_read_file(const char *file_name, struct swift_params *params); void parser_print_params(const struct swift_params *params); void parser_write_params_to_file(const struct swift_params *params, diff --git a/src/serial_io.c b/src/serial_io.c index 9403caad7..fda396907 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1006,10 +1006,15 @@ void write_output_serial(struct engine* e, const char* baseName, } /* Write everything */ - for (int i = 0; i < num_fields; ++i) - writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], - Nparticles, N_total[ptype], mpi_rank, offset[ptype], - internal_units, snapshot_units); + for (int i = 0; i < num_fields; ++i) { + char field[200] = "OutputFields:"; + strcat(field, list[i].name); + int should_write = parser_get_opt_param_int(output_fields, field, list[i].default_output); + if (should_write) + writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], + Nparticles, N_total[ptype], mpi_rank, offset[ptype], + internal_units, snapshot_units); + } /* Free temporary array */ if (dmparts) { diff --git a/src/single_io.c b/src/single_io.c index 866d830ac..bea3be483 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -594,6 +594,7 @@ void write_output_single(struct engine* e, const char* baseName, struct gpart* dmparts = NULL; const struct spart* sparts = e->s->sparts; const struct cooling_function_data* cooling = e->cooling_func; + const struct swift_params* output_fields = e->output_fields; /* Number of unassociated gparts */ const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0; @@ -825,9 +826,14 @@ void write_output_single(struct engine* e, const char* baseName, } /* Write everything */ - for (int i = 0; i < num_fields; ++i) - writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, - internal_units, snapshot_units); + for (int i = 0; i < num_fields; ++i) { + char field[200] = "OutputFields:"; + strcat(field, list[i].name); + int should_write = parser_get_opt_param_int(output_fields, field, list[i].default_output); + if (should_write) + writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, + internal_units, snapshot_units); + } /* Free temporary array */ if (dmparts) { diff --git a/src/stars/Default/star_io.h b/src/stars/Default/star_io.h index c3dc31096..974ed30fb 100644 --- a/src/stars/Default/star_io.h +++ b/src/stars/Default/star_io.h @@ -60,13 +60,13 @@ void star_write_particles(const struct spart* sparts, struct io_props* list, /* List what we want to read */ list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, - sparts, x); + sparts, x, 1); list[1] = - io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, sparts, v); + io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, sparts, v, 1); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, sparts, mass); + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, sparts, mass, 1); list[3] = io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, - sparts, id); + sparts, id, 1); } #endif /* SWIFT_DEFAULT_STAR_IO_H */ -- GitLab From c06ca66d8ebd80d33673c816c830a9f116a2149d Mon Sep 17 00:00:00 2001 From: lhausamm Date: Mon, 2 Apr 2018 14:25:37 +0200 Subject: [PATCH 02/39] Apply select io to all options --- examples/main.c | 22 +++++++------- src/chemistry/EAGLE/chemistry_io.h | 45 ++++++++++++++-------------- src/chemistry/GEAR/chemistry_io.h | 3 +- src/gravity/Default/gravity_io.h | 11 +++---- src/hydro/Default/hydro_io.h | 25 ++++++++-------- src/hydro/Gadget2/hydro_io.h | 22 +++++++------- src/hydro/GizmoMFM/hydro_io.h | 29 +++++++++--------- src/hydro/Minimal/hydro_io.h | 29 +++++++++--------- src/hydro/PressureEntropy/hydro_io.h | 31 +++++++++---------- src/hydro/Shadowswift/hydro_io.h | 18 +++++------ src/io_properties.h | 27 +++++++++-------- src/parallel_io.c | 9 +++--- src/serial_io.c | 17 ++++++----- src/single_io.c | 7 +++-- src/stars/Default/star_io.h | 6 ++-- 15 files changed, 158 insertions(+), 143 deletions(-) diff --git a/examples/main.c b/examples/main.c index 18ae54d3f..e6d13bb8a 100644 --- a/examples/main.c +++ b/examples/main.c @@ -261,13 +261,12 @@ int main(int argc, char *argv[]) { } break; case 'o': - if (sscanf(optarg, "%s", outputFieldsFileName) != 1) { - if (myrank == 0) - { - printf("Error parsing output fields filename"); - print_help_message(); - } - } + if (sscanf(optarg, "%s", outputFieldsFileName) != 1) { + if (myrank == 0) { + printf("Error parsing output fields filename"); + print_help_message(); + } + } break; case 'P': cmdparams[nparams] = optarg; @@ -470,9 +469,11 @@ int main(int argc, char *argv[]) { /* Read output fields */ struct swift_params *output_fields = (struct swift_params *)malloc(sizeof(struct swift_params)); - if (output_fields == NULL) error("Error allocating memory for the output fields file."); + if (output_fields == NULL) + error("Error allocating memory for the output fields file."); if (myrank == 0) { - message("Reading runtime output fields from file '%s'", outputFieldsFileName); + message("Reading runtime output fields from file '%s'", + outputFieldsFileName); if (strcmp(outputFieldsFileName, "") != 0) parser_read_file(outputFieldsFileName, output_fields); else @@ -483,7 +484,8 @@ int main(int argc, char *argv[]) { } #ifdef WITH_MPI /* Broadcast the parameter file */ - MPI_Bcast(output_fields, sizeof(struct swift_params), MPI_BYTE, 0, MPI_COMM_WORLD); + MPI_Bcast(output_fields, sizeof(struct swift_params), MPI_BYTE, 0, + MPI_COMM_WORLD); #endif /* Check that we can write the snapshots by testing if the output diff --git a/src/chemistry/EAGLE/chemistry_io.h b/src/chemistry/EAGLE/chemistry_io.h index aab8ec240..efef6b07a 100644 --- a/src/chemistry/EAGLE/chemistry_io.h +++ b/src/chemistry/EAGLE/chemistry_io.h @@ -49,48 +49,49 @@ int chemistry_write_particles(const struct part* parts, struct io_props* list) { /* List what we want to write */ list[0] = io_make_output_field("ElementAbundance", FLOAT, chemistry_element_count, UNIT_CONV_NO_UNITS, - parts, chemistry_data.metal_mass_fraction); + parts, chemistry_data.metal_mass_fraction, 1); - list[1] = io_make_output_field( - "SmoothedElementAbundance", FLOAT, chemistry_element_count, - UNIT_CONV_NO_UNITS, parts, chemistry_data.smoothed_metal_mass_fraction); + list[1] = + io_make_output_field("SmoothedElementAbundance", FLOAT, + chemistry_element_count, UNIT_CONV_NO_UNITS, parts, + chemistry_data.smoothed_metal_mass_fraction, 1); list[2] = io_make_output_field("Metallicity", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, - chemistry_data.metal_mass_fraction_total); + chemistry_data.metal_mass_fraction_total, 1); list[3] = io_make_output_field( "SmoothedMetallicity", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, - chemistry_data.smoothed_metal_mass_fraction_total); + chemistry_data.smoothed_metal_mass_fraction_total, 1); list[4] = io_make_output_field("TotalMassFromSNIa", FLOAT, 1, UNIT_CONV_MASS, - parts, chemistry_data.mass_from_SNIa); + parts, chemistry_data.mass_from_SNIa, 1); - list[5] = io_make_output_field("MetalMassFracFromSNIa", FLOAT, 1, - UNIT_CONV_NO_UNITS, parts, - chemistry_data.metal_mass_fraction_from_SNIa); + list[5] = io_make_output_field( + "MetalMassFracFromSNIa", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, + chemistry_data.metal_mass_fraction_from_SNIa, 1); list[6] = io_make_output_field("TotalMassFromAGB", FLOAT, 1, UNIT_CONV_MASS, - parts, chemistry_data.mass_from_AGB); + parts, chemistry_data.mass_from_AGB, 1); - list[7] = - io_make_output_field("MetalMassFracFromAGB", FLOAT, 1, UNIT_CONV_NO_UNITS, - parts, chemistry_data.metal_mass_fraction_from_AGB); + list[7] = io_make_output_field( + "MetalMassFracFromAGB", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, + chemistry_data.metal_mass_fraction_from_AGB, 1); list[8] = io_make_output_field("TotalMassFromSNII", FLOAT, 1, UNIT_CONV_MASS, - parts, chemistry_data.mass_from_SNII); + parts, chemistry_data.mass_from_SNII, 1); - list[9] = io_make_output_field("MetalMassFracFromSNII", FLOAT, 1, - UNIT_CONV_NO_UNITS, parts, - chemistry_data.metal_mass_fraction_from_SNII); + list[9] = io_make_output_field( + "MetalMassFracFromSNII", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, + chemistry_data.metal_mass_fraction_from_SNII, 1); - list[10] = - io_make_output_field("IronMassFracFromSNIa", FLOAT, 1, UNIT_CONV_NO_UNITS, - parts, chemistry_data.iron_mass_fraction_from_SNIa); + list[10] = io_make_output_field( + "IronMassFracFromSNIa", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, + chemistry_data.iron_mass_fraction_from_SNIa, 1); list[11] = io_make_output_field( "SmoothedIronMassFracFromSNIa", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, - chemistry_data.smoothed_iron_mass_fraction_from_SNIa); + chemistry_data.smoothed_iron_mass_fraction_from_SNIa, 1); return 12; } diff --git a/src/chemistry/GEAR/chemistry_io.h b/src/chemistry/GEAR/chemistry_io.h index 0557d5c52..e1e444cb4 100644 --- a/src/chemistry/GEAR/chemistry_io.h +++ b/src/chemistry/GEAR/chemistry_io.h @@ -76,12 +76,13 @@ __attribute__((always_inline)) INLINE static int chemistry_write_particles( list[0] = io_make_output_field( "SmoothedElementAbundance", FLOAT, chemistry_element_count, UNIT_CONV_NO_UNITS, parts, chemistry_data.smoothed_metal_mass_fraction); + list[1] = io_make_output_field("Z", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, chemistry_data.Z); list[2] = io_make_output_field("ElementAbundance", FLOAT, chemistry_element_count, UNIT_CONV_NO_UNITS, - parts, chemistry_data.metal_mass_fraction); + parts, chemistry_data.metal_mass_fraction, 1); return 3; } diff --git a/src/gravity/Default/gravity_io.h b/src/gravity/Default/gravity_io.h index efe508e97..2ee79ba9a 100644 --- a/src/gravity/Default/gravity_io.h +++ b/src/gravity/Default/gravity_io.h @@ -106,13 +106,14 @@ void darkmatter_write_particles(const struct gpart* gparts, /* List what we want to write */ list[0] = io_make_output_field_convert_gpart( - "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, gparts, convert_gpart_pos, 1); + "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, gparts, convert_gpart_pos, 1); list[1] = io_make_output_field_convert_gpart( - "Velocities", FLOAT, 3, UNIT_CONV_SPEED, gparts, convert_gpart_vel, 1); + "Velocities", FLOAT, 3, UNIT_CONV_SPEED, gparts, convert_gpart_vel, 1); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, gparts, mass, 1); - list[3] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, gparts, id_or_neg_offset, 1); + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, gparts, mass, 1); + list[3] = + io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, + gparts, id_or_neg_offset, 1); list[4] = io_make_output_field("Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, gparts, potential, 1); } diff --git a/src/hydro/Default/hydro_io.h b/src/hydro/Default/hydro_io.h index c7a0953eb..e8898fab6 100644 --- a/src/hydro/Default/hydro_io.h +++ b/src/hydro/Default/hydro_io.h @@ -127,22 +127,23 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, /* List what we want to write */ list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, - convert_part_pos); - list[1] = io_make_output_field_convert_part( - "Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, xparts, convert_part_vel); + convert_part_pos, 1); + list[1] = + io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, + parts, xparts, convert_part_vel, 1); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass); + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass, 1); list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - parts, h); + parts, h, 1); list[4] = io_make_output_field("InternalEnergy", FLOAT, 1, - UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u); + UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u, 1); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id); - list[6] = - io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho); - list[7] = io_make_output_field_convert_part("Potential", FLOAT, 1, - UNIT_CONV_POTENTIAL, parts, - xparts, convert_part_potential); + UNIT_CONV_NO_UNITS, parts, id, 1); + list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, + rho, 1); + list[7] = io_make_output_field_convert_part( + "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, + convert_part_potential, 1); } /** diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h index 9642d51cb..f769162cd 100644 --- a/src/hydro/Gadget2/hydro_io.h +++ b/src/hydro/Gadget2/hydro_io.h @@ -140,27 +140,29 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, convert_part_pos, 1); - list[1] = io_make_output_field_convert_part( - "Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, xparts, convert_part_vel, 1); + list[1] = + io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, + parts, xparts, convert_part_vel, 1); list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass, 1); list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, parts, h, 1); list[4] = io_make_output_field( - "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy, 1); + "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy, 1); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, parts, id, 1); - list[6] = - io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho, 1); + list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, + rho, 1); list[7] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, xparts, convert_part_u, 1); - list[8] = io_make_output_field_convert_part( - "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_part_P, 1); + list[8] = io_make_output_field_convert_part("Pressure", FLOAT, 1, + UNIT_CONV_PRESSURE, parts, xparts, + convert_part_P, 1); - list[9] = io_make_output_field_convert_part("Potential", FLOAT, 1, - UNIT_CONV_POTENTIAL, parts, - xparts, convert_part_potential, 1); + list[9] = io_make_output_field_convert_part( + "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, + convert_part_potential, 1); #ifdef DEBUG_INTERACTIONS_SPH diff --git a/src/hydro/GizmoMFM/hydro_io.h b/src/hydro/GizmoMFM/hydro_io.h index 94127b3fa..9683f0e89 100644 --- a/src/hydro/GizmoMFM/hydro_io.h +++ b/src/hydro/GizmoMFM/hydro_io.h @@ -184,31 +184,32 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, /* List what we want to write */ list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, - convert_part_pos); - list[1] = io_make_output_field_convert_part( - "Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, xparts, convert_part_vel); + convert_part_pos, 1); + list[1] = + io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, + parts, xparts, convert_part_vel, 1); list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, - conserved.mass); + conserved.mass, 1); list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - parts, h); + parts, h, 1); list[4] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - parts, xparts, convert_u); + parts, xparts, convert_u, 1); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id); + UNIT_CONV_NO_UNITS, parts, id, 1); list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - primitives.rho); + primitives.rho, 1); list[7] = io_make_output_field_convert_part( - "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY, parts, xparts, convert_A); + "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY, parts, xparts, convert_A, 1); list[8] = io_make_output_field("Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, - parts, primitives.P); + parts, primitives.P, 1); list[9] = io_make_output_field_convert_part( - "TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, xparts, convert_Etot); + "TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, xparts, convert_Etot, 1); - list[10] = io_make_output_field_convert_part("Potential", FLOAT, 1, - UNIT_CONV_POTENTIAL, parts, - xparts, convert_part_potential); + list[10] = io_make_output_field_convert_part( + "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, + convert_part_potential, 1); } /** diff --git a/src/hydro/Minimal/hydro_io.h b/src/hydro/Minimal/hydro_io.h index 846462a28..88f035552 100644 --- a/src/hydro/Minimal/hydro_io.h +++ b/src/hydro/Minimal/hydro_io.h @@ -154,28 +154,29 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, /* List what we want to write */ list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, - convert_part_pos); - list[1] = io_make_output_field_convert_part( - "Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, xparts, convert_part_vel); + convert_part_pos, 1); + list[1] = + io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, + parts, xparts, convert_part_vel, 1); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass); + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass, 1); list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - parts, h); + parts, h, 1); list[4] = io_make_output_field("InternalEnergy", FLOAT, 1, - UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u); + UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u, 1); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id); - list[6] = - io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho); + UNIT_CONV_NO_UNITS, parts, id, 1); + list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, + rho, 1); list[7] = io_make_output_field_convert_part("Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, - parts, xparts, convert_S); + parts, xparts, convert_S, 1); list[8] = io_make_output_field_convert_part( - "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_P); + "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_P, 1); - list[9] = io_make_output_field_convert_part("Potential", FLOAT, 1, - UNIT_CONV_POTENTIAL, parts, - xparts, convert_part_potential); + list[9] = io_make_output_field_convert_part( + "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, + convert_part_potential, 1); } /** diff --git a/src/hydro/PressureEntropy/hydro_io.h b/src/hydro/PressureEntropy/hydro_io.h index 59c49c066..ef43f9302 100644 --- a/src/hydro/PressureEntropy/hydro_io.h +++ b/src/hydro/PressureEntropy/hydro_io.h @@ -151,29 +151,30 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, /* List what we want to write */ list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, - convert_part_pos); - list[1] = io_make_output_field_convert_part( - "Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, xparts, convert_part_vel); + convert_part_pos, 1); + list[1] = + io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, + parts, xparts, convert_part_vel, 1); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass); + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass, 1); list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - parts, h); + parts, h, 1); list[4] = io_make_output_field( - "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy); + "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy, 1); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id); - list[6] = - io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho); + UNIT_CONV_NO_UNITS, parts, id, 1); + list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, + rho, 1); list[7] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - parts, xparts, convert_u); + parts, xparts, convert_u, 1); list[8] = io_make_output_field_convert_part( - "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_P); + "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_P, 1); list[9] = io_make_output_field("WeightedDensity", FLOAT, 1, UNIT_CONV_DENSITY, - parts, rho_bar); - list[10] = io_make_output_field_convert_part("Potential", FLOAT, 1, - UNIT_CONV_POTENTIAL, parts, - xparts, convert_part_potential); + parts, rho_bar, 1); + list[10] = io_make_output_field_convert_part( + "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, + convert_part_potential, 1); } /** diff --git a/src/hydro/Shadowswift/hydro_io.h b/src/hydro/Shadowswift/hydro_io.h index 4a15ec845..1f3df2bff 100644 --- a/src/hydro/Shadowswift/hydro_io.h +++ b/src/hydro/Shadowswift/hydro_io.h @@ -138,28 +138,28 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, UNIT_CONV_LENGTH, parts, xparts, convert_part_pos); list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, - primitives.v); + primitives.v, 1); list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, - conserved.mass); + conserved.mass, 1); list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - parts, h); + parts, h, 1); list[4] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, xparts, convert_u); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id); + UNIT_CONV_NO_UNITS, parts, id, 1); list[6] = io_make_output_field("Acceleration", FLOAT, 3, - UNIT_CONV_ACCELERATION, parts, a_hydro); + UNIT_CONV_ACCELERATION, parts, a_hydro, 1); list[7] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - primitives.rho); + primitives.rho, 1); list[8] = io_make_output_field("Volume", FLOAT, 1, UNIT_CONV_VOLUME, parts, - cell.volume); + cell.volume, 1); list[9] = io_make_output_field("GradDensity", FLOAT, 3, UNIT_CONV_DENSITY, - parts, primitives.gradients.rho); + parts, primitives.gradients.rho, 1); list[10] = io_make_output_field_convert_part( "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY, parts, xparts, convert_A); list[11] = io_make_output_field("Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, - parts, primitives.P); + parts, primitives.P, 1); list[12] = io_make_output_field_convert_part( "TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, xparts, convert_Etot); } diff --git a/src/io_properties.h b/src/io_properties.h index 49a4e0ecb..627ede9d4 100644 --- a/src/io_properties.h +++ b/src/io_properties.h @@ -107,7 +107,7 @@ struct io_props { * @brief Constructs an #io_props from its parameters */ #define io_make_input_field(name, type, dim, importance, units, part, field) \ - io_make_input_field_(name, type, dim, importance, units, \ + io_make_input_field_(name, type, dim, importance, units, \ (char*)(&(part[0]).field), sizeof(part[0])) /** @@ -151,7 +151,8 @@ 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, default_output) \ +#define io_make_output_field(name, type, dim, units, part, field, \ + default_output) \ io_make_output_field_(name, type, dim, units, (char*)(&(part[0]).field), \ sizeof(part[0]), default_output) @@ -196,9 +197,10 @@ INLINE static struct io_props io_make_output_field_( * @brief Constructs an #io_props (with conversion) from its parameters */ #define io_make_output_field_convert_part(name, type, dim, units, part, xpart, \ - convert, default_output) \ - io_make_output_field_convert_part_##type( \ - name, type, dim, units, sizeof(part[0]), part, xpart, convert, default_output) + convert, default_output) \ + io_make_output_field_convert_part_##type(name, type, dim, units, \ + sizeof(part[0]), part, xpart, \ + convert, default_output) /** * @brief Construct an #io_props from its parameters @@ -219,8 +221,7 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t partSize, const struct part* parts, const struct xpart* xparts, - conversion_func_part_float functionPtr, - int default_output) { + conversion_func_part_float functionPtr, int default_output) { struct io_props r; strcpy(r.name, name); @@ -288,11 +289,11 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE( /** * @brief Constructs an #io_props (with conversion) from its parameters */ -#define io_make_output_field_convert_gpart(name, type, dim, units, gpart, \ - convert, default_output) \ - io_make_output_field_convert_gpart_##type(name, type, dim, units, \ +#define io_make_output_field_convert_gpart(name, type, dim, units, gpart, \ + convert, default_output) \ + io_make_output_field_convert_gpart_##type(name, type, dim, units, \ sizeof(gpart[0]), gpart, convert, \ - default_output) + default_output) /** * @brief Construct an #io_props from its parameters @@ -312,7 +313,7 @@ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t gpartSize, const struct gpart* gparts, conversion_func_gpart_float functionPtr, - int default_output) { + int default_output) { struct io_props r; strcpy(r.name, name); @@ -353,7 +354,7 @@ INLINE static struct io_props io_make_output_field_convert_gpart_DOUBLE( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t gpartSize, const struct gpart* gparts, conversion_func_gpart_double functionPtr, - int default_output) { + int default_output) { struct io_props r; strcpy(r.name, name); diff --git a/src/parallel_io.c b/src/parallel_io.c index e17def2aa..0389b7f63 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1265,11 +1265,12 @@ void write_output_parallel(struct engine* e, const char* baseName, for (int i = 0; i < num_fields; ++i) { char field[200] = "OutputFields:"; strcat(field, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, list[i].default_output); + int should_write = parser_get_opt_param_int(output_fields, field, + list[i].default_output); if (should_write) - writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, - N_total[ptype], mpi_rank, offset[ptype], internal_units, - snapshot_units); + writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, + N_total[ptype], mpi_rank, offset[ptype], internal_units, + snapshot_units); } /* Free temporary array */ diff --git a/src/serial_io.c b/src/serial_io.c index fda396907..528d0c165 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1007,14 +1007,15 @@ void write_output_serial(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[200] = "OutputFields:"; - strcat(field, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, list[i].default_output); - if (should_write) - writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], - Nparticles, N_total[ptype], mpi_rank, offset[ptype], - internal_units, snapshot_units); - } + char field[200] = "OutputFields:"; + strcat(field, list[i].name); + int should_write = parser_get_opt_param_int(output_fields, field, + list[i].default_output); + if (should_write) + writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], + Nparticles, N_total[ptype], mpi_rank, offset[ptype], + internal_units, snapshot_units); + } /* Free temporary array */ if (dmparts) { diff --git a/src/single_io.c b/src/single_io.c index bea3be483..dd1c13248 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -829,10 +829,11 @@ void write_output_single(struct engine* e, const char* baseName, for (int i = 0; i < num_fields; ++i) { char field[200] = "OutputFields:"; strcat(field, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, list[i].default_output); + int should_write = parser_get_opt_param_int(output_fields, field, + list[i].default_output); if (should_write) - writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, - internal_units, snapshot_units); + writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, + internal_units, snapshot_units); } /* Free temporary array */ diff --git a/src/stars/Default/star_io.h b/src/stars/Default/star_io.h index 974ed30fb..c1cb03805 100644 --- a/src/stars/Default/star_io.h +++ b/src/stars/Default/star_io.h @@ -61,10 +61,10 @@ void star_write_particles(const struct spart* sparts, struct io_props* list, /* List what we want to read */ list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, sparts, x, 1); - list[1] = - io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, sparts, v, 1); + list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, + sparts, v, 1); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, sparts, mass, 1); + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, sparts, mass, 1); list[3] = io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, sparts, id, 1); } -- GitLab From e5328ed9e05e5ae4e198aecaaf21780697796cd1 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Mon, 2 Apr 2018 14:46:53 +0200 Subject: [PATCH 03/39] Add a small example file --- examples/output_fields_example.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 examples/output_fields_example.yml diff --git a/examples/output_fields_example.yml b/examples/output_fields_example.yml new file mode 100644 index 000000000..6ab88a74d --- /dev/null +++ b/examples/output_fields_example.yml @@ -0,0 +1,4 @@ +OutputFields: + Coordinates: 1 + Masses: 0 + SmoothingLenght: 1 \ No newline at end of file -- GitLab From 51fc81d87f34404c9bf83609c85a5c0c76f9c6b8 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Mon, 2 Apr 2018 14:47:40 +0200 Subject: [PATCH 04/39] Format --- src/parallel_io.c | 1 + src/serial_io.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/parallel_io.c b/src/parallel_io.c index 0389b7f63..cc9fe5566 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1072,6 +1072,7 @@ void write_output_parallel(struct engine* e, const char* baseName, struct gpart* dmparts = NULL; const struct spart* sparts = e->s->sparts; const struct cooling_function_data* cooling = e->cooling_func; + const struct swift_params* output_fields = e->output_fields; /* Number of unassociated gparts */ const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0; diff --git a/src/serial_io.c b/src/serial_io.c index 528d0c165..3dc793574 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -727,6 +727,7 @@ void write_output_serial(struct engine* e, const char* baseName, struct gpart* dmparts = NULL; const struct spart* sparts = e->s->sparts; const struct cooling_function_data* cooling = e->cooling_func; + const struct swift_params* output_fields = e->output_fields; FILE* xmfFile = 0; /* Number of unassociated gparts */ -- GitLab From 836ad36d3999102c01714c371851b2f16bb6fa91 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Mon, 2 Apr 2018 16:11:56 +0200 Subject: [PATCH 05/39] Update help string --- examples/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/main.c b/examples/main.c index e6d13bb8a..e439c17fe 100644 --- a/examples/main.c +++ b/examples/main.c @@ -90,6 +90,8 @@ void print_help_message(void) { printf(" %2s %14s %s\n", "-n", "{int}", "Execute a fixed number of time steps. When unset use the time_end " "parameter to stop."); + printf(" %2s %14s %s\n", "-o", "", + "Filename of the output fields parameters."); printf(" %2s %14s %s\n", "-P", "{sec:par:val}", "Set parameter value and overwrites values read from the parameters " "file. Can be used more than once."); -- GitLab From 72b924d43e17ad90529da023327c11e75488b999 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Tue, 3 Apr 2018 00:23:48 +0200 Subject: [PATCH 06/39] Move output field filename from cmd line to parameters --- examples/main.c | 17 +++++------------ examples/parameter_example.yml | 1 + 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/examples/main.c b/examples/main.c index e439c17fe..5adadfd26 100644 --- a/examples/main.c +++ b/examples/main.c @@ -90,8 +90,6 @@ void print_help_message(void) { printf(" %2s %14s %s\n", "-n", "{int}", "Execute a fixed number of time steps. When unset use the time_end " "parameter to stop."); - printf(" %2s %14s %s\n", "-o", "", - "Filename of the output fields parameters."); printf(" %2s %14s %s\n", "-P", "{sec:par:val}", "Set parameter value and overwrites values read from the parameters " "file. Can be used more than once."); @@ -200,12 +198,11 @@ int main(int argc, char *argv[]) { char *cmdparams[PARSER_MAX_NO_OF_PARAMS]; char paramFileName[200] = ""; char restart_file[200] = ""; - char outputFieldsFileName[200] = ""; unsigned long long cpufreq = 0; /* Parse the parameters */ int c; - while ((c = getopt(argc, argv, "acCdDef:FgGhMn:o:P:rsSt:Tv:y:Y:")) != -1) + while ((c = getopt(argc, argv, "acCdDef:FgGhMn:P:rsSt:Tv:y:Y:")) != -1) switch (c) { case 'a': #if defined(HAVE_SETAFFINITY) && defined(HAVE_LIBNUMA) @@ -262,14 +259,6 @@ int main(int argc, char *argv[]) { return 1; } break; - case 'o': - if (sscanf(optarg, "%s", outputFieldsFileName) != 1) { - if (myrank == 0) { - printf("Error parsing output fields filename"); - print_help_message(); - } - } - break; case 'P': cmdparams[nparams] = optarg; nparams++; @@ -473,6 +462,10 @@ int main(int argc, char *argv[]) { (struct swift_params *)malloc(sizeof(struct swift_params)); if (output_fields == NULL) error("Error allocating memory for the output fields file."); + + char outputFieldsFileName[200]; + parser_get_opt_param_string(params, "Snapshots:FieldsFilename", + outputFieldsFileName, ""); if (myrank == 0) { message("Reading runtime output fields from file '%s'", outputFieldsFileName); diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index 791db2758..75df3f7e8 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -78,6 +78,7 @@ Snapshots: UnitVelocity_in_cgs: 1 # (Optional) Unit system for the outputs (Centimeters per second) UnitCurrent_in_cgs: 1 # (Optional) Unit system for the outputs (Amperes) UnitTemp_in_cgs: 1 # (Optional) Unit system for the outputs (Kelvin) + FieldsFilename: output_fields_example.yml # (Optional) File defining output fields # Parameters governing the conserved quantities statistics Statistics: -- GitLab From 431b13daf00c5f20c0064268c1a03d5d4b213ab9 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Tue, 3 Apr 2018 00:27:37 +0200 Subject: [PATCH 07/39] Change output fields structure to PartType%i --- examples/output_fields_example.yml | 29 ++++++++++++++++++++++++++--- src/single_io.c | 4 ++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/examples/output_fields_example.yml b/examples/output_fields_example.yml index 6ab88a74d..9dabdac21 100644 --- a/examples/output_fields_example.yml +++ b/examples/output_fields_example.yml @@ -1,4 +1,27 @@ -OutputFields: +# Gas +PartType0: + Coordinates: 1 # Request to write output + Masses: 1 + Velocities: 1 + SmoothingLenght: 1 + Entropy: 1 + ParticleIDs: 1 + Density: 1 + InternalEnergy: 0 # Request to not write output + Pressure: 0 + Potential: 0 + +# Dark Matter +PartType1: Coordinates: 1 - Masses: 0 - SmoothingLenght: 1 \ No newline at end of file + Velocities: 1 + Masses: 1 + ParticleIDs: 1 + Potential: 0 + +# Stars +PartType2: + Coordinates: 1 + Velocities: 1 + Masses: 1 + ParticleIDs: 1 \ No newline at end of file diff --git a/src/single_io.c b/src/single_io.c index dd1c13248..fec094d11 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -827,8 +827,8 @@ void write_output_single(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[200] = "OutputFields:"; - strcat(field, list[i].name); + char field[200]; + sprintf(field, "ParticleType%i:%s", i, list[i].name); int should_write = parser_get_opt_param_int(output_fields, field, list[i].default_output); if (should_write) -- GitLab From e310691df6f5399ad9e56587e913c70f69931f60 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Tue, 3 Apr 2018 13:45:43 +0200 Subject: [PATCH 08/39] Remove default value for select io --- src/gravity/Default/gravity_io.h | 10 +++---- src/hydro/Default/hydro_io.h | 16 +++++------ src/hydro/Gadget2/hydro_io.h | 28 +++++++++---------- src/hydro/GizmoMFM/hydro_io.h | 22 +++++++-------- src/hydro/Minimal/hydro_io.h | 20 +++++++------- src/hydro/PressureEntropy/hydro_io.h | 22 +++++++-------- src/hydro/Shadowswift/hydro_io.h | 18 ++++++------ src/io_properties.h | 41 ++++++++-------------------- src/parallel_io.c | 3 +- src/serial_io.c | 3 +- src/single_io.c | 3 +- src/stars/Default/star_io.h | 8 +++--- 12 files changed, 86 insertions(+), 108 deletions(-) diff --git a/src/gravity/Default/gravity_io.h b/src/gravity/Default/gravity_io.h index 2ee79ba9a..a3f151510 100644 --- a/src/gravity/Default/gravity_io.h +++ b/src/gravity/Default/gravity_io.h @@ -106,16 +106,16 @@ void darkmatter_write_particles(const struct gpart* gparts, /* List what we want to write */ list[0] = io_make_output_field_convert_gpart( - "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, gparts, convert_gpart_pos, 1); + "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, 1); + "Velocities", FLOAT, 3, UNIT_CONV_SPEED, gparts, convert_gpart_vel); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, gparts, mass, 1); + 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, 1); + gparts, id_or_neg_offset); list[4] = io_make_output_field("Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, - gparts, potential, 1); + gparts, potential); } #endif /* SWIFT_DEFAULT_GRAVITY_IO_H */ diff --git a/src/hydro/Default/hydro_io.h b/src/hydro/Default/hydro_io.h index e8898fab6..490f9f47f 100644 --- a/src/hydro/Default/hydro_io.h +++ b/src/hydro/Default/hydro_io.h @@ -127,23 +127,23 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, /* List what we want to write */ list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, - convert_part_pos, 1); + convert_part_pos); list[1] = io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - parts, xparts, convert_part_vel, 1); + parts, xparts, convert_part_vel); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass, 1); + 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, 1); + parts, h); list[4] = io_make_output_field("InternalEnergy", FLOAT, 1, - UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u, 1); + UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id, 1); + UNIT_CONV_NO_UNITS, parts, id); list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - rho, 1); + rho); list[7] = io_make_output_field_convert_part( "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, - convert_part_potential, 1); + convert_part_potential); } /** diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h index f769162cd..d23716244 100644 --- a/src/hydro/Gadget2/hydro_io.h +++ b/src/hydro/Gadget2/hydro_io.h @@ -139,30 +139,30 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, /* List what we want to write */ list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, - convert_part_pos, 1); + convert_part_pos); list[1] = io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - parts, xparts, convert_part_vel, 1); + parts, xparts, convert_part_vel); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass, 1); + 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, 1); + parts, h); list[4] = io_make_output_field( - "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy, 1); + "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id, 1); + UNIT_CONV_NO_UNITS, parts, id); list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - rho, 1); + rho); list[7] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - parts, xparts, convert_part_u, 1); + parts, xparts, convert_part_u); list[8] = io_make_output_field_convert_part("Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, - convert_part_P, 1); + convert_part_P); list[9] = io_make_output_field_convert_part( "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, - convert_part_potential, 1); + convert_part_potential); #ifdef DEBUG_INTERACTIONS_SPH @@ -170,15 +170,15 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, *num_fields += 4; list[0] = io_make_output_field("Num_ngb_density", INT, 1, UNIT_CONV_NO_UNITS, - parts, num_ngb_density, 1); + parts, num_ngb_density); list[1] = io_make_output_field("Num_ngb_force", INT, 1, UNIT_CONV_NO_UNITS, - parts, num_ngb_force, 1); + parts, num_ngb_force); list[2] = io_make_output_field("Ids_ngb_density", LONGLONG, MAX_NUM_OF_NEIGHBOURS, - UNIT_CONV_NO_UNITS, parts, ids_ngbs_density, 1); + UNIT_CONV_NO_UNITS, parts, ids_ngbs_density); list[3] = io_make_output_field("Ids_ngb_force", LONGLONG, MAX_NUM_OF_NEIGHBOURS, - UNIT_CONV_NO_UNITS, parts, ids_ngbs_force, 1); + UNIT_CONV_NO_UNITS, parts, ids_ngbs_force); #endif } diff --git a/src/hydro/GizmoMFM/hydro_io.h b/src/hydro/GizmoMFM/hydro_io.h index 9683f0e89..f12a6e08c 100644 --- a/src/hydro/GizmoMFM/hydro_io.h +++ b/src/hydro/GizmoMFM/hydro_io.h @@ -184,32 +184,32 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, /* List what we want to write */ list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, - convert_part_pos, 1); + convert_part_pos); list[1] = io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - parts, xparts, convert_part_vel, 1); + parts, xparts, convert_part_vel); list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, - conserved.mass, 1); + conserved.mass); list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - parts, h, 1); + parts, h); list[4] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - parts, xparts, convert_u, 1); + parts, xparts, convert_u); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id, 1); + UNIT_CONV_NO_UNITS, parts, id); list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - primitives.rho, 1); + primitives.rho); list[7] = io_make_output_field_convert_part( - "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY, parts, xparts, convert_A, 1); + "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY, parts, xparts, convert_A); list[8] = io_make_output_field("Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, - parts, primitives.P, 1); + parts, primitives.P); list[9] = io_make_output_field_convert_part( - "TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, xparts, convert_Etot, 1); + "TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, xparts, convert_Etot); list[10] = io_make_output_field_convert_part( "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, - convert_part_potential, 1); + convert_part_potential); } /** diff --git a/src/hydro/Minimal/hydro_io.h b/src/hydro/Minimal/hydro_io.h index 88f035552..1f3c15996 100644 --- a/src/hydro/Minimal/hydro_io.h +++ b/src/hydro/Minimal/hydro_io.h @@ -154,29 +154,29 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, /* List what we want to write */ list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, - convert_part_pos, 1); + convert_part_pos); list[1] = io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - parts, xparts, convert_part_vel, 1); + parts, xparts, convert_part_vel); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass, 1); + 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, 1); + parts, h); list[4] = io_make_output_field("InternalEnergy", FLOAT, 1, - UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u, 1); + UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id, 1); + UNIT_CONV_NO_UNITS, parts, id); list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - rho, 1); + rho); list[7] = io_make_output_field_convert_part("Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, - parts, xparts, convert_S, 1); + parts, xparts, convert_S); list[8] = io_make_output_field_convert_part( - "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_P, 1); + "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_P); list[9] = io_make_output_field_convert_part( "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, - convert_part_potential, 1); + convert_part_potential); } /** diff --git a/src/hydro/PressureEntropy/hydro_io.h b/src/hydro/PressureEntropy/hydro_io.h index ef43f9302..18c5c0fc3 100644 --- a/src/hydro/PressureEntropy/hydro_io.h +++ b/src/hydro/PressureEntropy/hydro_io.h @@ -151,30 +151,30 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, /* List what we want to write */ list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, - convert_part_pos, 1); + convert_part_pos); list[1] = io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - parts, xparts, convert_part_vel, 1); + parts, xparts, convert_part_vel); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass, 1); + 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, 1); + parts, h); list[4] = io_make_output_field( - "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy, 1); + "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id, 1); + UNIT_CONV_NO_UNITS, parts, id); list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - rho, 1); + rho); list[7] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, - parts, xparts, convert_u, 1); + parts, xparts, convert_u); list[8] = io_make_output_field_convert_part( - "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_P, 1); + "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_P); list[9] = io_make_output_field("WeightedDensity", FLOAT, 1, UNIT_CONV_DENSITY, - parts, rho_bar, 1); + parts, rho_bar); list[10] = io_make_output_field_convert_part( "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, - convert_part_potential, 1); + convert_part_potential); } /** diff --git a/src/hydro/Shadowswift/hydro_io.h b/src/hydro/Shadowswift/hydro_io.h index 1f3df2bff..4a15ec845 100644 --- a/src/hydro/Shadowswift/hydro_io.h +++ b/src/hydro/Shadowswift/hydro_io.h @@ -138,28 +138,28 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, UNIT_CONV_LENGTH, parts, xparts, convert_part_pos); list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, - primitives.v, 1); + primitives.v); list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, - conserved.mass, 1); + conserved.mass); list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - parts, h, 1); + parts, h); list[4] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, xparts, convert_u); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, - UNIT_CONV_NO_UNITS, parts, id, 1); + UNIT_CONV_NO_UNITS, parts, id); list[6] = io_make_output_field("Acceleration", FLOAT, 3, - UNIT_CONV_ACCELERATION, parts, a_hydro, 1); + UNIT_CONV_ACCELERATION, parts, a_hydro); list[7] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - primitives.rho, 1); + primitives.rho); list[8] = io_make_output_field("Volume", FLOAT, 1, UNIT_CONV_VOLUME, parts, - cell.volume, 1); + cell.volume); list[9] = io_make_output_field("GradDensity", FLOAT, 3, UNIT_CONV_DENSITY, - parts, primitives.gradients.rho, 1); + parts, primitives.gradients.rho); list[10] = io_make_output_field_convert_part( "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY, parts, xparts, convert_A); list[11] = io_make_output_field("Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, - parts, primitives.P, 1); + parts, primitives.P); list[12] = io_make_output_field_convert_part( "TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, xparts, convert_Etot); } diff --git a/src/io_properties.h b/src/io_properties.h index 627ede9d4..565dbef33 100644 --- a/src/io_properties.h +++ b/src/io_properties.h @@ -98,9 +98,6 @@ struct io_props { conversion_func_gpart_float convert_gpart_f; conversion_func_gpart_double convert_gpart_d; - /* default output behaviour - * 0 means not writing, 1 means writing */ - int default_output; }; /** @@ -143,7 +140,6 @@ INLINE static struct io_props io_make_input_field_( r.convert_part_d = NULL; r.convert_gpart_f = NULL; r.convert_gpart_d = NULL; - r.default_output = 0; return r; } @@ -151,10 +147,9 @@ 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, \ - default_output) \ +#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]), default_output) + sizeof(part[0])) /** * @brief Construct an #io_props from its parameters @@ -165,14 +160,12 @@ INLINE static struct io_props io_make_input_field_( * @param units The units of the dataset * @param field Pointer to the field of the first particle * @param partSize The size in byte of the particle - * @param default_output Default output behaviour (0 -> not write, 1 -> write) * * Do not call this function directly. Use the macro defined above. */ 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, - int default_output) { + enum unit_conversion_factor units, char* field, size_t partSize) { struct io_props r; strcpy(r.name, name); r.type = type; @@ -188,7 +181,6 @@ INLINE static struct io_props io_make_output_field_( r.convert_part_d = NULL; r.convert_gpart_f = NULL; r.convert_gpart_d = NULL; - r.default_output = default_output; return r; } @@ -197,10 +189,10 @@ INLINE static struct io_props io_make_output_field_( * @brief Constructs an #io_props (with conversion) from its parameters */ #define io_make_output_field_convert_part(name, type, dim, units, part, xpart, \ - convert, default_output) \ + convert) \ io_make_output_field_convert_part_##type(name, type, dim, units, \ sizeof(part[0]), part, xpart, \ - convert, default_output) + convert) /** * @brief Construct an #io_props from its parameters @@ -213,7 +205,6 @@ INLINE static struct io_props io_make_output_field_( * @param parts The particle array * @param xparts The xparticle array * @param functionPtr The function used to convert a particle to a float - * @param default_output Default output behaviour (0 -> not write, 1 -> write) * * Do not call this function directly. Use the macro defined above. */ @@ -221,7 +212,7 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t partSize, const struct part* parts, const struct xpart* xparts, - conversion_func_part_float functionPtr, int default_output) { + conversion_func_part_float functionPtr) { struct io_props r; strcpy(r.name, name); @@ -239,7 +230,6 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT( r.convert_part_d = NULL; r.convert_gpart_f = NULL; r.convert_gpart_d = NULL; - r.default_output = default_output; return r; } @@ -255,7 +245,6 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT( * @param parts The particle array * @param xparts The xparticle array * @param functionPtr The function used to convert a particle to a float - * @param default_output Default output behaviour (0 -> not write, 1 -> write) * * Do not call this function directly. Use the macro defined above. */ @@ -263,7 +252,7 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t partSize, const struct part* parts, const struct xpart* xparts, - conversion_func_part_double functionPtr, int default_output) { + conversion_func_part_double functionPtr) { struct io_props r; strcpy(r.name, name); @@ -281,7 +270,6 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE( r.convert_part_d = functionPtr; r.convert_gpart_f = NULL; r.convert_gpart_d = NULL; - r.default_output = default_output; return r; } @@ -290,10 +278,9 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE( * @brief Constructs an #io_props (with conversion) from its parameters */ #define io_make_output_field_convert_gpart(name, type, dim, units, gpart, \ - convert, default_output) \ + convert) \ io_make_output_field_convert_gpart_##type(name, type, dim, units, \ - sizeof(gpart[0]), gpart, convert, \ - default_output) + sizeof(gpart[0]), gpart, convert) /** * @brief Construct an #io_props from its parameters @@ -305,15 +292,13 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE( * @param gpartSize The size in byte of the particle * @param gparts The particle array * @param functionPtr The function used to convert a g-particle to a float - * @param default_output Default output behaviour (0 -> not write, 1 -> write) * * Do not call this function directly. Use the macro defined above. */ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t gpartSize, - const struct gpart* gparts, conversion_func_gpart_float functionPtr, - int default_output) { + const struct gpart* gparts, conversion_func_gpart_float functionPtr) { struct io_props r; strcpy(r.name, name); @@ -331,7 +316,6 @@ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT( r.convert_part_d = NULL; r.convert_gpart_f = functionPtr; r.convert_gpart_d = NULL; - r.default_output = default_output; return r; } @@ -346,15 +330,13 @@ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT( * @param gpartSize The size in byte of the particle * @param gparts The particle array * @param functionPtr The function used to convert a g-particle to a float - * @param default_output Default output behaviour (0 -> not write, 1 -> write) * * Do not call this function directly. Use the macro defined above. */ INLINE static struct io_props io_make_output_field_convert_gpart_DOUBLE( const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension, enum unit_conversion_factor units, size_t gpartSize, - const struct gpart* gparts, conversion_func_gpart_double functionPtr, - int default_output) { + const struct gpart* gparts, conversion_func_gpart_double functionPtr) { struct io_props r; strcpy(r.name, name); @@ -372,7 +354,6 @@ INLINE static struct io_props io_make_output_field_convert_gpart_DOUBLE( r.convert_part_d = NULL; r.convert_gpart_f = NULL; r.convert_gpart_d = functionPtr; - r.default_output = default_output; return r; } diff --git a/src/parallel_io.c b/src/parallel_io.c index cc9fe5566..b0039fbb5 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1266,8 +1266,7 @@ void write_output_parallel(struct engine* e, const char* baseName, for (int i = 0; i < num_fields; ++i) { char field[200] = "OutputFields:"; strcat(field, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, - list[i].default_output); + int should_write = parser_get_opt_param_int(output_fields, field, 0); if (should_write) writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], internal_units, diff --git a/src/serial_io.c b/src/serial_io.c index 3dc793574..5af2abfda 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1010,8 +1010,7 @@ void write_output_serial(struct engine* e, const char* baseName, for (int i = 0; i < num_fields; ++i) { char field[200] = "OutputFields:"; strcat(field, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, - list[i].default_output); + int should_write = parser_get_opt_param_int(output_fields, field, 0); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], diff --git a/src/single_io.c b/src/single_io.c index fec094d11..42fad2675 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -829,8 +829,7 @@ void write_output_single(struct engine* e, const char* baseName, for (int i = 0; i < num_fields; ++i) { char field[200]; sprintf(field, "ParticleType%i:%s", i, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, - list[i].default_output); + int should_write = parser_get_opt_param_int(output_fields, field, 0); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, internal_units, snapshot_units); diff --git a/src/stars/Default/star_io.h b/src/stars/Default/star_io.h index c1cb03805..e465d8c24 100644 --- a/src/stars/Default/star_io.h +++ b/src/stars/Default/star_io.h @@ -60,13 +60,13 @@ void star_write_particles(const struct spart* sparts, struct io_props* list, /* List what we want to read */ list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, - sparts, x, 1); + sparts, x); list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - sparts, v, 1); + sparts, v); list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, sparts, mass, 1); + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, sparts, mass); list[3] = io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, - sparts, id, 1); + sparts, id); } #endif /* SWIFT_DEFAULT_STAR_IO_H */ -- GitLab From 1e5e884a1588c5e75e93f397475bbcfebe0c02bf Mon Sep 17 00:00:00 2001 From: lhausamm Date: Tue, 3 Apr 2018 15:26:47 +0200 Subject: [PATCH 09/39] Make output_fields filename mandatory --- examples/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/main.c b/examples/main.c index 5adadfd26..0dafea744 100644 --- a/examples/main.c +++ b/examples/main.c @@ -464,8 +464,8 @@ int main(int argc, char *argv[]) { error("Error allocating memory for the output fields file."); char outputFieldsFileName[200]; - parser_get_opt_param_string(params, "Snapshots:FieldsFilename", - outputFieldsFileName, ""); + parser_get_param_string(params, "Snapshots:FieldsFilename", + outputFieldsFileName); if (myrank == 0) { message("Reading runtime output fields from file '%s'", outputFieldsFileName); -- GitLab From 2abf1ee2eeee9efad62e3a49a0cd9ff9c4a86ffb Mon Sep 17 00:00:00 2001 From: lhausamm Date: Tue, 3 Apr 2018 16:46:28 +0200 Subject: [PATCH 10/39] Check if all parameters in output_fields are correct --- examples/main.c | 7 ++- examples/output_fields_example.yml | 2 +- src/chemistry/none/chemistry_io.h | 9 ++-- src/common_io.c | 87 ++++++++++++++++++++++++++++++ src/common_io.h | 3 ++ src/gravity/Default/gravity_io.h | 16 +++--- src/hydro/Gadget2/hydro_io.h | 41 ++++++++------ src/stars/Default/star_io.h | 8 +-- src/swift.h | 1 + 9 files changed, 141 insertions(+), 33 deletions(-) diff --git a/examples/main.c b/examples/main.c index 0dafea744..7ca517090 100644 --- a/examples/main.c +++ b/examples/main.c @@ -482,7 +482,6 @@ int main(int argc, char *argv[]) { MPI_Bcast(output_fields, sizeof(struct swift_params), MPI_BYTE, 0, MPI_COMM_WORLD); #endif - /* Check that we can write the snapshots by testing if the output * directory exists and is searchable and writable. */ char basename[PARSER_MAX_LINE_SIZE]; @@ -837,6 +836,10 @@ int main(int argc, char *argv[]) { &cooling_func, &chemistry, &sourceterms); engine_config(0, &e, params, nr_nodes, myrank, nr_threads, with_aff, talking, restart_file); + + /* check output field */ + io_check_output_fields(output_fields, &e); + if (myrank == 0) { clocks_gettime(&toc); message("engine_init took %.3f %s.", clocks_diff(&tic, &toc), @@ -871,6 +874,7 @@ int main(int argc, char *argv[]) { message("Time integration ready to start. End of dry-run."); engine_clean(&e); free(params); + free(output_fields); return 0; } @@ -1093,6 +1097,7 @@ int main(int argc, char *argv[]) { if (with_verbose_timers) timers_close_file(); if (with_cosmology) cosmology_clean(&cosmo); engine_clean(&e); + free(output_fields); free(params); /* Say goodbye. */ diff --git a/examples/output_fields_example.yml b/examples/output_fields_example.yml index 9dabdac21..22dfdc35a 100644 --- a/examples/output_fields_example.yml +++ b/examples/output_fields_example.yml @@ -3,7 +3,7 @@ PartType0: Coordinates: 1 # Request to write output Masses: 1 Velocities: 1 - SmoothingLenght: 1 + SmoothingLength: 1 Entropy: 1 ParticleIDs: 1 Density: 1 diff --git a/src/chemistry/none/chemistry_io.h b/src/chemistry/none/chemistry_io.h index 142d2f75c..fc460944e 100644 --- a/src/chemistry/none/chemistry_io.h +++ b/src/chemistry/none/chemistry_io.h @@ -29,7 +29,8 @@ * * @return Returns the number of fields to write. */ -int chemistry_read_particles(struct part* parts, struct io_props* list) { +__attribute__((always_inline)) INLINE static int chemistry_read_particles( + struct part* parts, struct io_props* list) { /* update list according to hydro_io */ @@ -45,7 +46,8 @@ int chemistry_read_particles(struct part* parts, struct io_props* list) { * * @return Returns the number of fields to write. */ -int chemistry_write_particles(const struct part* parts, struct io_props* list) { +__attribute__((always_inline)) INLINE static int chemistry_write_particles( + const struct part* parts, struct io_props* list) { /* update list according to hydro_io */ @@ -59,7 +61,8 @@ int chemistry_write_particles(const struct part* parts, struct io_props* list) { * @brief Writes the current model of SPH to the file * @param h_grp The HDF5 group in which to write */ -void chemistry_write_flavour(hid_t h_grp) { +__attribute__((always_inline)) INLINE static void chemistry_write_flavour( + hid_t h_grp) { io_write_attribute_s(h_grp, "Chemistry Model", "None"); } diff --git a/src/common_io.c b/src/common_io.c index 8b173adb7..f17ade1aa 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -25,12 +25,16 @@ #include "common_io.h" /* Local includes. */ +#include "chemistry_io.h" #include "engine.h" #include "error.h" +#include "gravity_io.h" #include "hydro.h" +#include "hydro_io.h" #include "io_properties.h" #include "kernel_hydro.h" #include "part.h" +#include "stars_io.h" #include "threadpool.h" #include "units.h" #include "version.h" @@ -805,3 +809,86 @@ void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot, error("Collected the wrong number of dm particles (%zu vs. %zu expected)", count, Ndm); } + +/** + * @brief Verify the io parameter file + * + * @param e The #engine + */ +void io_check_output_fields(const struct swift_params *output_fields, + const struct engine *e) { + + if (output_fields->paramCount == 0) + error("You need to provide an output field in %s", output_fields->fileName); + + /* particles */ + const struct part* parts = e->s->parts; + const struct xpart* xparts = e->s->xparts; + const struct gpart* gparts = e->s->gparts; + const struct spart* sparts = e->s->sparts; + + /* number of particles */ + const size_t Ngas = e->s->nr_parts; + const size_t Nstars = e->s->nr_sparts; + const size_t Ntot = e->s->nr_gparts; + + const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0; + + long long N_total[swift_type_count] = { + (long long)Ngas, (long long)Ndm, 0, 0, (long long)Nstars, 0}; + + + /* get all the possible outputs */ + for (int ptype = 0; ptype < swift_type_count; ptype++) { + int num_fields = 0; + struct io_props list[100]; + + /* Don't do anything if no particle of this kind */ + if (N_total[ptype] == 0) continue; + + /* Write particle fields from the particle structure */ + switch (ptype) { + + case swift_type_gas: + hydro_write_particles(parts, xparts, list, &num_fields); + num_fields += chemistry_write_particles(parts, list + num_fields); + break; + + case swift_type_dark_matter: + darkmatter_write_particles(gparts, list, &num_fields); + break; + + case swift_type_star: + star_write_particles(sparts, list, &num_fields); + break; + + default: + error("Particle Type %d not yet supported. Aborting", ptype); + } + /* loop over each parameter */ + for (int param_id = 0; param_id < output_fields->paramCount; param_id++) { + const char *param_name = output_fields->data[param_id].name; + + /* skip if wrong part type */ + char section_name[200]; + sprintf(section_name, "PartType%i", ptype); + if (strstr(param_name, section_name) == NULL) + continue; + + int found = 0; + + /* loop over each possible output field */ + for (int field_id = 0; field_id < num_fields; field_id++) { + char field_name[200]; + sprintf(field_name, "PartType%i:%s", ptype, list[field_id].name); + if (strcmp(param_name, field_name) == 0) { + found = 1; + continue; + } + } + if (!found) + error("Unable to find field corresponding to %s", param_name); + } + } + +} diff --git a/src/common_io.h b/src/common_io.h index d9e676db9..0aba3be1e 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -100,4 +100,7 @@ void io_duplicate_star_gparts(struct threadpool* tp, struct spart* const sparts, struct gpart* const gparts, size_t Nstars, size_t Ndm); +void io_check_output_fields(const struct swift_params *output_fields, + const struct engine *e); + #endif /* SWIFT_COMMON_IO_H */ diff --git a/src/gravity/Default/gravity_io.h b/src/gravity/Default/gravity_io.h index a3f151510..d69310f2f 100644 --- a/src/gravity/Default/gravity_io.h +++ b/src/gravity/Default/gravity_io.h @@ -21,8 +21,8 @@ #include "io_properties.h" -void convert_gpart_pos(const struct engine* e, const struct gpart* gp, - double* ret) { +__attribute__((always_inline)) INLINE static void convert_gpart_pos( + const struct engine* e, const struct gpart* gp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(gp->x[0], 0.0, e->s->dim[0]); @@ -35,8 +35,8 @@ void convert_gpart_pos(const struct engine* e, const struct gpart* gp, } } -void convert_gpart_vel(const struct engine* e, const struct gpart* gp, - float* ret) { +__attribute__((always_inline)) INLINE static void convert_gpart_vel( + const struct engine* e, const struct gpart* gp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -74,8 +74,8 @@ void convert_gpart_vel(const struct engine* e, const struct gpart* gp, * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void darkmatter_read_particles(struct gpart* gparts, struct io_props* list, - int* num_fields) { +__attribute__((always_inline)) INLINE static void darkmatter_read_particles( + struct gpart* gparts, struct io_props* list, int* num_fields) { /* Say how much we want to read */ *num_fields = 4; @@ -98,8 +98,8 @@ void darkmatter_read_particles(struct gpart* gparts, struct io_props* list, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void darkmatter_write_particles(const struct gpart* gparts, - struct io_props* list, int* num_fields) { +__attribute__((always_inline)) INLINE static void darkmatter_write_particles( + const struct gpart* gparts, struct io_props* list, int* num_fields) { /* Say how much we want to write */ *num_fields = 5; diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h index d23716244..3ed358ebb 100644 --- a/src/hydro/Gadget2/hydro_io.h +++ b/src/hydro/Gadget2/hydro_io.h @@ -31,8 +31,8 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void hydro_read_particles(struct part* parts, struct io_props* list, - int* num_fields) { +__attribute__((always_inline)) INLINE static void hydro_read_particles( + struct part* parts, struct io_props* list, int* num_fields) { *num_fields = 8; @@ -55,20 +55,23 @@ void hydro_read_particles(struct part* parts, struct io_props* list, UNIT_CONV_DENSITY, parts, rho); } -void convert_part_u(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +__attribute__((always_inline)) INLINE static void convert_part_u( + const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_internal_energy(p); } -void convert_part_P(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +__attribute__((always_inline)) INLINE static void convert_part_P( + const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_pressure(p); } -void convert_part_pos(const struct engine* e, const struct part* p, - const struct xpart* xp, double* ret) { +__attribute__((always_inline)) INLINE static void convert_part_pos( + const struct engine* e, const struct part* p, + const struct xpart* xp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -81,8 +84,9 @@ void convert_part_pos(const struct engine* e, const struct part* p, } } -void convert_part_vel(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +__attribute__((always_inline)) INLINE static void convert_part_vel( + const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -115,8 +119,9 @@ void convert_part_vel(const struct engine* e, const struct part* p, ret[2] *= cosmo->a2_inv; } -void convert_part_potential(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +__attribute__((always_inline)) INLINE static void convert_part_potential( + const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { if (p->gpart != NULL) ret[0] = gravity_get_comoving_potential(p->gpart); @@ -131,8 +136,9 @@ void convert_part_potential(const struct engine* e, const struct part* p, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void hydro_write_particles(const struct part* parts, const struct xpart* xparts, - struct io_props* list, int* num_fields) { +__attribute__((always_inline)) INLINE static void hydro_write_particles( + const struct part* parts, const struct xpart* xparts, + struct io_props* list, int* num_fields) { *num_fields = 10; @@ -187,7 +193,7 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -void hydro_write_flavour(hid_t h_grpsph) { +__attribute__((always_inline)) INLINE static void hydro_write_flavour(hid_t h_grpsph) { /* Viscosity and thermal conduction */ io_write_attribute_s(h_grpsph, "Thermal Conductivity Model", @@ -204,6 +210,9 @@ void hydro_write_flavour(hid_t h_grpsph) { * * @return 1 if entropy is in 'internal energy', 0 otherwise. */ -int writeEntropyFlag(void) { return 0; } +__attribute__((always_inline)) INLINE static int writeEntropyFlag(void) { + return 0; +} +>>>>>>> Check if all parameters in output_fields are correct #endif /* SWIFT_GADGET2_HYDRO_IO_H */ diff --git a/src/stars/Default/star_io.h b/src/stars/Default/star_io.h index e465d8c24..998913053 100644 --- a/src/stars/Default/star_io.h +++ b/src/stars/Default/star_io.h @@ -28,8 +28,8 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void star_read_particles(struct spart* sparts, struct io_props* list, - int* num_fields) { +__attribute__((always_inline)) INLINE static void star_read_particles( + struct spart* sparts, struct io_props* list, int* num_fields) { /* Say how much we want to read */ *num_fields = 4; @@ -52,8 +52,8 @@ void star_read_particles(struct spart* sparts, struct io_props* list, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void star_write_particles(const struct spart* sparts, struct io_props* list, - int* num_fields) { +__attribute__((always_inline)) INLINE static void star_write_particles( + const struct spart* sparts, struct io_props* list, int* num_fields) { /* Say how much we want to read */ *num_fields = 4; diff --git a/src/swift.h b/src/swift.h index 769172094..10cc8495f 100644 --- a/src/swift.h +++ b/src/swift.h @@ -29,6 +29,7 @@ #include "cell.h" #include "chemistry.h" #include "clocks.h" +#include "common_io.h" #include "const.h" #include "cooling.h" #include "cosmology.h" -- GitLab From 7584ad040523ed16423104bd091e1ecbcac4f8f1 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Tue, 3 Apr 2018 17:43:03 +0200 Subject: [PATCH 11/39] Fix printf errors --- src/common_io.c | 2 +- src/parallel_io.c | 2 +- src/serial_io.c | 2 +- src/single_io.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common_io.c b/src/common_io.c index f17ade1aa..f2c60e033 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -879,7 +879,7 @@ void io_check_output_fields(const struct swift_params *output_fields, /* loop over each possible output field */ for (int field_id = 0; field_id < num_fields; field_id++) { - char field_name[200]; + char field_name[256]; sprintf(field_name, "PartType%i:%s", ptype, list[field_id].name); if (strcmp(param_name, field_name) == 0) { found = 1; diff --git a/src/parallel_io.c b/src/parallel_io.c index b0039fbb5..0dcf9c5b2 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1264,7 +1264,7 @@ void write_output_parallel(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[200] = "OutputFields:"; + char field[256] = "OutputFields:"; strcat(field, list[i].name); int should_write = parser_get_opt_param_int(output_fields, field, 0); if (should_write) diff --git a/src/serial_io.c b/src/serial_io.c index 5af2abfda..9874da73e 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1008,7 +1008,7 @@ void write_output_serial(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[200] = "OutputFields:"; + char field[256] = "OutputFields:"; strcat(field, list[i].name); int should_write = parser_get_opt_param_int(output_fields, field, 0); if (should_write) diff --git a/src/single_io.c b/src/single_io.c index 42fad2675..2fc7d3822 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -827,7 +827,7 @@ void write_output_single(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[200]; + char field[256]; sprintf(field, "ParticleType%i:%s", i, list[i].name); int should_write = parser_get_opt_param_int(output_fields, field, 0); if (should_write) -- GitLab From 2d1eb581054d3f0a0e19cb905f8e210dcfe1476e Mon Sep 17 00:00:00 2001 From: lhausamm Date: Tue, 3 Apr 2018 17:43:21 +0200 Subject: [PATCH 12/39] Fix example mistake --- examples/SedovBlast_3D/sedov.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/SedovBlast_3D/sedov.yml b/examples/SedovBlast_3D/sedov.yml index 2df2c432c..5368c0264 100644 --- a/examples/SedovBlast_3D/sedov.yml +++ b/examples/SedovBlast_3D/sedov.yml @@ -19,7 +19,8 @@ Snapshots: time_first: 0. # Time of the first output (in internal units) delta_time: 1e-2 # Time difference between consecutive outputs (in internal units) compression: 4 - + FieldsFilename: ../output_fields_example.yml + # Parameters governing the conserved quantities statistics Statistics: delta_time: 1e-3 # Time between statistics output -- GitLab From 915667fb9516d3a21a2152c7b59ad0eaf4fcac7d Mon Sep 17 00:00:00 2001 From: lhausamm Date: Tue, 3 Apr 2018 17:58:24 +0200 Subject: [PATCH 13/39] Format and few fixes --- examples/main.c | 2 +- src/chemistry/EAGLE/chemistry_io.h | 45 +++++++++++----------- src/chemistry/GEAR/chemistry_io.h | 2 +- src/common_io.c | 56 +++++++++++++--------------- src/common_io.h | 4 +- src/gravity/Default/gravity_io.h | 5 +-- src/hydro/Default/hydro_io.h | 15 ++++---- src/hydro/Gadget2/hydro_io.h | 47 ++++++++++++----------- src/hydro/GizmoMFM/hydro_io.h | 11 +++--- src/hydro/Minimal/hydro_io.h | 15 ++++---- src/hydro/PressureEntropy/hydro_io.h | 15 ++++---- src/io_properties.h | 16 ++++---- src/stars/Default/star_io.h | 4 +- 13 files changed, 112 insertions(+), 125 deletions(-) diff --git a/examples/main.c b/examples/main.c index 7ca517090..605b2d330 100644 --- a/examples/main.c +++ b/examples/main.c @@ -465,7 +465,7 @@ int main(int argc, char *argv[]) { char outputFieldsFileName[200]; parser_get_param_string(params, "Snapshots:FieldsFilename", - outputFieldsFileName); + outputFieldsFileName); if (myrank == 0) { message("Reading runtime output fields from file '%s'", outputFieldsFileName); diff --git a/src/chemistry/EAGLE/chemistry_io.h b/src/chemistry/EAGLE/chemistry_io.h index efef6b07a..aab8ec240 100644 --- a/src/chemistry/EAGLE/chemistry_io.h +++ b/src/chemistry/EAGLE/chemistry_io.h @@ -49,49 +49,48 @@ int chemistry_write_particles(const struct part* parts, struct io_props* list) { /* List what we want to write */ list[0] = io_make_output_field("ElementAbundance", FLOAT, chemistry_element_count, UNIT_CONV_NO_UNITS, - parts, chemistry_data.metal_mass_fraction, 1); + parts, chemistry_data.metal_mass_fraction); - list[1] = - io_make_output_field("SmoothedElementAbundance", FLOAT, - chemistry_element_count, UNIT_CONV_NO_UNITS, parts, - chemistry_data.smoothed_metal_mass_fraction, 1); + list[1] = io_make_output_field( + "SmoothedElementAbundance", FLOAT, chemistry_element_count, + UNIT_CONV_NO_UNITS, parts, chemistry_data.smoothed_metal_mass_fraction); list[2] = io_make_output_field("Metallicity", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, - chemistry_data.metal_mass_fraction_total, 1); + chemistry_data.metal_mass_fraction_total); list[3] = io_make_output_field( "SmoothedMetallicity", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, - chemistry_data.smoothed_metal_mass_fraction_total, 1); + chemistry_data.smoothed_metal_mass_fraction_total); list[4] = io_make_output_field("TotalMassFromSNIa", FLOAT, 1, UNIT_CONV_MASS, - parts, chemistry_data.mass_from_SNIa, 1); + parts, chemistry_data.mass_from_SNIa); - list[5] = io_make_output_field( - "MetalMassFracFromSNIa", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, - chemistry_data.metal_mass_fraction_from_SNIa, 1); + list[5] = io_make_output_field("MetalMassFracFromSNIa", FLOAT, 1, + UNIT_CONV_NO_UNITS, parts, + chemistry_data.metal_mass_fraction_from_SNIa); list[6] = io_make_output_field("TotalMassFromAGB", FLOAT, 1, UNIT_CONV_MASS, - parts, chemistry_data.mass_from_AGB, 1); + parts, chemistry_data.mass_from_AGB); - list[7] = io_make_output_field( - "MetalMassFracFromAGB", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, - chemistry_data.metal_mass_fraction_from_AGB, 1); + list[7] = + io_make_output_field("MetalMassFracFromAGB", FLOAT, 1, UNIT_CONV_NO_UNITS, + parts, chemistry_data.metal_mass_fraction_from_AGB); list[8] = io_make_output_field("TotalMassFromSNII", FLOAT, 1, UNIT_CONV_MASS, - parts, chemistry_data.mass_from_SNII, 1); + parts, chemistry_data.mass_from_SNII); - list[9] = io_make_output_field( - "MetalMassFracFromSNII", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, - chemistry_data.metal_mass_fraction_from_SNII, 1); + list[9] = io_make_output_field("MetalMassFracFromSNII", FLOAT, 1, + UNIT_CONV_NO_UNITS, parts, + chemistry_data.metal_mass_fraction_from_SNII); - list[10] = io_make_output_field( - "IronMassFracFromSNIa", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, - chemistry_data.iron_mass_fraction_from_SNIa, 1); + list[10] = + io_make_output_field("IronMassFracFromSNIa", FLOAT, 1, UNIT_CONV_NO_UNITS, + parts, chemistry_data.iron_mass_fraction_from_SNIa); list[11] = io_make_output_field( "SmoothedIronMassFracFromSNIa", FLOAT, 1, UNIT_CONV_NO_UNITS, parts, - chemistry_data.smoothed_iron_mass_fraction_from_SNIa, 1); + chemistry_data.smoothed_iron_mass_fraction_from_SNIa); return 12; } diff --git a/src/chemistry/GEAR/chemistry_io.h b/src/chemistry/GEAR/chemistry_io.h index e1e444cb4..bee29dd3b 100644 --- a/src/chemistry/GEAR/chemistry_io.h +++ b/src/chemistry/GEAR/chemistry_io.h @@ -82,7 +82,7 @@ __attribute__((always_inline)) INLINE static int chemistry_write_particles( list[2] = io_make_output_field("ElementAbundance", FLOAT, chemistry_element_count, UNIT_CONV_NO_UNITS, - parts, chemistry_data.metal_mass_fraction, 1); + parts, chemistry_data.metal_mass_fraction); return 3; } diff --git a/src/common_io.c b/src/common_io.c index f2c60e033..2051d682e 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -815,8 +815,8 @@ void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot, * * @param e The #engine */ -void io_check_output_fields(const struct swift_params *output_fields, - const struct engine *e) { +void io_check_output_fields(const struct swift_params* output_fields, + const struct engine* e) { if (output_fields->paramCount == 0) error("You need to provide an output field in %s", output_fields->fileName); @@ -837,7 +837,6 @@ void io_check_output_fields(const struct swift_params *output_fields, long long N_total[swift_type_count] = { (long long)Ngas, (long long)Ndm, 0, 0, (long long)Nstars, 0}; - /* get all the possible outputs */ for (int ptype = 0; ptype < swift_type_count; ptype++) { int num_fields = 0; @@ -849,46 +848,43 @@ void io_check_output_fields(const struct swift_params *output_fields, /* Write particle fields from the particle structure */ switch (ptype) { - case swift_type_gas: - hydro_write_particles(parts, xparts, list, &num_fields); - num_fields += chemistry_write_particles(parts, list + num_fields); - break; + case swift_type_gas: + hydro_write_particles(parts, xparts, list, &num_fields); + num_fields += chemistry_write_particles(parts, list + num_fields); + break; - case swift_type_dark_matter: - darkmatter_write_particles(gparts, list, &num_fields); - break; + case swift_type_dark_matter: + darkmatter_write_particles(gparts, list, &num_fields); + break; - case swift_type_star: - star_write_particles(sparts, list, &num_fields); - break; + case swift_type_star: + star_write_particles(sparts, list, &num_fields); + break; - default: - error("Particle Type %d not yet supported. Aborting", ptype); - } + default: + error("Particle Type %d not yet supported. Aborting", ptype); + } /* loop over each parameter */ for (int param_id = 0; param_id < output_fields->paramCount; param_id++) { - const char *param_name = output_fields->data[param_id].name; - + const char* param_name = output_fields->data[param_id].name; + /* skip if wrong part type */ char section_name[200]; sprintf(section_name, "PartType%i", ptype); - if (strstr(param_name, section_name) == NULL) - continue; + if (strstr(param_name, section_name) == NULL) continue; int found = 0; - + /* loop over each possible output field */ for (int field_id = 0; field_id < num_fields; field_id++) { - char field_name[256]; - sprintf(field_name, "PartType%i:%s", ptype, list[field_id].name); - if (strcmp(param_name, field_name) == 0) { - found = 1; - continue; - } + char field_name[256]; + sprintf(field_name, "PartType%i:%s", ptype, list[field_id].name); + if (strcmp(param_name, field_name) == 0) { + found = 1; + continue; + } } - if (!found) - error("Unable to find field corresponding to %s", param_name); + if (!found) error("Unable to find field corresponding to %s", param_name); } } - } diff --git a/src/common_io.h b/src/common_io.h index 0aba3be1e..fd8434b09 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -100,7 +100,7 @@ void io_duplicate_star_gparts(struct threadpool* tp, struct spart* const sparts, struct gpart* const gparts, size_t Nstars, size_t Ndm); -void io_check_output_fields(const struct swift_params *output_fields, - const struct engine *e); +void io_check_output_fields(const struct swift_params* output_fields, + const struct engine* e); #endif /* SWIFT_COMMON_IO_H */ diff --git a/src/gravity/Default/gravity_io.h b/src/gravity/Default/gravity_io.h index d69310f2f..b1cddae1a 100644 --- a/src/gravity/Default/gravity_io.h +++ b/src/gravity/Default/gravity_io.h @@ -111,9 +111,8 @@ __attribute__((always_inline)) INLINE static void darkmatter_write_particles( "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[3] = io_make_output_field("ParticleIDs", ULONGLONG, 1, + UNIT_CONV_NO_UNITS, gparts, id_or_neg_offset); list[4] = io_make_output_field("Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, gparts, potential); } diff --git a/src/hydro/Default/hydro_io.h b/src/hydro/Default/hydro_io.h index 490f9f47f..c7a0953eb 100644 --- a/src/hydro/Default/hydro_io.h +++ b/src/hydro/Default/hydro_io.h @@ -128,9 +128,8 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, convert_part_pos); - list[1] = - io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - parts, xparts, convert_part_vel); + 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, @@ -139,11 +138,11 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, parts, id); - list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - rho); - list[7] = io_make_output_field_convert_part( - "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, - convert_part_potential); + list[6] = + io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho); + list[7] = io_make_output_field_convert_part("Potential", FLOAT, 1, + UNIT_CONV_POTENTIAL, parts, + xparts, convert_part_potential); } /** diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h index 3ed358ebb..dab03600a 100644 --- a/src/hydro/Gadget2/hydro_io.h +++ b/src/hydro/Gadget2/hydro_io.h @@ -56,22 +56,22 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles( } __attribute__((always_inline)) INLINE static void convert_part_u( - const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { + const struct engine* e, const struct part* p, const struct xpart* xp, + float* ret) { ret[0] = hydro_get_comoving_internal_energy(p); } __attribute__((always_inline)) INLINE static void convert_part_P( - const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { + const struct engine* e, const struct part* p, const struct xpart* xp, + float* ret) { ret[0] = hydro_get_comoving_pressure(p); } __attribute__((always_inline)) INLINE static void convert_part_pos( - const struct engine* e, const struct part* p, - const struct xpart* xp, double* ret) { + const struct engine* e, const struct part* p, const struct xpart* xp, + double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -85,8 +85,8 @@ __attribute__((always_inline)) INLINE static void convert_part_pos( } __attribute__((always_inline)) INLINE static void convert_part_vel( - const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { + const struct engine* e, const struct part* p, const struct xpart* xp, + float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -120,8 +120,8 @@ __attribute__((always_inline)) INLINE static void convert_part_vel( } __attribute__((always_inline)) INLINE static void convert_part_potential( - const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { + const struct engine* e, const struct part* p, const struct xpart* xp, + float* ret) { if (p->gpart != NULL) ret[0] = gravity_get_comoving_potential(p->gpart); @@ -137,8 +137,8 @@ __attribute__((always_inline)) INLINE static void convert_part_potential( * @param num_fields The number of i/o fields to write. */ __attribute__((always_inline)) INLINE static void hydro_write_particles( - const struct part* parts, const struct xpart* xparts, - struct io_props* list, int* num_fields) { + const struct part* parts, const struct xpart* xparts, struct io_props* list, + int* num_fields) { *num_fields = 10; @@ -146,9 +146,8 @@ __attribute__((always_inline)) INLINE static void hydro_write_particles( list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, convert_part_pos); - list[1] = - io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - parts, xparts, convert_part_vel); + 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, @@ -157,18 +156,17 @@ __attribute__((always_inline)) INLINE static void hydro_write_particles( "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, parts, id); - list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - rho); + list[6] = + io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho); list[7] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, xparts, convert_part_u); - list[8] = io_make_output_field_convert_part("Pressure", FLOAT, 1, - UNIT_CONV_PRESSURE, parts, xparts, - convert_part_P); + list[8] = io_make_output_field_convert_part( + "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_part_P); - list[9] = io_make_output_field_convert_part( - "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, - convert_part_potential); + list[9] = io_make_output_field_convert_part("Potential", FLOAT, 1, + UNIT_CONV_POTENTIAL, parts, + xparts, convert_part_potential); #ifdef DEBUG_INTERACTIONS_SPH @@ -193,7 +191,8 @@ __attribute__((always_inline)) INLINE static void hydro_write_particles( * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -__attribute__((always_inline)) INLINE static void hydro_write_flavour(hid_t h_grpsph) { +__attribute__((always_inline)) INLINE static void hydro_write_flavour( + hid_t h_grpsph) { /* Viscosity and thermal conduction */ io_write_attribute_s(h_grpsph, "Thermal Conductivity Model", diff --git a/src/hydro/GizmoMFM/hydro_io.h b/src/hydro/GizmoMFM/hydro_io.h index f12a6e08c..94127b3fa 100644 --- a/src/hydro/GizmoMFM/hydro_io.h +++ b/src/hydro/GizmoMFM/hydro_io.h @@ -185,9 +185,8 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, convert_part_pos); - list[1] = - io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - parts, xparts, convert_part_vel); + 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, conserved.mass); @@ -207,9 +206,9 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, list[9] = io_make_output_field_convert_part( "TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, xparts, convert_Etot); - list[10] = io_make_output_field_convert_part( - "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, - convert_part_potential); + list[10] = io_make_output_field_convert_part("Potential", FLOAT, 1, + UNIT_CONV_POTENTIAL, parts, + xparts, convert_part_potential); } /** diff --git a/src/hydro/Minimal/hydro_io.h b/src/hydro/Minimal/hydro_io.h index 1f3c15996..846462a28 100644 --- a/src/hydro/Minimal/hydro_io.h +++ b/src/hydro/Minimal/hydro_io.h @@ -155,9 +155,8 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, convert_part_pos); - list[1] = - io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - parts, xparts, convert_part_vel); + 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, @@ -166,17 +165,17 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, parts, id); - list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - rho); + list[6] = + io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho); list[7] = io_make_output_field_convert_part("Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, xparts, convert_S); list[8] = io_make_output_field_convert_part( "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_P); - list[9] = io_make_output_field_convert_part( - "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, - convert_part_potential); + list[9] = io_make_output_field_convert_part("Potential", FLOAT, 1, + UNIT_CONV_POTENTIAL, parts, + xparts, convert_part_potential); } /** diff --git a/src/hydro/PressureEntropy/hydro_io.h b/src/hydro/PressureEntropy/hydro_io.h index 18c5c0fc3..59c49c066 100644 --- a/src/hydro/PressureEntropy/hydro_io.h +++ b/src/hydro/PressureEntropy/hydro_io.h @@ -152,9 +152,8 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, xparts, convert_part_pos); - list[1] = - io_make_output_field_convert_part("Velocities", FLOAT, 3, UNIT_CONV_SPEED, - parts, xparts, convert_part_vel); + 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, @@ -163,8 +162,8 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy); list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1, UNIT_CONV_NO_UNITS, parts, id); - list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, - rho); + list[6] = + io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho); list[7] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1, UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, xparts, convert_u); @@ -172,9 +171,9 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, xparts, convert_P); list[9] = io_make_output_field("WeightedDensity", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho_bar); - list[10] = io_make_output_field_convert_part( - "Potential", FLOAT, 1, UNIT_CONV_POTENTIAL, parts, xparts, - convert_part_potential); + list[10] = io_make_output_field_convert_part("Potential", FLOAT, 1, + UNIT_CONV_POTENTIAL, parts, + xparts, convert_part_potential); } /** diff --git a/src/io_properties.h b/src/io_properties.h index 565dbef33..037d32338 100644 --- a/src/io_properties.h +++ b/src/io_properties.h @@ -97,7 +97,6 @@ struct io_props { /* Conversion function for gpart */ conversion_func_gpart_float convert_gpart_f; conversion_func_gpart_double convert_gpart_d; - }; /** @@ -147,7 +146,7 @@ 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) \ +#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])) @@ -189,10 +188,9 @@ INLINE static struct io_props io_make_output_field_( * @brief Constructs an #io_props (with conversion) from its parameters */ #define io_make_output_field_convert_part(name, type, dim, units, part, xpart, \ - convert) \ - io_make_output_field_convert_part_##type(name, type, dim, units, \ - sizeof(part[0]), part, xpart, \ - convert) + convert) \ + io_make_output_field_convert_part_##type( \ + name, type, dim, units, sizeof(part[0]), part, xpart, convert) /** * @brief Construct an #io_props from its parameters @@ -277,9 +275,9 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE( /** * @brief Constructs an #io_props (with conversion) from its parameters */ -#define io_make_output_field_convert_gpart(name, type, dim, units, gpart, \ - convert) \ - io_make_output_field_convert_gpart_##type(name, type, dim, units, \ +#define io_make_output_field_convert_gpart(name, type, dim, units, gpart, \ + convert) \ + io_make_output_field_convert_gpart_##type(name, type, dim, units, \ sizeof(gpart[0]), gpart, convert) /** diff --git a/src/stars/Default/star_io.h b/src/stars/Default/star_io.h index 998913053..2d7caacc0 100644 --- a/src/stars/Default/star_io.h +++ b/src/stars/Default/star_io.h @@ -61,8 +61,8 @@ __attribute__((always_inline)) INLINE static void star_write_particles( /* List what we want to read */ 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[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); list[3] = io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, -- GitLab From 3f514b1f76ded6ea14871ecc05148ed6c84100e3 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Wed, 4 Apr 2018 10:51:55 +0200 Subject: [PATCH 14/39] improve error message --- src/common_io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common_io.c b/src/common_io.c index 2051d682e..5c2aba037 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -884,7 +884,9 @@ void io_check_output_fields(const struct swift_params* output_fields, continue; } } - if (!found) error("Unable to find field corresponding to %s", param_name); + if (!found) + error("Unable to find field corresponding to %s in %s", + param_name, output_fields->fileName); } } } -- GitLab From f6ae914f6edd48ba57db96bce00f619dd57ce639 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Wed, 4 Apr 2018 16:53:52 +0200 Subject: [PATCH 15/39] Add example parameter files and a script generating right parameters --- examples/SedovBlast_3D/run.sh | 3 + examples/SedovBlast_3D/sedov.yml | 2 +- examples/create_ouput_fields.py | 291 ++++++++++++++++++ examples/main.c | 7 +- examples/output_fields_example.yml | 27 -- .../chemistry_eagle.yml | 14 + .../output_fields_examples/chemistry_gear.yml | 4 + .../output_fields_examples/chemistry_none.yml | 0 .../cooling_const_du.yml | 0 .../output_fields_examples/cooling_eagle.yml | 0 .../cooling_grackle.yml | 0 .../output_fields_examples/cooling_lambda.yml | 0 .../output_fields_examples/cooling_none.yml | 0 .../gravity_default.yml | 7 + .../output_fields_examples/hydro_default.yml | 10 + .../output_fields_examples/hydro_gadget2.yml | 17 + .../output_fields_examples/hydro_gizmo.yml | 13 + .../output_fields_examples/hydro_minimal.yml | 12 + .../hydro_pressureentropy.yml | 13 + .../hydro_shadowswift.yml | 16 + .../output_fields_examples/stars_default.yml | 6 + 21 files changed, 409 insertions(+), 33 deletions(-) create mode 100644 examples/create_ouput_fields.py delete mode 100644 examples/output_fields_example.yml create mode 100644 examples/output_fields_examples/chemistry_eagle.yml create mode 100644 examples/output_fields_examples/chemistry_gear.yml create mode 100644 examples/output_fields_examples/chemistry_none.yml create mode 100644 examples/output_fields_examples/cooling_const_du.yml create mode 100644 examples/output_fields_examples/cooling_eagle.yml create mode 100644 examples/output_fields_examples/cooling_grackle.yml create mode 100644 examples/output_fields_examples/cooling_lambda.yml create mode 100644 examples/output_fields_examples/cooling_none.yml create mode 100644 examples/output_fields_examples/gravity_default.yml create mode 100644 examples/output_fields_examples/hydro_default.yml create mode 100644 examples/output_fields_examples/hydro_gadget2.yml create mode 100644 examples/output_fields_examples/hydro_gizmo.yml create mode 100644 examples/output_fields_examples/hydro_minimal.yml create mode 100644 examples/output_fields_examples/hydro_pressureentropy.yml create mode 100644 examples/output_fields_examples/hydro_shadowswift.yml create mode 100644 examples/output_fields_examples/stars_default.yml diff --git a/examples/SedovBlast_3D/run.sh b/examples/SedovBlast_3D/run.sh index 00d5e5b91..590ed5efa 100755 --- a/examples/SedovBlast_3D/run.sh +++ b/examples/SedovBlast_3D/run.sh @@ -12,6 +12,9 @@ then python makeIC.py fi +# Generate output fields +../create_ouput_fields.py ../../config.h -o output_fields.yml -d ../output_fields_examples/ + # Run SWIFT ../swift -s -t 4 sedov.yml 2>&1 | tee output.log diff --git a/examples/SedovBlast_3D/sedov.yml b/examples/SedovBlast_3D/sedov.yml index 5368c0264..d73f70be0 100644 --- a/examples/SedovBlast_3D/sedov.yml +++ b/examples/SedovBlast_3D/sedov.yml @@ -19,7 +19,7 @@ Snapshots: time_first: 0. # Time of the first output (in internal units) delta_time: 1e-2 # Time difference between consecutive outputs (in internal units) compression: 4 - FieldsFilename: ../output_fields_example.yml + FieldsFilename: output_fields.yml # Parameters governing the conserved quantities statistics Statistics: diff --git a/examples/create_ouput_fields.py b/examples/create_ouput_fields.py new file mode 100644 index 000000000..86ca8a585 --- /dev/null +++ b/examples/create_ouput_fields.py @@ -0,0 +1,291 @@ +#!/usr/bin/env python3 + +from optparse import OptionParser +from regex import search +from os import path, remove + +# fields to do +todo = [ + "chemistry", "cooling", + "gravity", "stars", + "hydro"] + +# number of particle type +N_type = 6 + + +def parseOptions(): + """ + Parse options. + + Returns + ------- + + opt: + Option structure + + args: + Arguments + """ + usage = """usage: %prog [options] args1 + If options are not provided, this script will read the config.h file \ +provided (args1) and use theses values. + """ + + parser = OptionParser(usage=usage) + + parser.add_option("--with-cooling", + dest="cooling", + help="Cooling Type", + default="", + type=str, + metavar="STR") + + parser.add_option("--with-chemistry", + dest="chemistry", + help="Chemistry Type", + default="", + type=str, + metavar="STR") + + parser.add_option("--with-hydro", + dest="hydro", + help="Hydro Type", + default="", + type=str, + metavar="STR") + + parser.add_option("--with-stars", + dest="stars", + help="Stars Type", + default="default", + type=str, + metavar="STR") + + parser.add_option("--with-gravity", + dest="gravity", + help="Gravity Type", + default="default", + type=str, + metavar="STR") + + parser.add_option("-o", "--output", + dest="o", + help="Output filename", + type=str, + default=None, + metavar="STR") + + parser.add_option("-d", "--example_directory", + dest="d", + help="Directory containing the examples", + type=str, + default=None, + metavar="STR") + + return parser.parse_args() + + +def readConfig(filename): + """ + Read the config.h file and parse it to keep + only the definitions. + + Parameters + ---------- + + filename: str + Filename to parse + + Returns + ------- + + options: list + List of options + """ + expression = "#define (.*) 1" + options = [] + with open(filename, "r") as f: + for line in f: + tmp = search(expression, line) + if tmp is not None: + options.append(tmp.group(1)) + + return options + + +def getConfig(opt, swift_options, current): + """ + Parse the config.h options and extract the required + parameter. If not able to find an option, return False + + Parameters + ---------- + + opt: + Option structure + + swift_options: list + Option in config.h + + current: str + Current option + + Returns + ------- + + option: str + name of the option (in lower case) + """ + # if given in options, returns + if getattr(opt, current) != "": + return getattr(opt, current) + + # get current option + caps = current.upper() + expression = "%s_(.*)" % caps + if current == "hydro": + expression = "(.*)_SPH" + for i in swift_options: + tmp = search(expression, i) + if tmp is not None: + return tmp.group(1).lower() + return False + + +def readYamlFile(filename): + """ + Read quickly a yaml file. + + Parameters + ---------- + + filename: str + file to read + + Returns + ------- + + d: dict + key -> section name, value -> list of parameters + """ + d = {} + key = None + section = "(PartType\d+):" + with open(filename, "r") as f: + for line in f: + # check for section + tmp = search(section, line) + if tmp is not None: + key = tmp.group(1) + d[key] = [] + continue + + # skip if not a parameter or outside + # a section + if ":" not in line or key is None: + continue + + # ensure end of line + if "\n" not in line: + line += "\n" + + # write line + d[key].append(line) + + return d + + +def generateFile(opt): + """ + Generate an output fields file from examples. + + Parameters + ---------- + + opt: + Option structure + + Returns + ------- + + d: dict + key -> section name, value -> list of parameters + """ + d = {} + # read all files + for current in todo: + filename = current + "_" + getattr(opt, current) + ".yml" + filename = opt.d + "/" + filename + data = readYamlFile(filename) + + for tpe in range(N_type): + name = "PartType%i" % tpe + if name not in data: + continue + + if name not in d: + d[name] = data[name] + + else: + d[name].extend(data[name]) + return d + + +def writeOutputFields(d, opt): + """ + Write the output. + + Parameters + ---------- + + d: dict + key -> section name, value -> list of parameters + + opt: + Option structure + + """ + with open(opt.o, "w") as f: + for tpe in range(N_type): + name = "PartType%i" % tpe + if name not in d: + continue + f.write("%s:\n" % name) + for i in d[name]: + f.write(i) + + f.write("\n") + + +if __name__ == "__main__": + # parse option + opt, args = parseOptions() + + # check inputs + # arguments + if len(args) != 1: + raise IOError("A file should be provided") + filename = args[0] + + # output file + if opt.o is None: + raise IOError("The output option '-o' is required") + + # example directory + if opt.d is None: + raise IOError("The example directory option '-d' is required") + + # read configuration file + swift_options = readConfig(filename) + + # get correct configuration + for current in todo: + tmp = getConfig(opt, swift_options, current) + if tmp is False: + raise IOError("Unable to get field %s" % current) + setattr(opt, current, tmp) + + # generate and write output_fields file + d = generateFile(opt) + writeOutputFields(d, opt) diff --git a/examples/main.c b/examples/main.c index 605b2d330..ec0787bfd 100644 --- a/examples/main.c +++ b/examples/main.c @@ -469,11 +469,8 @@ int main(int argc, char *argv[]) { if (myrank == 0) { message("Reading runtime output fields from file '%s'", outputFieldsFileName); - if (strcmp(outputFieldsFileName, "") != 0) - parser_read_file(outputFieldsFileName, output_fields); - else - parser_init(outputFieldsFileName, output_fields); - + parser_read_file(outputFieldsFileName, output_fields); + /* And dump the parameters as used. */ parser_write_params_to_file(output_fields, "used_output_fields.yml"); } diff --git a/examples/output_fields_example.yml b/examples/output_fields_example.yml deleted file mode 100644 index 22dfdc35a..000000000 --- a/examples/output_fields_example.yml +++ /dev/null @@ -1,27 +0,0 @@ -# Gas -PartType0: - Coordinates: 1 # Request to write output - Masses: 1 - Velocities: 1 - SmoothingLength: 1 - Entropy: 1 - ParticleIDs: 1 - Density: 1 - InternalEnergy: 0 # Request to not write output - Pressure: 0 - Potential: 0 - -# Dark Matter -PartType1: - Coordinates: 1 - Velocities: 1 - Masses: 1 - ParticleIDs: 1 - Potential: 0 - -# Stars -PartType2: - Coordinates: 1 - Velocities: 1 - Masses: 1 - ParticleIDs: 1 \ No newline at end of file diff --git a/examples/output_fields_examples/chemistry_eagle.yml b/examples/output_fields_examples/chemistry_eagle.yml new file mode 100644 index 000000000..d62c2b32d --- /dev/null +++ b/examples/output_fields_examples/chemistry_eagle.yml @@ -0,0 +1,14 @@ +# gas +PartType0: + ElementAbundance: 1 + SmoothedElementAbundance: 1 + Metallicity: 1 + SmoothedMetallicity: 1 + TotalMassFromSNIa: 1 + MetalMassFracFromSNIa: 1 + TotalMassFromAGB: 1 + MetalMassFracFromAGB: 1 + TotalMassFromSNII: 1 + MetalMassFracFromSNII: 1 + IronMassFracFromSNIa: 1 + SmoothedIronMassFracFromSNIa: 1 \ No newline at end of file diff --git a/examples/output_fields_examples/chemistry_gear.yml b/examples/output_fields_examples/chemistry_gear.yml new file mode 100644 index 000000000..a64dbfb01 --- /dev/null +++ b/examples/output_fields_examples/chemistry_gear.yml @@ -0,0 +1,4 @@ +# gas +PartType0: + SmoothedElementAbundance: 1 + ElementAbundance: 1 \ No newline at end of file diff --git a/examples/output_fields_examples/chemistry_none.yml b/examples/output_fields_examples/chemistry_none.yml new file mode 100644 index 000000000..e69de29bb diff --git a/examples/output_fields_examples/cooling_const_du.yml b/examples/output_fields_examples/cooling_const_du.yml new file mode 100644 index 000000000..e69de29bb diff --git a/examples/output_fields_examples/cooling_eagle.yml b/examples/output_fields_examples/cooling_eagle.yml new file mode 100644 index 000000000..e69de29bb diff --git a/examples/output_fields_examples/cooling_grackle.yml b/examples/output_fields_examples/cooling_grackle.yml new file mode 100644 index 000000000..e69de29bb diff --git a/examples/output_fields_examples/cooling_lambda.yml b/examples/output_fields_examples/cooling_lambda.yml new file mode 100644 index 000000000..e69de29bb diff --git a/examples/output_fields_examples/cooling_none.yml b/examples/output_fields_examples/cooling_none.yml new file mode 100644 index 000000000..e69de29bb diff --git a/examples/output_fields_examples/gravity_default.yml b/examples/output_fields_examples/gravity_default.yml new file mode 100644 index 000000000..26e54f1fa --- /dev/null +++ b/examples/output_fields_examples/gravity_default.yml @@ -0,0 +1,7 @@ +# Dark Matter +PartType1: + Coordinates: 1 + Velocities: 1 + Masses: 1 + ParticleIDs: 1 + Potential: 1 diff --git a/examples/output_fields_examples/hydro_default.yml b/examples/output_fields_examples/hydro_default.yml new file mode 100644 index 000000000..350979d7a --- /dev/null +++ b/examples/output_fields_examples/hydro_default.yml @@ -0,0 +1,10 @@ +# Gas +PartType0: + Coordinates: 1 + Masses: 1 + Velocities: 1 + SmoothingLength: 1 + ParticleIDs: 1 + Density: 1 + InternalEnergy: 1 + Potential: 1 diff --git a/examples/output_fields_examples/hydro_gadget2.yml b/examples/output_fields_examples/hydro_gadget2.yml new file mode 100644 index 000000000..9cfcf123d --- /dev/null +++ b/examples/output_fields_examples/hydro_gadget2.yml @@ -0,0 +1,17 @@ +# Gas +PartType0: + Coordinates: 1 + Masses: 1 + Velocities: 1 + SmoothingLength: 1 + Entropy: 1 + ParticleIDs: 1 + Density: 1 + InternalEnergy: 1 + Pressure: 1 + Potential: 1 + # debug fields + # Num_ngb_density: 0 + # Num_ngb_force: 0 + # Ids_ngb_density: 0 + # Ids_ngb_force \ No newline at end of file diff --git a/examples/output_fields_examples/hydro_gizmo.yml b/examples/output_fields_examples/hydro_gizmo.yml new file mode 100644 index 000000000..17f4231d6 --- /dev/null +++ b/examples/output_fields_examples/hydro_gizmo.yml @@ -0,0 +1,13 @@ +# Gas +PartType0: + Coordinates: 1 + Masses: 1 + Velocities: 1 + SmoothingLength: 1 + Entropy: 1 + ParticleIDs: 1 + Density: 1 + InternalEnergy: 1 + Pressure: 1 + TotEnergy: 1 + Potential: 1 diff --git a/examples/output_fields_examples/hydro_minimal.yml b/examples/output_fields_examples/hydro_minimal.yml new file mode 100644 index 000000000..bbc1ae937 --- /dev/null +++ b/examples/output_fields_examples/hydro_minimal.yml @@ -0,0 +1,12 @@ +# Gas +PartType0: + Coordinates: 1 + Masses: 1 + Velocities: 1 + SmoothingLength: 1 + Entropy: 1 + ParticleIDs: 1 + Density: 1 + InternalEnergy: 1 + Pressure: 1 + Potential: 1 diff --git a/examples/output_fields_examples/hydro_pressureentropy.yml b/examples/output_fields_examples/hydro_pressureentropy.yml new file mode 100644 index 000000000..b4ea000c1 --- /dev/null +++ b/examples/output_fields_examples/hydro_pressureentropy.yml @@ -0,0 +1,13 @@ +# Gas +PartType0: + Coordinates: 1 + Masses: 1 + Velocities: 1 + SmoothingLength: 1 + Entropy: 1 + ParticleIDs: 1 + Density: 1 + InternalEnergy: 1 + Pressure: 1 + Potential: 1 + WeightedDensity: 1 \ No newline at end of file diff --git a/examples/output_fields_examples/hydro_shadowswift.yml b/examples/output_fields_examples/hydro_shadowswift.yml new file mode 100644 index 000000000..edd62d19a --- /dev/null +++ b/examples/output_fields_examples/hydro_shadowswift.yml @@ -0,0 +1,16 @@ +# Gas +PartType0: + Coordinates: 1 + Masses: 1 + Velocities: 1 + SmoothingLength: 1 + Entropy: 1 + ParticleIDs: 1 + Density: 1 + InternalEnergy: 1 + Pressure: 1 + Potential: 1 + Acceleration: 1 + Volume: 1 + GradDensity: 1 + TotEnergy: 1 \ No newline at end of file diff --git a/examples/output_fields_examples/stars_default.yml b/examples/output_fields_examples/stars_default.yml new file mode 100644 index 000000000..bc447626d --- /dev/null +++ b/examples/output_fields_examples/stars_default.yml @@ -0,0 +1,6 @@ +# Stars +PartType2: + Coordinates: 1 + Velocities: 1 + Masses: 1 + ParticleIDs: 1 \ No newline at end of file -- GitLab From 3af2890c2f28c06a1f09db12fcbf7d195b962450 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Mon, 23 Apr 2018 10:17:08 +0200 Subject: [PATCH 16/39] Add option generating output field parameter --- examples/main.c | 23 ++++++++++++++++++++++- src/common_io.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/common_io.h | 2 ++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/examples/main.c b/examples/main.c index ec0787bfd..d0662237e 100644 --- a/examples/main.c +++ b/examples/main.c @@ -90,6 +90,8 @@ void print_help_message(void) { printf(" %2s %14s %s\n", "-n", "{int}", "Execute a fixed number of time steps. When unset use the time_end " "parameter to stop."); + printf(" %2s %14s %s\n", "-o", "{str}", + "Generate a default output parameter file."); printf(" %2s %14s %s\n", "-P", "{sec:par:val}", "Set parameter value and overwrites values read from the parameters " "file. Can be used more than once."); @@ -195,6 +197,7 @@ int main(int argc, char *argv[]) { int nr_threads = 1; int with_verbose_timers = 0; int nparams = 0; + char output_parameters_filename[200] = ""; char *cmdparams[PARSER_MAX_NO_OF_PARAMS]; char paramFileName[200] = ""; char restart_file[200] = ""; @@ -202,7 +205,7 @@ int main(int argc, char *argv[]) { /* Parse the parameters */ int c; - while ((c = getopt(argc, argv, "acCdDef:FgGhMn:P:rsSt:Tv:y:Y:")) != -1) + while ((c = getopt(argc, argv, "acCdDef:FgGhMn:o:P:rsSt:Tv:y:Y:")) != -1) switch (c) { case 'a': #if defined(HAVE_SETAFFINITY) && defined(HAVE_LIBNUMA) @@ -259,6 +262,15 @@ int main(int argc, char *argv[]) { return 1; } break; + case 'o': + if (sscanf(optarg, "%s", output_parameters_filename) != 1) { + if (myrank == 0) { + printf("Error parsing output fields filename"); + print_help_message(); + } + return 1; + } + break; case 'P': cmdparams[nparams] = optarg; nparams++; @@ -324,6 +336,15 @@ int main(int argc, char *argv[]) { return 1; break; } + + /* Write output parameter file */ + if (strcmp(output_parameters_filename, "") != 0) { + io_write_output_field_parameter(output_parameters_filename); + printf("Ouput parameter file written in %s\n", output_parameters_filename); + return 0; + } + + /* check inputs */ if (optind == argc - 1) { if (!strcpy(paramFileName, argv[optind++])) error("Error reading parameter file name."); diff --git a/src/common_io.c b/src/common_io.c index 5c2aba037..624b00210 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -890,3 +890,49 @@ void io_check_output_fields(const struct swift_params* output_fields, } } } + +/** + * @brief Write the output field parameters file + * + * @param e The #engine + * @param filename The file to write + */ +void io_write_output_field_parameter(const char* filename) { + FILE *file = fopen(filename, "w"); + + /* Loop over all particle types */ + for (int ptype = 0; ptype < swift_type_count; ptype++) { + int num_fields = 0; + struct io_props list[100]; + + /* Write particle fields from the particle structure */ + switch (ptype) { + + case swift_type_gas: + hydro_write_particles(NULL, NULL, list, &num_fields); + num_fields += chemistry_write_particles(NULL, list + num_fields); + break; + + case swift_type_dark_matter: + darkmatter_write_particles(NULL, list, &num_fields); + break; + + case swift_type_star: + star_write_particles(NULL, list, &num_fields); + break; + + } + + if (num_fields > 0) + fprintf(file, "ParticleType%i:\n", ptype); + + /* Write everything */ + for (int i = 0; i < num_fields; ++i) { + fprintf(file, " %s: 1\n", list[i].name); + } + + fprintf(file, "\n"); + } + + fclose(file); +} diff --git a/src/common_io.h b/src/common_io.h index fd8434b09..c4bf2c724 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -103,4 +103,6 @@ void io_duplicate_star_gparts(struct threadpool* tp, struct spart* const sparts, void io_check_output_fields(const struct swift_params* output_fields, const struct engine* e); +void io_write_output_field_parameter(const char* filename); + #endif /* SWIFT_COMMON_IO_H */ -- GitLab From 462542b4c34f0681fa7a45745f49f0fe6e48a773 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Mon, 23 Apr 2018 10:34:55 +0200 Subject: [PATCH 17/39] fix selection bug --- src/parallel_io.c | 6 +++--- src/serial_io.c | 6 +++--- src/single_io.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/parallel_io.c b/src/parallel_io.c index 0dcf9c5b2..06bf551e9 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1264,9 +1264,9 @@ void write_output_parallel(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[256] = "OutputFields:"; - strcat(field, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, 0); + char field[256]; + sprintf(field, "ParticleType%i:%s", ptype, list[i].name); + int should_write = parser_get_opt_param_int(output_fields, field, 1); if (should_write) writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], internal_units, diff --git a/src/serial_io.c b/src/serial_io.c index 9874da73e..04a4e7b95 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1008,9 +1008,9 @@ void write_output_serial(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[256] = "OutputFields:"; - strcat(field, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, 0); + char field[256]; + sprintf(field, "ParticleType%i:%s", ptype, list[i].name); + int should_write = parser_get_opt_param_int(output_fields, field, 1); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], diff --git a/src/single_io.c b/src/single_io.c index 2fc7d3822..4fa18a46a 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -828,8 +828,8 @@ void write_output_single(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { char field[256]; - sprintf(field, "ParticleType%i:%s", i, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, 0); + sprintf(field, "ParticleType%i:%s", ptype, list[i].name); + int should_write = parser_get_opt_param_int(output_fields, field, 1); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, internal_units, snapshot_units); -- GitLab From 0fe5185f8a13b85769cbdc63b4f72f0a568a4c21 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Mon, 23 Apr 2018 10:35:27 +0200 Subject: [PATCH 18/39] Move output field parameter from mandatory to optional --- examples/main.c | 8 +++++--- src/common_io.c | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/main.c b/examples/main.c index d0662237e..1b211ad94 100644 --- a/examples/main.c +++ b/examples/main.c @@ -485,9 +485,11 @@ int main(int argc, char *argv[]) { error("Error allocating memory for the output fields file."); char outputFieldsFileName[200]; - parser_get_param_string(params, "Snapshots:FieldsFilename", - outputFieldsFileName); - if (myrank == 0) { + parser_get_opt_param_string(params, "Snapshots:FieldsFilename", + outputFieldsFileName, ""); + + parser_init(outputFieldsFileName, output_fields); + if (myrank == 0 && strcmp(outputFieldsFileName, "") != 0) { message("Reading runtime output fields from file '%s'", outputFieldsFileName); parser_read_file(outputFieldsFileName, output_fields); diff --git a/src/common_io.c b/src/common_io.c index 624b00210..399459f71 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -813,13 +813,14 @@ void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot, /** * @brief Verify the io parameter file * + * @param output_fields The #swift_params containing output information * @param e The #engine */ void io_check_output_fields(const struct swift_params* output_fields, const struct engine* e) { if (output_fields->paramCount == 0) - error("You need to provide an output field in %s", output_fields->fileName); + return; /* particles */ const struct part* parts = e->s->parts; -- GitLab From d391f87ed389755d5e2c05eb92de2de52aac961d Mon Sep 17 00:00:00 2001 From: lhausamm Date: Mon, 23 Apr 2018 10:36:00 +0200 Subject: [PATCH 19/39] Remove output selection from sedov --- examples/SedovBlast_3D/run.sh | 3 --- examples/SedovBlast_3D/sedov.yml | 1 - 2 files changed, 4 deletions(-) diff --git a/examples/SedovBlast_3D/run.sh b/examples/SedovBlast_3D/run.sh index 590ed5efa..00d5e5b91 100755 --- a/examples/SedovBlast_3D/run.sh +++ b/examples/SedovBlast_3D/run.sh @@ -12,9 +12,6 @@ then python makeIC.py fi -# Generate output fields -../create_ouput_fields.py ../../config.h -o output_fields.yml -d ../output_fields_examples/ - # Run SWIFT ../swift -s -t 4 sedov.yml 2>&1 | tee output.log diff --git a/examples/SedovBlast_3D/sedov.yml b/examples/SedovBlast_3D/sedov.yml index d73f70be0..c7212983f 100644 --- a/examples/SedovBlast_3D/sedov.yml +++ b/examples/SedovBlast_3D/sedov.yml @@ -19,7 +19,6 @@ Snapshots: time_first: 0. # Time of the first output (in internal units) delta_time: 1e-2 # Time difference between consecutive outputs (in internal units) compression: 4 - FieldsFilename: output_fields.yml # Parameters governing the conserved quantities statistics Statistics: -- GitLab From 3eaf02c4a3f1aaab91d0aa781be212c5c132520d Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 3 May 2018 16:11:21 +0200 Subject: [PATCH 20/39] Remove useless stuff --- examples/create_ouput_fields.py | 291 ------------------ .../chemistry_eagle.yml | 14 - .../output_fields_examples/chemistry_gear.yml | 4 - .../output_fields_examples/chemistry_none.yml | 0 .../cooling_const_du.yml | 0 .../output_fields_examples/cooling_eagle.yml | 0 .../cooling_grackle.yml | 0 .../output_fields_examples/cooling_lambda.yml | 0 .../output_fields_examples/cooling_none.yml | 0 .../gravity_default.yml | 7 - .../output_fields_examples/hydro_default.yml | 10 - .../output_fields_examples/hydro_gadget2.yml | 17 - .../output_fields_examples/hydro_gizmo.yml | 13 - .../output_fields_examples/hydro_minimal.yml | 12 - .../hydro_pressureentropy.yml | 13 - .../hydro_shadowswift.yml | 16 - .../output_fields_examples/stars_default.yml | 6 - 17 files changed, 403 deletions(-) delete mode 100644 examples/create_ouput_fields.py delete mode 100644 examples/output_fields_examples/chemistry_eagle.yml delete mode 100644 examples/output_fields_examples/chemistry_gear.yml delete mode 100644 examples/output_fields_examples/chemistry_none.yml delete mode 100644 examples/output_fields_examples/cooling_const_du.yml delete mode 100644 examples/output_fields_examples/cooling_eagle.yml delete mode 100644 examples/output_fields_examples/cooling_grackle.yml delete mode 100644 examples/output_fields_examples/cooling_lambda.yml delete mode 100644 examples/output_fields_examples/cooling_none.yml delete mode 100644 examples/output_fields_examples/gravity_default.yml delete mode 100644 examples/output_fields_examples/hydro_default.yml delete mode 100644 examples/output_fields_examples/hydro_gadget2.yml delete mode 100644 examples/output_fields_examples/hydro_gizmo.yml delete mode 100644 examples/output_fields_examples/hydro_minimal.yml delete mode 100644 examples/output_fields_examples/hydro_pressureentropy.yml delete mode 100644 examples/output_fields_examples/hydro_shadowswift.yml delete mode 100644 examples/output_fields_examples/stars_default.yml diff --git a/examples/create_ouput_fields.py b/examples/create_ouput_fields.py deleted file mode 100644 index 86ca8a585..000000000 --- a/examples/create_ouput_fields.py +++ /dev/null @@ -1,291 +0,0 @@ -#!/usr/bin/env python3 - -from optparse import OptionParser -from regex import search -from os import path, remove - -# fields to do -todo = [ - "chemistry", "cooling", - "gravity", "stars", - "hydro"] - -# number of particle type -N_type = 6 - - -def parseOptions(): - """ - Parse options. - - Returns - ------- - - opt: - Option structure - - args: - Arguments - """ - usage = """usage: %prog [options] args1 - If options are not provided, this script will read the config.h file \ -provided (args1) and use theses values. - """ - - parser = OptionParser(usage=usage) - - parser.add_option("--with-cooling", - dest="cooling", - help="Cooling Type", - default="", - type=str, - metavar="STR") - - parser.add_option("--with-chemistry", - dest="chemistry", - help="Chemistry Type", - default="", - type=str, - metavar="STR") - - parser.add_option("--with-hydro", - dest="hydro", - help="Hydro Type", - default="", - type=str, - metavar="STR") - - parser.add_option("--with-stars", - dest="stars", - help="Stars Type", - default="default", - type=str, - metavar="STR") - - parser.add_option("--with-gravity", - dest="gravity", - help="Gravity Type", - default="default", - type=str, - metavar="STR") - - parser.add_option("-o", "--output", - dest="o", - help="Output filename", - type=str, - default=None, - metavar="STR") - - parser.add_option("-d", "--example_directory", - dest="d", - help="Directory containing the examples", - type=str, - default=None, - metavar="STR") - - return parser.parse_args() - - -def readConfig(filename): - """ - Read the config.h file and parse it to keep - only the definitions. - - Parameters - ---------- - - filename: str - Filename to parse - - Returns - ------- - - options: list - List of options - """ - expression = "#define (.*) 1" - options = [] - with open(filename, "r") as f: - for line in f: - tmp = search(expression, line) - if tmp is not None: - options.append(tmp.group(1)) - - return options - - -def getConfig(opt, swift_options, current): - """ - Parse the config.h options and extract the required - parameter. If not able to find an option, return False - - Parameters - ---------- - - opt: - Option structure - - swift_options: list - Option in config.h - - current: str - Current option - - Returns - ------- - - option: str - name of the option (in lower case) - """ - # if given in options, returns - if getattr(opt, current) != "": - return getattr(opt, current) - - # get current option - caps = current.upper() - expression = "%s_(.*)" % caps - if current == "hydro": - expression = "(.*)_SPH" - for i in swift_options: - tmp = search(expression, i) - if tmp is not None: - return tmp.group(1).lower() - return False - - -def readYamlFile(filename): - """ - Read quickly a yaml file. - - Parameters - ---------- - - filename: str - file to read - - Returns - ------- - - d: dict - key -> section name, value -> list of parameters - """ - d = {} - key = None - section = "(PartType\d+):" - with open(filename, "r") as f: - for line in f: - # check for section - tmp = search(section, line) - if tmp is not None: - key = tmp.group(1) - d[key] = [] - continue - - # skip if not a parameter or outside - # a section - if ":" not in line or key is None: - continue - - # ensure end of line - if "\n" not in line: - line += "\n" - - # write line - d[key].append(line) - - return d - - -def generateFile(opt): - """ - Generate an output fields file from examples. - - Parameters - ---------- - - opt: - Option structure - - Returns - ------- - - d: dict - key -> section name, value -> list of parameters - """ - d = {} - # read all files - for current in todo: - filename = current + "_" + getattr(opt, current) + ".yml" - filename = opt.d + "/" + filename - data = readYamlFile(filename) - - for tpe in range(N_type): - name = "PartType%i" % tpe - if name not in data: - continue - - if name not in d: - d[name] = data[name] - - else: - d[name].extend(data[name]) - return d - - -def writeOutputFields(d, opt): - """ - Write the output. - - Parameters - ---------- - - d: dict - key -> section name, value -> list of parameters - - opt: - Option structure - - """ - with open(opt.o, "w") as f: - for tpe in range(N_type): - name = "PartType%i" % tpe - if name not in d: - continue - f.write("%s:\n" % name) - for i in d[name]: - f.write(i) - - f.write("\n") - - -if __name__ == "__main__": - # parse option - opt, args = parseOptions() - - # check inputs - # arguments - if len(args) != 1: - raise IOError("A file should be provided") - filename = args[0] - - # output file - if opt.o is None: - raise IOError("The output option '-o' is required") - - # example directory - if opt.d is None: - raise IOError("The example directory option '-d' is required") - - # read configuration file - swift_options = readConfig(filename) - - # get correct configuration - for current in todo: - tmp = getConfig(opt, swift_options, current) - if tmp is False: - raise IOError("Unable to get field %s" % current) - setattr(opt, current, tmp) - - # generate and write output_fields file - d = generateFile(opt) - writeOutputFields(d, opt) diff --git a/examples/output_fields_examples/chemistry_eagle.yml b/examples/output_fields_examples/chemistry_eagle.yml deleted file mode 100644 index d62c2b32d..000000000 --- a/examples/output_fields_examples/chemistry_eagle.yml +++ /dev/null @@ -1,14 +0,0 @@ -# gas -PartType0: - ElementAbundance: 1 - SmoothedElementAbundance: 1 - Metallicity: 1 - SmoothedMetallicity: 1 - TotalMassFromSNIa: 1 - MetalMassFracFromSNIa: 1 - TotalMassFromAGB: 1 - MetalMassFracFromAGB: 1 - TotalMassFromSNII: 1 - MetalMassFracFromSNII: 1 - IronMassFracFromSNIa: 1 - SmoothedIronMassFracFromSNIa: 1 \ No newline at end of file diff --git a/examples/output_fields_examples/chemistry_gear.yml b/examples/output_fields_examples/chemistry_gear.yml deleted file mode 100644 index a64dbfb01..000000000 --- a/examples/output_fields_examples/chemistry_gear.yml +++ /dev/null @@ -1,4 +0,0 @@ -# gas -PartType0: - SmoothedElementAbundance: 1 - ElementAbundance: 1 \ No newline at end of file diff --git a/examples/output_fields_examples/chemistry_none.yml b/examples/output_fields_examples/chemistry_none.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/output_fields_examples/cooling_const_du.yml b/examples/output_fields_examples/cooling_const_du.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/output_fields_examples/cooling_eagle.yml b/examples/output_fields_examples/cooling_eagle.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/output_fields_examples/cooling_grackle.yml b/examples/output_fields_examples/cooling_grackle.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/output_fields_examples/cooling_lambda.yml b/examples/output_fields_examples/cooling_lambda.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/output_fields_examples/cooling_none.yml b/examples/output_fields_examples/cooling_none.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/output_fields_examples/gravity_default.yml b/examples/output_fields_examples/gravity_default.yml deleted file mode 100644 index 26e54f1fa..000000000 --- a/examples/output_fields_examples/gravity_default.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Dark Matter -PartType1: - Coordinates: 1 - Velocities: 1 - Masses: 1 - ParticleIDs: 1 - Potential: 1 diff --git a/examples/output_fields_examples/hydro_default.yml b/examples/output_fields_examples/hydro_default.yml deleted file mode 100644 index 350979d7a..000000000 --- a/examples/output_fields_examples/hydro_default.yml +++ /dev/null @@ -1,10 +0,0 @@ -# Gas -PartType0: - Coordinates: 1 - Masses: 1 - Velocities: 1 - SmoothingLength: 1 - ParticleIDs: 1 - Density: 1 - InternalEnergy: 1 - Potential: 1 diff --git a/examples/output_fields_examples/hydro_gadget2.yml b/examples/output_fields_examples/hydro_gadget2.yml deleted file mode 100644 index 9cfcf123d..000000000 --- a/examples/output_fields_examples/hydro_gadget2.yml +++ /dev/null @@ -1,17 +0,0 @@ -# Gas -PartType0: - Coordinates: 1 - Masses: 1 - Velocities: 1 - SmoothingLength: 1 - Entropy: 1 - ParticleIDs: 1 - Density: 1 - InternalEnergy: 1 - Pressure: 1 - Potential: 1 - # debug fields - # Num_ngb_density: 0 - # Num_ngb_force: 0 - # Ids_ngb_density: 0 - # Ids_ngb_force \ No newline at end of file diff --git a/examples/output_fields_examples/hydro_gizmo.yml b/examples/output_fields_examples/hydro_gizmo.yml deleted file mode 100644 index 17f4231d6..000000000 --- a/examples/output_fields_examples/hydro_gizmo.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Gas -PartType0: - Coordinates: 1 - Masses: 1 - Velocities: 1 - SmoothingLength: 1 - Entropy: 1 - ParticleIDs: 1 - Density: 1 - InternalEnergy: 1 - Pressure: 1 - TotEnergy: 1 - Potential: 1 diff --git a/examples/output_fields_examples/hydro_minimal.yml b/examples/output_fields_examples/hydro_minimal.yml deleted file mode 100644 index bbc1ae937..000000000 --- a/examples/output_fields_examples/hydro_minimal.yml +++ /dev/null @@ -1,12 +0,0 @@ -# Gas -PartType0: - Coordinates: 1 - Masses: 1 - Velocities: 1 - SmoothingLength: 1 - Entropy: 1 - ParticleIDs: 1 - Density: 1 - InternalEnergy: 1 - Pressure: 1 - Potential: 1 diff --git a/examples/output_fields_examples/hydro_pressureentropy.yml b/examples/output_fields_examples/hydro_pressureentropy.yml deleted file mode 100644 index b4ea000c1..000000000 --- a/examples/output_fields_examples/hydro_pressureentropy.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Gas -PartType0: - Coordinates: 1 - Masses: 1 - Velocities: 1 - SmoothingLength: 1 - Entropy: 1 - ParticleIDs: 1 - Density: 1 - InternalEnergy: 1 - Pressure: 1 - Potential: 1 - WeightedDensity: 1 \ No newline at end of file diff --git a/examples/output_fields_examples/hydro_shadowswift.yml b/examples/output_fields_examples/hydro_shadowswift.yml deleted file mode 100644 index edd62d19a..000000000 --- a/examples/output_fields_examples/hydro_shadowswift.yml +++ /dev/null @@ -1,16 +0,0 @@ -# Gas -PartType0: - Coordinates: 1 - Masses: 1 - Velocities: 1 - SmoothingLength: 1 - Entropy: 1 - ParticleIDs: 1 - Density: 1 - InternalEnergy: 1 - Pressure: 1 - Potential: 1 - Acceleration: 1 - Volume: 1 - GradDensity: 1 - TotEnergy: 1 \ No newline at end of file diff --git a/examples/output_fields_examples/stars_default.yml b/examples/output_fields_examples/stars_default.yml deleted file mode 100644 index bc447626d..000000000 --- a/examples/output_fields_examples/stars_default.yml +++ /dev/null @@ -1,6 +0,0 @@ -# Stars -PartType2: - Coordinates: 1 - Velocities: 1 - Masses: 1 - ParticleIDs: 1 \ No newline at end of file -- GitLab From 2bb5e6b9b13cb45adcaa216ed32cdb44022b8d06 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 3 May 2018 16:34:37 +0200 Subject: [PATCH 21/39] Move output_fields.yml inside params --- examples/main.c | 28 +--------------------------- examples/parameter_example.yml | 1 - src/common_io.c | 25 ++++++++++--------------- src/common_io.h | 2 +- src/engine.c | 1 - src/engine.h | 3 --- src/parallel_io.c | 6 +++--- src/serial_io.c | 6 +++--- src/single_io.c | 6 +++--- 9 files changed, 21 insertions(+), 57 deletions(-) diff --git a/examples/main.c b/examples/main.c index 1b211ad94..f7f948677 100644 --- a/examples/main.c +++ b/examples/main.c @@ -478,30 +478,6 @@ int main(int argc, char *argv[]) { MPI_Bcast(params, sizeof(struct swift_params), MPI_BYTE, 0, MPI_COMM_WORLD); #endif - /* Read output fields */ - struct swift_params *output_fields = - (struct swift_params *)malloc(sizeof(struct swift_params)); - if (output_fields == NULL) - error("Error allocating memory for the output fields file."); - - char outputFieldsFileName[200]; - parser_get_opt_param_string(params, "Snapshots:FieldsFilename", - outputFieldsFileName, ""); - - parser_init(outputFieldsFileName, output_fields); - if (myrank == 0 && strcmp(outputFieldsFileName, "") != 0) { - message("Reading runtime output fields from file '%s'", - outputFieldsFileName); - parser_read_file(outputFieldsFileName, output_fields); - - /* And dump the parameters as used. */ - parser_write_params_to_file(output_fields, "used_output_fields.yml"); - } -#ifdef WITH_MPI - /* Broadcast the parameter file */ - MPI_Bcast(output_fields, sizeof(struct swift_params), MPI_BYTE, 0, - MPI_COMM_WORLD); -#endif /* Check that we can write the snapshots by testing if the output * directory exists and is searchable and writable. */ char basename[PARSER_MAX_LINE_SIZE]; @@ -858,7 +834,7 @@ int main(int argc, char *argv[]) { talking, restart_file); /* check output field */ - io_check_output_fields(output_fields, &e); + io_check_output_fields(params, &e); if (myrank == 0) { clocks_gettime(&toc); @@ -894,7 +870,6 @@ int main(int argc, char *argv[]) { message("Time integration ready to start. End of dry-run."); engine_clean(&e); free(params); - free(output_fields); return 0; } @@ -1117,7 +1092,6 @@ int main(int argc, char *argv[]) { if (with_verbose_timers) timers_close_file(); if (with_cosmology) cosmology_clean(&cosmo); engine_clean(&e); - free(output_fields); free(params); /* Say goodbye. */ diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index 75df3f7e8..791db2758 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -78,7 +78,6 @@ Snapshots: UnitVelocity_in_cgs: 1 # (Optional) Unit system for the outputs (Centimeters per second) UnitCurrent_in_cgs: 1 # (Optional) Unit system for the outputs (Amperes) UnitTemp_in_cgs: 1 # (Optional) Unit system for the outputs (Kelvin) - FieldsFilename: output_fields_example.yml # (Optional) File defining output fields # Parameters governing the conserved quantities statistics Statistics: diff --git a/src/common_io.c b/src/common_io.c index 399459f71..75799d8be 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -813,15 +813,12 @@ void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot, /** * @brief Verify the io parameter file * - * @param output_fields The #swift_params containing output information + * @param params The #swift_params * @param e The #engine */ -void io_check_output_fields(const struct swift_params* output_fields, +void io_check_output_fields(const struct swift_params* params, const struct engine* e) { - if (output_fields->paramCount == 0) - return; - /* particles */ const struct part* parts = e->s->parts; const struct xpart* xparts = e->s->xparts; @@ -866,12 +863,12 @@ void io_check_output_fields(const struct swift_params* output_fields, error("Particle Type %d not yet supported. Aborting", ptype); } /* loop over each parameter */ - for (int param_id = 0; param_id < output_fields->paramCount; param_id++) { - const char* param_name = output_fields->data[param_id].name; + for (int param_id = 0; param_id < params->paramCount; param_id++) { + const char* param_name = params->data[param_id].name; /* skip if wrong part type */ char section_name[200]; - sprintf(section_name, "PartType%i", ptype); + sprintf(section_name, "SelectOutput:"); if (strstr(param_name, section_name) == NULL) continue; int found = 0; @@ -879,15 +876,15 @@ void io_check_output_fields(const struct swift_params* output_fields, /* loop over each possible output field */ for (int field_id = 0; field_id < num_fields; field_id++) { char field_name[256]; - sprintf(field_name, "PartType%i:%s", ptype, list[field_id].name); + sprintf(field_name, "SelectOutput:PartType%i_%s", ptype, list[field_id].name); if (strcmp(param_name, field_name) == 0) { found = 1; continue; } } if (!found) - error("Unable to find field corresponding to %s in %s", - param_name, output_fields->fileName); + message("WARNING: Unable to find field corresponding to %s in %s", + param_name, params->fileName); } } } @@ -902,6 +899,7 @@ void io_write_output_field_parameter(const char* filename) { FILE *file = fopen(filename, "w"); /* Loop over all particle types */ + fprintf(file, "SelectOutput:\n"); for (int ptype = 0; ptype < swift_type_count; ptype++) { int num_fields = 0; struct io_props list[100]; @@ -924,12 +922,9 @@ void io_write_output_field_parameter(const char* filename) { } - if (num_fields > 0) - fprintf(file, "ParticleType%i:\n", ptype); - /* Write everything */ for (int i = 0; i < num_fields; ++i) { - fprintf(file, " %s: 1\n", list[i].name); + fprintf(file, " ParticleType%i_%s: 1\n", ptype, list[i].name); } fprintf(file, "\n"); diff --git a/src/common_io.h b/src/common_io.h index c4bf2c724..47eb17a5f 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -100,7 +100,7 @@ void io_duplicate_star_gparts(struct threadpool* tp, struct spart* const sparts, struct gpart* const gparts, size_t Nstars, size_t Ndm); -void io_check_output_fields(const struct swift_params* output_fields, +void io_check_output_fields(const struct swift_params* params, const struct engine* e); void io_write_output_field_parameter(const char* filename); diff --git a/src/engine.c b/src/engine.c index f62866456..9a7a7ede8 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5484,7 +5484,6 @@ void engine_init(struct engine *e, struct space *s, e->chemistry = chemistry; e->sourceterms = sourceterms; e->parameter_file = params; - e->output_fields = output_fields; #ifdef WITH_MPI e->cputime_last_step = 0; e->last_repartition = 0; diff --git a/src/engine.h b/src/engine.h index e04a80e99..72f440b2e 100644 --- a/src/engine.h +++ b/src/engine.h @@ -312,9 +312,6 @@ struct engine { /* The (parsed) parameter file */ const struct swift_params *parameter_file; - /* The (parsed) output fields */ - const struct swift_params *output_fields; - /* Temporary struct to hold a group of deferable properties (in MPI mode * these are reduced together, but may not be required just yet). */ struct collectgroup1 collect_group1; diff --git a/src/parallel_io.c b/src/parallel_io.c index 06bf551e9..6cbbcbe80 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1072,7 +1072,7 @@ void write_output_parallel(struct engine* e, const char* baseName, struct gpart* dmparts = NULL; const struct spart* sparts = e->s->sparts; const struct cooling_function_data* cooling = e->cooling_func; - const struct swift_params* output_fields = e->output_fields; + const struct swift_params* params = e->parameter_file; /* Number of unassociated gparts */ const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0; @@ -1265,8 +1265,8 @@ void write_output_parallel(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { char field[256]; - sprintf(field, "ParticleType%i:%s", ptype, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, 1); + sprintf(field, "SelectOutput:ParticleType%i_%s", ptype, list[i].name); + int should_write = parser_get_opt_param_int(params, field, 1); if (should_write) writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], internal_units, diff --git a/src/serial_io.c b/src/serial_io.c index 04a4e7b95..449154136 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -727,7 +727,7 @@ void write_output_serial(struct engine* e, const char* baseName, struct gpart* dmparts = NULL; const struct spart* sparts = e->s->sparts; const struct cooling_function_data* cooling = e->cooling_func; - const struct swift_params* output_fields = e->output_fields; + const struct swift_params* params = e->parameter_file; FILE* xmfFile = 0; /* Number of unassociated gparts */ @@ -1009,8 +1009,8 @@ void write_output_serial(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { char field[256]; - sprintf(field, "ParticleType%i:%s", ptype, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, 1); + sprintf(field, "SelectOutput:ParticleType%i_%s", ptype, list[i].name); + int should_write = parser_get_opt_param_int(params, field, 1); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], diff --git a/src/single_io.c b/src/single_io.c index 4fa18a46a..ed1fd21b6 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -594,7 +594,7 @@ void write_output_single(struct engine* e, const char* baseName, struct gpart* dmparts = NULL; const struct spart* sparts = e->s->sparts; const struct cooling_function_data* cooling = e->cooling_func; - const struct swift_params* output_fields = e->output_fields; + const struct swift_params* params = e->parameter_file; /* Number of unassociated gparts */ const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0; @@ -828,8 +828,8 @@ void write_output_single(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { char field[256]; - sprintf(field, "ParticleType%i:%s", ptype, list[i].name); - int should_write = parser_get_opt_param_int(output_fields, field, 1); + sprintf(field, "SelectOutput:ParticleType%i_%s", ptype, list[i].name); + int should_write = parser_get_opt_param_int(params, field, 1); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, internal_units, snapshot_units); -- GitLab From c3d002c7ba28470bac29c3f2d2626df268b7270e Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 3 May 2018 16:53:47 +0200 Subject: [PATCH 22/39] Update section name for select output --- src/common_io.c | 14 +++++++++++--- src/parallel_io.c | 2 +- src/serial_io.c | 2 +- src/single_io.c | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/common_io.c b/src/common_io.c index 75799d8be..a059de9a7 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -866,17 +866,21 @@ void io_check_output_fields(const struct swift_params* params, for (int param_id = 0; param_id < params->paramCount; param_id++) { const char* param_name = params->data[param_id].name; - /* skip if wrong part type */ char section_name[200]; + /* skip if wrong section */ sprintf(section_name, "SelectOutput:"); if (strstr(param_name, section_name) == NULL) continue; + /* skip if wrong particle type */ + sprintf(section_name, "_%i", ptype); + if (strstr(param_name, section_name) == NULL) continue; + int found = 0; /* loop over each possible output field */ for (int field_id = 0; field_id < num_fields; field_id++) { char field_name[256]; - sprintf(field_name, "SelectOutput:PartType%i_%s", ptype, list[field_id].name); + sprintf(field_name, "SelectOutput:%s_%i", list[field_id].name, ptype); if (strcmp(param_name, field_name) == 0) { found = 1; continue; @@ -922,9 +926,13 @@ void io_write_output_field_parameter(const char* filename) { } + if (num_fields == 0) + continue; + + fprintf(file, " # Particle Type %i\n", ptype); /* Write everything */ for (int i = 0; i < num_fields; ++i) { - fprintf(file, " ParticleType%i_%s: 1\n", ptype, list[i].name); + fprintf(file, " %s_%i: 1\n", list[i].name, ptype); } fprintf(file, "\n"); diff --git a/src/parallel_io.c b/src/parallel_io.c index 6cbbcbe80..950f0ef4f 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1265,7 +1265,7 @@ void write_output_parallel(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { char field[256]; - sprintf(field, "SelectOutput:ParticleType%i_%s", ptype, list[i].name); + sprintf(field, "SelectOutput:%s_%i", list[i].name, ptype); int should_write = parser_get_opt_param_int(params, field, 1); if (should_write) writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, diff --git a/src/serial_io.c b/src/serial_io.c index 449154136..dfee945a7 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1009,7 +1009,7 @@ void write_output_serial(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { char field[256]; - sprintf(field, "SelectOutput:ParticleType%i_%s", ptype, list[i].name); + sprintf(field, "SelectOutput:%s_%i", list[i].name, ptype); int should_write = parser_get_opt_param_int(params, field, 1); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], diff --git a/src/single_io.c b/src/single_io.c index ed1fd21b6..d3db4d3fc 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -828,7 +828,7 @@ void write_output_single(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { char field[256]; - sprintf(field, "SelectOutput:ParticleType%i_%s", ptype, list[i].name); + sprintf(field, "SelectOutput:%s_%i", list[i].name, ptype); int should_write = parser_get_opt_param_int(params, field, 1); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, -- GitLab From c7b6060ded76348e8ffeead949bdfbec0f2904f5 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 3 May 2018 16:56:03 +0200 Subject: [PATCH 23/39] Format --- examples/main.c | 18 +++++++++--------- src/common_io.c | 32 +++++++++++++++----------------- src/serial_io.c | 6 +++--- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/examples/main.c b/examples/main.c index f7f948677..ec42f5143 100644 --- a/examples/main.c +++ b/examples/main.c @@ -91,7 +91,7 @@ void print_help_message(void) { "Execute a fixed number of time steps. When unset use the time_end " "parameter to stop."); printf(" %2s %14s %s\n", "-o", "{str}", - "Generate a default output parameter file."); + "Generate a default output parameter file."); printf(" %2s %14s %s\n", "-P", "{sec:par:val}", "Set parameter value and overwrites values read from the parameters " "file. Can be used more than once."); @@ -263,14 +263,14 @@ int main(int argc, char *argv[]) { } break; case 'o': - if (sscanf(optarg, "%s", output_parameters_filename) != 1) { - if (myrank == 0) { - printf("Error parsing output fields filename"); - print_help_message(); - } - return 1; - } - break; + if (sscanf(optarg, "%s", output_parameters_filename) != 1) { + if (myrank == 0) { + printf("Error parsing output fields filename"); + print_help_message(); + } + return 1; + } + break; case 'P': cmdparams[nparams] = optarg; nparams++; diff --git a/src/common_io.c b/src/common_io.c index a059de9a7..bb4c3eb95 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -887,8 +887,8 @@ void io_check_output_fields(const struct swift_params* params, } } if (!found) - message("WARNING: Unable to find field corresponding to %s in %s", - param_name, params->fileName); + message("WARNING: Unable to find field corresponding to %s in %s", + param_name, params->fileName); } } } @@ -900,7 +900,7 @@ void io_check_output_fields(const struct swift_params* params, * @param filename The file to write */ void io_write_output_field_parameter(const char* filename) { - FILE *file = fopen(filename, "w"); + FILE* file = fopen(filename, "w"); /* Loop over all particle types */ fprintf(file, "SelectOutput:\n"); @@ -911,30 +911,28 @@ void io_write_output_field_parameter(const char* filename) { /* Write particle fields from the particle structure */ switch (ptype) { - case swift_type_gas: - hydro_write_particles(NULL, NULL, list, &num_fields); - num_fields += chemistry_write_particles(NULL, list + num_fields); - break; + case swift_type_gas: + hydro_write_particles(NULL, NULL, list, &num_fields); + num_fields += chemistry_write_particles(NULL, list + num_fields); + break; - case swift_type_dark_matter: - darkmatter_write_particles(NULL, list, &num_fields); - break; + case swift_type_dark_matter: + darkmatter_write_particles(NULL, list, &num_fields); + break; - case swift_type_star: - star_write_particles(NULL, list, &num_fields); - break; - + case swift_type_star: + star_write_particles(NULL, list, &num_fields); + break; } - if (num_fields == 0) - continue; + if (num_fields == 0) continue; fprintf(file, " # Particle Type %i\n", ptype); /* Write everything */ for (int i = 0; i < num_fields; ++i) { fprintf(file, " %s_%i: 1\n", list[i].name, ptype); } - + fprintf(file, "\n"); } diff --git a/src/serial_io.c b/src/serial_io.c index dfee945a7..5cae5ec4a 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1008,9 +1008,9 @@ void write_output_serial(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[256]; - sprintf(field, "SelectOutput:%s_%i", list[i].name, ptype); - int should_write = parser_get_opt_param_int(params, field, 1); + char field[256]; + sprintf(field, "SelectOutput:%s_%i", list[i].name, ptype); + int should_write = parser_get_opt_param_int(params, field, 1); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], -- GitLab From e57578894bf979419858a1d4fffab97421d268cb Mon Sep 17 00:00:00 2001 From: lhausamm Date: Mon, 28 May 2018 16:08:31 +0200 Subject: [PATCH 24/39] Update select output --- examples/SedovBlast_3D/sedov.yml | 2 +- examples/main.c | 3 ++- src/common_io.c | 37 +++++++++++++++++++------------- src/common_io.h | 3 ++- src/parallel_io.c | 5 +++-- src/serial_io.c | 5 +++-- src/single_io.c | 5 +++-- 7 files changed, 36 insertions(+), 24 deletions(-) diff --git a/examples/SedovBlast_3D/sedov.yml b/examples/SedovBlast_3D/sedov.yml index c7212983f..6b64d707a 100644 --- a/examples/SedovBlast_3D/sedov.yml +++ b/examples/SedovBlast_3D/sedov.yml @@ -33,4 +33,4 @@ SPH: InitialConditions: file_name: ./sedov.hdf5 smoothing_length_scaling: 3.33 - + \ No newline at end of file diff --git a/examples/main.c b/examples/main.c index ec42f5143..ab8fca819 100644 --- a/examples/main.c +++ b/examples/main.c @@ -834,7 +834,8 @@ int main(int argc, char *argv[]) { talking, restart_file); /* check output field */ - io_check_output_fields(params, &e); + if (myrank == 0) + io_check_output_fields(params, &e, N_total); if (myrank == 0) { clocks_gettime(&toc); diff --git a/src/common_io.c b/src/common_io.c index bb4c3eb95..faa41976f 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -34,6 +34,7 @@ #include "io_properties.h" #include "kernel_hydro.h" #include "part.h" +#include "part_type.h" #include "stars_io.h" #include "threadpool.h" #include "units.h" @@ -817,7 +818,8 @@ void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot, * @param e The #engine */ void io_check_output_fields(const struct swift_params* params, - const struct engine* e) { + const struct engine* e, + const long long *N_total) { /* particles */ const struct part* parts = e->s->parts; @@ -825,15 +827,9 @@ void io_check_output_fields(const struct swift_params* params, const struct gpart* gparts = e->s->gparts; const struct spart* sparts = e->s->sparts; - /* number of particles */ - const size_t Ngas = e->s->nr_parts; - const size_t Nstars = e->s->nr_sparts; - const size_t Ntot = e->s->nr_gparts; - - const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0; - - long long N_total[swift_type_count] = { - (long long)Ngas, (long long)Ndm, 0, 0, (long long)Nstars, 0}; + /* copy N_total to array with length == 6 */ + const long long nr_total[swift_type_count] = { + N_total[0], N_total[1], N_total[2], 0, 0, 0}; /* get all the possible outputs */ for (int ptype = 0; ptype < swift_type_count; ptype++) { @@ -841,7 +837,7 @@ void io_check_output_fields(const struct swift_params* params, struct io_props list[100]; /* Don't do anything if no particle of this kind */ - if (N_total[ptype] == 0) continue; + if (nr_total[ptype] == 0) continue; /* Write particle fields from the particle structure */ switch (ptype) { @@ -866,7 +862,7 @@ void io_check_output_fields(const struct swift_params* params, for (int param_id = 0; param_id < params->paramCount; param_id++) { const char* param_name = params->data[param_id].name; - char section_name[200]; + char section_name[PARSER_MAX_LINE_SIZE]; /* skip if wrong section */ sprintf(section_name, "SelectOutput:"); if (strstr(param_name, section_name) == NULL) continue; @@ -879,10 +875,20 @@ void io_check_output_fields(const struct swift_params* params, /* loop over each possible output field */ for (int field_id = 0; field_id < num_fields; field_id++) { - char field_name[256]; - sprintf(field_name, "SelectOutput:%s_%i", list[field_id].name, ptype); + char field_name[PARSER_MAX_LINE_SIZE]; + sprintf(field_name, "SelectOutput:%s_%s", + list[field_id].name, part_type_names[ptype]); + if (strcmp(param_name, field_name) == 0) { found = 1; + /* check if correct input */ + int retParam = 0; + char str[PARSER_MAX_LINE_SIZE]; + sscanf(params->data[field_id].value, "%d%s", &retParam, str); + + if (retParam != 0 && retParam != 1) + message("WARNING: Unexpected input for %s." + "Received %i but expect 0 or 1", field_name, retParam); continue; } } @@ -930,7 +936,8 @@ void io_write_output_field_parameter(const char* filename) { fprintf(file, " # Particle Type %i\n", ptype); /* Write everything */ for (int i = 0; i < num_fields; ++i) { - fprintf(file, " %s_%i: 1\n", list[i].name, ptype); + fprintf(file, " %s_%s: 1\n", + list[i].name, part_type_names[ptype]); } fprintf(file, "\n"); diff --git a/src/common_io.h b/src/common_io.h index 47eb17a5f..706387582 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -101,7 +101,8 @@ void io_duplicate_star_gparts(struct threadpool* tp, struct spart* const sparts, size_t Ndm); void io_check_output_fields(const struct swift_params* params, - const struct engine* e); + const struct engine* e, + const long long *N_total); void io_write_output_field_parameter(const char* filename); diff --git a/src/parallel_io.c b/src/parallel_io.c index 950f0ef4f..76278ac93 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -49,6 +49,7 @@ #include "io_properties.h" #include "kernel_hydro.h" #include "part.h" +#include "part_type.h" #include "stars_io.h" #include "units.h" #include "xmf.h" @@ -1264,8 +1265,8 @@ void write_output_parallel(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[256]; - sprintf(field, "SelectOutput:%s_%i", list[i].name, ptype); + char field[PARSER_MAX_LINE_SIZE]; + sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); if (should_write) writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, diff --git a/src/serial_io.c b/src/serial_io.c index 5cae5ec4a..d9d7f2cb8 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -49,6 +49,7 @@ #include "io_properties.h" #include "kernel_hydro.h" #include "part.h" +#include "part_type.h" #include "stars_io.h" #include "units.h" #include "xmf.h" @@ -1008,8 +1009,8 @@ void write_output_serial(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[256]; - sprintf(field, "SelectOutput:%s_%i", list[i].name, ptype); + char field[PARSER_MAX_LINE_SIZE]; + sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], diff --git a/src/single_io.c b/src/single_io.c index d3db4d3fc..244a8c65f 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -48,6 +48,7 @@ #include "io_properties.h" #include "kernel_hydro.h" #include "part.h" +#include "part_type.h" #include "stars_io.h" #include "units.h" #include "xmf.h" @@ -827,8 +828,8 @@ void write_output_single(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { - char field[256]; - sprintf(field, "SelectOutput:%s_%i", list[i].name, ptype); + char field[PARSER_MAX_LINE_SIZE]; + sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, -- GitLab From bf79259f17dec360e82f750fb75b27e2f30ca316 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Tue, 29 May 2018 09:08:13 +0200 Subject: [PATCH 25/39] Update part_id to part_name in select output --- src/common_io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common_io.c b/src/common_io.c index faa41976f..1f28098f6 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -868,7 +868,7 @@ void io_check_output_fields(const struct swift_params* params, if (strstr(param_name, section_name) == NULL) continue; /* skip if wrong particle type */ - sprintf(section_name, "_%i", ptype); + sprintf(section_name, "_%s", part_type_names[ptype]); if (strstr(param_name, section_name) == NULL) continue; int found = 0; @@ -884,10 +884,10 @@ void io_check_output_fields(const struct swift_params* params, /* check if correct input */ int retParam = 0; char str[PARSER_MAX_LINE_SIZE]; - sscanf(params->data[field_id].value, "%d%s", &retParam, str); + sscanf(params->data[param_id].value, "%d%s", &retParam, str); if (retParam != 0 && retParam != 1) - message("WARNING: Unexpected input for %s." + message("WARNING: Unexpected input for %s. " "Received %i but expect 0 or 1", field_name, retParam); continue; } -- GitLab From 5699230bdd7b51c3fa7ee8f62981da49bbab88b3 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Wed, 30 May 2018 11:00:12 +0200 Subject: [PATCH 26/39] fix gcc 8.1.0 warnings --- src/version.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/version.c b/src/version.c index 54749721d..9bae3515a 100644 --- a/src/version.c +++ b/src/version.c @@ -146,7 +146,7 @@ const char *configuration_options(void) { static int initialised = 0; static const char *config = SWIFT_CONFIG_FLAGS; if (!initialised) { - snprintf(buf, 1024, "'%s'", config); + snprintf(buf, 1024, "'%.1022s'", config); initialised = 1; } return buf; @@ -162,7 +162,7 @@ const char *compilation_cflags(void) { static int initialised = 0; static const char *cflags = SWIFT_CFLAGS; if (!initialised) { - snprintf(buf, 1024, "'%s'", cflags); + snprintf(buf, 1024, "'%.1022s'", cflags); initialised = 1; } return buf; @@ -272,12 +272,12 @@ const char *mpi_version(void) { #else /* Use autoconf guessed value. */ static char lib_version[60] = {0}; - snprintf(lib_version, 60, "%s", SWIFT_MPI_LIBRARY); + snprintf(lib_version, 60, "%.60s", SWIFT_MPI_LIBRARY); #endif /* Numeric version. */ MPI_Get_version(&std_version, &std_subversion); - snprintf(version, 80, "%s (MPI std v%i.%i)", lib_version, std_version, + snprintf(version, 80, "%.60s (MPI std v%i.%i)", lib_version, std_version, std_subversion); #else sprintf(version, "Code was not compiled with MPI support"); @@ -345,7 +345,7 @@ const char *libgsl_version(void) { static char version[256] = {0}; #if defined(HAVE_LIBGSL) - sprintf(version, "%s", gsl_version); + sprintf(version, "%.255s", gsl_version); #else sprintf(version, "Unknown version"); #endif -- GitLab From 87b9cd172f4c8b3908140178c7b0a6e6166b52ec Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 31 May 2018 07:41:42 +0200 Subject: [PATCH 27/39] Write field for any bad input --- src/common_io.c | 5 +++-- src/parallel_io.c | 2 +- src/serial_io.c | 2 +- src/single_io.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common_io.c b/src/common_io.c index 1f28098f6..34207113d 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -888,7 +888,8 @@ void io_check_output_fields(const struct swift_params* params, if (retParam != 0 && retParam != 1) message("WARNING: Unexpected input for %s. " - "Received %i but expect 0 or 1", field_name, retParam); + "Received %i but expect 0 or 1. " + "We will write this field.", field_name, retParam); continue; } } @@ -933,7 +934,7 @@ void io_write_output_field_parameter(const char* filename) { if (num_fields == 0) continue; - fprintf(file, " # Particle Type %i\n", ptype); + fprintf(file, " # Particle Type %s\n", part_type_names[ptype]); /* Write everything */ for (int i = 0; i < num_fields; ++i) { fprintf(file, " %s_%s: 1\n", diff --git a/src/parallel_io.c b/src/parallel_io.c index 76278ac93..a87c8e9fa 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1268,7 +1268,7 @@ void write_output_parallel(struct engine* e, const char* baseName, char field[PARSER_MAX_LINE_SIZE]; sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); - if (should_write) + if (should_write != 0) writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], internal_units, snapshot_units); diff --git a/src/serial_io.c b/src/serial_io.c index d9d7f2cb8..9c0a3c1fb 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1012,7 +1012,7 @@ void write_output_serial(struct engine* e, const char* baseName, char field[PARSER_MAX_LINE_SIZE]; sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); - if (should_write) + if (should_write != 0) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], internal_units, snapshot_units); diff --git a/src/single_io.c b/src/single_io.c index 244a8c65f..3a89d7a02 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -831,7 +831,7 @@ void write_output_single(struct engine* e, const char* baseName, char field[PARSER_MAX_LINE_SIZE]; sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); - if (should_write) + if (should_write != 0) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, internal_units, snapshot_units); } -- GitLab From c71519e49b7ceb907e23c153963ae139db50e719 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 31 May 2018 07:42:46 +0200 Subject: [PATCH 28/39] Add missing include --- src/swift.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/swift.h b/src/swift.h index 10cc8495f..17f7c5c7e 100644 --- a/src/swift.h +++ b/src/swift.h @@ -32,6 +32,7 @@ #include "common_io.h" #include "const.h" #include "cooling.h" +#include "cooling_struct.h" #include "cosmology.h" #include "cycle.h" #include "debug.h" -- GitLab From faafec011371cf938108eda3c8940b06e68479bf Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 31 May 2018 10:22:46 +0200 Subject: [PATCH 29/39] Fix gcc 8 warnings --- tests/test125cells.c | 4 ++-- tests/test27cells.c | 4 ++-- tests/testActivePair.c | 8 ++++---- tests/testPeriodicBC.c | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test125cells.c b/tests/test125cells.c index 41023aec1..33e945abf 100644 --- a/tests/test125cells.c +++ b/tests/test125cells.c @@ -759,7 +759,7 @@ int main(int argc, char *argv[]) { /* Dump if necessary */ if (n == 0) { - sprintf(outputFileName, "swift_dopair_125_%s.dat", + sprintf(outputFileName, "swift_dopair_125_%.150s.dat", outputFileNameExtension); dump_particle_fields(outputFileName, main_cell, solution, 0); } @@ -876,7 +876,7 @@ int main(int argc, char *argv[]) { /* Output timing */ message("Brute force calculation took : %15lli ticks.", toc - tic); - sprintf(outputFileName, "brute_force_125_%s.dat", outputFileNameExtension); + sprintf(outputFileName, "brute_force_125_%.150s.dat", outputFileNameExtension); dump_particle_fields(outputFileName, main_cell, solution, 0); /* Clean things to make the sanitizer happy ... */ diff --git a/tests/test27cells.c b/tests/test27cells.c index ccaaad8e8..ada1b782c 100644 --- a/tests/test27cells.c +++ b/tests/test27cells.c @@ -546,7 +546,7 @@ int main(int argc, char *argv[]) { /* Dump if necessary */ if (i % 50 == 0) { - sprintf(outputFileName, "swift_dopair_27_%s.dat", + sprintf(outputFileName, "swift_dopair_27_%.150s.dat", outputFileNameExtension); dump_particle_fields(outputFileName, main_cell, cells); } @@ -589,7 +589,7 @@ int main(int argc, char *argv[]) { end_calculation(main_cell, &cosmo); /* Dump */ - sprintf(outputFileName, "brute_force_27_%s.dat", outputFileNameExtension); + sprintf(outputFileName, "brute_force_27_%.150s.dat", outputFileNameExtension); dump_particle_fields(outputFileName, main_cell, cells); /* Output timing */ diff --git a/tests/testActivePair.c b/tests/testActivePair.c index 4a70e341d..9629f7c2d 100644 --- a/tests/testActivePair.c +++ b/tests/testActivePair.c @@ -578,8 +578,8 @@ int main(int argc, char *argv[]) { runner->e = &engine; /* Create output file names. */ - sprintf(swiftOutputFileName, "swift_dopair_%s.dat", outputFileNameExtension); - sprintf(bruteForceOutputFileName, "brute_force_pair_%s.dat", + sprintf(swiftOutputFileName, "swift_dopair_%.150s.dat", outputFileNameExtension); + sprintf(bruteForceOutputFileName, "brute_force_pair_%.150s.dat", outputFileNameExtension); /* Delete files if they already exist. */ @@ -632,9 +632,9 @@ int main(int argc, char *argv[]) { finalise = &end_calculation_force; /* Create new output file names. */ - sprintf(swiftOutputFileName, "swift_dopair2_force_%s.dat", + sprintf(swiftOutputFileName, "swift_dopair2_force_%.150s.dat", outputFileNameExtension); - sprintf(bruteForceOutputFileName, "brute_force_dopair2_%s.dat", + sprintf(bruteForceOutputFileName, "brute_force_dopair2_%.150s.dat", outputFileNameExtension); /* Delete files if they already exist. */ diff --git a/tests/testPeriodicBC.c b/tests/testPeriodicBC.c index 3e4cb5d38..ffaa3bda0 100644 --- a/tests/testPeriodicBC.c +++ b/tests/testPeriodicBC.c @@ -512,9 +512,9 @@ int main(int argc, char *argv[]) { } /* Create output file names. */ - sprintf(swiftOutputFileName, "swift_periodic_BC_%s.dat", + sprintf(swiftOutputFileName, "swift_periodic_BC_%.150s.dat", outputFileNameExtension); - sprintf(bruteForceOutputFileName, "brute_force_periodic_BC_%s.dat", + sprintf(bruteForceOutputFileName, "brute_force_periodic_BC_%.150s.dat", outputFileNameExtension); /* Delete files if they already exist. */ -- GitLab From 4d7c9ca53e5b782faa765e5f6905452e04391f5d Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 31 May 2018 10:23:14 +0200 Subject: [PATCH 30/39] Add testSelectOutput in makefiles --- configure.ac | 1 + tests/Makefile.am | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 583169d14..c0cfc443f 100644 --- a/configure.ac +++ b/configure.ac @@ -1207,6 +1207,7 @@ AC_CONFIG_FILES([tests/testPeriodicBC.sh], [chmod +x tests/testPeriodicBC.sh]) AC_CONFIG_FILES([tests/testPeriodicBCPerturbed.sh], [chmod +x tests/testPeriodicBCPerturbed.sh]) AC_CONFIG_FILES([tests/testInteractions.sh], [chmod +x tests/testInteractions.sh]) AC_CONFIG_FILES([tests/testParser.sh], [chmod +x tests/testParser.sh]) +AC_CONFIG_FILES([tests/testSelectOutput.sh], [chmod +x tests/testSelectOutput.sh]) # Save the compilation options AC_DEFINE_UNQUOTED([SWIFT_CONFIG_FLAGS],["$swift_config_flags"],[Flags passed to configure]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 891eef3f5..5ecddb2fd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -27,7 +27,7 @@ TESTS = testGreetings testMaths testReading.sh testSingle testKernel testSymmetr testMatrixInversion testThreadpool testDump testLogger testInteractions.sh \ testVoronoi1D testVoronoi2D testVoronoi3D testGravityDerivatives \ testPeriodicBC.sh testPeriodicBCPerturbed.sh testPotentialSelf \ - testPotentialPair testEOS testUtilities + testPotentialPair testEOS testUtilities testSelectOutput.sh # List of test programs to compile check_PROGRAMS = testGreetings testReading testSingle testTimeIntegration \ @@ -37,7 +37,8 @@ check_PROGRAMS = testGreetings testReading testSingle testTimeIntegration \ testAdiabaticIndex testRiemannExact testRiemannTRRS \ testRiemannHLLC testMatrixInversion testDump testLogger \ testVoronoi1D testVoronoi2D testVoronoi3D testPeriodicBC \ - testGravityDerivatives testPotentialSelf testPotentialPair testEOS testUtilities + testGravityDerivatives testPotentialSelf testPotentialPair testEOS testUtilities \ + testSelectOutput # Rebuild tests when SWIFT is updated. $(check_PROGRAMS): ../src/.libs/libswiftsim.a @@ -49,6 +50,8 @@ testMaths_SOURCES = testMaths.c testReading_SOURCES = testReading.c +testSelectOutput_SOURCES = testSelectOutput.c + testSymmetry_SOURCES = testSymmetry.c # Added because of issues using memcmp on clang 4.x @@ -120,4 +123,4 @@ EXTRA_DIST = testReading.sh makeInput.py testActivePair.sh \ tolerance_27_normal.dat tolerance_27_perturbed.dat tolerance_27_perturbed_h.dat tolerance_27_perturbed_h2.dat \ tolerance_testInteractions.dat tolerance_pair_active.dat tolerance_pair_force_active.dat \ fft_params.yml tolerance_periodic_BC_normal.dat tolerance_periodic_BC_perturbed.dat \ - testEOS.sh testEOS_plot.sh + testEOS.sh testEOS_plot.sh testSelectOutput.sh selectOutput.yml -- GitLab From 682d0678815e68d53e12f73187b25891b2681935 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 31 May 2018 10:24:23 +0200 Subject: [PATCH 31/39] Add a select output test --- tests/selectOutput.yml | 12 +++ tests/testSelectOutput.c | 160 +++++++++++++++++++++++++++++++++++ tests/testSelectOutput.py | 54 ++++++++++++ tests/testSelectOutput.sh.in | 11 +++ 4 files changed, 237 insertions(+) create mode 100644 tests/selectOutput.yml create mode 100644 tests/testSelectOutput.c create mode 100644 tests/testSelectOutput.py create mode 100644 tests/testSelectOutput.sh.in diff --git a/tests/selectOutput.yml b/tests/selectOutput.yml new file mode 100644 index 000000000..177893514 --- /dev/null +++ b/tests/selectOutput.yml @@ -0,0 +1,12 @@ +SelectOutput: + # Particle Type 0 + Coordinates_Gas: 1 # check if written when specified + Velocities_Gas: 0 # check if not written when specified + Masses_Gas: -5 # check warning if not 0 or 1 and if written + Pot_Gas: 1 # check warning if wrong name + # Density_Gas: 1 # check if written when not specified + +# Parameters for the hydrodynamics scheme +SPH: + resolution_eta: 1.2348 # Target smoothing length in units of the mean inter-particle separation (1.2348 == 48Ngbs with the cubic spline kernel). + CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration. diff --git a/tests/testSelectOutput.c b/tests/testSelectOutput.c new file mode 100644 index 000000000..e16c7a518 --- /dev/null +++ b/tests/testSelectOutput.c @@ -0,0 +1,160 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (C) 2015 Matthieu Schaller (matthieu.schaller@durham.ac.uk). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + ******************************************************************************/ + +/* Some standard headers. */ +#include + +/* Includes. */ +#include "swift.h" + +void select_output_engine_init(struct engine *e, struct space *s, + struct cosmology *cosmo, struct swift_params *params, + struct cooling_function_data *cooling, + struct hydro_props *hydro_properties) { + /* set structures */ + e->s = s; + e->cooling_func = cooling; + e->parameter_file = params; + e->cosmology = cosmo; + e->policy = engine_policy_hydro; + e->hydro_properties = hydro_properties; + + /* initialization of threadpool */ + threadpool_init(&e->threadpool, 1); + + /* set parameters */ + e->verbose = 1; + e->time = 0; + e->snapshotOutputCount = 0; + e->snapshotCompression = 0; + +}; + +void select_output_space_init(struct space *s, double *dim, int periodic, + size_t Ngas, size_t Nspart, size_t Ngpart, + struct part *parts, struct spart *sparts, + struct gpart *gparts) { + s->periodic = periodic; + for (int i=0; i<3; i++) { + s->dim[i] = dim[i]; + } + + /* init space particles */ + s->nr_parts = Ngas; + s->nr_sparts = Nspart; + s->nr_gparts = Ngpart; + + s->parts = parts; + s->gparts = gparts; + s->sparts = sparts; + + /* Allocate the extra parts array for the gas particles. */ + if (posix_memalign((void **)&s->xparts, xpart_align, + Ngas * sizeof(struct xpart)) != 0) + error("Failed to allocate xparts."); + bzero(s->xparts, Ngas * sizeof(struct xpart)); +}; + +void select_output_space_clean(struct space *s) { + free(s->xparts); +}; + + +void select_output_engine_clean(struct engine *e) { + threadpool_clean(&e->threadpool); +} + +int main() { + + char *base_name = "testSelectOutput"; + size_t Ngas = 0, Ngpart = 0, Nspart = 0; + int periodic = -1; + int flag_entropy_ICs = -1; + double dim[3]; + struct part *parts = NULL; + struct gpart *gparts = NULL; + struct spart *sparts = NULL; + + /* parse parameters */ + message("Reading parameters."); + struct swift_params param_file; + char *input_file = "selectOutput.yml"; + parser_read_file(input_file, ¶m_file); + + /* Default unit system */ + message("Initialization of the unit system."); + struct unit_system us; + units_init_cgs(&us); + + /* Default physical constants */ + message("Initialization of the physical constants."); + struct phys_const prog_const; + phys_const_init(&us, ¶m_file, &prog_const); + + /* Read data */ + message("Reading initial conditions."); + read_ic_single("input.hdf5", &us, dim, &parts, &gparts, &sparts, &Ngas, + &Ngpart, &Nspart, &periodic, &flag_entropy_ICs, 1, 0, 0, 0, 1., + 1, 0); + + /* pseudo initialization of the space */ + message("Initialization of the space."); + struct space s; + select_output_space_init(&s, dim, periodic, Ngas, Nspart, Ngpart, + parts, sparts, gparts); + + /* initialization of cosmology */ + message("Initialization of the cosmology."); + struct cosmology cosmo; + cosmology_init_no_cosmo(&cosmo); + + /* pseudo initialization of cooling */ + message("Initialization of the cooling."); + struct cooling_function_data cooling; + + /* pseudo initialization of hydro */ + message("Initialization of the hydro."); + struct hydro_props hydro_properties; + hydro_props_init(&hydro_properties, &prog_const, &us, ¶m_file); + + /* pseudo initialization of the engine */ + message("Initialization of the engine."); + struct engine e; + select_output_engine_init(&e, &s, &cosmo, ¶m_file, + &cooling, &hydro_properties); + + /* check output selection */ + message("Checking output parameters."); + long long N_total[swift_type_count] = {Ngas, Ngpart, 0, 0, Nspart, 0}; + io_check_output_fields(¶m_file, &e, N_total); + + /* write output file */ + message("Writing output."); + write_output_single(&e, base_name, &us, &us); + + /* Clean-up */ + message("Cleaning memory."); + select_output_engine_clean(&e); + select_output_space_clean(&s); + cosmology_clean(&cosmo); + free(parts); + free(gparts); + + return 0; +} diff --git a/tests/testSelectOutput.py b/tests/testSelectOutput.py new file mode 100644 index 000000000..c50afe894 --- /dev/null +++ b/tests/testSelectOutput.py @@ -0,0 +1,54 @@ +############################################################################### + # This file is part of SWIFT. + # Copyright (c) 2015 Bert Vandenbroucke (bert.vandenbroucke@ugent.be) + # Matthieu Schaller (matthieu.schaller@durham.ac.uk) + # + # This program is free software: you can redistribute it and/or modify + # it under the terms of the GNU Lesser General Public License as published + # by the Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + # + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU Lesser General Public License + # along with this program. If not, see . + # + ############################################################################## + +# Check the output done with swift + +import h5py + +filename = "testSelectOutput_0000.hdf5" +log_filename = "testSelectOutput.sh.log" + +# Read the simulation data +sim = h5py.File(filename, "r") +part0 = sim["/PartType0"] + +# check presence / absence fields +if "Velocities" in part0: + raise Exception("`Velocities` present in HDF5 but should not be written") + +if "Coordinates" not in part0: + raise Exception("`Coordinates` not present in HDF5 but should be written") + +if "Masses" not in part0: + raise Exception("`Masses` not present in HDF5 but should be written") + +if "Density" not in part0: + raise Exception("`Density` not present in HDF5 but should be written") + + +# check error detection +with open(log_filename, "r") as f: + data = f.read() + +if "SelectOutput:Masses_Gas" not in data: + raise Exception("Input error in `SelectOuput:Masses_Gas` not detected") + +if "SelectOutput:Pot_Gas" not in data: + raise Exception("Parameter name error not detected for `SelectOutput:Pot_Gas`") diff --git a/tests/testSelectOutput.sh.in b/tests/testSelectOutput.sh.in new file mode 100644 index 000000000..c3a12a724 --- /dev/null +++ b/tests/testSelectOutput.sh.in @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "Creating initial conditions" +python @srcdir@/makeInput.py + +echo "Generating output" +./testSelectOutput + +echo "Checking output" +python @srcdir@/testSelectOutput.py + -- GitLab From 3217007ec31110a0438b6f90d0e08ee6ced99a7e Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 31 May 2018 10:26:13 +0200 Subject: [PATCH 32/39] Remove tmp files for testSelectOutput --- tests/testSelectOutput.sh.in | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testSelectOutput.sh.in b/tests/testSelectOutput.sh.in index c3a12a724..5edf8d10e 100644 --- a/tests/testSelectOutput.sh.in +++ b/tests/testSelectOutput.sh.in @@ -9,3 +9,4 @@ echo "Generating output" echo "Checking output" python @srcdir@/testSelectOutput.py +rm -f testSelectOutput_0000.hdf5 testSelectOutput.xmf -- GitLab From e22677fe9514b5abfe7c397dad24a443e596997b Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 31 May 2018 10:46:45 +0200 Subject: [PATCH 33/39] Select Output: skip array preparation in parallel --- src/parallel_io.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/parallel_io.c b/src/parallel_io.c index a87c8e9fa..401e3b7da 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -839,6 +839,7 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6], const struct xpart* xparts = e->s->xparts; const struct gpart* gparts = e->s->gparts; const struct spart* sparts = e->s->sparts; + const struct swift_params* params = e->parameter_file; FILE* xmfFile = 0; int periodic = e->s->periodic; int numFiles = 1; @@ -1019,9 +1020,14 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6], } /* Prepare everything */ - for (int i = 0; i < num_fields; ++i) - prepareArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], - N_total[ptype], snapshot_units); + for (int i = 0; i < num_fields; ++i) { + char field[PARSER_MAX_LINE_SIZE]; + sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); + int should_write = parser_get_opt_param_int(params, field, 1); + if (should_write != 0) + prepareArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], + N_total[ptype], snapshot_units); + } /* Close particle group */ H5Gclose(h_grp); -- GitLab From c35e78268e986c24fa7d4f1a9379fbc4e393be7d Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 31 May 2018 10:59:52 +0200 Subject: [PATCH 34/39] Remove conflict flag --- src/hydro/Gadget2/hydro_io.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h index dab03600a..597c48c01 100644 --- a/src/hydro/Gadget2/hydro_io.h +++ b/src/hydro/Gadget2/hydro_io.h @@ -212,6 +212,5 @@ __attribute__((always_inline)) INLINE static void hydro_write_flavour( __attribute__((always_inline)) INLINE static int writeEntropyFlag(void) { return 0; } ->>>>>>> Check if all parameters in output_fields are correct #endif /* SWIFT_GADGET2_HYDRO_IO_H */ -- GitLab From b9c1b5172e27c72d4505e3e304f657c6a50ac80c Mon Sep 17 00:00:00 2001 From: lhausamm Date: Thu, 31 May 2018 11:02:38 +0200 Subject: [PATCH 35/39] Format --- examples/main.c | 3 +-- src/common_io.c | 32 ++++++++++++++++---------------- src/common_io.h | 3 +-- src/parallel_io.c | 10 ++++++---- src/serial_io.c | 3 ++- src/single_io.c | 3 ++- tests/test125cells.c | 3 ++- tests/testActivePair.c | 3 ++- tests/testSelectOutput.c | 35 ++++++++++++++++------------------- 9 files changed, 48 insertions(+), 47 deletions(-) diff --git a/examples/main.c b/examples/main.c index ab8fca819..8fdac673e 100644 --- a/examples/main.c +++ b/examples/main.c @@ -834,8 +834,7 @@ int main(int argc, char *argv[]) { talking, restart_file); /* check output field */ - if (myrank == 0) - io_check_output_fields(params, &e, N_total); + if (myrank == 0) io_check_output_fields(params, &e, N_total); if (myrank == 0) { clocks_gettime(&toc); diff --git a/src/common_io.c b/src/common_io.c index 34207113d..60158b195 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -818,8 +818,7 @@ void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot, * @param e The #engine */ void io_check_output_fields(const struct swift_params* params, - const struct engine* e, - const long long *N_total) { + const struct engine* e, const long long* N_total) { /* particles */ const struct part* parts = e->s->parts; @@ -829,7 +828,7 @@ void io_check_output_fields(const struct swift_params* params, /* copy N_total to array with length == 6 */ const long long nr_total[swift_type_count] = { - N_total[0], N_total[1], N_total[2], 0, 0, 0}; + N_total[0], N_total[1], N_total[2], 0, 0, 0}; /* get all the possible outputs */ for (int ptype = 0; ptype < swift_type_count; ptype++) { @@ -876,20 +875,22 @@ void io_check_output_fields(const struct swift_params* params, /* loop over each possible output field */ for (int field_id = 0; field_id < num_fields; field_id++) { char field_name[PARSER_MAX_LINE_SIZE]; - sprintf(field_name, "SelectOutput:%s_%s", - list[field_id].name, part_type_names[ptype]); + sprintf(field_name, "SelectOutput:%s_%s", list[field_id].name, + part_type_names[ptype]); if (strcmp(param_name, field_name) == 0) { found = 1; - /* check if correct input */ - int retParam = 0; - char str[PARSER_MAX_LINE_SIZE]; - sscanf(params->data[param_id].value, "%d%s", &retParam, str); - - if (retParam != 0 && retParam != 1) - message("WARNING: Unexpected input for %s. " - "Received %i but expect 0 or 1. " - "We will write this field.", field_name, retParam); + /* check if correct input */ + int retParam = 0; + char str[PARSER_MAX_LINE_SIZE]; + sscanf(params->data[param_id].value, "%d%s", &retParam, str); + + if (retParam != 0 && retParam != 1) + message( + "WARNING: Unexpected input for %s. " + "Received %i but expect 0 or 1. " + "We will write this field.", + field_name, retParam); continue; } } @@ -937,8 +938,7 @@ void io_write_output_field_parameter(const char* filename) { fprintf(file, " # Particle Type %s\n", part_type_names[ptype]); /* Write everything */ for (int i = 0; i < num_fields; ++i) { - fprintf(file, " %s_%s: 1\n", - list[i].name, part_type_names[ptype]); + fprintf(file, " %s_%s: 1\n", list[i].name, part_type_names[ptype]); } fprintf(file, "\n"); diff --git a/src/common_io.h b/src/common_io.h index 706387582..8f8312b19 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -101,8 +101,7 @@ void io_duplicate_star_gparts(struct threadpool* tp, struct spart* const sparts, size_t Ndm); void io_check_output_fields(const struct swift_params* params, - const struct engine* e, - const long long *N_total); + const struct engine* e, const long long* N_total); void io_write_output_field_parameter(const char* filename); diff --git a/src/parallel_io.c b/src/parallel_io.c index 401e3b7da..803d2e48d 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1022,11 +1022,12 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6], /* Prepare everything */ for (int i = 0; i < num_fields; ++i) { char field[PARSER_MAX_LINE_SIZE]; - sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); + sprintf(field, "SelectOutput:%s_%s", list[i].name, + part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); if (should_write != 0) - prepareArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], - N_total[ptype], snapshot_units); + prepareArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], + N_total[ptype], snapshot_units); } /* Close particle group */ @@ -1272,7 +1273,8 @@ void write_output_parallel(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { char field[PARSER_MAX_LINE_SIZE]; - sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); + sprintf(field, "SelectOutput:%s_%s", list[i].name, + part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); if (should_write != 0) writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, diff --git a/src/serial_io.c b/src/serial_io.c index 9c0a3c1fb..4e47f758a 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1010,7 +1010,8 @@ void write_output_serial(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { char field[PARSER_MAX_LINE_SIZE]; - sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); + sprintf(field, "SelectOutput:%s_%s", list[i].name, + part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); if (should_write != 0) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], diff --git a/src/single_io.c b/src/single_io.c index 3a89d7a02..a74a0adb7 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -829,7 +829,8 @@ void write_output_single(struct engine* e, const char* baseName, /* Write everything */ for (int i = 0; i < num_fields; ++i) { char field[PARSER_MAX_LINE_SIZE]; - sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); + sprintf(field, "SelectOutput:%s_%s", list[i].name, + part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); if (should_write != 0) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, diff --git a/tests/test125cells.c b/tests/test125cells.c index 33e945abf..ddce3176d 100644 --- a/tests/test125cells.c +++ b/tests/test125cells.c @@ -876,7 +876,8 @@ int main(int argc, char *argv[]) { /* Output timing */ message("Brute force calculation took : %15lli ticks.", toc - tic); - sprintf(outputFileName, "brute_force_125_%.150s.dat", outputFileNameExtension); + sprintf(outputFileName, "brute_force_125_%.150s.dat", + outputFileNameExtension); dump_particle_fields(outputFileName, main_cell, solution, 0); /* Clean things to make the sanitizer happy ... */ diff --git a/tests/testActivePair.c b/tests/testActivePair.c index 9629f7c2d..6889a1888 100644 --- a/tests/testActivePair.c +++ b/tests/testActivePair.c @@ -578,7 +578,8 @@ int main(int argc, char *argv[]) { runner->e = &engine; /* Create output file names. */ - sprintf(swiftOutputFileName, "swift_dopair_%.150s.dat", outputFileNameExtension); + sprintf(swiftOutputFileName, "swift_dopair_%.150s.dat", + outputFileNameExtension); sprintf(bruteForceOutputFileName, "brute_force_pair_%.150s.dat", outputFileNameExtension); diff --git a/tests/testSelectOutput.c b/tests/testSelectOutput.c index e16c7a518..fecffd861 100644 --- a/tests/testSelectOutput.c +++ b/tests/testSelectOutput.c @@ -24,9 +24,10 @@ #include "swift.h" void select_output_engine_init(struct engine *e, struct space *s, - struct cosmology *cosmo, struct swift_params *params, - struct cooling_function_data *cooling, - struct hydro_props *hydro_properties) { + struct cosmology *cosmo, + struct swift_params *params, + struct cooling_function_data *cooling, + struct hydro_props *hydro_properties) { /* set structures */ e->s = s; e->cooling_func = cooling; @@ -42,16 +43,15 @@ void select_output_engine_init(struct engine *e, struct space *s, e->verbose = 1; e->time = 0; e->snapshotOutputCount = 0; - e->snapshotCompression = 0; - + e->snapshotCompression = 0; }; void select_output_space_init(struct space *s, double *dim, int periodic, - size_t Ngas, size_t Nspart, size_t Ngpart, - struct part *parts, struct spart *sparts, - struct gpart *gparts) { + size_t Ngas, size_t Nspart, size_t Ngpart, + struct part *parts, struct spart *sparts, + struct gpart *gparts) { s->periodic = periodic; - for (int i=0; i<3; i++) { + for (int i = 0; i < 3; i++) { s->dim[i] = dim[i]; } @@ -66,18 +66,15 @@ void select_output_space_init(struct space *s, double *dim, int periodic, /* Allocate the extra parts array for the gas particles. */ if (posix_memalign((void **)&s->xparts, xpart_align, - Ngas * sizeof(struct xpart)) != 0) + Ngas * sizeof(struct xpart)) != 0) error("Failed to allocate xparts."); bzero(s->xparts, Ngas * sizeof(struct xpart)); }; -void select_output_space_clean(struct space *s) { - free(s->xparts); -}; - +void select_output_space_clean(struct space *s) { free(s->xparts); }; void select_output_engine_clean(struct engine *e) { - threadpool_clean(&e->threadpool); + threadpool_clean(&e->threadpool); } int main() { @@ -116,8 +113,8 @@ int main() { /* pseudo initialization of the space */ message("Initialization of the space."); struct space s; - select_output_space_init(&s, dim, periodic, Ngas, Nspart, Ngpart, - parts, sparts, gparts); + select_output_space_init(&s, dim, periodic, Ngas, Nspart, Ngpart, parts, + sparts, gparts); /* initialization of cosmology */ message("Initialization of the cosmology."); @@ -136,8 +133,8 @@ int main() { /* pseudo initialization of the engine */ message("Initialization of the engine."); struct engine e; - select_output_engine_init(&e, &s, &cosmo, ¶m_file, - &cooling, &hydro_properties); + select_output_engine_init(&e, &s, &cosmo, ¶m_file, &cooling, + &hydro_properties); /* check output selection */ message("Checking output parameters."); -- GitLab From d668907b7037ef08811fb9dc14cffba1c66a5b82 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Thu, 31 May 2018 14:49:11 +0200 Subject: [PATCH 36/39] Series of style improvements. --- .gitignore | 1 + examples/main.c | 10 ++--- src/chemistry/EAGLE/chemistry_io.h | 8 ++-- src/chemistry/GEAR/chemistry_io.h | 11 +++-- src/chemistry/none/chemistry_io.h | 11 +++-- src/common_io.c | 72 ++++++++++++++++++------------ src/common_io.h | 2 +- src/parallel_io.c | 14 ++++-- src/serial_io.c | 7 ++- src/single_io.c | 7 ++- 10 files changed, 86 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index 8c3ede8f3..68e34d196 100644 --- a/.gitignore +++ b/.gitignore @@ -102,6 +102,7 @@ tests/test125cells.sh tests/test125cellsPerturbed.sh tests/testParser.sh tests/testReading.sh +tests/testSelectOutput.sh tests/testAdiabaticIndex tests/testRiemannExact tests/testRiemannTRRS diff --git a/examples/main.c b/examples/main.c index 8fdac673e..cf30a9c2b 100644 --- a/examples/main.c +++ b/examples/main.c @@ -338,9 +338,9 @@ int main(int argc, char *argv[]) { } /* Write output parameter file */ - if (strcmp(output_parameters_filename, "") != 0) { + if (myrank == 0 && strcmp(output_parameters_filename, "") != 0) { io_write_output_field_parameter(output_parameters_filename); - printf("Ouput parameter file written in %s\n", output_parameters_filename); + printf("End of run.\n"); return 0; } @@ -734,6 +734,9 @@ int main(int argc, char *argv[]) { "ICs.", N_total[0], N_total[2], N_total[1]); + /* Verify that the fields to dump actually exist */ + if (myrank == 0) io_check_output_fields(params, N_total); + /* Initialize the space with these data. */ if (myrank == 0) clocks_gettime(&tic); space_init(&s, params, &cosmo, dim, parts, gparts, sparts, Ngas, Ngpart, @@ -833,9 +836,6 @@ int main(int argc, char *argv[]) { engine_config(0, &e, params, nr_nodes, myrank, nr_threads, with_aff, talking, restart_file); - /* check output field */ - if (myrank == 0) io_check_output_fields(params, &e, N_total); - if (myrank == 0) { clocks_gettime(&toc); message("engine_init took %.3f %s.", clocks_diff(&tic, &toc), diff --git a/src/chemistry/EAGLE/chemistry_io.h b/src/chemistry/EAGLE/chemistry_io.h index aab8ec240..f87807579 100644 --- a/src/chemistry/EAGLE/chemistry_io.h +++ b/src/chemistry/EAGLE/chemistry_io.h @@ -30,7 +30,8 @@ * * @return Returns the number of fields to read. */ -int chemistry_read_particles(struct part* parts, struct io_props* list) { +INLINE static int chemistry_read_particles(struct part* parts, + struct io_props* list) { /* Nothing to read */ return 0; @@ -44,7 +45,8 @@ int chemistry_read_particles(struct part* parts, struct io_props* list) { * * @return Returns the number of fields to write. */ -int chemistry_write_particles(const struct part* parts, struct io_props* list) { +INLINE static int chemistry_write_particles(const struct part* parts, + struct io_props* list) { /* List what we want to write */ list[0] = io_make_output_field("ElementAbundance", FLOAT, @@ -101,7 +103,7 @@ 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_grp) { +INLINE static 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) { diff --git a/src/chemistry/GEAR/chemistry_io.h b/src/chemistry/GEAR/chemistry_io.h index bee29dd3b..2a0847beb 100644 --- a/src/chemistry/GEAR/chemistry_io.h +++ b/src/chemistry/GEAR/chemistry_io.h @@ -48,8 +48,8 @@ chemistry_get_element_name(enum chemistry_element elem) { * * @return Returns the number of fields to read. */ -__attribute__((always_inline)) INLINE static int chemistry_read_particles( - struct part* parts, struct io_props* list) { +INLINE static int chemistry_read_particles(struct part* parts, + struct io_props* list) { /* List what we want to read */ list[0] = io_make_input_field( @@ -69,8 +69,8 @@ __attribute__((always_inline)) INLINE static int chemistry_read_particles( * * @return Returns the number of fields to write. */ -__attribute__((always_inline)) INLINE static int chemistry_write_particles( - const struct part* parts, struct io_props* list) { +INLINE static int chemistry_write_particles(const struct part* parts, + struct io_props* list) { /* List what we want to write */ list[0] = io_make_output_field( @@ -93,8 +93,7 @@ __attribute__((always_inline)) INLINE static int chemistry_write_particles( * @brief Writes the current model of SPH to the file * @param h_grp The HDF5 group in which to write */ -__attribute__((always_inline)) INLINE static void chemistry_write_flavour( - hid_t h_grp) { +INLINE static void chemistry_write_flavour(hid_t h_grp) { io_write_attribute_s(h_grp, "Chemistry Model", "GEAR"); for (enum chemistry_element i = chemistry_element_O; diff --git a/src/chemistry/none/chemistry_io.h b/src/chemistry/none/chemistry_io.h index fc460944e..ef7e0d8d8 100644 --- a/src/chemistry/none/chemistry_io.h +++ b/src/chemistry/none/chemistry_io.h @@ -29,8 +29,8 @@ * * @return Returns the number of fields to write. */ -__attribute__((always_inline)) INLINE static int chemistry_read_particles( - struct part* parts, struct io_props* list) { +INLINE static int chemistry_read_particles(struct part* parts, + struct io_props* list) { /* update list according to hydro_io */ @@ -46,8 +46,8 @@ __attribute__((always_inline)) INLINE static int chemistry_read_particles( * * @return Returns the number of fields to write. */ -__attribute__((always_inline)) INLINE static int chemistry_write_particles( - const struct part* parts, struct io_props* list) { +INLINE static int chemistry_write_particles(const struct part* parts, + struct io_props* list) { /* update list according to hydro_io */ @@ -61,8 +61,7 @@ __attribute__((always_inline)) INLINE static int chemistry_write_particles( * @brief Writes the current model of SPH to the file * @param h_grp The HDF5 group in which to write */ -__attribute__((always_inline)) INLINE static void chemistry_write_flavour( - hid_t h_grp) { +INLINE static void chemistry_write_flavour(hid_t h_grp) { io_write_attribute_s(h_grp, "Chemistry Model", "None"); } diff --git a/src/common_io.c b/src/common_io.c index 60158b195..bc8e547d6 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -815,58 +815,61 @@ void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot, * @brief Verify the io parameter file * * @param params The #swift_params - * @param e The #engine + * @param N_total The total number of each particle type. */ void io_check_output_fields(const struct swift_params* params, - const struct engine* e, const long long* N_total) { + const long long N_total[3]) { - /* particles */ - const struct part* parts = e->s->parts; - const struct xpart* xparts = e->s->xparts; - const struct gpart* gparts = e->s->gparts; - const struct spart* sparts = e->s->sparts; + /* Create some fake particles as arguments for the writing routines */ + struct part p; + struct xpart xp; + struct spart sp; + struct gpart gp; - /* copy N_total to array with length == 6 */ + /* Copy N_total to array with length == 6 */ const long long nr_total[swift_type_count] = { N_total[0], N_total[1], N_total[2], 0, 0, 0}; - /* get all the possible outputs */ + /* Loop over all particle types to check the fields */ for (int ptype = 0; ptype < swift_type_count; ptype++) { + int num_fields = 0; struct io_props list[100]; /* Don't do anything if no particle of this kind */ if (nr_total[ptype] == 0) continue; - /* Write particle fields from the particle structure */ + /* Gather particle fields from the particle structures */ switch (ptype) { case swift_type_gas: - hydro_write_particles(parts, xparts, list, &num_fields); - num_fields += chemistry_write_particles(parts, list + num_fields); + hydro_write_particles(&p, &xp, list, &num_fields); + num_fields += chemistry_write_particles(&p, list + num_fields); break; case swift_type_dark_matter: - darkmatter_write_particles(gparts, list, &num_fields); + darkmatter_write_particles(&gp, list, &num_fields); break; case swift_type_star: - star_write_particles(sparts, list, &num_fields); + star_write_particles(&sp, list, &num_fields); break; default: error("Particle Type %d not yet supported. Aborting", ptype); } + /* loop over each parameter */ for (int param_id = 0; param_id < params->paramCount; param_id++) { const char* param_name = params->data[param_id].name; char section_name[PARSER_MAX_LINE_SIZE]; - /* skip if wrong section */ + + /* Skip if wrong section */ sprintf(section_name, "SelectOutput:"); if (strstr(param_name, section_name) == NULL) continue; - /* skip if wrong particle type */ + /* Skip if wrong particle type */ sprintf(section_name, "_%s", part_type_names[ptype]); if (strstr(param_name, section_name) == NULL) continue; @@ -885,18 +888,20 @@ void io_check_output_fields(const struct swift_params* params, char str[PARSER_MAX_LINE_SIZE]; sscanf(params->data[param_id].value, "%d%s", &retParam, str); + /* Check that we have a 0 or 1 */ if (retParam != 0 && retParam != 1) - message( - "WARNING: Unexpected input for %s. " - "Received %i but expect 0 or 1. " - "We will write this field.", - field_name, retParam); - continue; + error("Unexpected input for %s. Received %i but expect 0 or 1. ", + field_name, retParam); + + /* Found it, so move to the next one. */ + break; } } if (!found) - message("WARNING: Unable to find field corresponding to %s in %s", - param_name, params->fileName); + message( + "WARNING: Trying to dump particle field '%s' (read from '%s') that " + "does not exist.", + param_name, params->fileName); } } } @@ -904,15 +909,17 @@ void io_check_output_fields(const struct swift_params* params, /** * @brief Write the output field parameters file * - * @param e The #engine * @param filename The file to write */ void io_write_output_field_parameter(const char* filename) { + FILE* file = fopen(filename, "w"); + if (file == NULL) error("Error opening file '%s'", filename); /* Loop over all particle types */ fprintf(file, "SelectOutput:\n"); for (int ptype = 0; ptype < swift_type_count; ptype++) { + int num_fields = 0; struct io_props list[100]; @@ -931,18 +938,27 @@ void io_write_output_field_parameter(const char* filename) { case swift_type_star: star_write_particles(NULL, list, &num_fields); break; + + default: + break; } if (num_fields == 0) continue; + /* Output a header for that particle type */ fprintf(file, " # Particle Type %s\n", part_type_names[ptype]); - /* Write everything */ - for (int i = 0; i < num_fields; ++i) { + + /* Write all the fields of this particle type */ + for (int i = 0; i < num_fields; ++i) fprintf(file, " %s_%s: 1\n", list[i].name, part_type_names[ptype]); - } fprintf(file, "\n"); } fclose(file); + + printf( + "List of valid ouput fields for the particle in snapshots dumped in " + "'%s'.\n", + filename); } diff --git a/src/common_io.h b/src/common_io.h index 8f8312b19..f26a635a6 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -101,7 +101,7 @@ void io_duplicate_star_gparts(struct threadpool* tp, struct spart* const sparts, size_t Ndm); void io_check_output_fields(const struct swift_params* params, - const struct engine* e, const long long* N_total); + const long long N_total[3]); void io_write_output_field_parameter(const char* filename); diff --git a/src/parallel_io.c b/src/parallel_io.c index 803d2e48d..3c073ce71 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1019,13 +1019,16 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6], error("Particle Type %d not yet supported. Aborting", ptype); } - /* Prepare everything */ + /* Prepare everything that is not cancelled */ for (int i = 0; i < num_fields; ++i) { + + /* Did the user cancel this field? */ char field[PARSER_MAX_LINE_SIZE]; sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); - if (should_write != 0) + + if (should_write) prepareArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N_total[ptype], snapshot_units); } @@ -1270,13 +1273,16 @@ void write_output_parallel(struct engine* e, const char* baseName, error("Particle Type %d not yet supported. Aborting", ptype); } - /* Write everything */ + /* Write everything that is not cancelled */ for (int i = 0; i < num_fields; ++i) { + + /* Did the user cancel this field? */ char field[PARSER_MAX_LINE_SIZE]; sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); - if (should_write != 0) + + if (should_write) writeArray(e, h_grp, fileName, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], internal_units, snapshot_units); diff --git a/src/serial_io.c b/src/serial_io.c index 4e47f758a..750ec23bf 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1007,13 +1007,16 @@ void write_output_serial(struct engine* e, const char* baseName, error("Particle Type %d not yet supported. Aborting", ptype); } - /* Write everything */ + /* Write everything that is not cancelled */ for (int i = 0; i < num_fields; ++i) { + + /* Did the user cancel this field? */ char field[PARSER_MAX_LINE_SIZE]; sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); - if (should_write != 0) + + if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], Nparticles, N_total[ptype], mpi_rank, offset[ptype], internal_units, snapshot_units); diff --git a/src/single_io.c b/src/single_io.c index a74a0adb7..47599eaaa 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -826,13 +826,16 @@ void write_output_single(struct engine* e, const char* baseName, error("Particle Type %d not yet supported. Aborting", ptype); } - /* Write everything */ + /* Write everything that is not cancelled */ for (int i = 0; i < num_fields; ++i) { + + /* Did the user cancel this field? */ char field[PARSER_MAX_LINE_SIZE]; sprintf(field, "SelectOutput:%s_%s", list[i].name, part_type_names[ptype]); int should_write = parser_get_opt_param_int(params, field, 1); - if (should_write != 0) + + if (should_write) writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, internal_units, snapshot_units); } -- GitLab From 1776ca03021ebd5dbe77001e0cbc082d8c6785e7 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Thu, 31 May 2018 15:13:43 +0200 Subject: [PATCH 37/39] Some fixes to the new test --- .gitignore | 1 + src/common_io.c | 6 ++++-- tests/testSelectOutput.c | 13 +++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 68e34d196..c31cac8ed 100644 --- a/.gitignore +++ b/.gitignore @@ -80,6 +80,7 @@ tests/test_nonsym_force_1_vec.dat tests/test_nonsym_force_2_vec.dat tests/potential.dat tests/testGreetings +tests/testSelectOutput tests/testReading tests/testSingle tests/testTimeIntegration diff --git a/src/common_io.c b/src/common_io.c index bc8e547d6..248fe016c 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -890,8 +890,10 @@ void io_check_output_fields(const struct swift_params* params, /* Check that we have a 0 or 1 */ if (retParam != 0 && retParam != 1) - error("Unexpected input for %s. Received %i but expect 0 or 1. ", - field_name, retParam); + message( + "WARNING: Unexpected input for %s. Received %i but expect 0 or " + "1. ", + field_name, retParam); /* Found it, so move to the next one. */ break; diff --git a/tests/testSelectOutput.c b/tests/testSelectOutput.c index fecffd861..3bedddd03 100644 --- a/tests/testSelectOutput.c +++ b/tests/testSelectOutput.c @@ -42,8 +42,9 @@ void select_output_engine_init(struct engine *e, struct space *s, /* set parameters */ e->verbose = 1; e->time = 0; - e->snapshotOutputCount = 0; - e->snapshotCompression = 0; + e->snapshot_output_count = 0; + e->snapshot_compression = 0; + e->snapshot_label_delta = 1; }; void select_output_space_init(struct space *s, double *dim, int periodic, @@ -77,7 +78,11 @@ void select_output_engine_clean(struct engine *e) { threadpool_clean(&e->threadpool); } -int main() { +int main(int argc, char *argv[]) { + + /* Initialize CPU frequency, this also starts time. */ + unsigned long long cpufreq = 0; + clocks_set_cpufreq(cpufreq); char *base_name = "testSelectOutput"; size_t Ngas = 0, Ngpart = 0, Nspart = 0; @@ -139,7 +144,7 @@ int main() { /* check output selection */ message("Checking output parameters."); long long N_total[swift_type_count] = {Ngas, Ngpart, 0, 0, Nspart, 0}; - io_check_output_fields(¶m_file, &e, N_total); + io_check_output_fields(¶m_file, N_total); /* write output file */ message("Writing output."); -- GitLab From 0da444606a3cd213b14cb0cfb48c86d745943d2c Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Thu, 31 May 2018 15:22:29 +0200 Subject: [PATCH 38/39] Modify all the other hydro schemes in the same way. --- src/gravity/Default/gravity_io.h | 18 ++++++----- src/hydro/Default/hydro_io.h | 30 +++++++++++------- src/hydro/Gadget2/hydro_io.h | 47 +++++++++++++--------------- src/hydro/GizmoMFM/hydro_io.h | 42 ++++++++++++++----------- src/hydro/GizmoMFV/hydro_io.h | 42 ++++++++++++++----------- src/hydro/Minimal/hydro_io.h | 38 ++++++++++++---------- src/hydro/MinimalMultiMat/hydro_io.h | 38 ++++++++++++---------- src/hydro/PressureEnergy/hydro_io.h | 37 ++++++++++++---------- src/hydro/PressureEntropy/hydro_io.h | 38 ++++++++++++---------- src/hydro/Shadowswift/hydro_io.h | 32 ++++++++++--------- src/stars/Default/star_io.h | 9 +++--- 11 files changed, 208 insertions(+), 163 deletions(-) diff --git a/src/gravity/Default/gravity_io.h b/src/gravity/Default/gravity_io.h index b1cddae1a..5016803b1 100644 --- a/src/gravity/Default/gravity_io.h +++ b/src/gravity/Default/gravity_io.h @@ -21,8 +21,8 @@ #include "io_properties.h" -__attribute__((always_inline)) INLINE static void convert_gpart_pos( - const struct engine* e, const struct gpart* gp, double* ret) { +INLINE static void convert_gpart_pos(const struct engine* e, + const struct gpart* gp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(gp->x[0], 0.0, e->s->dim[0]); @@ -35,8 +35,8 @@ __attribute__((always_inline)) INLINE static void convert_gpart_pos( } } -__attribute__((always_inline)) INLINE static void convert_gpart_vel( - const struct engine* e, const struct gpart* gp, float* ret) { +INLINE static void convert_gpart_vel(const struct engine* e, + const struct gpart* gp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -74,8 +74,9 @@ __attribute__((always_inline)) INLINE static void convert_gpart_vel( * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -__attribute__((always_inline)) INLINE static void darkmatter_read_particles( - struct gpart* gparts, struct io_props* list, int* num_fields) { +INLINE static void darkmatter_read_particles(struct gpart* gparts, + struct io_props* list, + int* num_fields) { /* Say how much we want to read */ *num_fields = 4; @@ -98,8 +99,9 @@ __attribute__((always_inline)) INLINE static void darkmatter_read_particles( * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -__attribute__((always_inline)) INLINE static void darkmatter_write_particles( - const struct gpart* gparts, struct io_props* list, int* num_fields) { +INLINE static void darkmatter_write_particles(const struct gpart* gparts, + struct io_props* list, + int* num_fields) { /* Say how much we want to write */ *num_fields = 5; diff --git a/src/hydro/Default/hydro_io.h b/src/hydro/Default/hydro_io.h index c7a0953eb..d6b6f36ba 100644 --- a/src/hydro/Default/hydro_io.h +++ b/src/hydro/Default/hydro_io.h @@ -31,8 +31,9 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void hydro_read_particles(struct part* parts, struct io_props* list, - int* num_fields) { +INLINE static void hydro_read_particles(struct part* parts, + struct io_props* list, + int* num_fields) { *num_fields = 8; @@ -55,8 +56,9 @@ void hydro_read_particles(struct part* parts, struct io_props* list, UNIT_CONV_DENSITY, parts, rho); } -void convert_part_pos(const struct engine* e, const struct part* p, - const struct xpart* xp, double* ret) { +INLINE static void convert_part_pos(const struct engine* e, + const struct part* p, + const struct xpart* xp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -69,8 +71,9 @@ void convert_part_pos(const struct engine* e, const struct part* p, } } -void convert_part_vel(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_vel(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -103,8 +106,9 @@ void convert_part_vel(const struct engine* e, const struct part* p, ret[2] *= cosmo->a2_inv; } -void convert_part_potential(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_potential(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { if (p->gpart != NULL) ret[0] = gravity_get_comoving_potential(p->gpart); @@ -119,8 +123,10 @@ void convert_part_potential(const struct engine* e, const struct part* p, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void hydro_write_particles(const struct part* parts, const struct xpart* xparts, - struct io_props* list, int* num_fields) { +INLINE static void hydro_write_particles(const struct part* parts, + const struct xpart* xparts, + struct io_props* list, + int* num_fields) { *num_fields = 8; @@ -149,7 +155,7 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -void hydro_write_flavour(hid_t h_grpsph) { +INLINE static void hydro_write_flavour(hid_t h_grpsph) { /* Viscosity and thermal conduction */ io_write_attribute_s(h_grpsph, "Thermal Conductivity Model", @@ -178,6 +184,6 @@ void hydro_write_flavour(hid_t h_grpsph) { * * @return 1 if entropy is in 'internal energy', 0 otherwise. */ -int writeEntropyFlag(void) { return 0; } +INLINE static int writeEntropyFlag(void) { return 0; } #endif /* SWIFT_DEFAULT_HYDRO_IO_H */ diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h index 597c48c01..8f503230e 100644 --- a/src/hydro/Gadget2/hydro_io.h +++ b/src/hydro/Gadget2/hydro_io.h @@ -31,8 +31,9 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -__attribute__((always_inline)) INLINE static void hydro_read_particles( - struct part* parts, struct io_props* list, int* num_fields) { +INLINE static void hydro_read_particles(struct part* parts, + struct io_props* list, + int* num_fields) { *num_fields = 8; @@ -55,23 +56,21 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles( UNIT_CONV_DENSITY, parts, rho); } -__attribute__((always_inline)) INLINE static void convert_part_u( - const struct engine* e, const struct part* p, const struct xpart* xp, - float* ret) { +INLINE static void convert_part_u(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_internal_energy(p); } -__attribute__((always_inline)) INLINE static void convert_part_P( - const struct engine* e, const struct part* p, const struct xpart* xp, - float* ret) { +INLINE static void convert_part_P(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_pressure(p); } -__attribute__((always_inline)) INLINE static void convert_part_pos( - const struct engine* e, const struct part* p, const struct xpart* xp, - double* ret) { +INLINE static void convert_part_pos(const struct engine* e, + const struct part* p, + const struct xpart* xp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -84,9 +83,9 @@ __attribute__((always_inline)) INLINE static void convert_part_pos( } } -__attribute__((always_inline)) INLINE static void convert_part_vel( - const struct engine* e, const struct part* p, const struct xpart* xp, - float* ret) { +INLINE static void convert_part_vel(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -119,9 +118,9 @@ __attribute__((always_inline)) INLINE static void convert_part_vel( ret[2] *= cosmo->a2_inv; } -__attribute__((always_inline)) INLINE static void convert_part_potential( - const struct engine* e, const struct part* p, const struct xpart* xp, - float* ret) { +INLINE static void convert_part_potential(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { if (p->gpart != NULL) ret[0] = gravity_get_comoving_potential(p->gpart); @@ -136,9 +135,10 @@ __attribute__((always_inline)) INLINE static void convert_part_potential( * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -__attribute__((always_inline)) INLINE static void hydro_write_particles( - const struct part* parts, const struct xpart* xparts, struct io_props* list, - int* num_fields) { +INLINE static void hydro_write_particles(const struct part* parts, + const struct xpart* xparts, + struct io_props* list, + int* num_fields) { *num_fields = 10; @@ -191,8 +191,7 @@ __attribute__((always_inline)) INLINE static void hydro_write_particles( * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -__attribute__((always_inline)) INLINE static void hydro_write_flavour( - hid_t h_grpsph) { +INLINE static void hydro_write_flavour(hid_t h_grpsph) { /* Viscosity and thermal conduction */ io_write_attribute_s(h_grpsph, "Thermal Conductivity Model", @@ -209,8 +208,6 @@ __attribute__((always_inline)) INLINE static void hydro_write_flavour( * * @return 1 if entropy is in 'internal energy', 0 otherwise. */ -__attribute__((always_inline)) INLINE static int writeEntropyFlag(void) { - return 0; -} +INLINE static int writeEntropyFlag(void) { return 0; } #endif /* SWIFT_GADGET2_HYDRO_IO_H */ diff --git a/src/hydro/GizmoMFM/hydro_io.h b/src/hydro/GizmoMFM/hydro_io.h index 94127b3fa..6ce5a23ee 100644 --- a/src/hydro/GizmoMFM/hydro_io.h +++ b/src/hydro/GizmoMFM/hydro_io.h @@ -40,8 +40,9 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void hydro_read_particles(struct part* parts, struct io_props* list, - int* num_fields) { +INLINE static void hydro_read_particles(struct part* parts, + struct io_props* list, + int* num_fields) { *num_fields = 8; @@ -72,8 +73,8 @@ void hydro_read_particles(struct part* parts, struct io_props* list, * @param p Particle. * @param ret (return) Internal energy of the particle */ -void convert_u(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_u(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_internal_energy(p); } @@ -85,8 +86,8 @@ void convert_u(const struct engine* e, const struct part* p, * @param p Particle. * @param ret (return) Entropic function of the particle */ -void convert_A(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_A(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_entropy(p); } @@ -97,8 +98,8 @@ void convert_A(const struct engine* e, const struct part* p, * @param p Particle. * @return Total energy of the particle */ -void convert_Etot(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_Etot(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { #ifdef GIZMO_TOTAL_ENERGY ret[0] = p->conserved.energy; #else @@ -112,8 +113,9 @@ void convert_Etot(const struct engine* e, const struct part* p, #endif } -void convert_part_pos(const struct engine* e, const struct part* p, - const struct xpart* xp, double* ret) { +INLINE static void convert_part_pos(const struct engine* e, + const struct part* p, + const struct xpart* xp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -126,8 +128,9 @@ void convert_part_pos(const struct engine* e, const struct part* p, } } -void convert_part_vel(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_vel(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -160,8 +163,9 @@ void convert_part_vel(const struct engine* e, const struct part* p, ret[2] *= cosmo->a2_inv; } -void convert_part_potential(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_potential(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { if (p->gpart != NULL) ret[0] = gravity_get_comoving_potential(p->gpart); @@ -176,8 +180,10 @@ void convert_part_potential(const struct engine* e, const struct part* p, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void hydro_write_particles(const struct part* parts, const struct xpart* xparts, - struct io_props* list, int* num_fields) { +INLINE static void hydro_write_particles(const struct part* parts, + const struct xpart* xparts, + struct io_props* list, + int* num_fields) { *num_fields = 11; @@ -215,7 +221,7 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -void hydro_write_flavour(hid_t h_grpsph) { +INLINE static void hydro_write_flavour(hid_t h_grpsph) { /* Gradient information */ io_write_attribute_s(h_grpsph, "Gradient reconstruction model", HYDRO_GRADIENT_IMPLEMENTATION); @@ -239,6 +245,6 @@ void hydro_write_flavour(hid_t h_grpsph) { * * @return 1 if entropy is in 'internal energy', 0 otherwise. */ -int writeEntropyFlag(void) { return 0; } +INLINE static int writeEntropyFlag(void) { return 0; } #endif /* SWIFT_GIZMO_MFM_HYDRO_IO_H */ diff --git a/src/hydro/GizmoMFV/hydro_io.h b/src/hydro/GizmoMFV/hydro_io.h index 18f023acb..7b1c65169 100644 --- a/src/hydro/GizmoMFV/hydro_io.h +++ b/src/hydro/GizmoMFV/hydro_io.h @@ -40,8 +40,9 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void hydro_read_particles(struct part* parts, struct io_props* list, - int* num_fields) { +INLINE static void hydro_read_particles(struct part* parts, + struct io_props* list, + int* num_fields) { *num_fields = 8; @@ -72,8 +73,8 @@ void hydro_read_particles(struct part* parts, struct io_props* list, * @param p Particle. * @param ret (return) Internal energy of the particle */ -void convert_u(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_u(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_internal_energy(p); } @@ -85,8 +86,8 @@ void convert_u(const struct engine* e, const struct part* p, * @param p Particle. * @param ret (return) Entropic function of the particle */ -void convert_A(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_A(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_entropy(p); } @@ -97,8 +98,8 @@ void convert_A(const struct engine* e, const struct part* p, * @param p Particle. * @return Total energy of the particle */ -void convert_Etot(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_Etot(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { #ifdef GIZMO_TOTAL_ENERGY ret[0] = p->conserved.energy; #else @@ -112,8 +113,9 @@ void convert_Etot(const struct engine* e, const struct part* p, #endif } -void convert_part_pos(const struct engine* e, const struct part* p, - const struct xpart* xp, double* ret) { +INLINE static void convert_part_pos(const struct engine* e, + const struct part* p, + const struct xpart* xp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -126,8 +128,9 @@ void convert_part_pos(const struct engine* e, const struct part* p, } } -void convert_part_vel(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_vel(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -160,8 +163,9 @@ void convert_part_vel(const struct engine* e, const struct part* p, ret[2] *= cosmo->a2_inv; } -void convert_part_potential(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_potential(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { if (p->gpart != NULL) ret[0] = gravity_get_comoving_potential(p->gpart); @@ -176,8 +180,10 @@ void convert_part_potential(const struct engine* e, const struct part* p, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void hydro_write_particles(const struct part* parts, const struct xpart* xparts, - struct io_props* list, int* num_fields) { +INLINE static void hydro_write_particles(const struct part* parts, + const struct xpart* xparts, + struct io_props* list, + int* num_fields) { *num_fields = 11; @@ -215,7 +221,7 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -void hydro_write_flavour(hid_t h_grpsph) { +INLINE static void hydro_write_flavour(hid_t h_grpsph) { /* Gradient information */ io_write_attribute_s(h_grpsph, "Gradient reconstruction model", HYDRO_GRADIENT_IMPLEMENTATION); @@ -239,6 +245,6 @@ void hydro_write_flavour(hid_t h_grpsph) { * * @return 1 if entropy is in 'internal energy', 0 otherwise. */ -int writeEntropyFlag(void) { return 0; } +INLINE static int writeEntropyFlag(void) { return 0; } #endif /* SWIFT_GIZMO_MFV_HYDRO_IO_H */ diff --git a/src/hydro/Minimal/hydro_io.h b/src/hydro/Minimal/hydro_io.h index 846462a28..833103e7a 100644 --- a/src/hydro/Minimal/hydro_io.h +++ b/src/hydro/Minimal/hydro_io.h @@ -45,8 +45,9 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void hydro_read_particles(struct part* parts, struct io_props* list, - int* num_fields) { +INLINE static void hydro_read_particles(struct part* parts, + struct io_props* list, + int* num_fields) { *num_fields = 8; @@ -69,20 +70,21 @@ void hydro_read_particles(struct part* parts, struct io_props* list, UNIT_CONV_DENSITY, parts, rho); } -void convert_S(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_S(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_entropy(p); } -void convert_P(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_P(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_pressure(p); } -void convert_part_pos(const struct engine* e, const struct part* p, - const struct xpart* xp, double* ret) { +INLINE static void convert_part_pos(const struct engine* e, + const struct part* p, + const struct xpart* xp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -95,8 +97,9 @@ void convert_part_pos(const struct engine* e, const struct part* p, } } -void convert_part_vel(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_vel(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -129,8 +132,9 @@ void convert_part_vel(const struct engine* e, const struct part* p, ret[2] *= cosmo->a2_inv; } -void convert_part_potential(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_potential(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { if (p->gpart != NULL) ret[0] = gravity_get_comoving_potential(p->gpart); @@ -146,8 +150,10 @@ void convert_part_potential(const struct engine* e, const struct part* p, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void hydro_write_particles(const struct part* parts, const struct xpart* xparts, - struct io_props* list, int* num_fields) { +INLINE static void hydro_write_particles(const struct part* parts, + const struct xpart* xparts, + struct io_props* list, + int* num_fields) { *num_fields = 10; @@ -182,7 +188,7 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -void hydro_write_flavour(hid_t h_grpsph) { +INLINE static void hydro_write_flavour(hid_t h_grpsph) { /* Viscosity and thermal conduction */ /* Nothing in this minimal model... */ @@ -200,6 +206,6 @@ void hydro_write_flavour(hid_t h_grpsph) { * * @return 1 if entropy is in 'internal energy', 0 otherwise. */ -int writeEntropyFlag(void) { return 0; } +INLINE static int writeEntropyFlag(void) { return 0; } #endif /* SWIFT_MINIMAL_HYDRO_IO_H */ diff --git a/src/hydro/MinimalMultiMat/hydro_io.h b/src/hydro/MinimalMultiMat/hydro_io.h index a1b6afa78..5542b93ae 100644 --- a/src/hydro/MinimalMultiMat/hydro_io.h +++ b/src/hydro/MinimalMultiMat/hydro_io.h @@ -46,8 +46,9 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void hydro_read_particles(struct part* parts, struct io_props* list, - int* num_fields) { +INLINE static void hydro_read_particles(struct part* parts, + struct io_props* list, + int* num_fields) { *num_fields = 9; @@ -72,20 +73,21 @@ void hydro_read_particles(struct part* parts, struct io_props* list, io_make_input_field("MaterialID", INT, 1, OPTIONAL, 1, parts, mat_id); } -void convert_S(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_S(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_entropy(p); } -void convert_P(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_P(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_pressure(p); } -void convert_part_pos(const struct engine* e, const struct part* p, - const struct xpart* xp, double* ret) { +INLINE static void convert_part_pos(const struct engine* e, + const struct part* p, + const struct xpart* xp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -98,8 +100,9 @@ void convert_part_pos(const struct engine* e, const struct part* p, } } -void convert_part_vel(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_vel(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -132,8 +135,9 @@ void convert_part_vel(const struct engine* e, const struct part* p, ret[2] *= cosmo->a2_inv; } -void convert_part_potential(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_potential(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { if (p->gpart != NULL) ret[0] = gravity_get_comoving_potential(p->gpart); @@ -149,8 +153,10 @@ void convert_part_potential(const struct engine* e, const struct part* p, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void hydro_write_particles(const struct part* parts, const struct xpart* xparts, - struct io_props* list, int* num_fields) { +INLINE static void hydro_write_particles(const struct part* parts, + const struct xpart* xparts, + struct io_props* list, + int* num_fields) { *num_fields = 11; @@ -186,7 +192,7 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -void hydro_write_flavour(hid_t h_grpsph) { +INLINE static void hydro_write_flavour(hid_t h_grpsph) { /* Viscosity and thermal conduction */ /* Nothing in this minimal model... */ @@ -204,6 +210,6 @@ void hydro_write_flavour(hid_t h_grpsph) { * * @return 1 if entropy is in 'internal energy', 0 otherwise. */ -int writeEntropyFlag(void) { return 0; } +INLINE static int writeEntropyFlag(void) { return 0; } #endif /* SWIFT_MINIMAL_MULTI_MAT_HYDRO_IO_H */ diff --git a/src/hydro/PressureEnergy/hydro_io.h b/src/hydro/PressureEnergy/hydro_io.h index 521f0ba28..4f168ed81 100644 --- a/src/hydro/PressureEnergy/hydro_io.h +++ b/src/hydro/PressureEnergy/hydro_io.h @@ -43,8 +43,9 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void hydro_read_particles(struct part* parts, struct io_props* list, - int* num_fields) { +INLINE static void hydro_read_particles(struct part* parts, + struct io_props* list, + int* num_fields) { *num_fields = 8; @@ -67,26 +68,27 @@ void hydro_read_particles(struct part* parts, struct io_props* list, UNIT_CONV_DENSITY, parts, rho); } -void convert_u(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_u(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_internal_energy(p); } -void convert_S(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_S(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_entropy(p); } -void convert_P(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_P(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_pressure(p); } -void convert_part_pos(const struct engine* e, const struct part* p, - const struct xpart* xp, double* ret) { +INLINE static void convert_part_pos(const struct engine* e, + const struct part* p, + const struct xpart* xp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -99,8 +101,9 @@ void convert_part_pos(const struct engine* e, const struct part* p, } } -void convert_part_vel(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_vel(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -140,8 +143,10 @@ void convert_part_vel(const struct engine* e, const struct part* p, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void hydro_write_particles(const struct part* parts, const struct xpart* xparts, - struct io_props* list, int* num_fields) { +INLINE static void hydro_write_particles(const struct part* parts, + const struct xpart* xparts, + struct io_props* list, + int* num_fields) { *num_fields = 9; @@ -173,7 +178,7 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -void hydro_write_flavour(hid_t h_grpsph) { +INLINE static void hydro_write_flavour(hid_t h_grpsph) { /* Viscosity and thermal conduction */ /* Nothing in this minimal model... */ @@ -191,6 +196,6 @@ void hydro_write_flavour(hid_t h_grpsph) { * * @return 1 if entropy is in 'internal energy', 0 otherwise. */ -int writeEntropyFlag(void) { return 0; } +INLINE static int writeEntropyFlag(void) { return 0; } #endif /* SWIFT_MINIMAL_HYDRO_IO_H */ diff --git a/src/hydro/PressureEntropy/hydro_io.h b/src/hydro/PressureEntropy/hydro_io.h index 59c49c066..f2247c234 100644 --- a/src/hydro/PressureEntropy/hydro_io.h +++ b/src/hydro/PressureEntropy/hydro_io.h @@ -42,8 +42,9 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void hydro_read_particles(struct part* parts, struct io_props* list, - int* num_fields) { +INLINE static void hydro_read_particles(struct part* parts, + struct io_props* list, + int* num_fields) { *num_fields = 8; @@ -67,20 +68,21 @@ void hydro_read_particles(struct part* parts, struct io_props* list, UNIT_CONV_DENSITY, parts, rho); } -void convert_u(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_u(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_internal_energy(p); } -void convert_P(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_P(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_comoving_pressure(p); } -void convert_part_pos(const struct engine* e, const struct part* p, - const struct xpart* xp, double* ret) { +INLINE static void convert_part_pos(const struct engine* e, + const struct part* p, + const struct xpart* xp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -93,8 +95,9 @@ void convert_part_pos(const struct engine* e, const struct part* p, } } -void convert_part_vel(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_vel(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { const int with_cosmology = (e->policy & engine_policy_cosmology); const struct cosmology* cosmo = e->cosmology; @@ -127,8 +130,9 @@ void convert_part_vel(const struct engine* e, const struct part* p, ret[2] *= cosmo->a2_inv; } -void convert_part_potential(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_part_potential(const struct engine* e, + const struct part* p, + const struct xpart* xp, float* ret) { if (p->gpart != NULL) ret[0] = gravity_get_comoving_potential(p->gpart); @@ -143,8 +147,10 @@ void convert_part_potential(const struct engine* e, const struct part* p, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void hydro_write_particles(const struct part* parts, const struct xpart* xparts, - struct io_props* list, int* num_fields) { +INLINE static void hydro_write_particles(const struct part* parts, + const struct xpart* xparts, + struct io_props* list, + int* num_fields) { *num_fields = 11; @@ -180,7 +186,7 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -void hydro_write_flavour(hid_t h_grpsph) { +INLINE static void hydro_write_flavour(hid_t h_grpsph) { /* Viscosity and thermal conduction */ /* Nothing in this minimal model... */ @@ -201,6 +207,6 @@ void hydro_write_flavour(hid_t h_grpsph) { * * @return 1 if entropy is in 'internal energy', 0 otherwise. */ -int writeEntropyFlag(void) { return 0; } +INLINE static int writeEntropyFlag(void) { return 0; } #endif /* SWIFT_PRESSURE_ENTROPY_HYDRO_IO_H */ diff --git a/src/hydro/Shadowswift/hydro_io.h b/src/hydro/Shadowswift/hydro_io.h index 4a15ec845..1f6bb86e6 100644 --- a/src/hydro/Shadowswift/hydro_io.h +++ b/src/hydro/Shadowswift/hydro_io.h @@ -32,8 +32,9 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -void hydro_read_particles(struct part* parts, struct io_props* list, - int* num_fields) { +INLINE static void hydro_read_particles(struct part* parts, + struct io_props* list, + int* num_fields) { *num_fields = 8; @@ -64,8 +65,8 @@ void hydro_read_particles(struct part* parts, struct io_props* list, * @param p Particle. * @return Internal energy of the particle */ -void convert_u(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_u(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_internal_energy(p); } @@ -76,8 +77,8 @@ void convert_u(const struct engine* e, const struct part* p, * @param p Particle. * @return Entropic function of the particle */ -void convert_A(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_A(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { ret[0] = hydro_get_entropy(p); } @@ -88,8 +89,8 @@ void convert_A(const struct engine* e, const struct part* p, * @param p Particle. * @return Total energy of the particle */ -void convert_Etot(const struct engine* e, const struct part* p, - const struct xpart* xp, float* ret) { +INLINE static void convert_Etot(const struct engine* e, const struct part* p, + const struct xpart* xp, float* ret) { #ifdef SHADOWFAX_TOTAL_ENERGY return p->conserved.energy; #else @@ -107,8 +108,9 @@ void convert_Etot(const struct engine* e, const struct part* p, #endif } -void convert_part_pos(const struct engine* e, const struct part* p, - const struct xpart* xp, double* ret) { +INLINE static void convert_part_pos(const struct engine* e, + const struct part* p, + const struct xpart* xp, double* ret) { if (e->s->periodic) { ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]); @@ -128,8 +130,10 @@ void convert_part_pos(const struct engine* e, const struct part* p, * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -void hydro_write_particles(const struct part* parts, const struct xpart* xparts, - struct io_props* list, int* num_fields) { +INLINE static void hydro_write_particles(const struct part* parts, + const struct xpart* xparts, + struct io_props* list, + int* num_fields) { *num_fields = 13; @@ -168,7 +172,7 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts, * @brief Writes the current model of SPH to the file * @param h_grpsph The HDF5 group in which to write */ -void hydro_write_flavour(hid_t h_grpsph) { +INLINE static void hydro_write_flavour(hid_t h_grpsph) { /* Gradient information */ io_write_attribute_s(h_grpsph, "Gradient reconstruction model", HYDRO_GRADIENT_IMPLEMENTATION); @@ -189,4 +193,4 @@ void hydro_write_flavour(hid_t h_grpsph) { * * @return 1 if entropy is in 'internal energy', 0 otherwise. */ -int writeEntropyFlag(void) { return 0; } +INLINE static int writeEntropyFlag(void) { return 0; } diff --git a/src/stars/Default/star_io.h b/src/stars/Default/star_io.h index 2d7caacc0..7ad29f0a9 100644 --- a/src/stars/Default/star_io.h +++ b/src/stars/Default/star_io.h @@ -28,8 +28,8 @@ * @param list The list of i/o properties to read. * @param num_fields The number of i/o fields to read. */ -__attribute__((always_inline)) INLINE static void star_read_particles( - struct spart* sparts, struct io_props* list, int* num_fields) { +INLINE static void star_read_particles(struct spart* sparts, + struct io_props* list, int* num_fields) { /* Say how much we want to read */ *num_fields = 4; @@ -52,8 +52,9 @@ __attribute__((always_inline)) INLINE static void star_read_particles( * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. */ -__attribute__((always_inline)) INLINE static void star_write_particles( - const struct spart* sparts, struct io_props* list, int* num_fields) { +INLINE static void star_write_particles(const struct spart* sparts, + struct io_props* list, + int* num_fields) { /* Say how much we want to read */ *num_fields = 4; -- GitLab From abaa8d020afa44e250cdc85099c1494bfd05a374 Mon Sep 17 00:00:00 2001 From: lhausamm Date: Fri, 1 Jun 2018 09:28:52 +0200 Subject: [PATCH 39/39] testSelectOuput.sh can be run without autotools --- tests/testSelectOutput.py | 2 +- tests/testSelectOutput.sh.in | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/testSelectOutput.py b/tests/testSelectOutput.py index c50afe894..aec7f4671 100644 --- a/tests/testSelectOutput.py +++ b/tests/testSelectOutput.py @@ -23,7 +23,7 @@ import h5py filename = "testSelectOutput_0000.hdf5" -log_filename = "testSelectOutput.sh.log" +log_filename = "select_output.log" # Read the simulation data sim = h5py.File(filename, "r") diff --git a/tests/testSelectOutput.sh.in b/tests/testSelectOutput.sh.in index 5edf8d10e..85fd99964 100644 --- a/tests/testSelectOutput.sh.in +++ b/tests/testSelectOutput.sh.in @@ -4,9 +4,11 @@ echo "Creating initial conditions" python @srcdir@/makeInput.py echo "Generating output" -./testSelectOutput +./testSelectOutput 2>&1 | tee select_output.log echo "Checking output" python @srcdir@/testSelectOutput.py -rm -f testSelectOutput_0000.hdf5 testSelectOutput.xmf +rm -f testSelectOutput_0000.hdf5 testSelectOutput.xmf select_output.log + +echo "Test passed" -- GitLab