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-2018 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  //- Disallow default bitwise copy construct
176  boundaryMesh(const boundaryMesh&);
177 
178  //- Disallow default bitwise assignment
179  void operator=(const boundaryMesh&);
180 
181 
182 public:
183 
184  //- Runtime type information
185  ClassName("boundaryMesh");
186 
187 
188  // Constructors
189 
190  //- Construct null
191  boundaryMesh();
192 
193 
194  //- Destructor
195  ~boundaryMesh();
196 
197  void clearOut();
198 
199 
200  // Member Functions
201 
202  // Access
204  const bMesh& mesh() const
205  {
206  if (!meshPtr_)
207  {
209  << "No mesh available. Probably mesh not yet"
210  << " read." << abort(FatalError);
211  }
212  return *meshPtr_;
213  }
215  const PtrList<boundaryPatch>& patches() const
216  {
217  return patches_;
218  }
219 
220 
221  //- Label of original face in polyMesh (before patchify(...))
222  const labelList& meshFace() const
223  {
224  return meshFace_;
225  }
226 
227  //- Feature points.
228  const pointField& featurePoints() const
229  {
230  return featurePoints_;
231  }
232 
233  //- Feature edges. Indices into featurePoints.
234  const edgeList& featureEdges() const
235  {
236  return featureEdges_;
237  }
238 
239  //- From index into featureEdge to index into meshedges,
240  const labelList& featureToEdge() const
241  {
242  return featureToEdge_;
243  }
244 
245  //- From edge into featureEdges
246  const labelList& edgeToFeature() const
247  {
248  return edgeToFeature_;
249  }
250 
251  //- Lists of connected featureEdges. Indices into featureEdges.
252  const labelListList& featureSegments() const
253  {
254  return featureSegments_;
255  }
256 
257  //- Indices into edges of additional edges.
258  const labelList& extraEdges() const
259  {
260  return extraEdges_;
261  }
262 
263 
264  // Edit
265 
266  //- Read from boundaryMesh of polyMesh.
267  void read(const polyMesh&);
268 
269  //- Read from triSurface
270  void readTriSurface(const fileName&);
271 
272  //- Write to file.
273  void writeTriSurface(const fileName&) const;
274 
275  //- Get bMesh index of nearest face for every boundary face in
276  // pMesh. Gets passed initial search box. If not found
277  // returns -1 for the face.
279  (
280  const primitiveMesh& pMesh,
281  const vector& searchSpan
282  ) const;
283 
284  //- Take over patches onto polyMesh from nearest face in *this
285  // (from call to getNearest). Insert as
286  // -new set of patches (newMesh.addPatches)
287  // -topoChanges to change faces.
288  // nearest is list of nearest face in *this for every boundary
289  // face. oldPatches is list of existing patches in mesh.
290  // newMesh is the mesh to which the new patches are added.
291  // (so has to be constructed without patches).
292  void patchify
293  (
294  const labelList& nearest,
295  const polyBoundaryMesh& oldPatches,
296  polyMesh& newMesh
297  ) const;
298 
299  // Patches
300 
301  //- Get index of patch face is in
302  label whichPatch(const label facei) const;
303 
304  //- Get index of patch by name
305  label findPatchID(const word& patchName) const;
306 
307  //- Get names of patches
308  wordList patchNames() const;
309 
310  //- Add to back of patch list.
311  void addPatch(const word& patchName);
312 
313  //- Delete from patch list.
314  void deletePatch(const word& patchName);
315 
316  //- Change patch.
317  void changePatchType(const word& patchName, const word& type);
318 
319  //- Recalculate face ordering and patches. Return old to new
320  // mapping.
321  void changeFaces(const labelList& patchIDs, labelList& oldToNew);
322 
323 
324  // Edges
325 
326  //- Set featureEdges, edgeToFeature, featureSegments according
327  // to angle of faces across edge
328  void setFeatureEdges(const scalar minCos);
329 
330  //- Set extraEdges to edges 'near' to edgeI. Uses point-edge walk
331  // to determine 'near'.
332  void setExtraEdges(const label edgeI);
333 
334 
335  // Faces
336 
337  //- Simple triangulation of face subset. Returns number of triangles
338  // needed.
339  label getNTris(const label facei) const;
340 
341  //- Simple triangulation of face subset. TotalNTris is total number
342  // of triangles, nTris is per face number of triangles.
344  (
345  const label startFacei,
346  const label nFaces,
347  labelList& nTris
348  ) const;
349 
350  //- Simple triangulation of face subset. TotalNTris is total number
351  // of triangles (from call to getNTris)
352  // triVerts is triangle vertices, three per triangle.
353  void triangulate
354  (
355  const label startFacei,
356  const label nFaces,
357  const label totalNTris,
358  labelList& triVerts
359  ) const;
360 
361  //- Number of points used in face subset.
362  label getNPoints(const label startFacei, const label nFaces) const;
363 
364  //- Same as triangulate but in local vertex numbering.
365  // (Map returned).
366  void triangulateLocal
367  (
368  const label startFacei,
369  const label nFaces,
370  const label totalNTris,
371  labelList& triVerts,
372  labelList& localToGlobal
373  ) const;
374 
375  // Other
376 
377  // Flood filling without crossing protected edges.
378  void markFaces
379  (
380  const labelList& protectedEdges,
381  const label facei,
382  boolList& visited
383  ) const;
384 };
385 
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
389 } // End namespace Foam
390 
391 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
392 
393 #endif
394 
395 // ************************************************************************* //
void addPatch(const word &patchName)
Add to back of patch list.
const edgeList & featureEdges() const
Feature edges. Indices into featurePoints.
Definition: boundaryMesh.H:233
const PtrList< boundaryPatch > & patches() const
Definition: boundaryMesh.H:214
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:69
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:239
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:251
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:221
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:257
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:481
const pointField & featurePoints() const
Feature points.
Definition: boundaryMesh.H:227
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:63
Macro definitions for declaring ClassName(), NamespaceName(), etc.
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:203
const labelList & edgeToFeature() const
From edge into featureEdges.
Definition: boundaryMesh.H:245
void changeFaces(const labelList &patchIDs, labelList &oldToNew)
Recalculate face ordering and patches. Return old to new.
Namespace for OpenFOAM.