space.h 10.1 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
52
#define space_subsize_pair_stars_default 256000000
#define space_subsize_self_stars_default 32000
53
#define space_subdepth_grav_default 2
54
#define space_max_top_level_cells_default 12
55
#define space_stretch 1.10f
56
#define space_maxreldx 0.1f
Pedro Gonnet's avatar
Pedro Gonnet committed
57

58
59
60
/* Maximum allowed depth of cell splits. */
#define space_cell_maxdepth 52

Pedro Gonnet's avatar
Pedro Gonnet committed
61
62
/* Split size. */
extern int space_splitsize;
63
extern int space_maxsize;
64
65
66
extern int space_subsize_pair_hydro;
extern int space_subsize_self_hydro;
extern int space_subsize_pair_grav;
67
extern int space_subsize_self_grav;
68
69
extern int space_subsize_pair_stars;
extern int space_subsize_self_stars;
70
extern int space_subdepth_grav;
Pedro Gonnet's avatar
Pedro Gonnet committed
71

72
/**
73
 * @brief The space in which the cells and particles reside.
74
 */
Pedro Gonnet's avatar
Pedro Gonnet committed
75
76
struct space {

77
  /*! Spatial extent. */
78
79
  double dim[3];

80
81
82
  /*! Is the space periodic? */
  int periodic;

83
84
85
  /*! Extra space information needed for some hydro schemes. */
  struct hydro_space hs;

86
87
88
  /*! Are we doing hydrodynamics? */
  int hydro;

89
90
91
  /*! Are we doing gravity? */
  int gravity;

92
93
  /*! Width of the top-level cells. */
  double width[3];
94

95
  /*! Inverse of the top-level cell width */
96
97
  double iwidth[3];

98
  /*! The minimum top-level cell width allowed. */
99
  double cell_min;
100

101
  /*! Current maximum displacement for particles. */
102
103
  float dx_max;

104
  /*! Space dimensions in number of top-cells. */
105
106
107
108
  int cdim[3];

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

110
111
112
113
114
115
  /*! Number of top-level cells. */
  int nr_cells;

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

116
  /*! Number of *local* top-level cells */
117
118
  int nr_local_cells;

119
120
121
  /*! Number of *local* top-level cells with tasks */
  int nr_local_cells_with_tasks;

122
123
  /*! The (level 0) cells themselves. */
  struct cell *cells_top;
124

125
126
  /*! Buffer of unused cells for the sub-cells. */
  struct cell *cells_sub;
127

128
  /*! The multipoles associated with the top-level (level 0) cells */
129
  struct gravity_tensors *multipoles_top;
130
131

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

134
  /*! The indices of the *local* top-level cells */
135
136
  int *local_cells_top;

137
138
139
  /*! The indices of the *local* top-level cells with tasks */
  int *local_cells_with_tasks_top;

140
  /*! The total number of parts in the space. */
141
  size_t nr_parts, size_parts;
142
143

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

146
147
148
  /*! The total number of g-parts in the space. */
  size_t nr_sparts, size_sparts;

149
150
151
152
153
154
155
156
157
  /*! 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;

158
159
  /*! The particle data (cells have pointers to this). */
  struct part *parts;
160

161
162
163
164
165
  /*! The extended particle data (cells have pointers to this). */
  struct xpart *xparts;

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

167
168
169
  /*! The s-particle data (cells have pointers to this). */
  struct spart *sparts;

170
171
172
  /*! The top-level FFT task */
  struct task *grav_top_level;

173
174
175
176
177
178
179
180
181
  /*! 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;

182
183
184
185
186
187
188
189
190
  /*! 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;

191
  /*! General-purpose lock for this space. */
192
  swift_lock_type lock;
193

194
  /*! Number of queues in the system. */
195
196
  int nr_queues;

197
  /*! The associated engine. */
198
  struct engine *e;
Pedro Gonnet's avatar
Pedro Gonnet committed
199

200
201
202
#ifdef WITH_MPI

  /*! Buffers for parts that we will receive from foreign cells. */
203
  struct part *parts_foreign;
204
  size_t nr_parts_foreign, size_parts_foreign;
205
206

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

210
211
212
213
  /*! Buffers for g-parts that we will receive from foreign cells. */
  struct spart *sparts_foreign;
  size_t nr_sparts_foreign, size_sparts_foreign;

214
#endif
215
};
Pedro Gonnet's avatar
Pedro Gonnet committed
216
217

/* function prototypes. */
218
void space_free_buff_sort_indices(struct space *s);
219
220
221
222
223
224
225
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,
                       struct spart *sparts, int *ind, int *counts,
                       int num_bins);
void space_sparts_sort(struct spart *sparts, int *ind, int *counts,
                       int num_bins, ptrdiff_t sparts_offset);
226
void space_getcells(struct space *s, int nr_cells, struct cell **cells);
lhausamm's avatar
lhausamm committed
227
void space_init(struct space *s, struct swift_params *params,
228
229
230
                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,
231
                int replicate, int generate_gas_in_ics, int hydro, int gravity,
232
                int verbose, int dry_run);
233
void space_sanitize(struct space *s);
234
235
236
237
238
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);
239
void space_map_parts_xparts(struct space *s,
240
241
                            void (*fun)(struct part *p, struct xpart *xp,
                                        struct cell *c));
242
243
void space_map_cells_post(struct space *s, int full,
                          void (*fun)(struct cell *c, void *data), void *data);
244
void space_rebuild(struct space *s, int repartitioned, int verbose);
245
void space_recycle(struct space *s, struct cell *c);
246
247
void space_recycle_list(struct space *s, struct cell *cell_list_begin,
                        struct cell *cell_list_end,
248
249
                        struct gravity_tensors *multipole_list_begin,
                        struct gravity_tensors *multipole_list_end);
250
251
void space_split(struct space *s, struct cell *cells, int nr_cells,
                 int verbose);
252
void space_split_mapper(void *map_data, int num_elements, void *extra_data);
253
void space_list_local_cells(struct space *s);
254
void space_list_cells_with_tasks(struct space *s);
255
void space_parts_get_cell_index(struct space *s, int *ind, int *cell_counts,
256
                                int *count_inibibited_parts, int verbose);
257
void space_gparts_get_cell_index(struct space *s, int *gind, int *cell_counts,
258
                                 int *count_inibibited_gparts, int verbose);
259
void space_sparts_get_cell_index(struct space *s, int *sind, int *cell_counts,
260
                                 int *count_inibibited_sparts, int verbose);
261
void space_synchronize_particle_positions(struct space *s);
262
263
264
void space_do_parts_sort(void);
void space_do_gparts_sort(void);
void space_do_sparts_sort(void);
lhausamm's avatar
format    
lhausamm committed
265
266
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
267
void space_first_init_sparts(struct space *s, int verbose);
268
269
void space_init_parts(struct space *s, int verbose);
void space_init_gparts(struct space *s, int verbose);
270
void space_init_sparts(struct space *s, int verbose);
271
void space_convert_quantities(struct space *s, int verbose);
272
void space_link_cleanup(struct space *s);
273
274
275
276
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);
277
void space_check_timesteps(struct space *s);
278
void space_replicate(struct space *s, int replicate, int verbose);
279
280
void space_generate_gas(struct space *s, const struct cosmology *cosmo,
                        int verbose);
281
282
void space_check_cosmology(struct space *s, const struct cosmology *cosmo,
                           int rank);
283
void space_reset_task_counters(struct space *s);
284
void space_clean(struct space *s);
285
void space_free_cells(struct space *s);
286

287
288
289
void space_struct_dump(struct space *s, FILE *stream);
void space_struct_restore(struct space *s, FILE *stream);

290
#endif /* SWIFT_SPACE_H */