-
Notifications
You must be signed in to change notification settings - Fork 0
/
neighbour.cpp
233 lines (143 loc) · 6.43 KB
/
neighbour.cpp
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "structures.hpp"
/*
This is a simple, brute-force approach to linking two tetrahedra.
*/
int link_tetra(tetra *t1, tetra *t2) {
assert(t1 && t2 && t1 != t2);
int sum1 = 0;
int sum2 = 0;
int matches = 0;
for (unsigned int i = 0; i < 4; ++i) {
for (unsigned int j = 0; j < 4; ++j) {
if (t1->p[i]->peanokey == t2->p[j]->peanokey) {
sum1 += i;
sum2 += j;
++matches;
}
}
}
if (matches >= 4)
throw std::runtime_error("Identical tetrahedra created in the mesh\n");
if (matches == 3) {
switch (sum1) {
case 6 : // 0 - 321
switch (sum2) {
case 6 : // 321
t1->ngb[0] = t2;
t2->ngb[0] = t1;
t1->nid[0] = 0;
t2->nid[0] = 0;
break;
case 5 : // 023
t1->ngb[0] = t2;
t2->ngb[1] = t1;
t1->nid[0] = 1;
t2->nid[1] = 0;
break;
case 4 : // 031
t1->ngb[0] = t2;
t2->ngb[2] = t1;
t1->nid[0] = 2;
t2->nid[2] = 0;
break;
case 3 : // 012
t1->ngb[0] = t2;
t2->ngb[3] = t1;
t1->nid[0] = 3;
t2->nid[3] = 0;
break;
}
break;
case 5 : // 1 - 023
switch (sum2) {
case 6 : // 321
t1->ngb[1] = t2;
t2->ngb[0] = t1;
t1->nid[1] = 0;
t2->nid[0] = 1;
break;
case 5 : // 023
t1->ngb[1] = t2;
t2->ngb[1] = t1;
t1->nid[1] = 1;
t2->nid[1] = 1;
break;
case 4 : // 031
t1->ngb[1] = t2;
t2->ngb[2] = t1;
t1->nid[1] = 2;
t2->nid[2] = 1;
break;
case 3 : // 012
t1->ngb[1] = t2;
t2->ngb[3] = t1;
t1->nid[1] = 3;
t2->nid[3] = 1;
break;
}
break;
case 4 : // 2 - 031
switch (sum2) {
case 6 : // 321
t1->ngb[2] = t2;
t2->ngb[0] = t1;
t1->nid[2] = 0;
t2->nid[0] = 2;
break;
case 5 : // 023
t1->ngb[2] = t2;
t2->ngb[1] = t1;
t1->nid[2] = 1;
t2->nid[1] = 2;
break;
case 4 : // 031
t1->ngb[2] = t2;
t2->ngb[2] = t1;
t1->nid[2] = 2;
t2->nid[2] = 2;
break;
case 3 : // 012
t1->ngb[2] = t2;
t2->ngb[3] = t1;
t1->nid[2] = 3;
t2->nid[3] = 2;
break;
}
break;
case 3 : // 3 - 012
switch (sum2) {
case 6 : // 321
t1->ngb[3] = t2;
t2->ngb[0] = t1;
t1->nid[3] = 0;
t2->nid[0] = 3;
break;
case 5 : // 023
t1->ngb[3] = t2;
t2->ngb[1] = t1;
t1->nid[3] = 1;
t2->nid[1] = 3;
break;
case 4 : // 031
t1->ngb[3] = t2;
t2->ngb[2] = t1;
t1->nid[3] = 2;
t2->nid[2] = 3;
break;
case 3 : // 012
t1->ngb[3] = t2;
t2->ngb[3] = t1;
t1->nid[3] = 3;
t2->nid[3] = 3;
break;
}
break;
}
if (verbose >= 1) {
std::cout << "link established between : " <<
"(" << t1 << ", " << t2 << ")" << std::endl;
}
return 0;
}
return 1;
}