space.h 15.2 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 "hydro_space.h"
34
#include "lock.h"
35
#include "parser.h"
36
#include "part.h"
Loic Hausammann's avatar
Loic Hausammann committed
37
#include "space_unique_id.h"
38
#include "velociraptor_struct.h"
39

40
41
/* Avoid cyclic inclusions */
struct cell;
42
struct cosmology;
43
struct gravity_props;
Loic Hausammann's avatar
Loic Hausammann committed
44
struct star_formation;
45
struct hydro_props;
46

Pedro Gonnet's avatar
Pedro Gonnet committed
47
/* Some constants. */
48
49
50
#define space_cellallocchunk 1000
#define space_splitsize_default 400
#define space_maxsize_default 8000000
51
52
#define space_extra_parts_default 0
#define space_extra_gparts_default 0
53
#define space_extra_sparts_default 100
54
#define space_extra_bparts_default 0
Loic Hausammann's avatar
Loic Hausammann committed
55
#define space_extra_sinks_default 0
56
#define space_expected_max_nr_strays_default 100
57
58
#define space_subsize_pair_hydro_default 256000000
#define space_subsize_self_hydro_default 32000
59
60
#define space_subsize_pair_stars_default 256000000
#define space_subsize_self_stars_default 32000
61
#define space_subsize_pair_grav_default 256000000
62
#define space_subsize_self_grav_default 32000
63
#define space_subdepth_diff_grav_default 4
64
#define space_max_top_level_cells_default 12
65
#define space_stretch 1.10f
66
#define space_maxreldx 0.1f
Pedro Gonnet's avatar
Pedro Gonnet committed
67

68
69
70
/* Maximum allowed depth of cell splits. */
#define space_cell_maxdepth 52

71
72
/* Globals needed in contexts without a space struct. Remember to dump and
 * restore these. */
Pedro Gonnet's avatar
Pedro Gonnet committed
73
extern int space_splitsize;
74
extern int space_maxsize;
75
76
extern int space_subsize_pair_hydro;
extern int space_subsize_self_hydro;
77
78
extern int space_subsize_pair_stars;
extern int space_subsize_self_stars;
79
extern int space_subsize_pair_grav;
80
extern int space_subsize_self_grav;
81
extern int space_subdepth_diff_grav;
82
83
84
extern int space_extra_parts;
extern int space_extra_gparts;
extern int space_extra_sparts;
85
extern int space_extra_bparts;
Pedro Gonnet's avatar
Pedro Gonnet committed
86

87
/**
88
 * @brief The space in which the cells and particles reside.
89
 */
Pedro Gonnet's avatar
Pedro Gonnet committed
90
91
struct space {

92
  /*! Spatial extent. */
93
94
  double dim[3];

95
96
97
  /*! Is the space periodic? */
  int periodic;

98
99
100
  /*! Extra space information needed for some hydro schemes. */
  struct hydro_space hs;

101
  /*! Are we doing hydrodynamics? */
102
  int with_hydro;
103

104
  /*! Are we doing gravity? */
105
  int with_self_gravity;
106

107
108
109
  /*! Are we doing star formation? */
  int with_star_formation;

110
111
112
  /*! Are we running with some DM background particles? */
  int with_DM_background;

113
114
  /*! Width of the top-level cells. */
  double width[3];
115

116
  /*! Inverse of the top-level cell width */
117
118
  double iwidth[3];

119
120
121
122
123
124
125
126
  /*! Position vector added to all the particles at rebuild
    time */
  double pos_dithering[3];

  /*! Position vector added to all the particles at rebuild
    time (value at the previous rebuild) */
  double pos_dithering_old[3];

127
  /*! The minimum top-level cell width allowed. */
128
  double cell_min;
129

130
  /*! Space dimensions in number of top-cells. */
131
132
133
134
  int cdim[3];

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

136
137
138
139
140
141
  /*! Number of top-level cells. */
  int nr_cells;

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

142
  /*! Number of *local* top-level cells */
143
144
  int nr_local_cells;

145
146
147
  /*! Number of *local* top-level cells with tasks */
  int nr_local_cells_with_tasks;

148
149
  /*! Number of top-level cells that have >0 particle (of any kind) */
  int nr_cells_with_particles;
150

151
152
153
  /*! Number of top-level cells that have >0 particle (of any kind) */
  int nr_local_cells_with_particles;

154
155
  /*! The (level 0) cells themselves. */
  struct cell *cells_top;
156

157
158
  /*! Buffer of unused cells for the sub-cells. */
  struct cell *cells_sub;
159

160
  /*! The multipoles associated with the top-level (level 0) cells */
161
  struct gravity_tensors *multipoles_top;
162
163

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

166
  /*! The indices of the *local* top-level cells */
167
168
  int *local_cells_top;

169
170
171
  /*! The indices of the *local* top-level cells with tasks */
  int *local_cells_with_tasks_top;

Peter W. Draper's avatar
Peter W. Draper committed
172
  /*! The indices of the top-level cells that have >0 particles (of any kind) */
173
  int *cells_with_particles_top;
174

Peter W. Draper's avatar
Peter W. Draper committed
175
  /*! The indices of the top-level cells that have >0 particles (of any kind) */
176
177
  int *local_cells_with_particles_top;

178
179
  /*! The total number of #part in the space. */
  size_t nr_parts;
180

181
182
  /*! The total number of #gpart in the space. */
  size_t nr_gparts;
183

184
185
186
  /*! The total number of #spart in the space. */
  size_t nr_sparts;

187
188
189
  /*! The total number of #bpart in the space. */
  size_t nr_bparts;

190
191
192
  /*! The total number of #sink in the space. */
  size_t nr_sinks;

193
194
195
196
197
198
199
200
  /*! The total number of #part we allocated memory for */
  size_t size_parts;

  /*! The total number of #gpart we allocated memory for */
  size_t size_gparts;

  /*! The total number of #spart we allocated memory for */
  size_t size_sparts;
201

202
203
204
  /*! The total number of #bpart we allocated memory for */
  size_t size_bparts;

205
206
207
  /*! The total number of #sink we allocated memory for. */
  size_t size_sinks;

208
209
210
211
212
213
214
215
216
  /*! Number of inhibted gas particles in the space */
  size_t nr_inhibited_parts;

  /*! Number of inhibted gravity particles in the space */
  size_t nr_inhibited_gparts;

  /*! Number of inhibted star particles in the space */
  size_t nr_inhibited_sparts;

217
218
219
  /*! Number of inhibted black hole particles in the space */
  size_t nr_inhibited_bparts;

220
221
222
  /*! Number of inhibted sinks in the space */
  size_t nr_inhibited_sinks;

223
  /*! Number of extra #part we allocated (for on-the-fly creation) */
224
225
  size_t nr_extra_parts;

226
  /*! Number of extra #gpart we allocated (for on-the-fly creation) */
227
228
  size_t nr_extra_gparts;

229
  /*! Number of extra #spart we allocated (for on-the-fly creation) */
230
231
  size_t nr_extra_sparts;

232
233
234
  /*! Number of extra #bpart we allocated (for on-the-fly creation) */
  size_t nr_extra_bparts;

235
236
237
  /*! Number of extra #sink we allocated (for on-the-fly creation) */
  size_t nr_extra_sinks;

238
239
  /*! The particle data (cells have pointers to this). */
  struct part *parts;
240

241
242
243
244
245
  /*! The extended particle data (cells have pointers to this). */
  struct xpart *xparts;

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

247
248
249
  /*! The s-particle data (cells have pointers to this). */
  struct spart *sparts;

250
251
252
  /*! The b-particle data (cells have pointers to this). */
  struct bpart *bparts;

253
254
255
  /*! The sink particle data (cells have pointers to this). */
  struct sink *sinks;

256
257
258
259
260
261
262
263
264
  /*! Minimal mass of all the #part */
  float min_part_mass;

  /*! Minimal mass of all the dark-matter #gpart */
  float min_gpart_mass;

  /*! Minimal mass of all the #spart */
  float min_spart_mass;

265
266
267
  /*! Minimal mass of all the #bpart */
  float min_bpart_mass;

268
269
270
271
272
273
274
275
276
  /*! Sum of the norm of the velocity of all the #part */
  float sum_part_vel_norm;

  /*! Sum of the norm of the velocity of all the dark-matter #gpart */
  float sum_gpart_vel_norm;

  /*! Sum of the norm of the velocity of all the #spart */
  float sum_spart_vel_norm;

277
278
279
  /*! Sum of the norm of the velocity of all the #bpart */
  float sum_bpart_vel_norm;

280
281
282
  /*! Initial value of the smoothing length read from the parameter file */
  float initial_spart_h;

283
284
285
  /*! Initial value of the smoothing length read from the parameter file */
  float initial_bpart_h;

286
  /*! General-purpose lock for this space. */
287
  swift_lock_type lock;
288

289
  /*! Number of queues in the system. */
290
291
  int nr_queues;

292
  /*! The associated engine. */
293
  struct engine *e;
Pedro Gonnet's avatar
Pedro Gonnet committed
294

295
296
297
  /*! The group information returned by VELOCIraptor for each #gpart. */
  struct velociraptor_gpart_data *gpart_group_data;

Loic Hausammann's avatar
Loic Hausammann committed
298
299
300
  /*! Structure dealing with the computation of a unique ID */
  struct unique_id unique_id;

301
302
303
#ifdef WITH_MPI

  /*! Buffers for parts that we will receive from foreign cells. */
304
  struct part *parts_foreign;
305
  size_t nr_parts_foreign, size_parts_foreign;
306
307

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

311
  /*! Buffers for s-parts that we will receive from foreign cells. */
312
313
314
  struct spart *sparts_foreign;
  size_t nr_sparts_foreign, size_sparts_foreign;

315
316
317
  /*! Buffers for b-parts that we will receive from foreign cells. */
  struct bpart *bparts_foreign;
  size_t nr_bparts_foreign, size_bparts_foreign;
318

319
#endif
320
};
Pedro Gonnet's avatar
Pedro Gonnet committed
321

Pedro Gonnet's avatar
Pedro Gonnet committed
322
/* Function prototypes. */
323
void space_free_buff_sort_indices(struct space *s);
324
325
326
void space_parts_sort(struct part *parts, struct xpart *xparts, int *ind,
                      int *counts, int num_bins, ptrdiff_t parts_offset);
void space_gparts_sort(struct gpart *gparts, struct part *parts,
Loic Hausammann's avatar
Loic Hausammann committed
327
328
329
                       struct sink *sinks, struct spart *sparts,
                       struct bpart *bparts, int *ind, int *counts,
                       int num_bins);
330
331
void space_sparts_sort(struct spart *sparts, int *ind, int *counts,
                       int num_bins, ptrdiff_t sparts_offset);
332
333
void space_bparts_sort(struct bpart *bparts, int *ind, int *counts,
                       int num_bins, ptrdiff_t bparts_offset);
Loic Hausammann's avatar
Loic Hausammann committed
334
335
void space_sinks_sort(struct sink *sinks, int *ind, int *counts, int num_bins,
                      ptrdiff_t sinks_offset);
336
void space_getcells(struct space *s, int nr_cells, struct cell **cells);
lhausamm's avatar
lhausamm committed
337
void space_init(struct space *s, struct swift_params *params,
338
                const struct cosmology *cosmo, double dim[3],
339
                const struct hydro_props *hydro_properties, struct part *parts,
Loic Hausammann's avatar
Loic Hausammann committed
340
341
                struct gpart *gparts, struct sink *sinks, struct spart *sparts,
                struct bpart *bparts, size_t Npart, size_t Ngpart, size_t Nsink,
342
                size_t Nspart, size_t Nbpart, int periodic, int replicate,
343
                int remap_ids, int generate_gas_in_ics, int hydro, int gravity,
Loic Hausammann's avatar
Loic Hausammann committed
344
345
                int star_formation, int DM_background, int verbose, int dry_run,
                int nr_nodes);
346
void space_sanitize(struct space *s);
347
348
349
350
351
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);
352
void space_map_parts_xparts(struct space *s,
353
354
                            void (*fun)(struct part *p, struct xpart *xp,
                                        struct cell *c));
355
356
void space_map_cells_post(struct space *s, int full,
                          void (*fun)(struct cell *c, void *data), void *data);
357
void space_rebuild(struct space *s, int repartitioned, int verbose);
358
void space_recycle(struct space *s, struct cell *c);
359
360
void space_recycle_list(struct space *s, struct cell *cell_list_begin,
                        struct cell *cell_list_end,
361
362
                        struct gravity_tensors *multipole_list_begin,
                        struct gravity_tensors *multipole_list_end);
363
void space_split(struct space *s, int verbose);
364
void space_reorder_extras(struct space *s, int verbose);
365
void space_split_mapper(void *map_data, int num_elements, void *extra_data);
366
void space_list_useful_top_level_cells(struct space *s);
367
void space_parts_get_cell_index(struct space *s, int *ind, int *cell_counts,
368
369
                                size_t *count_inhibited_parts,
                                size_t *count_extra_parts, int verbose);
370
void space_gparts_get_cell_index(struct space *s, int *gind, int *cell_counts,
371
372
                                 size_t *count_inhibited_gparts,
                                 size_t *count_extra_gparts, int verbose);
373
void space_sparts_get_cell_index(struct space *s, int *sind, int *cell_counts,
374
375
                                 size_t *count_inhibited_sparts,
                                 size_t *count_extra_sparts, int verbose);
376
377
378
void space_bparts_get_cell_index(struct space *s, int *sind, int *cell_counts,
                                 size_t *count_inhibited_bparts,
                                 size_t *count_extra_bparts, int verbose);
Loic Hausammann's avatar
Loic Hausammann committed
379
380
381
void space_sinks_get_cell_index(struct space *s, int *sind, int *cell_counts,
                                size_t *count_inhibited_sinks,
                                size_t *count_extra_sinks, int verbose);
382
void space_synchronize_particle_positions(struct space *s);
lhausamm's avatar
format    
lhausamm committed
383
384
void space_first_init_parts(struct space *s, int verbose);
void space_first_init_gparts(struct space *s, int verbose);
lhausamm's avatar
lhausamm committed
385
void space_first_init_sparts(struct space *s, int verbose);
386
void space_first_init_bparts(struct space *s, int verbose);
Loic Hausammann's avatar
Loic Hausammann committed
387
void space_first_init_sinks(struct space *s, int verbose);
388
389
void space_init_parts(struct space *s, int verbose);
void space_init_gparts(struct space *s, int verbose);
390
void space_init_sparts(struct space *s, int verbose);
391
void space_init_bparts(struct space *s, int verbose);
Loic Hausammann's avatar
Loic Hausammann committed
392
void space_init_sinks(struct space *s, int verbose);
393
void space_convert_quantities(struct space *s, int verbose);
394
void space_link_cleanup(struct space *s);
395
396
397
398
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);
399
void space_check_timesteps(const struct space *s);
400
void space_check_limiter(struct space *s);
401
void space_check_swallow(struct space *s);
402
void space_check_sort_flags(struct space *s);
403
404
void space_remap_ids(struct space *s, int nr_nodes, int verbose);
long long space_get_max_parts_id(struct space *s);
405
void space_replicate(struct space *s, int replicate, int verbose);
406
void space_generate_gas(struct space *s, const struct cosmology *cosmo,
407
                        const struct hydro_props *hydro_properties,
408
409
                        const int periodic, const int with_DM_background,
                        const double dim[3], const int verbose);
410
411
void space_check_cosmology(struct space *s, const struct cosmology *cosmo,
                           int rank);
412
void space_reset_task_counters(struct space *s);
413
void space_clean(struct space *s);
414
void space_free_cells(struct space *s);
415

416
void space_free_foreign_parts(struct space *s, const int clear_cell_pointers);
417

418
419
void space_struct_dump(struct space *s, FILE *stream);
void space_struct_restore(struct space *s, FILE *stream);
Loic Hausammann's avatar
Loic Hausammann committed
420
void space_write_cell_hierarchy(const struct space *s, int j);
Loic Hausammann's avatar
Loic Hausammann committed
421
422
void space_compute_star_formation_stats(const struct space *s,
                                        struct star_formation *star_form);
423
#endif /* SWIFT_SPACE_H */