space.h 4.52 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
8
 * 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.
9
 *
10
11
12
13
 * 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.
14
 *
15
16
 * 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/>.
17
 *
18
 ******************************************************************************/
19
20
#ifndef SWIFT_SPACE_H
#define SWIFT_SPACE_H
Pedro Gonnet's avatar
Pedro Gonnet committed
21

22
/* Includes. */
23
#include "cell.h"
24
#include "part.h"
25

26
27
28
/* Forward-declare the engine to avoid cyclic includes. */
struct engine;

Pedro Gonnet's avatar
Pedro Gonnet committed
29
/* Some constants. */
30
31
32
33
34
35
36
#define space_maxdepth 10
#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
37

Pedro Gonnet's avatar
Pedro Gonnet committed
38
39
/* Split size. */
extern int space_splitsize;
40
extern int space_maxsize;
41
extern int space_subsize;
Pedro Gonnet's avatar
Pedro Gonnet committed
42

Pedro Gonnet's avatar
Pedro Gonnet committed
43
44
/* Map shift vector to sortlist. */
extern const int sortlistID[27];
45

Pedro Gonnet's avatar
Pedro Gonnet committed
46
47
/* Entry in a list of sorted indices. */
struct entry {
48
49
50
51
  float d;
  int i;
};

Pedro Gonnet's avatar
Pedro Gonnet committed
52
53
54
/* The space in which the cells reside. */
struct space {

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  /* Spatial extent. */
  double dim[3];

  /* Cell widths. */
  double h[3], ih[3];

  /* The minimum and maximum cutoff radii. */
  double h_max, cell_min;

  /* Current time step for particles. */
  float dt_step;

  /* Current maximum displacement for particles. */
  float dx_max;

  /* Number of cells. */
  int nr_cells, tot_cells;

  /* Space dimensions in number of cells. */
  int maxdepth, cdim[3];

  /* The (level 0) cells themselves. */
  struct cell *cells;

  /* Buffer of unused cells. */
  struct cell *cells_new;

  /* The particle data (cells have pointers to this). */
  struct part *parts;
  struct xpart *xparts;
  struct gpart *gparts;

  /* The total number of parts in the space. */
88
89
  size_t nr_parts, size_parts;
  size_t nr_gparts, size_gparts;
90
91
92
93
94
95
96
97
98
99
100
101

  /* Is the space periodic? */
  int periodic;

  /* General-purpose lock for this space. */
  lock_type lock;

  /* Number of queues in the system. */
  int nr_queues;

  /* The associated engine. */
  struct engine *e;
Pedro Gonnet's avatar
Pedro Gonnet committed
102

103
104
  /* Buffers for parts that we will receive from foreign cells. */
  struct part *parts_foreign;
105
  size_t nr_parts_foreign, size_parts_foreign;
106
};
Pedro Gonnet's avatar
Pedro Gonnet committed
107

108
109
/* Interval stack necessary for parallel particle sorting. */
struct qstack {
110
111
  volatile size_t i, j;
  volatile int min, max;
112
113
114
115
116
  volatile int ready;
};
struct parallel_sort {
  struct part *parts;
  struct xpart *xparts;
117
  size_t *ind;
118
119
120
121
122
123
  struct qstack *stack;
  unsigned int stack_size;
  volatile unsigned int first, last, waiting;
};
extern struct parallel_sort space_sort_struct;

Pedro Gonnet's avatar
Pedro Gonnet committed
124
/* function prototypes. */
125
void space_parts_sort(struct space *s, size_t *ind, size_t N, int min, int max,
126
                      int verbose);
127
void space_gparts_sort(struct gpart *gparts, size_t *ind, size_t N, int min, int max);
128
129
130
struct cell *space_getcell(struct space *s);
int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
                 double *shift);
131
void space_init(struct space *s, double dim[3], struct part *parts, size_t N,
132
                int periodic, double h_max, int verbose);
133
134
135
136
137
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);
138
void space_map_parts_xparts(struct space *s,
139
140
                            void (*fun)(struct part *p, struct xpart *xp,
                                        struct cell *c));
141
142
void space_map_cells_post(struct space *s, int full,
                          void (*fun)(struct cell *c, void *data), void *data);
143
void space_rebuild(struct space *s, double h_max, int verbose);
144
void space_recycle(struct space *s, struct cell *c);
145
146
void space_split(struct space *s, struct cell *cells, int verbose);
void space_do_split(struct space *s, struct cell *c);
147
void space_do_parts_sort();
148
void space_link_cleanup(struct space *s);
149
#endif /* SWIFT_SPACE_H */