space.h 5.49 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 "lock.h"
35
#include "parser.h"
36
#include "part.h"
37
#include "space.h"
38

Pedro Gonnet's avatar
Pedro Gonnet committed
39
/* Some constants. */
40
41
42
43
44
45
#define space_cellallocchunk 1000
#define space_splitsize_default 400
#define space_maxsize_default 8000000
#define space_subsize_default 8000000
#define space_stretch 1.10f
#define space_maxreldx 0.25f
Pedro Gonnet's avatar
Pedro Gonnet committed
46

Pedro Gonnet's avatar
Pedro Gonnet committed
47
48
/* Split size. */
extern int space_splitsize;
49
extern int space_maxsize;
50
extern int space_subsize;
Pedro Gonnet's avatar
Pedro Gonnet committed
51

Pedro Gonnet's avatar
Pedro Gonnet committed
52
53
/* Map shift vector to sortlist. */
extern const int sortlistID[27];
54

55
/**
56
 * @brief The space in which the cells and particles reside.
57
 */
Pedro Gonnet's avatar
Pedro Gonnet committed
58
59
struct space {

60
  /*! Spatial extent. */
61
62
  double dim[3];

63
64
65
66
67
68
  /*! Is the space periodic? */
  int periodic;

  /*! Are we doing gravity? */
  int gravity;

69
70
  /*! Width of the top-level cells. */
  double width[3];
71

72
  /*! Inverse of the top-level cell width */
73
74
  double iwidth[3];

75
  /*! The minimum top-level cell width allowed. */
76
  double cell_min;
77

78
  /*! Current maximum displacement for particles. */
79
80
  float dx_max;

81
  /*! Space dimensions in number of top-cells. */
82
83
84
85
  int cdim[3];

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

87
88
89
90
91
92
  /*! Number of top-level cells. */
  int nr_cells;

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

93
94
  /*! The (level 0) cells themselves. */
  struct cell *cells_top;
95

96
97
  /*! Buffer of unused cells for the sub-cells. */
  struct cell *cells_sub;
98

99
  /*! The total number of parts in the space. */
100
  size_t nr_parts, size_parts;
101
102

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

105
106
  /*! The particle data (cells have pointers to this). */
  struct part *parts;
107

108
109
110
111
112
  /*! The extended particle data (cells have pointers to this). */
  struct xpart *xparts;

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

114
  /*! General-purpose lock for this space. */
115
  swift_lock_type lock;
116

117
  /*! Number of queues in the system. */
118
119
  int nr_queues;

120
  /*! The associated engine. */
121
  struct engine *e;
Pedro Gonnet's avatar
Pedro Gonnet committed
122

123
124
125
#ifdef WITH_MPI

  /*! Buffers for parts that we will receive from foreign cells. */
126
  struct part *parts_foreign;
127
  size_t nr_parts_foreign, size_parts_foreign;
128
129

  /*! Buffers for g-parts that we will receive from foreign cells. */
130
131
  struct gpart *gparts_foreign;
  size_t nr_gparts_foreign, size_gparts_foreign;
132
133

#endif
134
};
Pedro Gonnet's avatar
Pedro Gonnet committed
135
136

/* function prototypes. */
137
void space_parts_sort(struct space *s, int *ind, size_t N, int min, int max,
138
                      int verbose);
Matthieu Schaller's avatar
Matthieu Schaller committed
139
void space_gparts_sort(struct space *s, int *ind, size_t N, int min, int max,
140
                       int verbose);
141
142
143
struct cell *space_getcell(struct space *s);
int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
                 double *shift);
144
145
void space_init(struct space *s, const struct swift_params *params,
                double dim[3], struct part *parts, struct gpart *gparts,
146
147
                size_t Npart, size_t Ngpart, int periodic, int gravity,
                int verbose, int dry_run);
148
149
150
151
152
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);
153
void space_map_parts_xparts(struct space *s,
154
155
                            void (*fun)(struct part *p, struct xpart *xp,
                                        struct cell *c));
156
157
void space_map_cells_post(struct space *s, int full,
                          void (*fun)(struct cell *c, void *data), void *data);
158
159
160
161
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);
162
void space_rebuild(struct space *s, double h_max, int verbose);
163
void space_recycle(struct space *s, struct cell *c);
164
void space_split(struct space *s, struct cell *cells, int verbose);
165
void space_split_mapper(void *map_data, int num_elements, void *extra_data);
166
void space_do_parts_sort();
167
void space_do_gparts_sort();
168
169
void space_init_parts(struct space *s);
void space_init_gparts(struct space *s);
170
void space_link_cleanup(struct space *s);
171
void space_clean(struct space *s);
172

173
#endif /* SWIFT_SPACE_H */