-
Notifications
You must be signed in to change notification settings - Fork 0
/
kd.h
180 lines (158 loc) · 3.17 KB
/
kd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef KD_HINCLUDED
#define KD_HINCLUDED
#define ROOT 1
#define LOWER(i) (i<<1)
#define UPPER(i) ((i<<1)+1)
#define PARENT(i) (i>>1)
#define SIBLING(i) ((i&1)?i-1:i+1)
#define SETNEXT(i)\
{\
while (i&1) i=i>>1;\
++i;\
}
#define DARK 1
#define GAS 2
#define STAR 4
typedef struct Particle {
float r[3];
float v[3];
float fMass;
int iOrder;
int iMark;
float fDensity;
float vMean[3];
float fVel2;
float fDivv;
float fSmooth;
} PARTICLE;
typedef struct bndBound {
float fMin[3];
float fMax[3];
} BND;
typedef struct kdNode {
float fSplit;
BND bnd;
int iDim;
int pLower;
int pUpper;
} KDN;
typedef struct kdContext {
int nBucket;
int nParticles;
int nDark;
int nGas;
int nStar;
int bDark;
int bGas;
int bStar;
int nActive;
float fTime;
int nLevels;
int nNodes;
int nSplit;
PARTICLE *p;
KDN *kdNodes;
int uSecond;
int uMicro;
} * KD;
#define INTERSECT(c,cp,fBall2,lx,ly,lz,x,y,z,sx,sy,sz)\
{\
float INTRSCT_dx,INTRSCT_dy,INTRSCT_dz;\
float INTRSCT_dx1,INTRSCT_dy1,INTRSCT_dz1,INTRSCT_fDist2;\
INTRSCT_dx = c[cp].bnd.fMin[0]-x;\
INTRSCT_dx1 = x-c[cp].bnd.fMax[0];\
INTRSCT_dy = c[cp].bnd.fMin[1]-y;\
INTRSCT_dy1 = y-c[cp].bnd.fMax[1];\
INTRSCT_dz = c[cp].bnd.fMin[2]-z;\
INTRSCT_dz1 = z-c[cp].bnd.fMax[2];\
if (INTRSCT_dx > 0.0) {\
INTRSCT_dx1 += lx;\
if (INTRSCT_dx1 < INTRSCT_dx) {\
INTRSCT_fDist2 = INTRSCT_dx1*INTRSCT_dx1;\
sx = x+lx;\
}\
else {\
INTRSCT_fDist2 = INTRSCT_dx*INTRSCT_dx;\
sx = x;\
}\
if (INTRSCT_fDist2 > fBall2) goto GetNextCell;\
}\
else if (INTRSCT_dx1 > 0.0) {\
INTRSCT_dx += lx;\
if (INTRSCT_dx < INTRSCT_dx1) {\
INTRSCT_fDist2 = INTRSCT_dx*INTRSCT_dx;\
sx = x-lx;\
}\
else {\
INTRSCT_fDist2 = INTRSCT_dx1*INTRSCT_dx1;\
sx = x;\
}\
if (INTRSCT_fDist2 > fBall2) goto GetNextCell;\
}\
else {\
INTRSCT_fDist2 = 0.0;\
sx = x;\
}\
if (INTRSCT_dy > 0.0) {\
INTRSCT_dy1 += ly;\
if (INTRSCT_dy1 < INTRSCT_dy) {\
INTRSCT_fDist2 += INTRSCT_dy1*INTRSCT_dy1;\
sy = y+ly;\
}\
else {\
INTRSCT_fDist2 += INTRSCT_dy*INTRSCT_dy;\
sy = y;\
}\
if (INTRSCT_fDist2 > fBall2) goto GetNextCell;\
}\
else if (INTRSCT_dy1 > 0.0) {\
INTRSCT_dy += ly;\
if (INTRSCT_dy < INTRSCT_dy1) {\
INTRSCT_fDist2 += INTRSCT_dy*INTRSCT_dy;\
sy = y-ly;\
}\
else {\
INTRSCT_fDist2 += INTRSCT_dy1*INTRSCT_dy1;\
sy = y;\
}\
if (INTRSCT_fDist2 > fBall2) goto GetNextCell;\
}\
else {\
sy = y;\
}\
if (INTRSCT_dz > 0.0) {\
INTRSCT_dz1 += lz;\
if (INTRSCT_dz1 < INTRSCT_dz) {\
INTRSCT_fDist2 += INTRSCT_dz1*INTRSCT_dz1;\
sz = z+lz;\
}\
else {\
INTRSCT_fDist2 += INTRSCT_dz*INTRSCT_dz;\
sz = z;\
}\
if (INTRSCT_fDist2 > fBall2) goto GetNextCell;\
}\
else if (INTRSCT_dz1 > 0.0) {\
INTRSCT_dz += lz;\
if (INTRSCT_dz < INTRSCT_dz1) {\
INTRSCT_fDist2 += INTRSCT_dz*INTRSCT_dz;\
sz = z-lz;\
}\
else {\
INTRSCT_fDist2 += INTRSCT_dz1*INTRSCT_dz1;\
sz = z;\
}\
if (INTRSCT_fDist2 > fBall2) goto GetNextCell;\
}\
else {\
sz = z;\
}\
}
void kdTime(KD,int *,int *);
int kdInit(KD *,int);
int kdReadTipsy(KD,FILE *,int,int,int,int);
void kdInMark(KD,char *);
void kdBuildTree(KD);
void kdOrder(KD);
void kdFinish(KD);
#endif