space.h 7.67 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 "cell.h"
34
#include "hydro_space.h"
35
#include "lock.h"
36
#include "parser.h"
37
#include "part.h"
38
#include "space.h"
39

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

50
51
52
/* Maximum allowed depth of cell splits. */
#define space_cell_maxdepth 52

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

Pedro Gonnet's avatar
Pedro Gonnet committed
59
60
/* Map shift vector to sortlist. */
extern const int sortlistID[27];
61

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

136
  /*! General-purpose lock for this space. */
137
  swift_lock_type lock;
138

139
  /*! Number of queues in the system. */
140
141
  int nr_queues;

142
143
144
  /*! Has this space already been sanitized ? */
  int sanitized;

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

148
149
150
#ifdef WITH_MPI

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

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

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

162
#endif
163
};
Pedro Gonnet's avatar
Pedro Gonnet committed
164
165

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

225
#endif /* SWIFT_SPACE_H */