Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/meshing/clusters.cpp
3206 views
1
#include <mystdlib.h>
2
3
#include "meshing.hpp"
4
5
namespace netgen
6
{
7
8
AnisotropicClusters :: AnisotropicClusters (const Mesh & amesh)
9
: mesh(amesh)
10
{
11
;
12
}
13
14
AnisotropicClusters :: ~AnisotropicClusters ()
15
{
16
;
17
}
18
19
void AnisotropicClusters :: Update()
20
{
21
int i, j, k;
22
23
const MeshTopology & top = mesh.GetTopology();
24
25
bool hasedges = top.HasEdges();
26
bool hasfaces = top.HasFaces();
27
28
if (!hasedges || !hasfaces) return;
29
30
31
PrintMessage (3, "Update Clusters");
32
33
nv = mesh.GetNV();
34
ned = top.GetNEdges();
35
nfa = top.GetNFaces();
36
ne = mesh.GetNE();
37
int nse = mesh.GetNSE();
38
39
cluster_reps.SetSize (nv+ned+nfa+ne);
40
41
ARRAY<int> nnums, ednums, fanums;
42
int changed;
43
44
for (i = 1; i <= cluster_reps.Size(); i++)
45
cluster_reps.Elem(i) = -1;
46
47
48
for (i = 1; i <= ne; i++)
49
{
50
const Element & el = mesh.VolumeElement(i);
51
ELEMENT_TYPE typ = el.GetType();
52
53
top.GetElementEdges (i, ednums);
54
top.GetElementFaces (i, fanums);
55
56
int elnv = top.GetNVertices (typ);
57
int elned = ednums.Size();
58
int elnfa = fanums.Size();
59
60
nnums.SetSize(elnv+elned+elnfa+1);
61
for (j = 1; j <= elnv; j++)
62
nnums.Elem(j) = el.PNum(j);
63
for (j = 1; j <= elned; j++)
64
nnums.Elem(elnv+j) = nv+ednums.Elem(j);
65
for (j = 1; j <= elnfa; j++)
66
nnums.Elem(elnv+elned+j) = nv+ned+fanums.Elem(j);
67
nnums.Elem(elnv+elned+elnfa+1) = nv+ned+nfa+i;
68
69
for (j = 0; j < nnums.Size(); j++)
70
cluster_reps.Elem(nnums[j]) = nnums[j];
71
}
72
73
74
75
for (i = 1; i <= nse; i++)
76
{
77
const Element2d & el = mesh.SurfaceElement(i);
78
ELEMENT_TYPE typ = el.GetType();
79
80
top.GetSurfaceElementEdges (i, ednums);
81
int fanum = top.GetSurfaceElementFace (i);
82
83
int elnv = top.GetNVertices (typ);
84
int elned = ednums.Size();
85
86
nnums.SetSize(elnv+elned+1);
87
for (j = 1; j <= elnv; j++)
88
nnums.Elem(j) = el.PNum(j);
89
for (j = 1; j <= elned; j++)
90
nnums.Elem(elnv+j) = nv+ednums.Elem(j);
91
nnums.Elem(elnv+elned+1) = fanum;
92
93
for (j = 0; j < nnums.Size(); j++)
94
cluster_reps.Elem(nnums[j]) = nnums[j];
95
}
96
97
static const int hex_cluster[] =
98
{
99
1, 2, 3, 4, 1, 2, 3, 4,
100
5, 6, 7, 8, 5, 6, 7, 8, 1, 2, 3, 4,
101
9, 9, 5, 8, 6, 7,
102
9
103
};
104
105
static const int prism_cluster[] =
106
{
107
1, 2, 3, 1, 2, 3,
108
4, 5, 6, 4, 5, 6, 3, 1, 2,
109
7, 7, 4, 5, 6,
110
7
111
};
112
113
static const int pyramid_cluster[] =
114
{
115
1, 2, 2, 1, 3,
116
4, 2, 1, 4, 6, 5, 5, 6,
117
7, 5, 7, 6, 4,
118
7
119
};
120
static const int tet_cluster14[] =
121
{ 1, 2, 3, 1, 1, 4, 5, 4, 5, 6, 7, 5, 4, 7, 7 };
122
123
static const int tet_cluster12[] =
124
{ 1, 1, 2, 3, 4, 4, 5, 1, 6, 6, 7, 7, 4, 6, 7 };
125
126
static const int tet_cluster13[] =
127
{ 1, 2, 1, 3, 4, 6, 4, 5, 1, 5, 7, 4, 7, 5, 7 };
128
129
static const int tet_cluster23[] =
130
{ 2, 1, 1, 3, 6, 5, 5, 4, 4, 1, 5, 7, 7, 4, 7 };
131
132
static const int tet_cluster24[] =
133
{ 2, 1, 3, 1, 4, 1, 5, 4, 6, 5, 5, 7, 4, 7, 7 };
134
135
static const int tet_cluster34[] =
136
{ 2, 3, 1, 1, 4, 5, 1, 6, 4, 5, 5, 4, 7, 7, 7 };
137
138
int cnt = 0;
139
140
do
141
{
142
143
cnt++;
144
changed = 0;
145
146
for (i = 1; i <= ne; i++)
147
{
148
const Element & el = mesh.VolumeElement(i);
149
ELEMENT_TYPE typ = el.GetType();
150
151
top.GetElementEdges (i, ednums);
152
top.GetElementFaces (i, fanums);
153
154
int elnv = top.GetNVertices (typ);
155
int elned = ednums.Size();
156
int elnfa = fanums.Size();
157
158
nnums.SetSize(elnv+elned+elnfa+1);
159
for (j = 1; j <= elnv; j++)
160
nnums.Elem(j) = el.PNum(j);
161
for (j = 1; j <= elned; j++)
162
nnums.Elem(elnv+j) = nv+ednums.Elem(j);
163
for (j = 1; j <= elnfa; j++)
164
nnums.Elem(elnv+elned+j) = nv+ned+fanums.Elem(j);
165
nnums.Elem(elnv+elned+elnfa+1) = nv+ned+nfa+i;
166
167
168
const int * clustertab = NULL;
169
switch (typ)
170
{
171
case PRISM:
172
case PRISM12:
173
clustertab = prism_cluster;
174
break;
175
case HEX:
176
clustertab = hex_cluster;
177
break;
178
case PYRAMID:
179
clustertab = pyramid_cluster;
180
break;
181
case TET:
182
case TET10:
183
if (cluster_reps.Get(el.PNum(1)) ==
184
cluster_reps.Get(el.PNum(2)))
185
clustertab = tet_cluster12;
186
else if (cluster_reps.Get(el.PNum(1)) ==
187
cluster_reps.Get(el.PNum(3)))
188
clustertab = tet_cluster13;
189
else if (cluster_reps.Get(el.PNum(1)) ==
190
cluster_reps.Get(el.PNum(4)))
191
clustertab = tet_cluster14;
192
else if (cluster_reps.Get(el.PNum(2)) ==
193
cluster_reps.Get(el.PNum(3)))
194
clustertab = tet_cluster23;
195
else if (cluster_reps.Get(el.PNum(2)) ==
196
cluster_reps.Get(el.PNum(4)))
197
clustertab = tet_cluster24;
198
else if (cluster_reps.Get(el.PNum(3)) ==
199
cluster_reps.Get(el.PNum(4)))
200
clustertab = tet_cluster34;
201
202
else
203
clustertab = NULL;
204
break;
205
default:
206
clustertab = NULL;
207
}
208
209
if (clustertab)
210
for (j = 0; j < nnums.Size(); j++)
211
for (k = 0; k < j; k++)
212
if (clustertab[j] == clustertab[k])
213
{
214
int jj = nnums[j];
215
int kk = nnums[k];
216
if (cluster_reps.Get(jj) < cluster_reps.Get(kk))
217
{
218
cluster_reps.Elem(kk) = cluster_reps.Get(jj);
219
changed = 1;
220
}
221
else if (cluster_reps.Get(kk) < cluster_reps.Get(jj))
222
{
223
cluster_reps.Elem(jj) = cluster_reps.Get(kk);
224
changed = 1;
225
}
226
}
227
228
/*
229
if (clustertab)
230
{
231
if (typ == PYRAMID)
232
(*testout) << "pyramid";
233
else if (typ == PRISM || typ == PRISM12)
234
(*testout) << "prism";
235
else if (typ == TET || typ == TET10)
236
(*testout) << "tet";
237
else
238
(*testout) << "unknown type" << endl;
239
240
(*testout) << ", nnums = ";
241
for (j = 0; j < nnums.Size(); j++)
242
(*testout) << "node " << j << " = " << nnums[j] << ", rep = "
243
<< cluster_reps.Get(nnums[j]) << endl;
244
}
245
*/
246
}
247
}
248
while (changed);
249
250
/*
251
(*testout) << "cluster reps:" << endl;
252
for (i = 1; i <= cluster_reps.Size(); i++)
253
{
254
(*testout) << i << ": ";
255
if (i <= nv)
256
(*testout) << "v" << i << " ";
257
else if (i <= nv+ned)
258
(*testout) << "e" << i-nv << " ";
259
else if (i <= nv+ned+nfa)
260
(*testout) << "f" << i-nv-ned << " ";
261
else
262
(*testout) << "c" << i-nv-ned-nfa << " ";
263
(*testout) << cluster_reps.Get(i) << endl;
264
}
265
*/
266
}
267
}
268
269