common_io.h 4 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
24
25

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

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

29
30
31
#define FIELD_BUFFER_SIZE 200
#define PARTICLE_GROUP_BUFFER_SIZE 50
#define FILENAME_BUFFER_SIZE 150
32
#define IO_BUFFER_ALIGNMENT 1024
33

34
/* Avoid cyclic inclusion problems */
35
36
37
struct part;
struct gpart;
struct spart;
38
39
struct io_props;
struct engine;
40
struct threadpool;
41

42
43
44
45
46
/**
 * @brief The different types of data used in the GADGET IC files.
 *
 * (This is admittedly a poor substitute to C++ templates...)
 */
47
enum IO_DATA_TYPE {
48
49
50
51
52
53
54
55
56
57
  INT,
  LONG,
  LONGLONG,
  UINT,
  ULONG,
  ULONGLONG,
  FLOAT,
  DOUBLE,
  CHAR
};
58

59
60
61
62
/**
 * @brief The different formats for when to run structure finding.
 *
 */
Matthieu Schaller's avatar
Matthieu Schaller committed
63
enum IO_STF_OUTPUT_FORMAT { STEPS = 0, TIME };
64

65
66
#if defined(HAVE_HDF5)

67
hid_t io_hdf5_type(enum IO_DATA_TYPE type);
68

69
void io_read_attribute(hid_t grp, const char* name, enum IO_DATA_TYPE type,
70
                       void* data);
71

72
73
void io_write_attribute(hid_t grp, const char* name, enum IO_DATA_TYPE type,
                        void* data, int num);
74

75
76
77
78
79
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);
80

81
void io_write_code_description(hid_t h_file);
82
void io_write_engine_policy(hid_t h_file, const struct engine* e);
83

84
85
86
void io_read_unit_system(hid_t h_file, struct unit_system* ic_units,
                         const struct unit_system* internal_units,
                         int mpi_rank);
87
88
void io_write_unit_system(hid_t h_grp, const struct unit_system* us,
                          const char* groupName);
89

90
91
92
93
94
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);

95
#endif /* defined HDF5 */
96

97
98
99
size_t io_sizeof_type(enum IO_DATA_TYPE type);
int io_is_double_precision(enum IO_DATA_TYPE type);

100
101
void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot,
                          struct gpart* const dmparts, size_t Ndm);
102
103
void io_prepare_dm_gparts(struct threadpool* tp, struct gpart* const gparts,
                          size_t Ndm);
104
void io_duplicate_hydro_gparts(struct threadpool* tp, struct part* const parts,
105
106
                               struct gpart* const gparts, size_t Ngas,
                               size_t Ndm);
107
void io_duplicate_stars_gparts(struct threadpool* tp, struct spart* const sparts,
108
109
110
                              struct gpart* const gparts, size_t Nstars,
                              size_t Ndm);

111
void io_check_output_fields(const struct swift_params* params,
112
                            const long long N_total[3]);
113

114
115
void io_write_output_field_parameter(const char* filename);

116
#endif /* SWIFT_COMMON_IO_H */