space.h 3.93 KB
Newer Older
1
/*******************************************************************************
2
 * This file is part of SWIFT.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
 * 
 * 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.
 * 
 * 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.
 * 
 * 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/>.
 * 
 ******************************************************************************/


Pedro Gonnet's avatar
Pedro Gonnet committed
21
22
23
24
25
26


/* Some constants. */
#define space_maxdepth                  10
#define space_cellallocchunk            1000
#define space_splitratio                0.875
Pedro Gonnet's avatar
Pedro Gonnet committed
27
#define space_splitsize_default         400
28
#define space_subsize_default           1000
29
#define space_dosub                     1
30
#define space_stretch                   1.0
31
#define space_maxtaskspercell           43
Pedro Gonnet's avatar
Pedro Gonnet committed
32
33


Pedro Gonnet's avatar
Pedro Gonnet committed
34
35
36
/* Convert cell location to ID. */
#define cell_getid( cdim , i , j , k ) ( (int)(k) + (cdim)[2]*( (int)(j) + (cdim)[1]*(int)(i) ) )

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

Pedro Gonnet's avatar
Pedro Gonnet committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Map shift vector to sortlist. */
extern const int sortlistID[27];
    
    
/* Entry in a list of sorted indices. */
struct entry {
    float d;
    int i;
    };
    
    
/* The space in which the cells reside. */
struct space {

    /* Spatial extent. */
    double dim[3];
    
    /* Cell widths. */
    double h[3], ih[3];
    
    /* The minimum and maximum cutoff radii. */
62
    double h_min, h_max, cell_min;
Pedro Gonnet's avatar
Pedro Gonnet committed
63
    
64
    /* Current time step for particles. */
65
    float dt_max;
66
    
Pedro Gonnet's avatar
Pedro Gonnet committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    /* 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;
81
    struct cpart *cparts;
Pedro Gonnet's avatar
Pedro Gonnet committed
82
83
84
85
86
87
88
89
90
    
    /* The total number of parts in the space. */
    int nr_parts;
    
    /* Is the space periodic? */
    int periodic;
    
    /* The list of tasks. */
    struct task *tasks;
91
    int nr_tasks, tasks_size;
Pedro Gonnet's avatar
Pedro Gonnet committed
92
    int *tasks_ind;
93
94
95
    
    /* General-purpose lock for this space. */
    lock_type lock;
Pedro Gonnet's avatar
Pedro Gonnet committed
96
97
98
99
100
    
    };


/* function prototypes. */
101
void space_addsorts ( struct space *s , struct task *t , struct cell *ci , struct cell *cj , int sid );
102
void parts_sort ( struct part *parts , int *ind , int N , int min , int max );
Pedro Gonnet's avatar
Pedro Gonnet committed
103
104
struct cell *space_getcell ( struct space *s );
struct task *space_gettask ( struct space *s );
105
struct task *space_addtask ( struct space *s , int type , int subtype , int flags , int wait , struct cell *ci , struct cell *cj , int tight );
106
int space_getsid ( struct space *s , struct cell **ci , struct cell **cj , double *shift );
Pedro Gonnet's avatar
Pedro Gonnet committed
107
108
void space_init ( struct space *s , double dim[3] , struct part *parts , int N , int periodic , double h_max );
void space_maketasks ( struct space *s , int do_sort );
109
void space_map_cells_pre ( struct space *s , int full , void (*fun)( struct cell *c , void *data ) , void *data );
Pedro Gonnet's avatar
Pedro Gonnet committed
110
void space_map_parts ( struct space *s , void (*fun)( struct part *p , struct cell *c , void *data ) , void *data );
111
112
113
114
void space_map_cells_post ( struct space *s , int full , void (*fun)( struct cell *c , void *data ) , void *data );
void space_prepare ( struct space *s );
void space_ranktasks ( struct space *s );
void space_rebuild ( struct space *s , double h_max );
Pedro Gonnet's avatar
Pedro Gonnet committed
115
void space_recycle ( struct space *s , struct cell *c );
116
void space_split ( struct space *s , struct cell *c );
Pedro Gonnet's avatar
Pedro Gonnet committed
117
118
119