diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index a9fd08c585638d553c605749806bd55b7b426452..65384be73c02dcdde36cd63e87577e946693b8f9 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -91,8 +91,8 @@ Snapshots: output_list_on: 0 # (Optional) Enable the output list output_list: snaplist.txt # (Optional) File containing the output times (see documentation in "Parameter File" section) logger_max_steps: 10 # (Optional) Number of particle steps between two chunk writing if using logger - logger_size: 1e7 # buffer size of the logger file in bytes - + logger_size: 10. # buffer size of the logger file in MB + # Parameters governing the conserved quantities statistics Statistics: delta_time: 1e-2 # Time between statistics output diff --git a/src/dump.c b/src/dump.c index 5ea033e8fc03055838d1b5d085758a0b3f149129..5c0fb80604eaf899f2ef8771b5251808caf75406 100644 --- a/src/dump.c +++ b/src/dump.c @@ -56,6 +56,7 @@ void *dump_get(struct dump *d, size_t count, size_t *offset) { return (char *)d->data + local_offset; } + /** * @brief Ensure that at least size bytes are available in the #dump. */ diff --git a/src/engine.c b/src/engine.c index 96b2eeeaf0f3ab11149642ef15e5e5f682f02d90..d0741dc866c4a39cf1050dfcb81d99ac36364334 100644 --- a/src/engine.c +++ b/src/engine.c @@ -6701,11 +6701,17 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params, /* Logger params */ char logger_name_file[PARSER_MAX_LINE_SIZE]; e->logger_max_steps = parser_get_opt_param_int(params, "Snapshots:logger_max_steps", 10); - e->logger_size = parser_get_param_float(params, "Snapshots:logger_size"); + e->logger_size = parser_get_param_float(params, "Snapshots:logger_size") * 1e6; + + /* generate dump filename */ strcpy(logger_name_file, e->snapshotBaseName); strcat(logger_name_file, ".dump"); + + /* init dump */ e->logger_dump = malloc(sizeof(struct dump)); - dump_init(e->logger_dump, logger_name_file, e->logger_size); + struct dump *dump_file = e->logger_dump; + dump_init(dump_file, logger_name_file, e->logger_size); + logger_write_file_header(dump_file); e->logger_time_offset = 0; #endif diff --git a/src/logger.c b/src/logger.c index 4d71d471d9fbc410a6cfc08a097938bde989c3d0..1ae37686ea2365b32ceee47a0f37f10c3e2dde4e 100644 --- a/src/logger.c +++ b/src/logger.c @@ -257,6 +257,120 @@ void logger_log_timestamp(unsigned long long int timestamp, size_t *offset, *offset = offset_new; } +/** + * @brief Write a file header to a logger file + * + * @param offset Pointer to the offset of the previous log of this particle. + * @param dump The #dump in which to log the particle data. + * + */ +void logger_write_file_header(struct dump *dump) { + size_t i, j; + char *buff, *name_buff, *skip_header; + size_t *file_offset; + size_t mask_size; + + struct logger_const log_const; + logger_const_init(&log_const); + + file_offset = &dump->file_offset; + + if (*file_offset != 0) error("Something was already written in the dump file"); + + /* Write version information */ + buff = dump_get(dump, LOGGER_VERSION_SIZE, file_offset); + memcpy(buff, LOGGER_VERSION, LOGGER_VERSION_SIZE); + + /* write number of bytes used for the offsets */ + buff = dump_get(dump, LOGGER_OFFSET_SIZE, file_offset); + memcpy(buff, &log_const.offset, LOGGER_OFFSET_SIZE); + + /* will write the offset of the first particle here */ + skip_header = dump_get(dump, log_const.name, file_offset); + + /* write number of bytes used for names */ + buff = dump_get(dump, LOGGER_NAME_SIZE, file_offset); + memcpy(buff, &log_const.name, LOGGER_NAME_SIZE); + + + mask_size = log_const.nber_mask * (log_const.name + log_const.mask); + name_buff = dump_get(dump, mask_size, file_offset); + for(i=0; i<log_const.nber_mask; i++) { + j = i * (log_const.name + log_const.mask); + + // name + memcpy(name_buff, &log_const.masks_name[j], log_const.name); + name_buff += j; + + // mask + memcpy(name_buff, &log_const.masks[i], log_const.mask); + name_buff += log_const.mask; + } + + + /* last step */ + memcpy(skip_header, file_offset, log_const.offset); + +} + +void logger_const_init(struct logger_const* log_const) { + log_const->name = 10; + log_const->offset = 7; + log_const->mask = 1; + + log_const->nber_mask = 8; + + // masks value + log_const->masks = malloc(sizeof(size_t)*log_const->nber_mask); + log_const->masks[0] = logger_mask_x; + log_const->masks[1] = logger_mask_v; + log_const->masks[2] = logger_mask_a; + log_const->masks[3] = logger_mask_u; + log_const->masks[4] = logger_mask_h; + log_const->masks[5] = logger_mask_rho; + log_const->masks[6] = logger_mask_consts; + log_const->masks[7] = logger_mask_timestamp; + + // masks name + size_t name_size = sizeof(char) * log_const->name; + log_const->masks_name = malloc(name_size*log_const->nber_mask); + char *tmp = malloc(sizeof(char) * log_const->name); + + tmp = "position"; + memcpy(log_const->masks_name, &tmp, log_const->name); + log_const->masks_name += log_const->name * sizeof(char); + + tmp = "velocity"; + memcpy(log_const->masks_name, &tmp, log_const->name); + log_const->masks_name += log_const->name * sizeof(char); + + tmp = "acceleration"; + memcpy(log_const->masks_name, &tmp, log_const->name); + log_const->masks_name += log_const->name * sizeof(char); + + tmp = "entropy"; + memcpy(log_const->masks_name, &tmp, log_const->name); + log_const->masks_name += log_const->name * sizeof(char); + + tmp = "cutoff radius"; + memcpy(log_const->masks_name, &tmp, log_const->name); + log_const->masks_name += log_const->name * sizeof(char); + + tmp = "density"; + memcpy(log_const->masks_name, &tmp, log_const->name); + log_const->masks_name += log_const->name * sizeof(char); + + tmp = "consts"; + memcpy(log_const->masks_name, &tmp, log_const->name); + log_const->masks_name += log_const->name * sizeof(char); + + tmp = "timestamp"; + memcpy(log_const->masks_name, &tmp, log_const->name); + log_const->masks_name += log_const->name * sizeof(char); + +} + + /** * @brief Read a logger message and store the data in a #part. * diff --git a/src/logger.h b/src/logger.h index 37795f036a1260419a755a317395a272a3b0b625..962180dc4d7b193dcd07d3c5b64a000d5c4f1e31 100644 --- a/src/logger.h +++ b/src/logger.h @@ -29,6 +29,7 @@ /* Forward declaration */ struct dump; +#define LOGGER_VERSION "0.1" /** * Logger entries contain messages representing the particle data at a given @@ -78,6 +79,26 @@ struct dump; #define logger_mask_consts 64 #define logger_mask_timestamp 128 +/* header constants + * Thoses are definitions from the format and therefore should not be changed! + * Size in bytes + */ +#define LOGGER_VERSION_SIZE 20 // size of the version message +#define LOGGER_OFFSET_SIZE 1// size of the offset size information +#define LOGGER_NAME_SIZE 2 // size of the labels +#define LOGGER_MASK_SIZE 1 // size of the masks +#define LOGGER_NBER_SIZE 1 // size of the number of elements + +struct logger_const { + size_t name; + size_t offset; + size_t mask; + size_t nber_mask; + size_t *masks; + char *masks_name; +}; + + /* Function prototypes. */ int logger_size(unsigned int mask); void logger_log_part(struct part *p, unsigned int mask, size_t *offset, @@ -90,7 +111,8 @@ int logger_read_part(struct part *p, size_t *offset, const char *buff); int logger_read_gpart(struct gpart *p, size_t *offset, const char *buff); int logger_read_timestamp(unsigned long long int *t, size_t *offset, const char *buff); - +void logger_write_file_header(struct dump *dump); +void logger_const_init(struct logger_const* log_const); /**