diff --git a/examples/main.c b/examples/main.c index 1b211ad946c432dfc9fb03d7003e9456e9f1ad41..f7f9486779ac38953804c6a32cacf1bf866eabc1 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 75df3f7e86f9154030ee750dd98b5c2714185a14..791db2758290e400d4ed9ffe5b8e0d4303057874 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 399459f716262ff90f80b93c75ce3d630c978144..75799d8be01781a46de03ff98e4a7a8db10cfb2e 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 c4bf2c724431d1fb8315ef82458428bc4a6b5f26..47eb17a5f4cc35f9e982e1f432a3260dbf9e5926 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 f62866456fc73c8461946305b7858075414bd26f..9a7a7ede8b5c7d5633543f083d6bef451c0f0059 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 e04a80e997e2f0716fdac0be9d8c28f7d51bc6fd..72f440b2e3c0efe4b86c8adb3c06bbe20d1a635c 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 06bf551e98f6093e744ef9cb18c2895731485f24..6cbbcbe80bae347ef9997deff7f576a305e0f0ff 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 04a4e7b9579847fc48241563bad31c7f4537cdd5..449154136b1c0f02648108246a4eaa44cd2ab8d4 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 4fa18a46a703f4271d9a1e16f86ccb223254393b..ed1fd21b6d2862eb7208dec4ac105359da400794 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);