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