diff --git a/src/chemistry/GEAR/csds_chemistry.c b/src/chemistry/GEAR/csds_chemistry.c index 9e8a7a5bafb10c183994c190a537a05eb114def4..a06ba2e701cc84cb9ea36b14252aaecd9d823580 100644 --- a/src/chemistry/GEAR/csds_chemistry.c +++ b/src/chemistry/GEAR/csds_chemistry.c @@ -24,18 +24,16 @@ #include "csds_tools.h" /* Hydro part */ -const int chemistry_csds_field_size_part[chemistry_csds_field_part_count] = - { - member_size(struct part, chemistry_data.smoothed_metal_mass_fraction) + - member_size(struct part, chemistry_data.metal_mass), +const int chemistry_csds_field_size_part[chemistry_csds_field_part_count] = { + member_size(struct part, chemistry_data.smoothed_metal_mass_fraction) + + member_size(struct part, chemistry_data.metal_mass), }; int chemistry_csds_local_to_global_part[chemistry_csds_field_part_count]; /* Stellar part */ -const int - chemistry_csds_field_size_spart[chemistry_csds_field_spart_count] = { - member_size(struct spart, chemistry_data.metal_mass_fraction), +const int chemistry_csds_field_size_spart[chemistry_csds_field_spart_count] = { + member_size(struct spart, chemistry_data.metal_mass_fraction), }; int chemistry_csds_local_to_global_spart[chemistry_csds_field_spart_count]; diff --git a/src/chemistry/GEAR/csds_chemistry.h b/src/chemistry/GEAR/csds_chemistry.h index 43c3b24f32fd46b5c4060a9817d0d3ce18e0abf0..bf5997f190584586432f93ce23693686d5a368d9 100644 --- a/src/chemistry/GEAR/csds_chemistry.h +++ b/src/chemistry/GEAR/csds_chemistry.h @@ -29,8 +29,7 @@ #include "csds_python_tools.h" /* Index of the mask in the header mask array */ -extern int - chemistry_csds_local_to_global_part[chemistry_csds_field_part_count]; +extern int chemistry_csds_local_to_global_part[chemistry_csds_field_part_count]; extern int chemistry_csds_local_to_global_spart[chemistry_csds_field_spart_count]; @@ -74,11 +73,13 @@ chemistry_csds_reader_link_derivatives_spart(struct header *head) {} * @param params The simulation's #csds_parameters. */ __attribute__((always_inline)) INLINE static void -chemistry_csds_interpolate_field_part( - const double t_before, const struct csds_field *restrict before, - const double t_after, const struct csds_field *restrict after, - void *restrict output, const double t, const int field, - const struct csds_parameters *params) { +chemistry_csds_interpolate_field_part(const double t_before, + const struct csds_field *restrict before, + const double t_after, + const struct csds_field *restrict after, + void *restrict output, const double t, + const int field, + const struct csds_parameters *params) { #ifdef SWIFT_DEBUG_CHECKS /* Check the times */ if (t_before > t || t_after < t) { @@ -92,8 +93,8 @@ chemistry_csds_interpolate_field_part( switch (field) { case chemistry_csds_field_part_all: interpolate_linear_double_ND(t_before, before, t_after, after, output, t, - 2 * GEAR_CHEMISTRY_ELEMENT_COUNT, /* periodic */0, - params); + 2 * GEAR_CHEMISTRY_ELEMENT_COUNT, + /* periodic */ 0, params); break; default: @@ -119,11 +120,13 @@ chemistry_csds_interpolate_field_part( * @param params The simulation's #csds_parameters. */ __attribute__((always_inline)) INLINE static void -chemistry_csds_interpolate_field_spart( - const double t_before, const struct csds_field *restrict before, - const double t_after, const struct csds_field *restrict after, - void *restrict output, const double t, const int field, - const struct csds_parameters *params) { +chemistry_csds_interpolate_field_spart(const double t_before, + const struct csds_field *restrict before, + const double t_after, + const struct csds_field *restrict after, + void *restrict output, const double t, + const int field, + const struct csds_parameters *params) { #ifdef SWIFT_DEBUG_CHECKS /* Check the times */ diff --git a/src/chemistry/none/csds_chemistry.c b/src/chemistry/none/csds_chemistry.c index 8a3b440ac5a54ad9fd15eacb131ae98f0c071217..98e364fa54e2c76f6b02a1b6d34ca3c10432f4c3 100644 --- a/src/chemistry/none/csds_chemistry.c +++ b/src/chemistry/none/csds_chemistry.c @@ -24,13 +24,12 @@ #include "csds_tools.h" /* Hydro part */ -const int chemistry_csds_field_size_part[chemistry_csds_field_part_count] = - {}; +const int chemistry_csds_field_size_part[chemistry_csds_field_part_count] = {}; int chemistry_csds_local_to_global_part[chemistry_csds_field_part_count]; /* Stellar part */ -const int - chemistry_csds_field_size_spart[chemistry_csds_field_spart_count] = {}; +const int chemistry_csds_field_size_spart[chemistry_csds_field_spart_count] = + {}; int chemistry_csds_local_to_global_spart[chemistry_csds_field_spart_count]; diff --git a/src/chemistry/none/csds_chemistry.h b/src/chemistry/none/csds_chemistry.h index 2ff913cc1edea79cec3d13002dcd51d064a1ec90..4e44f2dcd3a06b0bbc9b71b10a4c80fc3478c30f 100644 --- a/src/chemistry/none/csds_chemistry.h +++ b/src/chemistry/none/csds_chemistry.h @@ -29,8 +29,7 @@ #include "csds_python_tools.h" /* Index of the mask in the header mask array */ -extern int - chemistry_csds_local_to_global_part[chemistry_csds_field_part_count]; +extern int chemistry_csds_local_to_global_part[chemistry_csds_field_part_count]; extern int chemistry_csds_local_to_global_spart[chemistry_csds_field_spart_count]; @@ -74,11 +73,13 @@ chemistry_csds_reader_link_derivatives_spart(struct header *head) {} * @param params The simulation's #csds_parameters. */ __attribute__((always_inline)) INLINE static void -chemistry_csds_interpolate_field_part( - const double t_before, const struct csds_field *restrict before, - const double t_after, const struct csds_field *restrict after, - void *restrict output, const double t, const int field, - const struct csds_parameters *params) {} +chemistry_csds_interpolate_field_part(const double t_before, + const struct csds_field *restrict before, + const double t_after, + const struct csds_field *restrict after, + void *restrict output, const double t, + const int field, + const struct csds_parameters *params) {} /** * @brief Interpolate a field of the #spart at the given time. @@ -98,11 +99,13 @@ chemistry_csds_interpolate_field_part( * @param params The simulation's #csds_parameters. */ __attribute__((always_inline)) INLINE static void -chemistry_csds_interpolate_field_spart( - const double t_before, const struct csds_field *restrict before, - const double t_after, const struct csds_field *restrict after, - void *restrict output, const double t, const int field, - const struct csds_parameters *params) {} +chemistry_csds_interpolate_field_spart(const double t_before, + const struct csds_field *restrict before, + const double t_after, + const struct csds_field *restrict after, + void *restrict output, const double t, + const int field, + const struct csds_parameters *params) {} #ifdef HAVE_PYTHON /** diff --git a/src/csds_header.c b/src/csds_header.c index 6d15de01586b6d7476b2571445e9e5ee81b9838d..e75c3137f33d7f5dfe6ca9feca9be24684e7e1a5 100644 --- a/src/csds_header.c +++ b/src/csds_header.c @@ -94,35 +94,34 @@ void header_change_offset_direction(struct header *h, size_t offset = CSDS_VERSION_SIZE + 2 * sizeof(int); csds_loader_io_write_data(h->log->log.map + offset, sizeof(unsigned int), - &new_value); + &new_value); } /** * @brief Set the links between the local (module) and global (header) indexes. */ -#define set_links_local_global_internal(MODULE, PART) \ - for (int j = 0; j < MODULE##_csds_field##PART##_count; j++) { \ - MODULE##_csds_local_to_global##PART[j] = -1; \ - for (int i = 0; i < h->masks_count; i++) { \ - if (strcmp(h->masks[i].name, MODULE##_csds_field_names##PART[j]) == \ - 0) { \ - MODULE##_csds_local_to_global##PART[j] = i; \ - break; \ - } \ - } \ - \ - /* Check if everything is fine. */ \ - const int index = MODULE##_csds_local_to_global##PART[j]; \ - if (index == -1) { \ - error("Field %s in " #MODULE " is not set", \ - MODULE##_csds_field_names##PART[j]); \ - } \ - if (h->masks[index].size != MODULE##_csds_field_size##PART[j]) { \ - error("Field %s in " #MODULE " does not have the correct size", \ - MODULE##_csds_field_names##PART[j]); \ - } \ - } \ - \ +#define set_links_local_global_internal(MODULE, PART) \ + for (int j = 0; j < MODULE##_csds_field##PART##_count; j++) { \ + MODULE##_csds_local_to_global##PART[j] = -1; \ + for (int i = 0; i < h->masks_count; i++) { \ + if (strcmp(h->masks[i].name, MODULE##_csds_field_names##PART[j]) == 0) { \ + MODULE##_csds_local_to_global##PART[j] = i; \ + break; \ + } \ + } \ + \ + /* Check if everything is fine. */ \ + const int index = MODULE##_csds_local_to_global##PART[j]; \ + if (index == -1) { \ + error("Field %s in " #MODULE " is not set", \ + MODULE##_csds_field_names##PART[j]); \ + } \ + if (h->masks[index].size != MODULE##_csds_field_size##PART[j]) { \ + error("Field %s in " #MODULE " does not have the correct size", \ + MODULE##_csds_field_names##PART[j]); \ + } \ + } \ + \ MODULE##_csds_reader_link_derivatives##PART(h); /** @@ -178,13 +177,12 @@ void header_read(struct header *h, struct csds_logfile *log) { /* Read offset to first record. */ h->offset_first_record = 0; - map = csds_loader_io_read_data(map, CSDS_OFFSET_SIZE, - &h->offset_first_record); + map = + csds_loader_io_read_data(map, CSDS_OFFSET_SIZE, &h->offset_first_record); /* Read the size of the strings. */ h->string_length = 0; - map = - csds_loader_io_read_data(map, sizeof(unsigned int), &h->string_length); + map = csds_loader_io_read_data(map, sizeof(unsigned int), &h->string_length); /* Check if value defined in this file is large enough. */ if (STRING_SIZE < h->string_length) { @@ -210,8 +208,8 @@ void header_read(struct header *h, struct csds_logfile *log) { h->masks[i].mask = 1 << i; /* Read the mask data size. */ - map = csds_loader_io_read_data(map, sizeof(unsigned int), - &h->masks[i].size); + map = + csds_loader_io_read_data(map, sizeof(unsigned int), &h->masks[i].size); /* Print the information. */ if (reader->verbose > 1) { diff --git a/src/csds_index.c b/src/csds_index.c index 13bafda28ea1e25871702dab71e459cd5ceba190..be3c640ef756cce7315850d490233cc02d38949b 100644 --- a/src/csds_index.c +++ b/src/csds_index.c @@ -56,8 +56,7 @@ * @param index The #csds_index. * @param filename The filename of the index file. */ -void csds_index_read_header(struct csds_index *index, - const char *filename) { +void csds_index_read_header(struct csds_index *index, const char *filename) { /* Open the file */ if (index->reader->verbose > 1) { @@ -157,7 +156,7 @@ struct index_data *csds_index_get_data(struct csds_index *index, int type) { * @param type The particle type. */ struct index_data *csds_index_get_created_history(struct csds_index *index, - int type) { + int type) { /* Get the position after the previous array. */ char *ret = (char *)csds_index_get_data(index, swift_type_count); @@ -184,7 +183,7 @@ struct index_data *csds_index_get_created_history(struct csds_index *index, * @param type The particle type. */ struct index_data *csds_index_get_removed_history(struct csds_index *index, - int type) { + int type) { /* Get the position after the previous array. */ char *ret = (char *)csds_index_get_created_history(index, swift_type_count); @@ -230,7 +229,7 @@ int csds_index_contains_time_array(struct csds_index *index) { * @param sorted Does the file needs to be sorted? */ void csds_index_map_file(struct csds_index *index, const char *filename, - int sorted) { + int sorted) { /* Un-map previous file */ if (index->index.map != NULL) { error_python("Trying to remap."); @@ -243,7 +242,7 @@ void csds_index_map_file(struct csds_index *index, const char *filename, } /* Map the index file */ csds_loader_io_mmap_file(&index->index, filename, - /* read_only */ 0); + /* read_only */ 0); /* Sort the file */ for (int i = 0; i < swift_type_count; i++) { if (index->nparts[i] != 0) { @@ -265,7 +264,7 @@ void csds_index_map_file(struct csds_index *index, const char *filename, /* Map the index file */ csds_loader_io_mmap_file(&index->index, filename, - /* read_only */ 1); + /* read_only */ 1); } /** @@ -289,8 +288,8 @@ void csds_index_free(struct csds_index *index) { * * @return The offset of the particle or 0 if not found. */ -size_t csds_index_get_particle_offset(struct csds_index *index, - long long id, int type) { +size_t csds_index_get_particle_offset(struct csds_index *index, long long id, + int type) { /* Define a few variables */ const struct index_data *data = csds_index_get_data(index, type); size_t left = 0; @@ -317,8 +316,7 @@ size_t csds_index_get_particle_offset(struct csds_index *index, * @param index The #csds_index. * @param reader The #csds_reader. */ -void csds_index_init(struct csds_index *index, - struct csds_reader *reader) { +void csds_index_init(struct csds_index *index, struct csds_reader *reader) { /* Set the mapped file to NULL */ index->index.map = NULL; @@ -340,7 +338,7 @@ void csds_index_init(struct csds_index *index, * @return Did we find the particle? */ int csds_index_get_offset(struct csds_index *index, int64_t id, int type, - uint64_t *offset) { + uint64_t *offset) { /* Ensure that the file is sorted according to the ids. */ if (!index->is_sorted) { diff --git a/src/csds_index.h b/src/csds_index.h index 80181f35023beaca624ab200839ab08b2e3ed59e..128cc2b650c384631419aedc59dcf21c4fc88d1f 100644 --- a/src/csds_index.h +++ b/src/csds_index.h @@ -78,21 +78,20 @@ struct csds_index { int csds_index_contains_time_array(struct csds_index *index); void csds_index_write_sorted(struct csds_index *index); -void csds_index_init(struct csds_index *index, - struct csds_reader *reader); +void csds_index_init(struct csds_index *index, struct csds_reader *reader); void csds_index_read_header(struct csds_index *index, const char *filename); void csds_index_map_file(struct csds_index *index, const char *filename, - int sorted); -size_t csds_index_get_particle_offset(struct csds_index *index, - long long id, int type); + int sorted); +size_t csds_index_get_particle_offset(struct csds_index *index, long long id, + int type); void csds_index_free(struct csds_index *index); void csds_index_sort_file(struct csds_index *index); int csds_index_get_offset(struct csds_index *index, int64_t id, int type, - uint64_t *offset); + uint64_t *offset); struct index_data *csds_index_get_data(struct csds_index *index, int type); struct index_data *csds_index_get_created_history(struct csds_index *index, - int type); + int type); struct index_data *csds_index_get_removed_history(struct csds_index *index, - int type); + int type); #endif // CSDS_CSDS_INDEX_H diff --git a/src/csds_loader_io.c b/src/csds_loader_io.c index 71af9b542336879631082c9d8de89a620f48383e..d6874bb0c684b8d4bcb6c36e05963b47dad62197 100644 --- a/src/csds_loader_io.c +++ b/src/csds_loader_io.c @@ -52,7 +52,7 @@ size_t csds_loader_io_get_file_size(int fd) { * */ void csds_loader_io_mmap_file(struct mapped_file *map, const char *filename, - int read_only) { + int read_only) { /* open the file. */ int fd; diff --git a/src/csds_loader_io.h b/src/csds_loader_io.h index 4829fb56c6d0a0fecc020c3b1f9000a29dd77e11..56ba179c3d4626935f8b7c01fd1862b8854385e1 100644 --- a/src/csds_loader_io.h +++ b/src/csds_loader_io.h @@ -40,7 +40,7 @@ struct mapped_file { size_t csds_loader_io_get_file_size(int fd); void csds_loader_io_mmap_file(struct mapped_file *map, const char *filename, - int read_only); + int read_only); void csds_loader_io_munmap_file(struct mapped_file *map); /** diff --git a/src/csds_logfile.c b/src/csds_logfile.c index 39efabaa979f9c2d54917ae23358b9077ef4e96a..39541b5a03bcb32f816b2fb171605dbe85b1d3a1 100644 --- a/src/csds_logfile.c +++ b/src/csds_logfile.c @@ -31,8 +31,7 @@ * @param only_header Read only the header. */ void csds_logfile_init_from_file(struct csds_logfile *log, char *filename, - struct csds_reader *reader, - int only_header) { + struct csds_reader *reader, int only_header) { /* Set the pointer to the reader. */ log->reader = reader; @@ -44,7 +43,7 @@ void csds_logfile_init_from_file(struct csds_logfile *log, char *filename, /* Open file, map it and get its size. */ if (reader->verbose > 1) message("Mapping the log file."); csds_loader_io_mmap_file(&log->log, filename, - /* read_only */ 1); + /* read_only */ 1); /* Read the header. */ if (reader->verbose > 1) message("Reading the header."); @@ -165,7 +164,7 @@ void csds_logfile_reverse_offset(struct csds_logfile *log, char *filename) { /* Close and reopen the file in write mode. */ csds_loader_io_munmap_file(&log->log); csds_loader_io_mmap_file(&log->log, filename, - /* read_only */ 0); + /* read_only */ 0); /* Get pointers */ struct header *header = &log->header; @@ -238,5 +237,5 @@ void csds_logfile_reverse_offset(struct csds_logfile *log, char *filename) { /* Close and reopen the file in read mode. */ csds_loader_io_munmap_file(&log->log); csds_loader_io_mmap_file(&log->log, filename, - /* read_only */ 1); + /* read_only */ 1); } diff --git a/src/csds_logfile.h b/src/csds_logfile.h index 8d2bc92f6d981851fb528cae9e4365435c6851b9..6e4c6cae3fb70fea889aa71aaf158bf0810d1340 100644 --- a/src/csds_logfile.h +++ b/src/csds_logfile.h @@ -55,8 +55,7 @@ struct csds_logfile { }; void csds_logfile_init_from_file(struct csds_logfile *log, char *filename, - struct csds_reader *reader, - int only_header); + struct csds_reader *reader, int only_header); void csds_logfile_reverse_offset(struct csds_logfile *log, char *filename); void csds_logfile_free(struct csds_logfile *log); diff --git a/src/csds_parameters.c b/src/csds_parameters.c index b2bd59e59ffc83c07c522dc1287d6fd8c3ab2e93..bd2f7f65f2c252bad379fc67ba9ce80c7bd7fa74 100644 --- a/src/csds_parameters.c +++ b/src/csds_parameters.c @@ -37,8 +37,8 @@ * */ void csds_parameters_init(struct csds_parameters *params, - const struct csds_reader *reader, - int number_threads) { + const struct csds_reader *reader, + int number_threads) { /* Generate filename */ char filename[STRING_SIZE]; @@ -78,17 +78,17 @@ void csds_parameters_init(struct csds_parameters *params, } /* Read the initial number of particles. */ - for(int i = 0; i < swift_type_count; i++) { + for (int i = 0; i < swift_type_count; i++) { params->approximate_number_particles[i] = 0; } params->approximate_number_particles[swift_type_gas] = - parser_get_param_longlong(&swift_params, "Header:NumberParts"); + parser_get_param_longlong(&swift_params, "Header:NumberParts"); params->approximate_number_particles[swift_type_stars] = - parser_get_param_longlong(&swift_params, "Header:NumberSParts"); + parser_get_param_longlong(&swift_params, "Header:NumberSParts"); params->approximate_number_particles[swift_type_dark_matter] = - parser_get_param_longlong(&swift_params, "Header:NumberGParts"); + parser_get_param_longlong(&swift_params, "Header:NumberGParts"); /* Read the maximal fraction of tagged elements */ params->arrays_maximal_tagged_fraction = parser_get_opt_param_float( - &swift_params, "ReaderOptions:arrays_maximal_tagged_fraction", 0.15); + &swift_params, "ReaderOptions:arrays_maximal_tagged_fraction", 0.15); } diff --git a/src/csds_parameters.h b/src/csds_parameters.h index 7b1361a0e9d36070a1c43edc6993eaafc9a62c1e..e9c40e8830975b62773a92c878e21a96790a4274 100644 --- a/src/csds_parameters.h +++ b/src/csds_parameters.h @@ -57,7 +57,6 @@ struct csds_parameters { }; void csds_parameters_init(struct csds_parameters *params, - const struct csds_reader *reader, - int number_threads); + const struct csds_reader *reader, int number_threads); #endif // CSDS_CSDS_PARAMETERS_H diff --git a/src/csds_particle.c b/src/csds_particle.c index cac3ec6d39bf4a4cf52e3415fcbbf7e2e82fd4da..d63c9d1a88202aadda5f37370d50548c6e7a8f4e 100644 --- a/src/csds_particle.c +++ b/src/csds_particle.c @@ -106,9 +106,9 @@ __attribute__((always_inline)) INLINE size_t csds_particle_read_field( * @return The special flag. */ __attribute__((always_inline)) INLINE enum csds_special_flags -csds_particle_read_special_flag(const struct csds_reader *reader, - size_t offset, size_t *mask, size_t *h_offset, - int *data, int *part_type) { +csds_particle_read_special_flag(const struct csds_reader *reader, size_t offset, + size_t *mask, size_t *h_offset, int *data, + int *part_type) { /* Get a few pointers. */ const struct header *h = &reader->log.header; @@ -132,8 +132,8 @@ csds_particle_read_special_flag(const struct csds_reader *reader, /* Read the special flag */ uint32_t packed_data = 0; - map = csds_loader_io_read_data( - map, h->masks[csds_index_special_flags].size, &packed_data); + map = csds_loader_io_read_data(map, h->masks[csds_index_special_flags].size, + &packed_data); return csds_unpack_flags_and_data(packed_data, data, part_type); } @@ -150,12 +150,14 @@ csds_particle_read_special_flag(const struct csds_reader *reader, * @param field The field to reconstruct. * @param params The simulation's #csds_parameters. */ -void csds_particle_interpolate_field( - const double time_before, const struct csds_field *restrict before, - const double time_after, const struct csds_field *restrict after, - void *restrict output, const double time, - const struct field_information *field, enum part_type type, - const struct csds_parameters *params) { +void csds_particle_interpolate_field(const double time_before, + const struct csds_field *restrict before, + const double time_after, + const struct csds_field *restrict after, + void *restrict output, const double time, + const struct field_information *field, + enum part_type type, + const struct csds_parameters *params) { /* Select the correct interpolation */ switch (type) { @@ -165,14 +167,14 @@ void csds_particle_interpolate_field( switch (field->module) { case field_module_default: hydro_csds_interpolate_field(time_before, before, time_after, after, - output, time, field->local_index, - params); + output, time, field->local_index, + params); break; case field_module_chemistry: - chemistry_csds_interpolate_field_part( - time_before, before, time_after, after, output, time, - field->local_index, params); + chemistry_csds_interpolate_field_part(time_before, before, time_after, + after, output, time, + field->local_index, params); break; default: @@ -187,8 +189,7 @@ void csds_particle_interpolate_field( if (field->module != field_module_default) error("Module not implemented"); gravity_csds_interpolate_field(time_before, before, time_after, after, - output, time, field->local_index, - params); + output, time, field->local_index, params); break; /* Stars */ @@ -196,8 +197,8 @@ void csds_particle_interpolate_field( switch (field->module) { case field_module_default: stars_csds_interpolate_field(time_before, before, time_after, after, - output, time, field->local_index, - params); + output, time, field->local_index, + params); break; case field_module_chemistry: @@ -207,9 +208,9 @@ void csds_particle_interpolate_field( break; case field_module_star_formation: - star_formation_csds_interpolate_field( - time_before, before, time_after, after, output, time, - field->local_index, params); + star_formation_csds_interpolate_field(time_before, before, time_after, + after, output, time, + field->local_index, params); break; default: diff --git a/src/csds_particle.h b/src/csds_particle.h index 2c8424f17ca75f93e11df4ebf52b0106fbc9f323..189b2dab77f88b054849165eba8dd0c21354c075 100644 --- a/src/csds_particle.h +++ b/src/csds_particle.h @@ -43,19 +43,21 @@ enum csds_reader_type { csds_reader_lin, /* Linear interpolation. */ }; -size_t csds_particle_read_field(const struct csds_reader *reader, - size_t offset, void *output, - const struct field_information *all_fields, - const int all_fields_count, - const int global_index, size_t *mask, - size_t *h_offset); +size_t csds_particle_read_field(const struct csds_reader *reader, size_t offset, + void *output, + const struct field_information *all_fields, + const int all_fields_count, + const int global_index, size_t *mask, + size_t *h_offset); -void csds_particle_interpolate_field( - const double t_before, const struct csds_field *restrict before, - const double t_after, const struct csds_field *restrict after, - void *restrict output, const double t, - const struct field_information *field, enum part_type type, - const struct csds_parameters *params); +void csds_particle_interpolate_field(const double t_before, + const struct csds_field *restrict before, + const double t_after, + const struct csds_field *restrict after, + void *restrict output, const double t, + const struct field_information *field, + enum part_type type, + const struct csds_parameters *params); enum csds_special_flags csds_particle_read_special_flag( const struct csds_reader *reader, size_t offset, size_t *mask, diff --git a/src/csds_python_tools.h b/src/csds_python_tools.h index 3947c0decd03e91d2a8f5b13b01fd3d3d3766008..a7da56d26117207c2d8004cf73787b58c2c8bb92 100644 --- a/src/csds_python_tools.h +++ b/src/csds_python_tools.h @@ -106,8 +106,8 @@ csds_loader_python_field(int dimension, int numpy_type) { */ __attribute__((always_inline)) INLINE static void csds_loader_python_field_add_subfield(struct csds_python_field *field, - const char *name, size_t offset, - int dimension, int numpy_type) { + const char *name, size_t offset, + int dimension, int numpy_type) { /* Ensure that we still have enough place */ if (field->subfields_registred == field->dimension) { @@ -134,8 +134,8 @@ csds_loader_python_field_add_subfield(struct csds_python_field *field, * * @param field The #csds_python_field to clean. */ -__attribute__((always_inline)) INLINE static void -csds_loader_python_field_free(struct csds_python_field *field) { +__attribute__((always_inline)) INLINE static void csds_loader_python_field_free( + struct csds_python_field *field) { if (field->typenum == CUSTOM_NPY_TYPE) { free(field->subfields); field->subfields = NULL; diff --git a/src/csds_python_wrapper.c b/src/csds_python_wrapper.c index 3376266cd2e88184bf74877f08f555b64408d497..c514fda7456922a2d422df6c9e8a35b17575c47e 100644 --- a/src/csds_python_wrapper.c +++ b/src/csds_python_wrapper.c @@ -140,7 +140,8 @@ static int Reader_init(PyObjectReader *self, PyObject *args, PyObject *kwds) { int number_index = 10; /* List of keyword arguments. */ - static char *kwlist[] = {"basename", "verbose", "number_threads", "number_index", NULL}; + static char *kwlist[] = {"basename", "verbose", "number_threads", + "number_index", NULL}; /* parse the arguments. */ if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|iii", kwlist, &basename, @@ -216,8 +217,8 @@ static PyObject *get_box_size(PyObject *self, PyObject *Py_UNUSED(ignored)) { } #define find_field_in_module_internal(MODULE, PART) \ - for (int local = 0; local < MODULE##_csds_field##PART##_count; local++) { \ - const int global = MODULE##_csds_local_to_global##PART[local]; \ + for (int local = 0; local < MODULE##_csds_field##PART##_count; local++) { \ + const int global = MODULE##_csds_local_to_global##PART[local]; \ const int local_shifted = local + total_number_fields; \ if (field_indices[i] == global) { \ /* Check if we have the same fields for the different modules */ \ @@ -228,10 +229,10 @@ static PyObject *get_box_size(PyObject *self, PyObject *Py_UNUSED(ignored)) { error_python( \ "The python definition of the field %s does not correspond " \ "between the modules.", \ - MODULE##_csds_field_names##PART[local]); \ + MODULE##_csds_field_names##PART[local]); \ } \ } \ - strcpy(field_name, MODULE##_csds_field_names##PART[local]); \ + strcpy(field_name, MODULE##_csds_field_names##PART[local]); \ current_field = &python_fields[local_shifted]; \ break; \ } \ @@ -264,8 +265,8 @@ static PyObject *get_box_size(PyObject *self, PyObject *Py_UNUSED(ignored)) { */ __attribute__((always_inline)) INLINE static PyObject * csds_loader_create_output(void **output, const int *field_indices, - const int n_fields, const uint64_t *n_part, - uint64_t n_tot) { + const int n_fields, const uint64_t *n_part, + uint64_t n_tot) { struct csds_python_field python_fields[100]; @@ -785,8 +786,8 @@ static PyObject *pyGetData(__attribute__((unused)) PyObject *self, /* Enable multithreading */ Py_BEGIN_ALLOW_THREADS; - csds_reader_read_all_particles(reader, time, csds_reader_lin, - field_indices, n_fields, output, n_part); + csds_reader_read_all_particles(reader, time, csds_reader_lin, field_indices, + n_fields, output, n_part); /* Disable multithreading */ Py_END_ALLOW_THREADS; @@ -815,8 +816,8 @@ static PyObject *pyGetData(__attribute__((unused)) PyObject *self, /* Read the particles. */ csds_reader_read_particles_from_ids(reader, time, csds_reader_lin, - field_indices, n_fields, output, - n_part, c_part_ids); + field_indices, n_fields, output, n_part, + c_part_ids); /* Disable multithreading */ Py_END_ALLOW_THREADS; @@ -831,8 +832,8 @@ static PyObject *pyGetData(__attribute__((unused)) PyObject *self, } /* Create the python output. */ - PyObject *array = csds_loader_create_output(output, field_indices, n_fields, - n_part, n_tot); + PyObject *array = + csds_loader_create_output(output, field_indices, n_fields, n_part, n_tot); /* Free the reader. */ free(field_indices); diff --git a/src/csds_reader.c b/src/csds_reader.c index 2aa6db61365d15e105396c08d8ad2a362e4b62da..395bf11a178db5d8cdcf886bcbd38e9e1277eb34 100644 --- a/src/csds_reader.c +++ b/src/csds_reader.c @@ -62,7 +62,7 @@ void csds_reader_init(struct csds_reader *reader, const char *basename, /* Initialize the log file. */ csds_logfile_init_from_file(&reader->log, logfile_name, reader, - /* only_header */ 0); + /* only_header */ 0); /* Initialize the index files and creates them if needed */ csds_reader_init_index(reader, number_index); @@ -102,11 +102,11 @@ void csds_reader_init_index(struct csds_reader *reader, int number_index) { if (count == 0) { csds_reader_generate_index_files(reader, number_index); count = number_index; - } - else if (reader->verbose > 0 && count != number_index) { - message("Found %i index files. If you wish to have the" - " requested %i files, please delete the old ones.", - count, number_index); + } else if (reader->verbose > 0 && count != number_index) { + message( + "Found %i index files. If you wish to have the" + " requested %i files, please delete the old ones.", + count, number_index); } reader->index.n_files = count; @@ -198,11 +198,11 @@ void csds_reader_set_time(struct csds_reader *reader, double time) { /* Read the file */ csds_index_read_header(&reader->index.index_prev, filename_prev); csds_index_map_file(&reader->index.index_prev, filename_prev, - /* sorted */ 1); + /* sorted */ 1); csds_index_read_header(&reader->index.index_next, filename_next); csds_index_map_file(&reader->index.index_next, filename_next, - /* sorted */ 1); + /* sorted */ 1); /* Get the offset of the time chunk */ size_t ind = time_array_get_index_from_time(&reader->log.times, time); @@ -234,7 +234,7 @@ void csds_reader_set_time(struct csds_reader *reader, double time) { * @param The number of new particles. */ size_t csds_reader_count_number_new_particles(struct csds_reader *reader, - enum part_type part_type) { + enum part_type part_type) { const size_t threshold = reader->time.time_offset; @@ -284,8 +284,8 @@ size_t csds_reader_count_number_new_particles(struct csds_reader *reader, * * @param The number of removed particles. */ -size_t csds_reader_count_number_removed_particles( - struct csds_reader *reader, enum part_type part_type) { +size_t csds_reader_count_number_removed_particles(struct csds_reader *reader, + enum part_type part_type) { const size_t threshold = reader->time.time_offset; @@ -333,8 +333,8 @@ size_t csds_reader_count_number_removed_particles( * @param read_types Should we read this type of particles? */ void csds_reader_get_number_particles(struct csds_reader *reader, - uint64_t *n_parts, - const int *read_types) { + uint64_t *n_parts, + const int *read_types) { for (enum part_type i = (enum part_type)0; i < swift_type_count; i++) { /* Should we skip this type of particles? */ if (read_types[i] == 0) { @@ -425,8 +425,7 @@ int csds_reader_read_field(struct csds_reader *reader, double time, */ while (offset < offset_time) { /* Read the particle. */ - csds_loader_io_read_mask(h, reader->log.log.map + offset, &mask, - &h_offset); + csds_loader_io_read_mask(h, reader->log.log.map + offset, &mask, &h_offset); /* Is the particle removed from the logfile? */ if (mask & h->masks[csds_index_special_flags].mask) { @@ -463,7 +462,7 @@ int csds_reader_read_field(struct csds_reader *reader, double time, /* Read the field */ csds_particle_read_field(reader, offset_before, output, all_fields, - all_fields_count, global, &mask, &h_offset); + all_fields_count, global, &mask, &h_offset); /* Deal with the first derivative. */ const size_t size_first = mask_first == NULL ? 0 : mask_first->size; @@ -473,8 +472,7 @@ int csds_reader_read_field(struct csds_reader *reader, double time, if (first_found) { /* Read the first derivative */ csds_particle_read_field(reader, offset_before, first_deriv, all_fields, - all_fields_count, global_first, &mask, - &h_offset); + all_fields_count, global_first, &mask, &h_offset); } /* Deal with the second derivative. */ @@ -485,8 +483,7 @@ int csds_reader_read_field(struct csds_reader *reader, double time, if (second_found) { /* Read the first derivative */ csds_particle_read_field(reader, offset_before, second_deriv, all_fields, - all_fields_count, global_second, &mask, - &h_offset); + all_fields_count, global_second, &mask, &h_offset); } /* Get the time. */ @@ -503,7 +500,7 @@ int csds_reader_read_field(struct csds_reader *reader, double time, /* Read the particle. */ csds_loader_io_read_mask(h, reader->log.log.map + offset, &mask, - &h_offset); + &h_offset); /* Do we have the field? */ if (mask & mask_field->mask) { @@ -524,7 +521,7 @@ int csds_reader_read_field(struct csds_reader *reader, double time, /* Read the field */ csds_particle_read_field(reader, offset, output_after, all_fields, - all_fields_count, global, &mask, &h_offset); + all_fields_count, global, &mask, &h_offset); /* Deal with the first derivative. */ char first_deriv_after[size_first]; @@ -534,8 +531,8 @@ int csds_reader_read_field(struct csds_reader *reader, double time, if (first_found) { /* Read the first derivative */ csds_particle_read_field(reader, offset, first_deriv_after, all_fields, - all_fields_count, global_first, &mask, - &h_offset); + all_fields_count, global_first, &mask, + &h_offset); } /* Deal with the second derivative. */ @@ -547,8 +544,8 @@ int csds_reader_read_field(struct csds_reader *reader, double time, if (second_found) { /* Read the second derivative */ csds_particle_read_field(reader, offset, second_deriv_after, all_fields, - all_fields_count, global_second, &mask, - &h_offset); + all_fields_count, global_second, &mask, + &h_offset); } /* Get the time. */ @@ -567,8 +564,8 @@ int csds_reader_read_field(struct csds_reader *reader, double time, /* Interpolate the data. */ csds_particle_interpolate_field(time_before, &before, time_after, &after, - output, time, field_wanted, type, - &reader->params); + output, time, field_wanted, type, + &reader->params); } return 0; } @@ -586,12 +583,11 @@ int csds_reader_read_field(struct csds_reader *reader, double time, * @param type The type of the particle. */ void csds_reader_get_fields_wanted(const struct csds_reader *reader, - const int *global_fields_wanted, - struct field_information *fields_wanted, - const int n_fields_wanted, - struct field_information *all_fields, - int all_fields_count, - enum part_type type) { + const int *global_fields_wanted, + struct field_information *fields_wanted, + const int n_fields_wanted, + struct field_information *all_fields, + int all_fields_count, enum part_type type) { const struct header *h = &reader->log.header; @@ -676,8 +672,8 @@ struct extra_data_read_all { * @param extra_data Pointer to a #extra_data_read_all. */ void csds_reader_read_all_particles_single_type_mapper(void *map_data, - int num_elements, - void *extra_data) { + int num_elements, + void *extra_data) { /* Extract the data */ struct extra_data_read_all *data_tp = @@ -799,10 +795,9 @@ void csds_reader_read_all_particles_single_type_mapper(void *map_data, * @param type The particle type */ void csds_reader_read_all_particles_single_type( - struct csds_reader *reader, double time, - enum csds_reader_type interp_type, const int *global_fields_wanted, - const int n_fields_wanted, void **output, const uint64_t *n_part, - enum part_type type) { + struct csds_reader *reader, double time, enum csds_reader_type interp_type, + const int *global_fields_wanted, const int n_fields_wanted, void **output, + const uint64_t *n_part, enum part_type type) { const struct header *h = &reader->log.header; /* Allocate temporary memory. */ @@ -820,8 +815,8 @@ void csds_reader_read_all_particles_single_type( /* Convert fields into the local array. */ csds_reader_get_fields_wanted(reader, global_fields_wanted, fields_wanted, - n_fields_wanted, all_fields, all_fields_count, - type); + n_fields_wanted, all_fields, all_fields_count, + type); /* Compact the data */ struct extra_data_read_all extra = {reader, @@ -869,10 +864,10 @@ void csds_reader_read_all_particles_single_type( * @param n_part Number of particles of each type. */ void csds_reader_read_all_particles(struct csds_reader *reader, double time, - enum csds_reader_type interp_type, - const int *global_fields_wanted, - const int n_fields_wanted, void **output, - const uint64_t *n_part) { + enum csds_reader_type interp_type, + const int *global_fields_wanted, + const int n_fields_wanted, void **output, + const uint64_t *n_part) { /* Read the gas */ if (n_part[swift_type_gas] != 0) { @@ -924,10 +919,9 @@ void csds_reader_read_all_particles(struct csds_reader *reader, double time, * The ids not found are removed from this array. */ void csds_reader_read_particles_from_ids_single_type( - struct csds_reader *reader, double time, - enum csds_reader_type interp_type, const int *global_fields_wanted, - const int n_fields_wanted, void **output, uint64_t *n_part, - enum part_type type, long long *ids) { + struct csds_reader *reader, double time, enum csds_reader_type interp_type, + const int *global_fields_wanted, const int n_fields_wanted, void **output, + uint64_t *n_part, enum part_type type, long long *ids) { const struct header *h = &reader->log.header; @@ -952,16 +946,16 @@ void csds_reader_read_particles_from_ids_single_type( /* Convert fields into the local array. */ csds_reader_get_fields_wanted(reader, global_fields_wanted, fields_wanted, - n_fields_wanted, all_fields, all_fields_count, - type); + n_fields_wanted, all_fields, all_fields_count, + type); /* Read the particles */ for (size_t i = 0; i < n_part[type]; i++) { /* Get the offset */ size_t offset = 0; - int found = csds_index_get_offset(&reader->index.index_prev, ids[i], type, - &offset); + int found = + csds_index_get_offset(&reader->index.index_prev, ids[i], type, &offset); /* Deal with the particles not found */ if (!found) { @@ -1013,13 +1007,10 @@ void csds_reader_read_particles_from_ids_single_type( * @param ids The particles' ids. * The ids not found are removed from this array. */ -void csds_reader_read_particles_from_ids(struct csds_reader *reader, - double time, - enum csds_reader_type interp_type, - const int *global_fields_wanted, - const int n_fields_wanted, - void **output, uint64_t *n_part, - long long **ids) { +void csds_reader_read_particles_from_ids( + struct csds_reader *reader, double time, enum csds_reader_type interp_type, + const int *global_fields_wanted, const int n_fields_wanted, void **output, + uint64_t *n_part, long long **ids) { /* Read the gas */ if (n_part[swift_type_gas] != 0) { @@ -1081,7 +1072,7 @@ double csds_reader_get_time_end(struct csds_reader *reader) { * @return The offset of the timestamp. */ size_t csds_reader_get_next_offset_from_time(struct csds_reader *reader, - double time) { + double time) { size_t ind = time_array_get_index_from_time(&reader->log.times, time); /* We do not want to have the sentiel */ if (reader->log.times.size - 2 == ind) { @@ -1106,8 +1097,7 @@ size_t csds_reader_get_next_offset_from_time(struct csds_reader *reader, * @return The offset after the record. */ size_t csds_reader_read_record(struct csds_reader *reader, void **output, - double *time, int *is_particle, - size_t offset) { + double *time, int *is_particle, size_t offset) { /* Get a few pointers. */ const struct header *h = &reader->log.header; diff --git a/src/csds_reader.h b/src/csds_reader.h index 6bda900a200bbf32b9229e272fd6ea22514fc74c..6f5fbe410f5523886e24a10c6f5881d94530f666 100644 --- a/src/csds_reader.h +++ b/src/csds_reader.h @@ -112,7 +112,7 @@ struct csds_reader { enum csds_reader_event { csds_reader_event_null, /* No event */ csds_reader_event_deleted, /* Particle has been deleted */ - csds_reader_event_stars, /* The particle has been transformed into a star */ + csds_reader_event_stars, /* The particle has been transformed into a star */ }; void csds_reader_init_index(struct csds_reader *reader, int number_index); @@ -125,28 +125,29 @@ void csds_reader_set_time(struct csds_reader *reader, double time); double csds_reader_get_time_begin(struct csds_reader *reader); double csds_reader_get_time_end(struct csds_reader *reader); size_t csds_reader_get_next_offset_from_time(struct csds_reader *reader, - double time); + double time); void csds_reader_get_number_particles(struct csds_reader *reader, - uint64_t *n_parts, - const int *read_types); + uint64_t *n_parts, const int *read_types); void csds_reader_read_all_particles(struct csds_reader *reader, double time, - enum csds_reader_type interp_type, - const int *id_masks_wanted, - const int n_mask_wanted, void **output, - const uint64_t *n_part); -void csds_reader_read_particles_from_ids( - struct csds_reader *reader, double time, - enum csds_reader_type interp_type, const int *id_masks_wanted, - const int n_mask_wanted, void **output, uint64_t *n_part, long long **ids); + enum csds_reader_type interp_type, + const int *id_masks_wanted, + const int n_mask_wanted, void **output, + const uint64_t *n_part); +void csds_reader_read_particles_from_ids(struct csds_reader *reader, + double time, + enum csds_reader_type interp_type, + const int *id_masks_wanted, + const int n_mask_wanted, void **output, + uint64_t *n_part, long long **ids); size_t csds_reader_read_record(struct csds_reader *reader, void **output, - double *time, int *is_particle, size_t offset); -void csds_reader_generate_index_files(const struct csds_reader *reader, int number_index); + double *time, int *is_particle, size_t offset); +void csds_reader_generate_index_files(const struct csds_reader *reader, + int number_index); void csds_reader_get_fields_wanted(const struct csds_reader *reader, const int *global_fields_wanted, struct field_information *fields_wanted, const int n_fields_wanted, struct field_information *all_fields, - int all_fields_count, - enum part_type type); + int all_fields_count, enum part_type type); #endif // CSDS_CSDS_READER_H diff --git a/src/csds_reader_generate_index.c b/src/csds_reader_generate_index.c index d5f0c6edd91d8a6e57833e569a9dcc197af1a98a..b17c9aa2481dfc9583841bd2ff9928dcafeb788a 100644 --- a/src/csds_reader_generate_index.c +++ b/src/csds_reader_generate_index.c @@ -75,8 +75,8 @@ void index_writer_init(struct index_writer *writer, size_t init_size, } /* Allocate the memory */ - writer->data = (struct index_data *) - malloc(sizeof(struct index_data) * init_size); + writer->data = + (struct index_data *)malloc(sizeof(struct index_data) * init_size); if (writer->data == NULL) { error("Failed to allocate memory for the index_writer."); } @@ -88,8 +88,7 @@ void index_writer_init(struct index_writer *writer, size_t init_size, * @param writer The #index_writer. */ void index_writer_reset(struct index_writer *writer) { - if (writer->size == 0) - return; + if (writer->size == 0) return; free(writer->data); index_writer_init(writer, writer->init_size, writer->max_frac_tag); @@ -124,9 +123,10 @@ void index_writer_log(struct index_writer *writer, const int64_t id, /* Ensure that it was correctly allocated */ if (writer->capacity == 0) { - error("Trying to add a particle to an empty index_writer." - " If your are sure that your particle type is implemented, " - "please increase the value of ReaderOptions:Number*."); + error( + "Trying to add a particle to an empty index_writer." + " If your are sure that your particle type is implemented, " + "please increase the value of ReaderOptions:Number*."); } #ifdef SWIFT_DEBUG_CHECKS @@ -146,8 +146,7 @@ void index_writer_log(struct index_writer *writer, const int64_t id, writer->capacity *= 2; /* Allocate the new array and copy the content of the previous one */ - struct index_data *tmp = - (struct index_data *) malloc(2 * memsize); + struct index_data *tmp = (struct index_data *)malloc(2 * memsize); memcpy(tmp, writer->data, memsize); @@ -171,8 +170,8 @@ void index_writer_log(struct index_writer *writer, const int64_t id, * @param writer The #index_writer. * @param force Force the removal? */ -void index_writer_remove_tagged_particles( - struct index_writer *writer, const int force) { +void index_writer_remove_tagged_particles(struct index_writer *writer, + const int force) { /* No need to clean the empty arrays. */ if (writer->size == 0) { @@ -180,19 +179,17 @@ void index_writer_remove_tagged_particles( } /* Do we need to clean? */ - const float frac = (float) writer->number_tag / (float) writer->size; - if (!force && frac < writer->max_frac_tag) - return; + const float frac = (float)writer->number_tag / (float)writer->size; + if (!force && frac < writer->max_frac_tag) return; /* Clean */ size_t count = 0; - for(size_t i = 0; i < writer->size; i++) { - if (writer->data[i].offset != PARTICLE_REMOVED) - continue; + for (size_t i = 0; i < writer->size; i++) { + if (writer->data[i].offset != PARTICLE_REMOVED) continue; count += 1; /* Now replace it with the last particle. */ - writer->data[i] = writer->data[writer->size-1]; + writer->data[i] = writer->data[writer->size - 1]; writer->size--; /* We need to ensure that the last particle was not @@ -208,7 +205,7 @@ void index_writer_remove_tagged_particles( // TODO sort the particles #ifdef SWIFT_DEBUG_CHECKS - for(size_t i = 0; i < writer->size; i++) { + for (size_t i = 0; i < writer->size; i++) { if (writer->data[i].offset == PARTICLE_REMOVED) error("Found a tagged particle after cleaning."); } @@ -229,7 +226,7 @@ void index_writer_remove_part(struct index_writer *current_state, // TODO use a binary search + ensure ids are sorted // Do not forget to write in the index file that the files are sorted - for(size_t j = 0; j < current_state->size; j++) { + for (size_t j = 0; j < current_state->size; j++) { if (current_state->data[j].offset == PARTICLE_REMOVED || part_id != current_state->data[j].id) { continue; @@ -263,23 +260,21 @@ void index_writer_check_implemented(const struct index_writer *writers) { /** * @brief Write the number of particles and their data into the index file */ -void index_writer_write_in_index(const struct index_writer *writers, - FILE *f) { +void index_writer_write_in_index(const struct index_writer *writers, FILE *f) { /* Write the number of particles */ uint64_t N_total[swift_type_count]; - for(int type = 0; type < swift_type_count; type++) { + for (int type = 0; type < swift_type_count; type++) { N_total[type] = writers[type].size; } fwrite(N_total, sizeof(uint64_t), swift_type_count, f); /* Write the index data */ - for(int type = 0; type < swift_type_count; type++) { - if (N_total[type] == 0) - continue; + for (int type = 0; type < swift_type_count; type++) { + if (N_total[type] == 0) continue; - fwrite(writers[type].data, sizeof(struct index_data), - writers[type].size, f); + fwrite(writers[type].data, sizeof(struct index_data), writers[type].size, + f); } } @@ -293,14 +288,16 @@ void index_writer_write_in_index(const struct index_writer *writers, * (since last index file) of created particles * (size given by swift_type_count). * @param parts_removed The arrays containing the last reference - * (since last index file) of removed particles (size given by swift_type_count). + * (since last index file) of removed particles (size given by + * swift_type_count). * @param time The time corresponding to the current index file. * @param file_number The current file number. */ -void csds_reader_write_index( - const struct csds_reader *reader, struct index_writer *current_state, - struct index_writer *parts_created, struct index_writer *parts_removed, - const struct time_record *time, int file_number) { +void csds_reader_write_index(const struct csds_reader *reader, + struct index_writer *current_state, + struct index_writer *parts_created, + struct index_writer *parts_removed, + const struct time_record *time, int file_number) { /* Get the filename */ char filename[STRING_SIZE + 15]; @@ -308,7 +305,7 @@ void csds_reader_write_index( /* Trigger a cleaning of the arrays */ // TODO Remove this and skip the particles when writing? - for(int i = 0; i < swift_type_count; i++) { + for (int i = 0; i < swift_type_count; i++) { index_writer_remove_tagged_particles(¤t_state[i], /* force */ 1); } @@ -318,7 +315,7 @@ void csds_reader_write_index( index_writer_check_implemented(parts_removed); /* Open file */ - FILE* f = NULL; + FILE *f = NULL; f = fopen(filename, "wb"); if (f == NULL) { @@ -332,7 +329,7 @@ void csds_reader_write_index( /* Write number of particles */ uint64_t N_total[swift_type_count]; - for(int type = 0; type < swift_type_count; type++) { + for (int type = 0; type < swift_type_count; type++) { N_total[type] = current_state[type].size; } fwrite(N_total, sizeof(uint64_t), swift_type_count, f); @@ -352,9 +349,8 @@ void csds_reader_write_index( } /* Write the arrays */ - for(int type = 0; type < swift_type_count; type++) { - if (N_total[type] == 0) - continue; + for (int type = 0; type < swift_type_count; type++) { + if (N_total[type] == 0) continue; fwrite(current_state[type].data, sizeof(struct index_data), current_state[type].size, f); @@ -368,7 +364,7 @@ void csds_reader_write_index( fclose(f); /* Cleanup the arrays */ - for(int type = 0; type < swift_type_count; type++) { + for (int type = 0; type < swift_type_count; type++) { index_writer_reset(&parts_created[type]); index_writer_reset(&parts_removed[type]); } @@ -378,10 +374,14 @@ void csds_reader_write_index( * @brief Get the initial state of the simulation. * * @param reader The #csds_reader. - * @param current_state The arrays that will be updated with (size swift_type_count). - * @param all_fields The complete list of fields for the different particles (size swift_type_count). - * @param all_fields_count The number of fields for each particle type (size swift_type_count). - * @param time_record (output) The first #time_record in the logfile (for writing the index file). + * @param current_state The arrays that will be updated with (size + * swift_type_count). + * @param all_fields The complete list of fields for the different particles + * (size swift_type_count). + * @param all_fields_count The number of fields for each particle type (size + * swift_type_count). + * @param time_record (output) The first #time_record in the logfile (for + * writing the index file). * * @return The offset of the second #time_record * (the first record that does not correspond to the IC). @@ -416,12 +416,13 @@ size_t csds_reader_get_initial_state(const struct csds_reader *reader, /* Skip the time record */ size_t time_mask = 0; - csds_loader_io_read_mask(header, log->log.map + offset_first, &time_mask, NULL); + csds_loader_io_read_mask(header, log->log.map + offset_first, &time_mask, + NULL); const int time_size = header_get_record_size_from_mask(header, time_mask); offset_first += time_size + size_record_header; /* Get the initial state */ - for(size_t offset = offset_first; offset < offset_max; ) { + for (size_t offset = offset_first; offset < offset_max;) { /* Get the particle type */ size_t mask = 0; size_t prev_offset = 0; @@ -437,8 +438,7 @@ size_t csds_reader_get_initial_state(const struct csds_reader *reader, /* TODO Implement missing particle types */ if (part_type == swift_type_neutrino || part_type == swift_type_sink || part_type == swift_type_black_hole) { - error("Particle type not implemented (%s)", - part_type_names[part_type]); + error("Particle type not implemented (%s)", part_type_names[part_type]); } /* Get the particle ID */ @@ -449,8 +449,8 @@ size_t csds_reader_get_initial_state(const struct csds_reader *reader, /* Read the particle ID */ int64_t id = 0; csds_particle_read_field(reader, offset, &id, all_fields[part_type], - all_fields_count[part_type], index_mask_id, - &mask, &prev_offset); + all_fields_count[part_type], index_mask_id, &mask, + &prev_offset); /* Log the particle */ index_writer_log(¤t_state[part_type], id, offset); @@ -463,26 +463,31 @@ size_t csds_reader_get_initial_state(const struct csds_reader *reader, return offset_max; } - /** - * @brief Update the state of the simulation until the next index file along with the history. + * @brief Update the state of the simulation until the next index file along + * with the history. * * @param reader The #csds_reader. * @param init_offset The initial offset to read. * @param time_record The #time_record of the next index file. - * @param all_fields The complete list of fields for the different particles (size swift_type_count). - * @param all_fields_count The number of fields for each particle type (size swift_type_count). - * @param current_state The arrays containing the state of the simulation (size swift_type_count). - * @param parts_created The arrays containing the particles created since last index (size swift_type_count). - * @param parts_removed The arrays containing the particles removed since last index (size swift_type_count). + * @param all_fields The complete list of fields for the different particles + * (size swift_type_count). + * @param all_fields_count The number of fields for each particle type (size + * swift_type_count). + * @param current_state The arrays containing the state of the simulation (size + * swift_type_count). + * @param parts_created The arrays containing the particles created since last + * index (size swift_type_count). + * @param parts_removed The arrays containing the particles removed since last + * index (size swift_type_count). * * @return The starting offset for the update. */ size_t csds_reader_update_state_to_next_index( - const struct csds_reader *reader, size_t init_offset, struct time_record time_record, - struct field_information **all_fields, int *all_fields_count, - struct index_writer *current_state, struct index_writer *parts_created, - struct index_writer *parts_removed) { + const struct csds_reader *reader, size_t init_offset, + struct time_record time_record, struct field_information **all_fields, + int *all_fields_count, struct index_writer *current_state, + struct index_writer *parts_created, struct index_writer *parts_removed) { const struct csds_logfile *log = &reader->log; const struct header *header = &log->header; const int size_record_header = CSDS_MASK_SIZE + CSDS_OFFSET_SIZE; @@ -495,113 +500,113 @@ size_t csds_reader_update_state_to_next_index( /* Look for all the created / removed particles */ size_t offset = init_offset; - while(offset < time_record.offset) { - size_t mask = 0; - size_t h_offset = 0; - int part_type = 0; // only available if the record is flagged. - int data = 0; + while (offset < time_record.offset) { + size_t mask = 0; + size_t h_offset = 0; + int part_type = 0; // only available if the record is flagged. + int data = 0; - /* Get the mask */ - csds_loader_io_read_mask(header, log->log.map + offset, &mask, &h_offset); + /* Get the mask */ + csds_loader_io_read_mask(header, log->log.map + offset, &mask, &h_offset); - /* Go to the next record */ - const size_t old_offset = offset; - offset += header_get_record_size_from_mask(header, mask); - offset += size_record_header; + /* Go to the next record */ + const size_t old_offset = offset; + offset += header_get_record_size_from_mask(header, mask); + offset += size_record_header; - /* Check if we have a particle with a flag */ - if (mask & header->masks[csds_index_timestamp].mask || - !(mask & header->masks[csds_index_special_flags].mask)) { - continue; - } + /* Check if we have a particle with a flag */ + if (mask & header->masks[csds_index_timestamp].mask || + !(mask & header->masks[csds_index_special_flags].mask)) { + continue; + } - /* Get the special flag */ - enum csds_special_flags flag = csds_particle_read_special_flag( - reader, old_offset, &mask, &h_offset, &data, &part_type); + /* Get the special flag */ + enum csds_special_flags flag = csds_particle_read_special_flag( + reader, old_offset, &mask, &h_offset, &data, &part_type); #ifdef SWIFT_DEBUG_CHECKS - if (flag == csds_flag_none) { - error("A record should not have a mask " - "for a flag and the flag set to 0"); - } + if (flag == csds_flag_none) { + error( + "A record should not have a mask " + "for a flag and the flag set to 0"); + } #endif - /* Read the ID */ - int64_t id = 0; - csds_particle_read_field(reader, old_offset, &id, all_fields[part_type], - all_fields_count[part_type], index_mask_id, - &mask, &h_offset); - - /* Add the particle to the arrays */ - if (flag == csds_flag_change_type || flag == csds_flag_mpi_exit || - flag == csds_flag_delete) { - index_writer_log(&parts_removed[part_type], id, old_offset); - index_writer_remove_part(¤t_state[part_type], id); - } - else if (flag == csds_flag_create || flag == csds_flag_mpi_enter) { - index_writer_log(&parts_created[part_type], id, old_offset); - index_writer_log(¤t_state[part_type], id, old_offset); - } + /* Read the ID */ + int64_t id = 0; + csds_particle_read_field(reader, old_offset, &id, all_fields[part_type], + all_fields_count[part_type], index_mask_id, &mask, + &h_offset); + + /* Add the particle to the arrays */ + if (flag == csds_flag_change_type || flag == csds_flag_mpi_exit || + flag == csds_flag_delete) { + index_writer_log(&parts_removed[part_type], id, old_offset); + index_writer_remove_part(¤t_state[part_type], id); + } else if (flag == csds_flag_create || flag == csds_flag_mpi_enter) { + index_writer_log(&parts_created[part_type], id, old_offset); + index_writer_log(¤t_state[part_type], id, old_offset); } + } - /* Update the offsets of current_state - * No need to update the others as they contain - * when particles are removed/created*/ - for(int type = 0; type < swift_type_count; type++) { - for(size_t i = 0; i < current_state[type].size; i++) { - size_t current_offset = current_state[type].data[i].offset; - - /* Skip the flagged particles. */ - if (current_offset == PARTICLE_REMOVED) - continue; - - /* Get the full mask */ - size_t full_mask = 0; - size_t h_offset = 0; - csds_loader_io_read_mask(header, log->log.map + current_offset, &full_mask, &h_offset); + /* Update the offsets of current_state + * No need to update the others as they contain + * data about when particles are removed/created*/ + for (int type = 0; type < swift_type_count; type++) { + for (size_t i = 0; i < current_state[type].size; i++) { + size_t current_offset = current_state[type].data[i].offset; - /* Remove the special mask */ - full_mask = full_mask & !header->masks[csds_index_special_flags].mask; + /* Skip the flagged particles. */ + if (current_offset == PARTICLE_REMOVED) continue; - /* Find the last offset before the current time */ - size_t last_full_offset = current_offset; + /* Get the full mask */ + size_t full_mask = 0; + size_t h_offset = 0; + csds_loader_io_read_mask(header, log->log.map + current_offset, + &full_mask, &h_offset); + + /* Remove the special mask */ + full_mask = full_mask & !header->masks[csds_index_special_flags].mask; + + /* Find the last offset before the current time */ + size_t last_full_offset = current_offset; + current_offset += h_offset; + while (1) { + /* Get the mask */ + size_t mask = 0; + h_offset = 0; + csds_loader_io_read_mask(header, log->log.map + current_offset, &mask, + &h_offset); + + /* update the offset */ current_offset += h_offset; - while(1) { - /* Get the mask */ - size_t mask = 0; - h_offset = 0; - csds_loader_io_read_mask(header, log->log.map + current_offset, &mask, &h_offset); - - /* update the offset */ - current_offset += h_offset; - if (current_offset > time_record.offset) { - break; - } - - /* The particle should not have a special flag - due to the previous loop */ - if (mask & header->masks[csds_index_special_flags].mask) { - error("Found a special flag when updating the particles."); - } - - /* Update the last full offset */ - if (full_mask == mask) { - last_full_offset = current_offset; - } - - /* Are we at the end of the file? */ - if (h_offset == 0) { - break; - } + if (current_offset > time_record.offset) { + break; + } + /* The particle should not have a special flag + due to the previous loop */ + if (mask & header->masks[csds_index_special_flags].mask) { + error("Found a special flag when updating the particles."); } - /* Update the offset */ - current_state[type].data[i].offset = last_full_offset; + /* Update the last full offset */ + if (full_mask == mask) { + last_full_offset = current_offset; + } + + /* Are we at the end of the file? */ + if (h_offset == 0) { + break; + } } + + /* Update the offset */ + current_state[type].data[i].offset = last_full_offset; } + } - return offset; + return offset; } /** @@ -610,7 +615,8 @@ size_t csds_reader_update_state_to_next_index( * @param reader The #csds_reader. * @param number_index The number of index to generate. */ -void csds_reader_generate_index_files(const struct csds_reader *reader, int number_index) { +void csds_reader_generate_index_files(const struct csds_reader *reader, + int number_index) { /* Get a few pointers */ const struct csds_logfile *log = &reader->log; const struct header *header = &log->header; @@ -641,7 +647,7 @@ void csds_reader_generate_index_files(const struct csds_reader *reader, int numb int all_fields_count[swift_type_count]; struct field_information *all_fields[swift_type_count]; struct field_information field_id[swift_type_count]; - for(int type = 0; type < swift_type_count; type++) { + for (int type = 0; type < swift_type_count; type++) { /* TODO Implement missing particle types */ if (type == swift_type_neutrino || type == swift_type_sink || type == swift_type_black_hole) @@ -653,12 +659,12 @@ void csds_reader_generate_index_files(const struct csds_reader *reader, int numb tools_get_list_fields(all_fields[type], type, header); /* Convert fields into the local array. */ - csds_reader_get_fields_wanted(reader, &global_fields_wanted, &field_id[type], + csds_reader_get_fields_wanted(reader, &global_fields_wanted, + &field_id[type], /* n_fields_wanted */ 1, all_fields[type], all_fields_count[type], type); } - /* Create the different arrays that will store the information */ struct index_writer current_state[swift_type_count]; struct index_writer parts_created[swift_type_count]; @@ -666,8 +672,9 @@ void csds_reader_generate_index_files(const struct csds_reader *reader, int numb const size_t default_size = 1024; /* Allocate the arrays */ - for(int i = 0; i < swift_type_count; i++) { - index_writer_init(¤t_state[i], reader->params.approximate_number_particles[i], + for (int i = 0; i < swift_type_count; i++) { + index_writer_init(¤t_state[i], + reader->params.approximate_number_particles[i], reader->params.arrays_maximal_tagged_fraction); index_writer_init(&parts_created[i], default_size, reader->params.arrays_maximal_tagged_fraction); @@ -675,25 +682,24 @@ void csds_reader_generate_index_files(const struct csds_reader *reader, int numb reader->params.arrays_maximal_tagged_fraction); } - /* Get the initial state */ struct time_record time_record; size_t offset = csds_reader_get_initial_state( reader, current_state, all_fields, all_fields_count, &time_record); /* Write the first index file */ - csds_reader_write_index(reader, current_state, parts_created, - parts_removed, &time_record, /* file_number */0); - + csds_reader_write_index(reader, current_state, parts_created, parts_removed, + &time_record, /* file_number */ 0); /* Compute the state of all the other files and write them. */ const double t_min = time_record.time; const double t_max = log->times.records[log->times.size - 1].time; const double dt = (t_max - t_min) / (number_index - 1); - for(int file_number = 1; file_number < number_index; file_number++) { + for (int file_number = 1; file_number < number_index; file_number++) { /* Get the corresponding time record */ const double current_approximate_time = t_min + file_number * dt; - const size_t index_time = time_array_get_index_from_time(&log->times, current_approximate_time); + const size_t index_time = + time_array_get_index_from_time(&log->times, current_approximate_time); time_record = log->times.records[index_time]; /* Ensure that we really have the final time (rounding error). */ @@ -712,7 +718,7 @@ void csds_reader_generate_index_files(const struct csds_reader *reader, int numb } /* Free the memory */ - for(int type = 0; type < swift_type_count; type++) { + for (int type = 0; type < swift_type_count; type++) { index_writer_free(¤t_state[type]); index_writer_free(&parts_created[type]); index_writer_free(&parts_removed[type]); diff --git a/src/csds_time.c b/src/csds_time.c index a8cb1dc5ae8be1c5ddb69926d578d39ac5743516..1b1ad7141073d50d70628830bdeef41d5fe1c014 100644 --- a/src/csds_time.c +++ b/src/csds_time.c @@ -108,8 +108,8 @@ size_t time_read(struct time_record *time_record, #endif /* read the record. */ - map = - csds_loader_io_read_data(map, sizeof(unsigned long long int), &time_record->int_time); + map = csds_loader_io_read_data(map, sizeof(unsigned long long int), + &time_record->int_time); map = csds_loader_io_read_data(map, sizeof(double), &time_record->time); return map - h->log->log.map; @@ -231,7 +231,7 @@ void time_array_load(struct time_array *t, struct csds_index *index) { /* Read the elements */ csds_loader_io_read_data(map, t->size * sizeof(struct time_record), - t->records); + t->records); } /** @@ -247,8 +247,7 @@ int time_array_restore(struct time_array *t, struct csds_logfile *log) { char filename[STRING_SIZE + 50]; int savefile = time_array_get_filename_savefile(log, filename); - if (!savefile) - return 0; + if (!savefile) return 0; /* Initialize the index file that might contain the time array */ struct csds_index index; diff --git a/src/csds_time.h b/src/csds_time.h index a52fbc8ac4d73cf9b263eedb69d40e0490c34e31..71ae20d0e60ece22f12dae4694d5a37378eb2936 100644 --- a/src/csds_time.h +++ b/src/csds_time.h @@ -71,8 +71,8 @@ struct time_array { void time_array_append(struct time_array *t, const integertime_t int_time, const double time, const size_t offset); -size_t time_read(struct time_record *time, - const struct csds_reader *reader, size_t offset); +size_t time_read(struct time_record *time, const struct csds_reader *reader, + size_t offset); void time_array_init(struct time_array *t, size_t initial_size); void time_array_populate(struct time_array *t, struct csds_logfile *log); diff --git a/src/csds_tools.c b/src/csds_tools.c index 0301774b4bff0ef8a4b2f70dc536044d30cbc608..8a12429b2f0d792e46656c0951e638241694e760 100644 --- a/src/csds_tools.c +++ b/src/csds_tools.c @@ -58,48 +58,48 @@ int tools_get_number_fields(enum part_type type) { } } -#define copy_field_to_struct_internal(MODULE, PART, TYPE) \ +#define copy_field_to_struct_internal(MODULE, PART, TYPE) \ for (int j = 0; j < MODULE##_csds_field##PART##_count; j++) { \ - \ - /* Save the main properties */ \ - fields[i].module = TYPE; \ + \ + /* Save the main properties */ \ + fields[i].module = TYPE; \ fields[i].name = MODULE##_csds_field_names##PART[j]; \ - \ - /* Get the indexes */ \ + \ + /* Get the indexes */ \ const int global = MODULE##_csds_local_to_global##PART[j]; \ - int first = h->masks[global].reader.first_deriv; \ - int second = h->masks[global].reader.second_deriv; \ - \ - /* Save the global indexes */ \ - fields[i].global_index = global; \ - fields[i].global_index_first = first; \ - fields[i].global_index_second = second; \ - \ - /* Convert the first derivatives into local index */ \ - if (first != -1) { \ + int first = h->masks[global].reader.first_deriv; \ + int second = h->masks[global].reader.second_deriv; \ + \ + /* Save the global indexes */ \ + fields[i].global_index = global; \ + fields[i].global_index_first = first; \ + fields[i].global_index_second = second; \ + \ + /* Convert the first derivatives into local index */ \ + if (first != -1) { \ for (int k = 0; k < MODULE##_csds_field##PART##_count; k++) { \ if (MODULE##_csds_local_to_global##PART[k] == first) { \ - first = k; \ - break; \ - } \ - } \ - } \ - \ - /* Convert the second derivatives into local index */ \ - if (second != -1) { \ + first = k; \ + break; \ + } \ + } \ + } \ + \ + /* Convert the second derivatives into local index */ \ + if (second != -1) { \ for (int k = 0; k < MODULE##_csds_field##PART##_count; k++) { \ if (MODULE##_csds_local_to_global##PART[k] == second) { \ - second = k; \ - break; \ - } \ - } \ - } \ - \ - /* Initialize the structure */ \ - fields[i].local_index = j; \ - fields[i].local_index_first = first; \ - fields[i].local_index_second = second; \ - i++; \ + second = k; \ + break; \ + } \ + } \ + } \ + \ + /* Initialize the structure */ \ + fields[i].local_index = j; \ + fields[i].local_index_first = first; \ + fields[i].local_index_second = second; \ + i++; \ } /** @@ -339,8 +339,7 @@ size_t tools_check_record_consistency(const struct csds_reader *reader, /* read mask of the pointed record. */ size_t pointed_mask = 0; - csds_loader_io_read_mask(h, file_init + pointed_offset, &pointed_mask, - NULL); + csds_loader_io_read_mask(h, file_init + pointed_offset, &pointed_mask, NULL); /* check if not mixing timestamp and particles. */ if ((pointed_mask != h->timestamp_mask && mask == h->timestamp_mask) || diff --git a/src/csds_tools.h b/src/csds_tools.h index 2d7f7e4cbcc63a2869be8df2ed220d69c861eee1..74c2974751a86b8a385d31aa54dfdd641ce4bf42 100644 --- a/src/csds_tools.h +++ b/src/csds_tools.h @@ -25,11 +25,11 @@ #include "../config.h" /* Swift include */ +#include "../src/csds.h" +#include "../src/csds_io.h" #include "../src/dimension.h" #include "../src/error.h" #include "../src/inline.h" -#include "../src/csds.h" -#include "../src/csds_io.h" #include "../src/part_type.h" #ifdef HAVE_PYTHON @@ -140,10 +140,10 @@ __attribute__((always_inline)) INLINE static void csds_loader_print_traceback( PyGILState_Release(gstate); } -#define error_python(s, ...) \ - ({ \ +#define error_python(s, ...) \ + ({ \ csds_loader_print_traceback(); \ - error(s, ##__VA_ARGS__); \ + error(s, ##__VA_ARGS__); \ }) #endif diff --git a/src/gravity/MultiSoftening/csds_gravity.h b/src/gravity/MultiSoftening/csds_gravity.h index 6aebf6ff38c21dda153b4a5dc677d6228a322722..c0f4c79aa44a9cbbfcf877b931b9c28b97afefce 100644 --- a/src/gravity/MultiSoftening/csds_gravity.h +++ b/src/gravity/MultiSoftening/csds_gravity.h @@ -22,11 +22,11 @@ #include "../config.h" /* local includes */ -#include "gravity_csds.h" #include "csds_interpolation.h" #include "csds_loader_io.h" #include "csds_parameters.h" #include "csds_python_tools.h" +#include "gravity_csds.h" /* Index of the mask in the header mask array */ extern int gravity_csds_local_to_global[gravity_csds_field_count]; @@ -77,12 +77,12 @@ gravity_csds_reader_link_derivatives(struct header *head) { */ __attribute__((always_inline)) INLINE static void gravity_csds_interpolate_field(const double t_before, - const struct csds_field *restrict before, - const double t_after, - const struct csds_field *restrict after, - void *restrict output, const double t, - const int field, - const struct csds_parameters *params) { + const struct csds_field *restrict before, + const double t_after, + const struct csds_field *restrict after, + void *restrict output, const double t, + const int field, + const struct csds_parameters *params) { #ifdef SWIFT_DEBUG_CHECKS /* Check the times */ @@ -122,8 +122,8 @@ gravity_csds_interpolate_field(const double t_before, } #ifdef HAVE_PYTHON -__attribute__((always_inline)) INLINE static void -gravity_csds_generate_python(struct csds_python_field *fields) { +__attribute__((always_inline)) INLINE static void gravity_csds_generate_python( + struct csds_python_field *fields) { fields[gravity_csds_field_coordinates] = csds_loader_python_field(/* Dimension */ 3, NPY_DOUBLE); diff --git a/src/hydro/Gadget2/csds_hydro.h b/src/hydro/Gadget2/csds_hydro.h index d4a414383adda4f58d844c4544b02368c6806deb..5aad453e6b260d48946b7c13bdc653baea72c3cd 100644 --- a/src/hydro/Gadget2/csds_hydro.h +++ b/src/hydro/Gadget2/csds_hydro.h @@ -22,11 +22,11 @@ #include "../config.h" /* local includes */ -#include "hydro_csds.h" #include "csds_interpolation.h" #include "csds_loader_io.h" #include "csds_parameters.h" #include "csds_python_tools.h" +#include "hydro_csds.h" /* Index of the mask in the header mask array */ extern int hydro_csds_local_to_global[hydro_csds_field_count]; @@ -43,12 +43,9 @@ __attribute__((always_inline)) INLINE static void hydro_csds_reader_link_derivatives(struct header *head) { /* Set the first and second derivatives */ - const int pos_id = - hydro_csds_local_to_global[hydro_csds_field_coordinates]; - const int vel_id = - hydro_csds_local_to_global[hydro_csds_field_velocities]; - const int acc_id = - hydro_csds_local_to_global[hydro_csds_field_accelerations]; + const int pos_id = hydro_csds_local_to_global[hydro_csds_field_coordinates]; + const int vel_id = hydro_csds_local_to_global[hydro_csds_field_velocities]; + const int acc_id = hydro_csds_local_to_global[hydro_csds_field_accelerations]; /* Coordinates */ header_set_first_derivative(head, pos_id, vel_id); @@ -75,14 +72,11 @@ hydro_csds_reader_link_derivatives(struct header *head) { * #hydro_csds_fields). * @param params The simulation's #csds_parameters. */ -__attribute__((always_inline)) INLINE static void -hydro_csds_interpolate_field(const double t_before, - const struct csds_field *restrict before, - const double t_after, - const struct csds_field *restrict after, - void *restrict output, const double t, - const int field, - const struct csds_parameters *params) { +__attribute__((always_inline)) INLINE static void hydro_csds_interpolate_field( + const double t_before, const struct csds_field *restrict before, + const double t_after, const struct csds_field *restrict after, + void *restrict output, const double t, const int field, + const struct csds_parameters *params) { #ifdef SWIFT_DEBUG_CHECKS /* Check the times */ diff --git a/src/hydro/SPHENIX/csds_hydro.h b/src/hydro/SPHENIX/csds_hydro.h index adea342d4b8641e263506d16de6ad9b612715033..2560deb29f3a400c256f468a999f12c27f8d275f 100644 --- a/src/hydro/SPHENIX/csds_hydro.h +++ b/src/hydro/SPHENIX/csds_hydro.h @@ -22,12 +22,12 @@ #include "../config.h" /* local includes */ -#include "hydro.h" -#include "hydro_csds.h" #include "csds_interpolation.h" #include "csds_loader_io.h" #include "csds_parameters.h" #include "csds_python_tools.h" +#include "hydro.h" +#include "hydro_csds.h" /* Index of the mask in the header mask array */ extern int hydro_csds_local_to_global[hydro_csds_field_count]; @@ -44,12 +44,9 @@ __attribute__((always_inline)) INLINE static void hydro_csds_reader_link_derivatives(struct header *head) { /* Set the first and second derivatives */ - const int pos_id = - hydro_csds_local_to_global[hydro_csds_field_coordinates]; - const int vel_id = - hydro_csds_local_to_global[hydro_csds_field_velocities]; - const int acc_id = - hydro_csds_local_to_global[hydro_csds_field_accelerations]; + const int pos_id = hydro_csds_local_to_global[hydro_csds_field_coordinates]; + const int vel_id = hydro_csds_local_to_global[hydro_csds_field_velocities]; + const int acc_id = hydro_csds_local_to_global[hydro_csds_field_accelerations]; /* Coordinates */ header_set_first_derivative(head, pos_id, vel_id); @@ -76,14 +73,11 @@ hydro_csds_reader_link_derivatives(struct header *head) { * #hydro_csds_fields). * @param params The simulation's #csds_parameters. */ -__attribute__((always_inline)) INLINE static void -hydro_csds_interpolate_field(const double t_before, - const struct csds_field *restrict before, - const double t_after, - const struct csds_field *restrict after, - void *restrict output, const double t, - const int field, - const struct csds_parameters *params) { +__attribute__((always_inline)) INLINE static void hydro_csds_interpolate_field( + const double t_before, const struct csds_field *restrict before, + const double t_after, const struct csds_field *restrict after, + void *restrict output, const double t, const int field, + const struct csds_parameters *params) { #ifdef SWIFT_DEBUG_CHECKS /* Check the times */ diff --git a/src/star_formation/GEAR/csds_star_formation.c b/src/star_formation/GEAR/csds_star_formation.c index 59e634401c83198e4514f4a7eb5638fe76add8ef..e8e41f34b46d6cd62244a69a3a6a72881e083250 100644 --- a/src/star_formation/GEAR/csds_star_formation.c +++ b/src/star_formation/GEAR/csds_star_formation.c @@ -23,11 +23,10 @@ /* Local headers */ #include "csds_tools.h" -const int star_formation_csds_field_size[star_formation_csds_field_count] = - { - member_size(struct spart, sf_data.birth_density) + - member_size(struct spart, sf_data.birth_mass) + - member_size(struct spart, sf_data.progenitor_id), +const int star_formation_csds_field_size[star_formation_csds_field_count] = { + member_size(struct spart, sf_data.birth_density) + + member_size(struct spart, sf_data.birth_mass) + + member_size(struct spart, sf_data.progenitor_id), }; int star_formation_csds_local_to_global[star_formation_csds_field_count]; diff --git a/src/star_formation/GEAR/csds_star_formation.h b/src/star_formation/GEAR/csds_star_formation.h index c73c6e052acca85287734d888c3349a32f7e15f0..0c79210a387f260079370ee21351bef524b7a897 100644 --- a/src/star_formation/GEAR/csds_star_formation.h +++ b/src/star_formation/GEAR/csds_star_formation.h @@ -29,8 +29,7 @@ #include "star_formation_csds.h" /* Index of the mask in the header mask array */ -extern int - star_formation_csds_local_to_global[star_formation_csds_field_count]; +extern int star_formation_csds_local_to_global[star_formation_csds_field_count]; /* Size for each mask */ extern const int @@ -62,11 +61,13 @@ star_formation_csds_reader_link_derivatives(struct header *head) {} * @param params The simulation's #csds_parameters. */ __attribute__((always_inline)) INLINE static void -star_formation_csds_interpolate_field( - const double t_before, const struct csds_field *restrict before, - const double t_after, const struct csds_field *restrict after, - void *restrict output, const double t, const int field, - const struct csds_parameters *params) { +star_formation_csds_interpolate_field(const double t_before, + const struct csds_field *restrict before, + const double t_after, + const struct csds_field *restrict after, + void *restrict output, const double t, + const int field, + const struct csds_parameters *params) { #ifdef SWIFT_DEBUG_CHECKS /* Check the times */ diff --git a/src/star_formation/none/csds_star_formation.c b/src/star_formation/none/csds_star_formation.c index 767190eec9f68e440afeaa4d32dade2d5b33d223..53f5b7ce0cd7dedc6e1a0cb0d4c3b02b2d2ff9af 100644 --- a/src/star_formation/none/csds_star_formation.c +++ b/src/star_formation/none/csds_star_formation.c @@ -23,7 +23,6 @@ /* Local headers */ #include "csds_tools.h" -const int star_formation_csds_field_size[star_formation_csds_field_count] = - {}; +const int star_formation_csds_field_size[star_formation_csds_field_count] = {}; int star_formation_csds_local_to_global[star_formation_csds_field_count]; diff --git a/src/star_formation/none/csds_star_formation.h b/src/star_formation/none/csds_star_formation.h index 13f806cf75bd7c2104a552383ba5c0e2635fa4a9..2e129a7cab58fc7ffc968d7f1f15f8ad43b4d3f0 100644 --- a/src/star_formation/none/csds_star_formation.h +++ b/src/star_formation/none/csds_star_formation.h @@ -29,8 +29,7 @@ #include "star_formation_csds.h" /* Index of the mask in the header mask array */ -extern int - star_formation_csds_local_to_global[star_formation_csds_field_count]; +extern int star_formation_csds_local_to_global[star_formation_csds_field_count]; /* Size for each mask */ extern const int @@ -62,11 +61,13 @@ star_formation_csds_reader_link_derivatives(struct header *head) {} * @param params The simulation's #csds_parameters. */ __attribute__((always_inline)) INLINE static void -star_formation_csds_interpolate_field( - const double t_before, const struct csds_field *restrict before, - const double t_after, const struct csds_field *restrict after, - void *restrict output, const double t, const int field, - const struct csds_parameters *params) {} +star_formation_csds_interpolate_field(const double t_before, + const struct csds_field *restrict before, + const double t_after, + const struct csds_field *restrict after, + void *restrict output, const double t, + const int field, + const struct csds_parameters *params) {} #ifdef HAVE_PYTHON __attribute__((always_inline)) INLINE static void diff --git a/src/stars/Basic/csds_stars.h b/src/stars/Basic/csds_stars.h index 1f989f672d833e9d470e3452214d0af1e2cf1eea..d3dbc427b61a5bd05556c18f5a0e84679ad48a9f 100644 --- a/src/stars/Basic/csds_stars.h +++ b/src/stars/Basic/csds_stars.h @@ -43,12 +43,9 @@ __attribute__((always_inline)) INLINE static void stars_csds_reader_link_derivatives(struct header *head) { /* Set the first and second derivatives */ - const int pos_id = - stars_csds_local_to_global[stars_csds_field_coordinates]; - const int vel_id = - stars_csds_local_to_global[stars_csds_field_velocities]; - const int acc_id = - stars_csds_local_to_global[stars_csds_field_accelerations]; + const int pos_id = stars_csds_local_to_global[stars_csds_field_coordinates]; + const int vel_id = stars_csds_local_to_global[stars_csds_field_velocities]; + const int acc_id = stars_csds_local_to_global[stars_csds_field_accelerations]; /* Coordinates */ header_set_first_derivative(head, pos_id, vel_id); @@ -75,14 +72,11 @@ stars_csds_reader_link_derivatives(struct header *head) { * #stars_csds_fields). * @param params The simulation's #csds_parameters. */ -__attribute__((always_inline)) INLINE static void -stars_csds_interpolate_field(const double t_before, - const struct csds_field *restrict before, - const double t_after, - const struct csds_field *restrict after, - void *restrict output, const double t, - const int field, - const struct csds_parameters *params) { +__attribute__((always_inline)) INLINE static void stars_csds_interpolate_field( + const double t_before, const struct csds_field *restrict before, + const double t_after, const struct csds_field *restrict after, + void *restrict output, const double t, const int field, + const struct csds_parameters *params) { #ifdef SWIFT_DEBUG_CHECKS /* Check the times */ diff --git a/src/stars/GEAR/csds_stars.h b/src/stars/GEAR/csds_stars.h index 9609f1d03a5a85f6c66c46ef921cc2c498d464f6..65f7831c4c78a7bb201f8400d03370228917c8c9 100644 --- a/src/stars/GEAR/csds_stars.h +++ b/src/stars/GEAR/csds_stars.h @@ -43,12 +43,9 @@ __attribute__((always_inline)) INLINE static void stars_csds_reader_link_derivatives(struct header *head) { /* Set the first and second derivatives */ - const int pos_id = - stars_csds_local_to_global[stars_csds_field_coordinates]; - const int vel_id = - stars_csds_local_to_global[stars_csds_field_velocities]; - const int acc_id = - stars_csds_local_to_global[stars_csds_field_accelerations]; + const int pos_id = stars_csds_local_to_global[stars_csds_field_coordinates]; + const int vel_id = stars_csds_local_to_global[stars_csds_field_velocities]; + const int acc_id = stars_csds_local_to_global[stars_csds_field_accelerations]; /* Coordinates */ header_set_first_derivative(head, pos_id, vel_id); @@ -75,14 +72,11 @@ stars_csds_reader_link_derivatives(struct header *head) { * #stars_csds_fields). * @param params The simulation's #csds_parameters. */ -__attribute__((always_inline)) INLINE static void -stars_csds_interpolate_field(const double t_before, - const struct csds_field *restrict before, - const double t_after, - const struct csds_field *restrict after, - void *restrict output, const double t, - const int field, - const struct csds_parameters *params) { +__attribute__((always_inline)) INLINE static void stars_csds_interpolate_field( + const double t_before, const struct csds_field *restrict before, + const double t_after, const struct csds_field *restrict after, + void *restrict output, const double t, const int field, + const struct csds_parameters *params) { #ifdef SWIFT_DEBUG_CHECKS /* Check the times */ diff --git a/tests/generate_log.h b/tests/generate_log.h index 62387bb355e869abbde233ae1f8626f4a6b4fef4..270aba9d0b3f0772c8416c68a6eb59c43fcb18c4 100644 --- a/tests/generate_log.h +++ b/tests/generate_log.h @@ -21,10 +21,10 @@ #include "../../config.h" /* Local headers */ -#include "engine.h" -#include "hydro.h" #include "csds.h" #include "csds_io.h" +#include "engine.h" +#include "hydro.h" /* Not all the fields are written at every step. * Here we define how often a few fields are written. @@ -118,7 +118,7 @@ void write_particles(struct csds_writer *log, struct engine *e) { // TODO write only a few masks at the time csds_log_part(log, &parts[j], &xparts[j], e, /* log_all */ 0, - /* flag */ 0, /* flag_data */ 0); + /* flag */ 0, /* flag_data */ 0); } } } @@ -184,21 +184,19 @@ void generate_log(struct swift_params *params, struct part *parts, csds_ensure_size(&log, nparts, /* number gpart */ 0, 0); /* Log all the particles before starting */ - csds_log_all_particles(&log, &e, /* first_log */1); + csds_log_all_particles(&log, &e, /* first_log */ 1); /* Write particles */ write_particles(&log, &e); /* Write a sentinel timestamp */ - csds_log_timestamp(e.csds, e.ti_current, e.time, - &e.csds->timestamp_offset); + csds_log_timestamp(e.csds, e.ti_current, e.time, &e.csds->timestamp_offset); /* Write all the particles at the end */ - csds_log_all_particles(e.csds, &e, /* first_log */0); + csds_log_all_particles(e.csds, &e, /* first_log */ 0); /* Write a sentinel timestamp */ - csds_log_timestamp(e.csds, e.ti_current, e.time, - &e.csds->timestamp_offset); + csds_log_timestamp(e.csds, e.ti_current, e.time, &e.csds->timestamp_offset); /* Cleanup the memory */ csds_free(&log); diff --git a/tests/testLogfileHeader.c b/tests/testLogfileHeader.c index dbe07b7555301e811dd77fefcca434d31a36d009..3890a761b7d3f9795d510245131aee4eac3a8ea1 100644 --- a/tests/testLogfileHeader.c +++ b/tests/testLogfileHeader.c @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) { /* Read the header */ csds_logfile_init_from_file(logfile, dump_filename, &reader, - /* only_header */ 1); + /* only_header */ 1); /* Finally check everything. */ diff --git a/tests/testLogfileReader.c b/tests/testLogfileReader.c index e9bd7663babc475459e172cd25b856039a103404..5d33ce98d9e4eff0e1d236b829ac639a2c3d691f 100644 --- a/tests/testLogfileReader.c +++ b/tests/testLogfileReader.c @@ -80,7 +80,7 @@ void check_data(struct csds_reader *reader, struct part *parts, /* Loop over each record. */ for (size_t offset = csds_reader_read_record(reader, output, &time, &is_particle, - logfile->header.offset_first_record); + logfile->header.offset_first_record); offset < logfile->log.mmap_size; offset = csds_reader_read_record(reader, output, &time, &is_particle, offset)) { diff --git a/tests/testVirtualReality.c b/tests/testVirtualReality.c index 132a8d69886daea06038f6d46f066cd460270141..183e62ea9117fef8f5980bdb72782a2cf9126c70 100644 --- a/tests/testVirtualReality.c +++ b/tests/testVirtualReality.c @@ -25,10 +25,10 @@ #include <stdlib.h> /* Local include */ -#include "generate_log.h" -#include "hydro.h" #include "csds.h" #include "csds_reader.h" +#include "generate_log.h" +#include "hydro.h" #define number_steps 10. #define number_parts 100 @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) { strcat(basename, "_0000"); csds_reader_init(&reader, basename, /* Verbose */ 0, /* number_threads */ 1, - /* number_index */5); + /* number_index */ 5); /* Read the time limits */ double begin = csds_reader_get_time_begin(&reader); @@ -135,9 +135,8 @@ int main(int argc, char *argv[]) { csds_reader_set_time(&reader, t); /* Read the next time */ - csds_reader_read_all_particles(&reader, t, csds_reader_lin, - required_fields, n_fields, output, - n_parts); + csds_reader_read_all_particles(&reader, t, csds_reader_lin, required_fields, + n_fields, output, n_parts); message("Particle %lli: %f %f %f %f", ids[part_ind], pos[3 * part_ind + 0], pos[3 * part_ind + 1], pos[3 * part_ind + 2], t);