diff --git a/examples/SedovBlast_3D/sedov.yml b/examples/SedovBlast_3D/sedov.yml index c7212983ffaba57e0ee849372c73f9c76ccc4cbf..6b64d707a866f6abf499530105dc7af641ef7c3e 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 ec42f514398ddcb7d3fbd29344903258100f91c9..ab8fca8197550470b18c5327ed3a2a5ed5dc6ff3 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 bb4c3eb9508848607719406dd5567069f3013d5f..faa41976fddd4fcebc09831fdde6e7f1fd11d048 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 47eb17a5f4cc35f9e982e1f432a3260dbf9e5926..706387582547e5c806624e1d63a1eef72a46d3ff 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 950f0ef4f79f7d44c362c2967cda4dcc5a796545..76278ac93ac2e374cee8182383f576c96f277798 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 5cae5ec4af35aaa966a170a6cd6bf796f708b4b8..d9d7f2cb8b7d9f964de17bf58530a8d5f9f7be20 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 d3db4d3fc2ee5c57075959280193597a314dd8f8..244a8c65fb9071072e918aa4b177dc48e08e6d76 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,