common_io.h 8.51 KB
Newer Older
1 2
/*******************************************************************************
 * This file is part of SWIFT.
3
 * Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk),
4
 *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk).
5
 *
6 7 8 9
 * 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.
10
 *
11 12 13 14
 * 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.
15
 *
16 17
 * 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/>.
18
 *
19
 ******************************************************************************/
20 21
#ifndef SWIFT_COMMON_IO_H
#define SWIFT_COMMON_IO_H
22 23

/* Config parameters. */
24
#include "config.h"
25

26
/* Local includes. */
27
#include "part_type.h"
28

29
#define FIELD_BUFFER_SIZE 64
30
#define DESCRIPTION_BUFFER_SIZE 512
31 32
#define PARTICLE_GROUP_BUFFER_SIZE 50
#define FILENAME_BUFFER_SIZE 150
33
#define IO_BUFFER_ALIGNMENT 1024
34

35
/* Avoid cyclic inclusion problems */
36
struct cell;
37 38
struct part;
struct gpart;
39
struct velociraptor_gpart_data;
40
struct spart;
41
struct bpart;
42
struct xpart;
Loic Hausammann's avatar
Loic Hausammann committed
43
struct sink;
44 45
struct io_props;
struct engine;
46
struct threadpool;
47 48
struct output_options;
struct unit_system;
49

50 51 52 53 54
/**
 * @brief The different types of data used in the GADGET IC files.
 *
 * (This is admittedly a poor substitute to C++ templates...)
 */
55
enum IO_DATA_TYPE {
56 57 58 59
  INT,
  LONG,
  LONGLONG,
  UINT,
Loic Hausammann's avatar
Loic Hausammann committed
60
  UINT64,
61 62 63 64
  ULONG,
  ULONGLONG,
  FLOAT,
  DOUBLE,
Loic Hausammann's avatar
Loic Hausammann committed
65 66
  CHAR,
  SIZE_T,
67
};
68

69 70
#if defined(HAVE_HDF5)

71 72 73
/* Library header */
#include <hdf5.h>

74
hid_t io_hdf5_type(enum IO_DATA_TYPE type);
75

Loic Hausammann's avatar
Gear  
Loic Hausammann committed
76 77
hsize_t io_get_number_element_in_attribute(hid_t attr);
hsize_t io_get_number_element_in_dataset(hid_t dataset);
78
void io_read_attribute(hid_t grp, const char* name, enum IO_DATA_TYPE type,
79
                       void* data);
Josh Borrow's avatar
Josh Borrow committed
80 81 82
void io_read_attribute_graceful(hid_t grp, const char* name,
                                enum IO_DATA_TYPE type, void* data);
void io_assert_valid_header_cosmology(hid_t h_grp, double a);
83

Loic Hausammann's avatar
Gear  
Loic Hausammann committed
84 85 86 87 88
void io_read_array_attribute(hid_t grp, const char* name,
                             enum IO_DATA_TYPE type, void* data,
                             hsize_t number_element);
void io_read_array_dataset(hid_t grp, const char* name, enum IO_DATA_TYPE type,
                           void* data, hsize_t number_element);
89
void io_write_attribute(hid_t grp, const char* name, enum IO_DATA_TYPE type,
90
                        const void* data, int num);
91

92 93 94 95 96
void io_write_attribute_d(hid_t grp, const char* name, double data);
void io_write_attribute_f(hid_t grp, const char* name, float data);
void io_write_attribute_i(hid_t grp, const char* name, int data);
void io_write_attribute_l(hid_t grp, const char* name, long data);
void io_write_attribute_s(hid_t grp, const char* name, const char* str);
97

98 99 100 101
void io_write_meta_data(hid_t h_file, const struct engine* e,
                        const struct unit_system* internal_units,
                        const struct unit_system* snapshot_units);

102
void io_write_code_description(hid_t h_file);
103
void io_write_engine_policy(hid_t h_file, const struct engine* e);
104

105
void io_write_cell_offsets(hid_t h_grp, const int cdim[3], const double dim[3],
106 107
                           const struct cell* cells_top, const int nr_cells,
                           const double width[3], const int nodeID,
108
                           const int distributed,
109
                           const long long global_counts[swift_type_count],
110
                           const long long global_offsets[swift_type_count],
111
                           const int num_fields[swift_type_count],
112 113
                           const struct unit_system* internal_units,
                           const struct unit_system* snapshot_units);
114

115 116 117
void io_read_unit_system(hid_t h_file, struct unit_system* ic_units,
                         const struct unit_system* internal_units,
                         int mpi_rank);
118 119
void io_write_unit_system(hid_t h_grp, const struct unit_system* us,
                          const char* groupName);
120

121 122 123 124 125
void io_copy_temp_buffer(void* temp, const struct engine* e,
                         const struct io_props props, size_t N,
                         const struct unit_system* internal_units,
                         const struct unit_system* snapshot_units);

126
#endif /* HAVE_HDF5 */
127

128 129 130
size_t io_sizeof_type(enum IO_DATA_TYPE type);
int io_is_double_precision(enum IO_DATA_TYPE type);

131
void io_collect_parts_to_write(const struct part* restrict parts,
Matthieu Schaller's avatar
Matthieu Schaller committed
132 133 134 135 136
                               const struct xpart* restrict xparts,
                               struct part* restrict parts_written,
                               struct xpart* restrict xparts_written,
                               const size_t Nparts,
                               const size_t Nparts_written);
Loic Hausammann's avatar
Loic Hausammann committed
137 138 139 140
void io_collect_sinks_to_write(const struct sink* restrict sinks,
                               struct sink* restrict sinks_written,
                               const size_t Nsinks,
                               const size_t Nsinks_written);
141
void io_collect_sparts_to_write(const struct spart* restrict sparts,
Matthieu Schaller's avatar
Matthieu Schaller committed
142 143 144
                                struct spart* restrict sparts_written,
                                const size_t Nsparts,
                                const size_t Nsparts_written);
145 146 147 148
void io_collect_bparts_to_write(const struct bpart* restrict bparts,
                                struct bpart* restrict bparts_written,
                                const size_t Nbparts,
                                const size_t Nbparts_written);
149
void io_collect_gparts_to_write(const struct gpart* restrict gparts,
150
                                const struct velociraptor_gpart_data* vr_data,
Matthieu Schaller's avatar
Matthieu Schaller committed
151
                                struct gpart* restrict gparts_written,
152
                                struct velociraptor_gpart_data* vr_data_written,
Matthieu Schaller's avatar
Matthieu Schaller committed
153
                                const size_t Ngparts,
154
                                const size_t Ngparts_written, int with_stf);
155 156 157 158 159 160
void io_collect_gparts_background_to_write(
    const struct gpart* restrict gparts,
    const struct velociraptor_gpart_data* vr_data,
    struct gpart* restrict gparts_written,
    struct velociraptor_gpart_data* vr_data_written, const size_t Ngparts,
    const size_t Ngparts_written, int with_stf);
161 162
void io_prepare_dm_gparts(struct threadpool* tp, struct gpart* const gparts,
                          size_t Ndm);
163 164
void io_prepare_dm_background_gparts(struct threadpool* tp,
                                     struct gpart* const gparts, size_t Ndm);
165 166
size_t io_count_dm_background_gparts(const struct gpart* const gparts,
                                     size_t Ndm);
167
void io_duplicate_hydro_gparts(struct threadpool* tp, struct part* const parts,
168 169
                               struct gpart* const gparts, size_t Ngas,
                               size_t Ndm);
170 171 172 173
void io_duplicate_stars_gparts(struct threadpool* tp,
                               struct spart* const sparts,
                               struct gpart* const gparts, size_t Nstars,
                               size_t Ndm);
Loic Hausammann's avatar
Loic Hausammann committed
174 175 176
void io_duplicate_sinks_gparts(struct threadpool* tp, struct sink* const sinks,
                               struct gpart* const gparts, size_t Nsinks,
                               size_t Ndm);
177 178 179 180
void io_duplicate_black_holes_gparts(struct threadpool* tp,
                                     struct bpart* const bparts,
                                     struct gpart* const gparts, size_t Nstars,
                                     size_t Ndm);
181

182 183 184
void io_prepare_output_fields(struct output_options* output_options,
                              const int with_cosmology, const int with_fof,
                              const int with_stf);
185

186
void io_write_output_field_parameter(const char* filename, int with_cosmology);
187

188 189
void io_make_snapshot_subdir(const char* dirname);

190 191 192 193 194 195
void io_get_snapshot_filename(char filename[1024], char xmf_filename[1024],
                              const int use_time_label,
                              const int snapshots_invoke_stf, const double time,
                              const int stf_count, const int snap_count,
                              const char* subdir, const char* basename);

196
void io_set_ids_to_one(struct gpart* gparts, const size_t Ngparts);
197

198
#endif /* SWIFT_COMMON_IO_H */