space.h 7.91 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"
37
#include "space.h"
38

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

Pedro Gonnet's avatar
Pedro Gonnet committed
42
/* Some constants. */
43
44
45
#define space_cellallocchunk 1000
#define space_splitsize_default 400
#define space_maxsize_default 8000000
46
#define space_subsize_default 64000000
47
#define space_maxcount_default 10000
48
#define space_max_top_level_cells_default 12
49
#define space_stretch 1.10f
50
#define space_maxreldx 0.1f
Pedro Gonnet's avatar
Pedro Gonnet committed
51

52
53
54
/* Maximum allowed depth of cell splits. */
#define space_cell_maxdepth 52

Pedro Gonnet's avatar
Pedro Gonnet committed
55
56
/* Split size. */
extern int space_splitsize;
57
extern int space_maxsize;
58
extern int space_subsize;
59
extern int space_maxcount;
Pedro Gonnet's avatar
Pedro Gonnet committed
60

61
/**
62
 * @brief The space in which the cells and particles reside.
63
 */
Pedro Gonnet's avatar
Pedro Gonnet committed
64
65
struct space {

66
  /*! Spatial extent. */
67
68
  double dim[3];

69
70
71
  /*! Is the space periodic? */
  int periodic;

72
73
74
  /*! Extra space information needed for some hydro schemes. */
  struct hydro_space hs;

75
76
77
  /*! Are we doing gravity? */
  int gravity;

78
79
  /*! Width of the top-level cells. */
  double width[3];
80

81
  /*! Inverse of the top-level cell width */
82
83
  double iwidth[3];

84
  /*! The minimum top-level cell width allowed. */
85
  double cell_min;
86

87
  /*! Current maximum displacement for particles. */
88
89
  float dx_max;

90
  /*! Space dimensions in number of top-cells. */
91
92
93
94
  int cdim[3];

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

96
97
98
99
100
101
  /*! Number of top-level cells. */
  int nr_cells;

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

102
103
  /*! The (level 0) cells themselves. */
  struct cell *cells_top;
104

105
106
  /*! Buffer of unused cells for the sub-cells. */
  struct cell *cells_sub;
107

108
  /*! The multipoles associated with the top-level (level 0) cells */
109
  struct gravity_tensors *multipoles_top;
110
111

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

114
  /*! The total number of parts in the space. */
115
  size_t nr_parts, size_parts;
116
117

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

120
121
122
  /*! The total number of g-parts in the space. */
  size_t nr_sparts, size_sparts;

123
124
  /*! The particle data (cells have pointers to this). */
  struct part *parts;
125

126
127
128
129
130
  /*! The extended particle data (cells have pointers to this). */
  struct xpart *xparts;

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

132
133
134
  /*! The s-particle data (cells have pointers to this). */
  struct spart *sparts;

135
136
137
  /*! The top-level FFT task */
  struct task *grav_top_level;

138
  /*! General-purpose lock for this space. */
139
  swift_lock_type lock;
140

141
  /*! Number of queues in the system. */
142
143
  int nr_queues;

144
145
146
  /*! Has this space already been sanitized ? */
  int sanitized;

147
  /*! The associated engine. */
148
  struct engine *e;
Pedro Gonnet's avatar
Pedro Gonnet committed
149

150
151
152
#ifdef WITH_MPI

  /*! Buffers for parts that we will receive from foreign cells. */
153
  struct part *parts_foreign;
154
  size_t nr_parts_foreign, size_parts_foreign;
155
156

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

160
161
162
163
  /*! Buffers for g-parts that we will receive from foreign cells. */
  struct spart *sparts_foreign;
  size_t nr_sparts_foreign, size_sparts_foreign;

164
#endif
165
};
Pedro Gonnet's avatar
Pedro Gonnet committed
166
167

/* function prototypes. */
168
void space_parts_sort(struct space *s, int *ind, size_t N, int min, int max,
169
                      int verbose);
Matthieu Schaller's avatar
Matthieu Schaller committed
170
void space_gparts_sort(struct space *s, int *ind, size_t N, int min, int max,
171
                       int verbose);
172
173
void space_sparts_sort(struct space *s, int *ind, size_t N, int min, int max,
                       int verbose);
174
void space_getcells(struct space *s, int nr_cells, struct cell **cells);
175
176
int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
                 double *shift);
177
178
void space_init(struct space *s, const struct swift_params *params,
                double dim[3], struct part *parts, struct gpart *gparts,
179
                struct spart *sparts, size_t Npart, size_t Ngpart,
180
                size_t Nspart, int periodic, int replicate, int gravity,
181
                int verbose, int dry_run);
182
void space_sanitize(struct space *s);
183
184
185
186
187
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);
188
void space_map_parts_xparts(struct space *s,
189
190
                            void (*fun)(struct part *p, struct xpart *xp,
                                        struct cell *c));
191
192
void space_map_cells_post(struct space *s, int full,
                          void (*fun)(struct cell *c, void *data), void *data);
193
194
195
196
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);
197
198
void space_sparts_sort_mapper(void *map_data, int num_elements,
                              void *extra_data);
199
void space_rebuild(struct space *s, int verbose);
200
void space_recycle(struct space *s, struct cell *c);
201
202
void space_recycle_list(struct space *s, struct cell *cell_list_begin,
                        struct cell *cell_list_end,
203
204
                        struct gravity_tensors *multipole_list_begin,
                        struct gravity_tensors *multipole_list_end);
205
206
void space_split(struct space *s, struct cell *cells, int nr_cells,
                 int verbose);
207
void space_split_mapper(void *map_data, int num_elements, void *extra_data);
208
209
210
211
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);
212
213
void space_sparts_get_cell_index(struct space *s, int *sind, struct cell *cells,
                                 int verbose);
214
void space_synchronize_particle_positions(struct space *s);
215
void space_do_parts_sort();
216
void space_do_gparts_sort();
217
void space_do_sparts_sort();
218
219
void space_init_parts(struct space *s);
void space_init_gparts(struct space *s);
220
void space_init_sparts(struct space *s);
221
void space_link_cleanup(struct space *s);
222
223
224
225
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);
226
void space_check_timesteps(struct space *s);
227
void space_replicate(struct space *s, int replicate, int verbose);
228
void space_reset_task_counters(struct space *s);
229
void space_clean(struct space *s);
230

231
#endif /* SWIFT_SPACE_H */