space.h 9.02 KB
Newer Older
1
/*******************************************************************************
2
 * This file is part of SWIFT.
3
 * Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
4
5
6
7
 *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
 *               2015 Peter W. Draper (p.w.draper@durham.ac.uk)
 *               2016 John A. Regan (john.a.regan@durham.ac.uk)
 *                    Tom Theuns (tom.theuns@durham.ac.uk)
8
 *
9
10
11
12
 * 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.
13
 *
14
15
16
17
 * 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.
18
 *
19
20
 * 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/>.
21
 *
22
 ******************************************************************************/
23
24
#ifndef SWIFT_SPACE_H
#define SWIFT_SPACE_H
Pedro Gonnet's avatar
Pedro Gonnet committed
25

26
27
28
29
/* Config parameters. */
#include "../config.h"

/* Some standard headers. */
30
31
#include <stddef.h>

32
/* Includes. */
33
#include "gravity_properties.h"
34
#include "hydro_space.h"
35
#include "lock.h"
36
#include "parser.h"
37
#include "part.h"
38

39
40
/* Avoid cyclic inclusions */
struct cell;
41
struct cosmology;
42

Pedro Gonnet's avatar
Pedro Gonnet committed
43
/* Some constants. */
44
45
46
#define space_cellallocchunk 1000
#define space_splitsize_default 400
#define space_maxsize_default 8000000
47
48
49
#define space_subsize_pair_hydro_default 256000000
#define space_subsize_self_hydro_default 32000
#define space_subsize_pair_grav_default 256000000
50
#define space_subsize_self_grav_default 32000
51
#define space_max_top_level_cells_default 12
52
#define space_stretch 1.10f
53
#define space_maxreldx 0.1f
Pedro Gonnet's avatar
Pedro Gonnet committed
54

55
56
57
/* Maximum allowed depth of cell splits. */
#define space_cell_maxdepth 52

Pedro Gonnet's avatar
Pedro Gonnet committed
58
59
/* Split size. */
extern int space_splitsize;
60
extern int space_maxsize;
61
62
63
extern int space_subsize_pair_hydro;
extern int space_subsize_self_hydro;
extern int space_subsize_pair_grav;
64
extern int space_subsize_self_grav;
Pedro Gonnet's avatar
Pedro Gonnet committed
65

66
/**
67
 * @brief The space in which the cells and particles reside.
68
 */
Pedro Gonnet's avatar
Pedro Gonnet committed
69
70
struct space {

71
  /*! Spatial extent. */
72
73
  double dim[3];

74
75
76
  /*! Is the space periodic? */
  int periodic;

77
78
79
  /*! Extra space information needed for some hydro schemes. */
  struct hydro_space hs;

80
81
82
  /*! Are we doing gravity? */
  int gravity;

83
84
  /*! Width of the top-level cells. */
  double width[3];
85

86
  /*! Inverse of the top-level cell width */
87
88
  double iwidth[3];

89
  /*! The minimum top-level cell width allowed. */
90
  double cell_min;
91

92
  /*! Current maximum displacement for particles. */
93
94
  float dx_max;

95
  /*! Space dimensions in number of top-cells. */
96
97
98
99
  int cdim[3];

  /*! Maximal depth reached by the tree */
  int maxdepth;
100

101
102
103
104
105
106
  /*! Number of top-level cells. */
  int nr_cells;

  /*! Total number of cells (top- and sub-) */
  int tot_cells;

107
  /*! Number of *local* top-level cells with tasks */
108
109
  int nr_local_cells;

110
111
  /*! The (level 0) cells themselves. */
  struct cell *cells_top;
112

113
114
  /*! Buffer of unused cells for the sub-cells. */
  struct cell *cells_sub;
115

116
  /*! The multipoles associated with the top-level (level 0) cells */
117
  struct gravity_tensors *multipoles_top;
118
119

  /*! Buffer of unused multipoles for the sub-cells. */
120
  struct gravity_tensors *multipoles_sub;
121

122
  /*! The indices of the *local* top-level cells with tasks */
123
124
  int *local_cells_top;

125
  /*! The total number of parts in the space. */
126
  size_t nr_parts, size_parts;
127
128

  /*! The total number of g-parts in the space. */
129
  size_t nr_gparts, size_gparts;
130

131
132
133
  /*! The total number of g-parts in the space. */
  size_t nr_sparts, size_sparts;

134
135
  /*! The particle data (cells have pointers to this). */
  struct part *parts;
136

137
138
139
140
141
  /*! The extended particle data (cells have pointers to this). */
  struct xpart *xparts;

  /*! The g-particle data (cells have pointers to this). */
  struct gpart *gparts;
142

143
144
145
  /*! The s-particle data (cells have pointers to this). */
  struct spart *sparts;

146
147
148
  /*! The top-level FFT task */
  struct task *grav_top_level;

149
  /*! General-purpose lock for this space. */
150
  swift_lock_type lock;
151

152
  /*! Number of queues in the system. */
153
154
  int nr_queues;

155
  /*! The associated engine. */
156
  struct engine *e;
Pedro Gonnet's avatar
Pedro Gonnet committed
157

158
159
160
#ifdef WITH_MPI

  /*! Buffers for parts that we will receive from foreign cells. */
161
  struct part *parts_foreign;
162
  size_t nr_parts_foreign, size_parts_foreign;
163
164

  /*! Buffers for g-parts that we will receive from foreign cells. */
165
166
  struct gpart *gparts_foreign;
  size_t nr_gparts_foreign, size_gparts_foreign;
167

168
169
170
171
  /*! Buffers for g-parts that we will receive from foreign cells. */
  struct spart *sparts_foreign;
  size_t nr_sparts_foreign, size_sparts_foreign;

172
#endif
173
};
Pedro Gonnet's avatar
Pedro Gonnet committed
174
175

/* function prototypes. */
176
void space_parts_sort(struct space *s, int *ind, size_t N, int min, int max,
177
                      int verbose);
Matthieu Schaller's avatar
Matthieu Schaller committed
178
void space_gparts_sort(struct space *s, int *ind, size_t N, int min, int max,
179
                       int verbose);
180
181
void space_sparts_sort(struct space *s, int *ind, size_t N, int min, int max,
                       int verbose);
182
void space_getcells(struct space *s, int nr_cells, struct cell **cells);
183
void space_init(struct space *s, const struct swift_params *params,
184
185
186
187
                const struct cosmology *cosmo, double dim[3],
                struct part *parts, struct gpart *gparts, struct spart *sparts,
                size_t Npart, size_t Ngpart, size_t Nspart, int periodic,
                int replicate, int generate_gas_in_ics, int gravity,
188
                int verbose, int dry_run);
189
void space_sanitize(struct space *s);
190
191
192
193
194
void space_map_cells_pre(struct space *s, int full,
                         void (*fun)(struct cell *c, void *data), void *data);
void space_map_parts(struct space *s,
                     void (*fun)(struct part *p, struct cell *c, void *data),
                     void *data);
195
void space_map_parts_xparts(struct space *s,
196
197
                            void (*fun)(struct part *p, struct xpart *xp,
                                        struct cell *c));
198
199
void space_map_cells_post(struct space *s, int full,
                          void (*fun)(struct cell *c, void *data), void *data);
200
201
202
203
void space_parts_sort_mapper(void *map_data, int num_elements,
                             void *extra_data);
void space_gparts_sort_mapper(void *map_data, int num_elements,
                              void *extra_data);
204
205
void space_sparts_sort_mapper(void *map_data, int num_elements,
                              void *extra_data);
206
void space_rebuild(struct space *s, int verbose);
207
void space_recycle(struct space *s, struct cell *c);
208
209
void space_recycle_list(struct space *s, struct cell *cell_list_begin,
                        struct cell *cell_list_end,
210
211
                        struct gravity_tensors *multipole_list_begin,
                        struct gravity_tensors *multipole_list_end);
212
213
void space_split(struct space *s, struct cell *cells, int nr_cells,
                 int verbose);
214
void space_split_mapper(void *map_data, int num_elements, void *extra_data);
215
void space_list_cells_with_tasks(struct space *s);
216
217
218
219
void space_parts_get_cell_index(struct space *s, int *ind, struct cell *cells,
                                int verbose);
void space_gparts_get_cell_index(struct space *s, int *gind, struct cell *cells,
                                 int verbose);
220
221
void space_sparts_get_cell_index(struct space *s, int *sind, struct cell *cells,
                                 int verbose);
222
void space_synchronize_particle_positions(struct space *s);
223
void space_do_parts_sort();
224
void space_do_gparts_sort();
225
void space_do_sparts_sort();
226
void space_first_init_parts(struct space *s,
227
228
                            const struct chemistry_data *chemistry,
                            const struct cooling_function_data *cool_func);
229
230
void space_first_init_gparts(struct space *s,
                             const struct gravity_props *grav_props);
231
void space_first_init_sparts(struct space *s);
232
233
234
void space_init_parts(struct space *s, int verbose);
void space_init_gparts(struct space *s, int verbose);
void space_convert_quantities(struct space *s, int verbose);
235
void space_link_cleanup(struct space *s);
236
237
238
239
void space_check_drift_point(struct space *s, integertime_t ti_drift,
                             int multipole);
void space_check_top_multipoles_drift_point(struct space *s,
                                            integertime_t ti_drift);
240
void space_check_timesteps(struct space *s);
241
void space_replicate(struct space *s, int replicate, int verbose);
242
243
void space_generate_gas(struct space *s, const struct cosmology *cosmo,
                        int verbose);
244
245
void space_check_cosmology(struct space *s, const struct cosmology *cosmo,
                           int rank);
246
void space_reset_task_counters(struct space *s);
247
void space_clean(struct space *s);
248
void space_free_cells(struct space *s);
249

250
251
252
void space_struct_dump(struct space *s, FILE *stream);
void space_struct_restore(struct space *s, FILE *stream);

253
#endif /* SWIFT_SPACE_H */