logger.h 5.62 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*******************************************************************************
 * This file is part of SWIFT.
 * Copyright (c) 2017 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/
#ifndef SWIFT_LOGGER_H
#define SWIFT_LOGGER_H

lhausamm's avatar
lhausamm committed
22
23
#ifdef WITH_LOGGER

24
/* Includes. */
lhausamm's avatar
lhausamm committed
25
26
27
#include "common_io.h"
#include "engine.h"
#include "logger_struct.h"
28
#include "part.h"
lhausamm's avatar
lhausamm committed
29
#include "units.h"
30

31
32
33
/* Forward declaration */
struct dump;

34
35
/**
 * Logger entries contain messages representing the particle data at a given
36
 * point in time during the simulation.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 *
 * The logger messages always start with an 8-byte header structured as
 * follows:
 *
 *   data: [ mask |                     offset                     ]
 *   byte: [  01  |  02  |  03  |  04  |  05  |  06  |  07  |  08  ]
 *
 * I.e. a first "mask" byte followed by 7 "offset" bytes. The mask contains
 * information on what kind of data is packed after the header. The mask
 * bits correspond to the following data:
 *
 *   bit | name   | size | comment
 *   -------------------------------------------------------------------------
 *   0   | x      | 24   | The particle position, in absolute coordinates,
 *       |        |      | stored as three doubles.
 *   1   | v      | 12   | Particle velocity, stored as three floats.
 *   2   | a      | 12   | Particle acceleration, stored as three floats.
54
55
 *   3   | u      | 4    | Particle internal energy (or entropy, if Gadget-SPH
 *       |        |      | is used), stored as a single float.
56
57
 *   4   | h      | 4    | Particle smoothing length (or epsilon, if a gpart),
 *       |        |      | stored as a single float.
58
 *   5   | rho    | 4    | Particle density, stored as a single float.
59
60
 *   6   | consts | 12   | Particle constants, i.e. mass and ID.
 *   7   | time   | 8    | Timestamp, not associated with a particle, just
61
62
63
64
65
66
67
 *       |        |      | marks the transitions from one timestep to another.
 *
 * There is no distinction between gravity and SPH particles.
 *
 * The offset refers to the relative location of the previous message for the
 * same particle or for the previous timestamp (if mask bit 7 is set). I.e.
 * the previous log entry will be at the address of the current mask byte minus
lhausamm's avatar
lhausamm committed
68
69
 * the unsigned value stored in the offset. An offset equal to the chunk offset
 * indicated that this is the first message for the given particle/timestamp.
70
71
72
73
74
75
76
77
78
79
80
81
 */

/* Some constants. */
#define logger_mask_x 1
#define logger_mask_v 2
#define logger_mask_a 4
#define logger_mask_u 8
#define logger_mask_h 16
#define logger_mask_rho 32
#define logger_mask_consts 64
#define logger_mask_timestamp 128

lhausamm's avatar
lhausamm committed
82
83
84
#define logger_size_mask 1 // size of the mask
#define logger_size_offset 7 // size of the offset

85
86
87
88
89
/* 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
lhausamm's avatar
lhausamm committed
90
91
92
#define LOGGER_NAME_SIZE 2 // size of the labels size information
#define LOGGER_MASK_SIZE 1 // size of the masks size information
#define LOGGER_NBER_SIZE 1 // size of the number of elements information
lhausamm's avatar
lhausamm committed
93
#define LOGGER_OFFSET_SIZE 1// size of the offset size information
lhausamm's avatar
lhausamm committed
94
#define LOGGER_DATATYPE_SIZE 1 // size of the data type information
95

lhausamm's avatar
lhausamm committed
96
97
extern char LOGGER_VERSION[LOGGER_VERSION_SIZE];

lhausamm's avatar
lhausamm committed
98

99
struct logger_const {
lhausamm's avatar
lhausamm committed
100
101
102
  size_t name; // labels size
  size_t offset; // offset size
  size_t mask; // mask size
lhausamm's avatar
lhausamm committed
103
  size_t number; // number size
lhausamm's avatar
lhausamm committed
104
105
106
107
108
  size_t nber_mask; // number of different masks
  size_t *masks; // value of each masks (e.g. logger_mask_...)
  size_t *masks_size; // size of each mask
  char *masks_name; // label of each mask
  char *masks_type; // type of data (e.g. 'CHAR', 'INT', 'FLOAT')
109
110
};

111
112
113
114
115
enum logger_datatype {
  logger_data_int,
  logger_data_float,
  logger_data_double,
  logger_data_char,
116
  logger_data_longlong,
lhausamm's avatar
lhausamm committed
117
118
  logger_data_bool,
  logger_data_count /* should be last */
119
};
120

lhausamm's avatar
lhausamm committed
121
122
extern const unsigned int logger_data_size[];

123
/* Function prototypes. */
lhausamm's avatar
lhausamm committed
124
int logger_compute_chunk_size(unsigned int mask);
125
void logger_log_all(struct part *p,
lhausamm's avatar
lhausamm committed
126
127
		    const long long Np, struct dump *dump);
void logger_log_part(const struct part *p, const unsigned int mask, size_t *offset,
128
                     struct dump *dump);
lhausamm's avatar
lhausamm committed
129
void logger_log_gpart(const struct gpart *p, const unsigned int mask, size_t *offset,
130
                      struct dump *dump);
131
void logger_log_timestamp(integertime_t t, size_t *offset,
132
                          struct dump *dump);
Pedro Gonnet's avatar
Pedro Gonnet committed
133
134
135
136
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);
137
void logger_write_file_header(struct dump *dump, struct engine* e);
138
void logger_const_init(struct logger_const* log_const);
lhausamm's avatar
lhausamm committed
139
void logger_const_free(struct logger_const* log_const);
lhausamm's avatar
lhausamm committed
140
void logger_ensure_size(size_t total_nr_parts, size_t logger_buffer_size);
lhausamm's avatar
lhausamm committed
141

lhausamm's avatar
lhausamm committed
142
143
#endif /* WITH_LOGGER */

144
#endif /* SWIFT_LOGGER_H */