boundaryMesh.H
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 Copyright (C) 2020-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::boundaryMesh
29
30Description
31 Addressing for all faces on surface of mesh. Can either be read
32 from polyMesh or from triSurface. Used for repatching existing meshes.
33
34SourceFiles
35 boundaryMesh.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_boundaryMesh_H
40#define Foam_boundaryMesh_H
41
42#include "bMesh.H"
43#include "boundaryPatch.H"
44#include "className.H"
45#include "polyPatch.H"
46#include "PrimitivePatch.H"
47#include "PtrList.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53
54// Forward Declarations
55class Time;
56class polyMesh;
57class primitiveMesh;
58
59/*---------------------------------------------------------------------------*\
60 Class boundaryMesh Declaration
61\*---------------------------------------------------------------------------*/
63class boundaryMesh
64{
65 // Static Data
66
67 //- Normal along which to divide faces into categories
68 // (used in getNearest)
69 static const vector splitNormal_;
70
71 //- Distance to face tolerance for getNearest. Triangles are considered
72 // near if they are nearer than distanceTol_*typDim where typDim is
73 // the largest distance from face centre to one of its vertices.
74 static const scalar distanceTol_;
75
76
77 // Private Data
78
79 //- All boundary mesh data. Reconstructed every time faces are repatched
80 unique_ptr<bMesh> meshPtr_;
81
82 //- Patches. Reconstructed every time faces are repatched.
84
85 //- For every face in mesh() gives corresponding polyMesh face
86 // (not sensible if mesh read from triSurface)
87 labelList meshFace_;
88
89
90 //
91 // Edge handling
92 //
93
94 //- Points referenced by feature edges.
95 pointField featurePoints_;
96
97 //- Feature edges. Indices into featurePoints.
98 edgeList featureEdges_;
99
100 //- From feature edge to mesh edge.
101 labelList featureToEdge_;
102
103 //- From mesh edges to featureEdges_;
104 labelList edgeToFeature_;
105
106 //- Feature 'segments'. Collections of connected featureEdges.
107 // Indices into featureEdges_.
108 labelListList featureSegments_;
109
110 //- Additional edges (indices of mesh edges)
111 labelList extraEdges_;
112
113
114 // Private Member Functions
115
116 //- Number of connected feature edges.
117 label nFeatureEdges(label pointi) const;
118
119 //- Step to next feature edge
120 label nextFeatureEdge(const label edgeI, const label vertI) const;
121
122 //- Return connected list of feature edges.
123 labelList collectSegment
124 (
125 const boolList& isFeaturePoint,
126 const label startEdgeI,
127 boolList& featVisited
128 ) const;
129
130 //- Do point-edge walk to determine nearest (to edgeI). Stops if
131 // distance >= maxDistance. Used to determine edges close to seed
132 // point.
133 void markEdges
134 (
135 const label maxDistance,
136 const label edgeI,
137 const label distance,
138 labelList& minDistance,
139 DynamicList<label>& visited
140 ) const;
141
142 //- Get index of polypatch by name
143 label findPatchID(const polyPatchList&, const word&) const;
144
145 //- Get index of patch for face
146 label whichPatch(const polyPatchList&, const label) const;
147
148 //- Gets labels of changed faces and propagates them to the edges.
149 // Returns labels of edges changed. Fills edgeRegion of visited edges
150 // with current region.
151 labelList faceToEdge
152 (
153 const boolList& regionEdge,
154 const label region,
155 const labelList& changedFaces,
156 labelList& edgeRegion
157 ) const;
158
159 //- Reverse of faceToEdge: gets edges and returns faces
160 labelList edgeToFace
161 (
162 const label region,
163 const labelList& changedEdges,
164 labelList& faceRegion
165 ) const;
166
167 //- Finds area, starting at facei, delimited by borderEdge. Marks all
168 // faces thus visited with currentZone.
169 void markZone
170 (
171 const boolList& borderEdge,
172 label facei,
173 label currentZone,
175 ) const;
176
177
178 //- No copy construct
179 boundaryMesh(const boundaryMesh&) = delete;
180
181 //- No copy assignment
182 void operator=(const boundaryMesh&) = delete;
183
184
185public:
186
187 //- Runtime type information
188 ClassName("boundaryMesh");
189
190
191 // Constructors
192
193 //- Default construct
194 boundaryMesh();
195
196
197 //- Destructor
198 ~boundaryMesh() = default;
199
200 void clearOut();
201
202
203 // Member Functions
204
205 // Access
207 const bMesh& mesh() const
208 {
209 if (!meshPtr_)
210 {
212 << "No mesh available. Probably mesh not yet read\n"
213 << abort(FatalError);
214 }
215 return *meshPtr_;
216 }
218 const PtrList<boundaryPatch>& patches() const
219 {
220 return patches_;
221 }
222
223
224 //- Label of original face in polyMesh (before patchify(...))
225 const labelList& meshFace() const
226 {
227 return meshFace_;
228 }
229
230 //- Feature points.
231 const pointField& featurePoints() const
232 {
233 return featurePoints_;
234 }
235
236 //- Feature edges. Indices into featurePoints.
237 const edgeList& featureEdges() const
238 {
239 return featureEdges_;
240 }
241
242 //- From index into featureEdge to index into meshedges,
243 const labelList& featureToEdge() const
244 {
245 return featureToEdge_;
246 }
247
248 //- From edge into featureEdges
249 const labelList& edgeToFeature() const
250 {
251 return edgeToFeature_;
252 }
253
254 //- Lists of connected featureEdges. Indices into featureEdges.
255 const labelListList& featureSegments() const
256 {
257 return featureSegments_;
258 }
259
260 //- Indices into edges of additional edges.
261 const labelList& extraEdges() const
262 {
263 return extraEdges_;
264 }
265
266
267 // Edit
268
269 //- Read from boundaryMesh of polyMesh.
270 void read(const polyMesh&);
271
272 //- Read from triSurface
273 void readTriSurface(const fileName&);
274
275 //- Write to file.
276 void writeTriSurface(const fileName&) const;
277
278 //- Get bMesh index of nearest face for every boundary face in
279 // pMesh. Gets passed initial search box. If not found
280 // returns -1 for the face.
282 (
283 const primitiveMesh& pMesh,
284 const vector& searchSpan
285 ) const;
286
287 //- Take over patches onto polyMesh from nearest face in *this
288 // (from call to getNearest). Insert as
289 // -new set of patches (newMesh.addPatches)
290 // -topoChanges to change faces.
291 // nearest is list of nearest face in *this for every boundary
292 // face. oldPatches is list of existing patches in mesh.
293 // newMesh is the mesh to which the new patches are added.
294 // (so has to be constructed without patches).
295 void patchify
296 (
297 const labelList& nearest,
298 const polyBoundaryMesh& oldPatches,
299 polyMesh& newMesh
300 ) const;
301
302 // Patches
303
304 //- Get index of patch face is in
305 label whichPatch(const label facei) const;
306
307 //- Get index of patch by name
308 label findPatchID(const word& patchName) const;
309
310 //- Get names of patches
311 wordList patchNames() const;
312
313 //- Add to back of patch list.
314 void addPatch(const word& patchName);
315
316 //- Delete from patch list.
317 void deletePatch(const word& patchName);
318
319 //- Change patch.
320 void changePatchType(const word& patchName, const word& type);
321
322 //- Recalculate face ordering and patches. Return old to new
323 // mapping.
324 void changeFaces(const labelList& patchIDs, labelList& oldToNew);
325
326
327 // Edges
328
329 //- Set featureEdges, edgeToFeature, featureSegments according
330 // to angle of faces across edge
331 void setFeatureEdges(const scalar minCos);
332
333 //- Set extraEdges to edges 'near' to edgeI. Uses point-edge walk
334 // to determine 'near'.
335 void setExtraEdges(const label edgeI);
336
337
338 // Faces
339
340 //- Simple triangulation of face subset. Returns number of triangles
341 // needed.
342 label getNTris(const label facei) const;
343
344 //- Simple triangulation of face subset. TotalNTris is total number
345 // of triangles, nTris is per face number of triangles.
346 label getNTris
347 (
348 const label startFacei,
349 const label nFaces,
350 labelList& nTris
351 ) const;
352
353 //- Simple triangulation of face subset. TotalNTris is total number
354 // of triangles (from call to getNTris)
355 // triVerts is triangle vertices, three per triangle.
356 void triangulate
357 (
358 const label startFacei,
359 const label nFaces,
360 const label totalNTris,
361 labelList& triVerts
362 ) const;
363
364 //- Number of points used in face subset.
365 label getNPoints(const label startFacei, const label nFaces) const;
366
367 //- Same as triangulate but in local vertex numbering.
368 // (Map returned).
370 (
371 const label startFacei,
372 const label nFaces,
373 const label totalNTris,
374 labelList& triVerts,
375 labelList& localToGlobal
376 ) const;
377
378 // Other
379
380 // Flood filling without crossing protected edges.
381 void markFaces
382 (
383 const labelList& protectedEdges,
384 const label facei,
385 boolList& visited
386 ) const;
387};
388
389
390// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391
392} // End namespace Foam
393
394// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395
396#endif
397
398// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
A list of faces which address into the list of points.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:63
void addPatch(const word &patchName)
Add to back of patch list.
void writeTriSurface(const fileName &) const
Write to file.
Definition: boundaryMesh.C:757
const edgeList & featureEdges() const
Feature edges. Indices into featurePoints.
Definition: boundaryMesh.H:236
void setFeatureEdges(const scalar minCos)
Set featureEdges, edgeToFeature, featureSegments according.
label getNTris(const label facei) const
Simple triangulation of face subset. Returns number of triangles.
void setExtraEdges(const label edgeI)
Set extraEdges to edges 'near' to edgeI. Uses point-edge walk.
void readTriSurface(const fileName &)
Read from triSurface.
Definition: boundaryMesh.C:589
void triangulate(const label startFacei, const label nFaces, const label totalNTris, labelList &triVerts) const
Simple triangulation of face subset. TotalNTris is total number.
void deletePatch(const word &patchName)
Delete from patch list.
wordList patchNames() const
Get names of patches.
Definition: boundaryMesh.C:275
~boundaryMesh()=default
Destructor.
const PtrList< boundaryPatch > & patches() const
Definition: boundaryMesh.H:217
boundaryMesh()
Default construct.
Definition: boundaryMesh.C:440
void triangulateLocal(const label startFacei, const label nFaces, const label totalNTris, labelList &triVerts, labelList &localToGlobal) const
Same as triangulate but in local vertex numbering.
labelList getNearest(const primitiveMesh &pMesh, const vector &searchSpan) const
Get bMesh index of nearest face for every boundary face in.
Definition: boundaryMesh.C:847
const labelListList & featureSegments() const
Lists of connected featureEdges. Indices into featureEdges.
Definition: boundaryMesh.H:254
const labelList & extraEdges() const
Indices into edges of additional edges.
Definition: boundaryMesh.H:260
const labelList & edgeToFeature() const
From edge into featureEdges.
Definition: boundaryMesh.H:248
const bMesh & mesh() const
Definition: boundaryMesh.H:206
void changeFaces(const labelList &patchIDs, labelList &oldToNew)
Recalculate face ordering and patches. Return old to new.
const labelList & meshFace() const
Label of original face in polyMesh (before patchify(...))
Definition: boundaryMesh.H:224
const pointField & featurePoints() const
Feature points.
Definition: boundaryMesh.H:230
label getNPoints(const label startFacei, const label nFaces) const
Number of points used in face subset.
void markFaces(const labelList &protectedEdges, const label facei, boolList &visited) const
void read(const polyMesh &)
Read from boundaryMesh of polyMesh.
Definition: boundaryMesh.C:462
const labelList & featureToEdge() const
From index into featureEdge to index into meshedges,.
Definition: boundaryMesh.H:242
void patchify(const labelList &nearest, const polyBoundaryMesh &oldPatches, polyMesh &newMesh) const
Take over patches onto polyMesh from nearest face in *this.
void changePatchType(const word &patchName, const word &type)
Change patch.
ClassName("boundaryMesh")
Runtime type information.
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:67
A class for handling file names.
Definition: fileName.H:76
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:79
A class for handling words, derived from Foam::string.
Definition: word.H:68
Macro definitions for declaring ClassName(), NamespaceName(), etc.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:67
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
Namespace for OpenFOAM.
scalar distance(const vector &p1, const vector &p2)
Definition: curveTools.C:12
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError