Loading...
Searching...
No Matches
wedgeMatcher.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
28#include "wedgeMatcher.H"
29#include "primitiveMesh.H"
30#include "ListOps.H"
31
32// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33
35:
37 (
38 vertPerCell,
39 facePerCell,
40 maxVertPerFace,
41 "wedge" // == cellModel::modelNames[cellModel::WEDGE]
42 )
43{}
44
45
46// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
47
49(
50 const bool checkOnly,
51 const faceList& faces,
52 const labelList& owner,
53 const label celli,
54 const labelList& myFaces
55)
56{
57 if (!faceSizeMatch(faces, myFaces))
58 {
59 return false;
60 }
61
62 // Calculate localFaces_ and mapping pointMap_, faceMap_
63 label numVert = calcLocalFaces(faces, myFaces);
64
65 if (numVert != vertPerCell)
66 {
67 return false;
68 }
69
70 // Set up 'edge' to face mapping.
71 calcEdgeAddressing(numVert);
72
73 // Set up point on face to index-in-face mapping
74 calcPointFaceIndex();
75
76 // Storage for maps -vertex to mesh and -face to mesh
77 vertLabels_.setSize(vertPerCell);
78 faceLabels_.setSize(facePerCell);
79
80 //
81 // Try first triangular face. Rotate in all directions.
82 // Walk path to other triangular face.
83 //
84
85 label face0I = -1;
86 forAll(faceSize_, facei)
87 {
88 if (faceSize_[facei] == 3)
89 {
90 face0I = facei;
91 break;
92 }
93 }
94
95 const face& face0 = localFaces_[face0I];
96
97 // Try all rotations of this face
98 for (label face0vert0 = 0; face0vert0 < faceSize_[face0I]; face0vert0++)
99 {
100 //
101 // Try to follow prespecified path on faces of cell,
102 // starting at face0vert0
103 //
104
105 vertLabels_[0] = pointMap_[face0[face0vert0]];
106 faceLabels_[0] = faceMap_[face0I];
107 //Info<< endl << "Wedge vertex 0: vertex " << face0[face0vert0]
108 // << " at position " << face0vert0 << " in face " << face0
109 // << endl;
110
111 // Walk face 0 from vertex 0 to 1
112 label face0vert1 =
113 nextVert
114 (
115 face0vert0,
116 faceSize_[face0I],
117 !(owner[faceMap_[face0I]] == celli)
118 );
119 vertLabels_[1] = pointMap_[face0[face0vert1]];
120 //Info<< "Wedge vertex 1: vertex " << face0[face0vert1]
121 // << " at position " << face0vert1 << " in face " << face0
122 // << endl;
123
124 // Jump edge from face0 to face4
125 label face4I =
127 (
128 numVert,
129 face0[face0vert0],
130 face0[face0vert1],
131 face0I
132 );
133 const face& face4 = localFaces_[face4I];
134 //Info<< "Stepped to wedge face 4 " << face4
135 // << " across edge " << face0[face0vert0] << " "
136 // << face0[face0vert1]
137 // << endl;
138
139 if (faceSize_[face4I] != 4)
140 {
141 //Info<< "Cannot be Wedge Face 4 since size="
142 // << faceSize_[face4I] << endl;
143 continue;
144 }
145
146 // Is wedge for sure now
147 if (checkOnly)
148 {
149 return true;
150 }
151
152 faceLabels_[4] = faceMap_[face4I];
153
154 // Get index of vertex 0 in face4
155 label face4vert0 = pointFaceIndex_[face0[face0vert0]][face4I];
156
157 //Info<< "Wedge vertex 0 also: vertex " << face4[face4vert0]
158 // << " at position " << face4vert0 << " in face " << face4
159 // << endl;
160
161 // Walk face 4 from vertex 4 to 3
162 label face4vert3 =
163 nextVert
164 (
165 face4vert0,
166 faceSize_[face4I],
167 !(owner[faceMap_[face4I]] == celli)
168 );
169 vertLabels_[3] = pointMap_[face4[face4vert3]];
170 //Info<< "Wedge vertex 3: vertex " << face4[face4vert3]
171 // << " at position " << face4vert3 << " in face " << face4
172 // << endl;
173
174
175 // Jump edge from face4 to face2
176 label face2I =
178 (
179 numVert,
180 face4[face4vert0],
181 face4[face4vert3],
182 face4I
183 );
184 const face& face2 = localFaces_[face2I];
185 //Info<< "Stepped to wedge face 2 " << face2
186 // << " across edge " << face4[face4vert0] << " "
187 // << face4[face4vert3]
188 // << endl;
189
190 if (faceSize_[face2I] != 3)
191 {
192 //Info<< "Cannot be Wedge Face 2 since size="
193 // << faceSize_[face2I] << endl;
194 continue;
195 }
196 faceLabels_[2] = faceMap_[face2I];
197
198 // Is wedge for sure now
199 //Info<< "** WEDGE **" << endl;
200
201
202 //
203 // Walk to other faces and vertices and assign mapping.
204 //
205
206 // Vertex 6
207 label face2vert3 = pointFaceIndex_[face4[face4vert3]][face2I];
208
209 // Walk face 2 from vertex 3 to 6
210 label face2vert6 =
211 nextVert
212 (
213 face2vert3,
214 faceSize_[face2I],
215 (owner[faceMap_[face2I]] == celli)
216 );
217 vertLabels_[6] = pointMap_[face2[face2vert6]];
218
219 // Jump edge from face2 to face1
220 label face1I =
222 (
223 numVert,
224 face2[face2vert3],
225 face2[face2vert6],
226 face2I
227 );
228 faceLabels_[1] = faceMap_[face1I];
229 const face& face1 = localFaces_[face1I];
230 //Info<< "Stepped to wedge face 1 " << face1
231 // << " across edge " << face2[face2vert3] << " "
232 // << face2[face2vert6]
233 // << endl;
234
235 label face1vert6 = pointFaceIndex_[face2[face2vert6]][face1I];
236
237 // Walk face 1 from vertex 6 to 5
238 label face1vert5 =
239 nextVert
240 (
241 face1vert6,
242 faceSize_[face1I],
243 !(owner[faceMap_[face1I]] == celli)
244 );
245 vertLabels_[5] = pointMap_[face1[face1vert5]];
246
247 // Walk face 1 from vertex 5 to 4
248 label face1vert4 =
249 nextVert
250 (
251 face1vert5,
252 faceSize_[face1I],
253 !(owner[faceMap_[face1I]] == celli)
254 );
255 vertLabels_[4] = pointMap_[face1[face1vert4]];
256
257 // Walk face 0 from vertex 1 to 2
258 label face0vert2 =
259 nextVert
260 (
261 face0vert1,
262 faceSize_[face0I],
263 !(owner[faceMap_[face0I]] == celli)
264 );
265 vertLabels_[2] = pointMap_[face0[face0vert2]];
266 //Info<< "Wedge vertex 2: vertex " << face0[face0vert2]
267 // << " at position " << face0vert2 << " in face " << face0
268 // << endl;
269
270 // Jump edge from face0 to face3
271 label face3I =
273 (
274 numVert,
275 face0[face0vert1],
276 face0[face0vert2],
277 face0I
278 );
279 faceLabels_[3] = faceMap_[face3I];
280 //const face& face3 = localFaces_[face3I];
281 //Info<< "Stepped to wedge face 3 " << face3
282 // << " across edge " << face0[face0vert1] << " "
283 // << face0[face0vert2]
284 // << endl;
285
286
287 // Jump edge from face0 to face5
288 label face5I =
290 (
291 numVert,
292 face0[face0vert2],
293 face0[face0vert0],
294 face0I
295 );
296 faceLabels_[5] = faceMap_[face5I];
297 //const face& face5 = localFaces_[face5I];
298 //Info<< "Stepped to wedge face 5 " << face5
299 // << " across edge " << face0[face0vert2] << " "
300 // << face0[face0vert0]
301 // << endl;
302
303 return true;
305
306 // Tried all triangular faces, in all rotations but no match found
307 return false;
308}
309
311Foam::label Foam::wedgeMatcher::faceHashValue() const
312{
313 return 2*3 + 4*4;
314}
315
316
318(
319 const faceList& faces,
320 const labelList& myFaces
321) const
322{
323 if (myFaces.size() != 6)
324 {
325 return false;
326 }
327
328 label nTris = 0;
329 label nQuads = 0;
330
331 for (const label facei : myFaces)
332 {
333 const label size = faces[facei].size();
334
335 if (size == 3)
336 {
337 ++nTris;
338 }
339 else if (size == 4)
340 {
341 ++nQuads;
342 }
343 else
344 {
345 return false;
347 }
348
349 return (nTris == 2 && nQuads == 4);
350}
351
352
353bool Foam::wedgeMatcher::isA(const primitiveMesh& mesh, const label celli)
354{
355 return matchShape
356 (
357 true,
358 mesh.faces(),
359 mesh.faceOwner(),
360 celli,
361 mesh.cells()[celli]
362 );
363}
364
365
366bool Foam::wedgeMatcher::isA(const faceList& faces)
367{
368 // Do as if mesh with one cell only
369 return matchShape
370 (
371 true,
372 faces, // all faces in mesh
373 labelList(faces.size(), Zero), // cell 0 is owner of all faces
374 0, // cell label
375 identity(faces.size()) // faces of cell 0
376 );
377}
378
379
381(
382 const primitiveMesh& mesh,
383 const label celli,
384 cellShape& shape
385)
386{
387 if
388 (
389 matchShape
390 (
391 false,
392 mesh.faces(),
393 mesh.faceOwner(),
394 celli,
395 mesh.cells()[celli]
396 )
397 )
398 {
399 shape.reset(model(), vertLabels());
400 return true;
401 }
402
403 return false;
404}
405
406
407// ************************************************************************* //
Various functions to operate on Lists.
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
const cellModel & model() const
labelListList pointFaceIndex_
pointFaceIndex[localVertI][localFacei] is index in localFace
labelList faceMap_
Map from local to mesh face numbering.
label calcLocalFaces(const faceList &faces, const labelList &myFaces)
Calculates localFaces. Returns number of local vertices (or -1.
Definition cellMatcher.C:67
labelList pointMap_
Map from local to mesh vertex numbering.
labelList faceLabels_
After matching: holds mesh faces in cellmodel order.
static label nextVert(const label, const label, const bool)
Step along face either in righthand or lefthand direction.
labelList vertLabels_
After matching: holds mesh vertices in cellmodel order.
const labelList & vertLabels() const
labelList faceSize_
Number of vertices per face in localFaces_.
label otherFace(const label numVert, const label v0, const label v1, const label localFacei) const
Given start,end of edge lookup both faces sharing it and return.
void calcEdgeAddressing(const label numVert)
Fill edge (start, end) to face number.
faceList localFaces_
Faces using local vertex numbering.
cellMatcher(const cellMatcher &)=delete
No copy construct.
void calcPointFaceIndex()
Fill vertex/face to index in face data structure.
An analytical geometric cellShape.
Definition cellShape.H:71
void reset(const cellModel &model, const labelUList &labels, const bool doCollapse=false)
Reset from components.
Definition cellShapeI.H:359
A face is a list of labels corresponding to mesh vertices.
Definition face.H:71
virtual const faceList & faces() const
Return raw faces.
Definition polyMesh.C:1088
Cell-face mesh analysis engine.
virtual bool faceSizeMatch(const faceList &, const labelList &) const
Check whether number of face sizes match the shape.
virtual bool matchShape(const bool checkOnly, const faceList &faces, const labelList &faceOwner, const label celli, const labelList &myFaces)
Low level shape recognition. Return true if matches.
virtual bool matches(const primitiveMesh &mesh, const label celli, cellShape &shape)
Like isA but also constructs a cellShape (if shape matches).
virtual bool isA(const primitiveMesh &mesh, const label celli)
Exact match. Uses faceSizeMatch.
virtual label faceHashValue() const
Hash value of all face sizes of this shape. Can be used for.
wedgeMatcher()
Default construct.
dynamicFvMesh & mesh
label otherFace(const primitiveMesh &mesh, const label celli, const label facei, const label edgeI)
Return face on cell using edgeI but not facei. Throws error.
Definition meshTools.C:548
List< label > labelList
A List of labels.
Definition List.H:62
List< face > faceList
List of faces.
Definition faceListFwd.H:41
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299