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 | Copyright (C) 2011-2016 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  // Private data
74 
75  //- All boundary mesh data. Reconstructed every time faces are repatched
76  bMesh* meshPtr_;
77 
78  //- Patches. Reconstructed every time faces are repatched.
79  PtrList<boundaryPatch> patches_;
80 
81  //- For every face in mesh() gives corresponding polyMesh face
82  // (not sensible if mesh read from triSurface)
83  labelList meshFace_;
84 
85 
86  //
87  // Edge handling
88  //
89 
90  //- Points referenced by feature edges.
91  pointField featurePoints_;
92 
93  //- Feature edges. Indices into featurePoints.
94  edgeList featureEdges_;
95 
96  //- From feature edge to mesh edge.
97  labelList featureToEdge_;
98 
99  //- From mesh edges to featureEdges_;
100  labelList edgeToFeature_;
101 
102  //- Feature 'segments'. Collections of connected featureEdges.
103  // Indices into featureEdges_.
104  labelListList featureSegments_;
105 
106  //- Additional edges (indices of mesh edges)
107  labelList extraEdges_;
108 
109 
110  // Private Member Functions
111 
112  //- Number of connected feature edges.
113  label nFeatureEdges(label pointi) const;
114 
115  //- Step to next feature edge
116  label nextFeatureEdge(const label edgeI, const label vertI) const;
117 
118  //- Return connected list of feature edges.
119  labelList collectSegment
120  (
121  const boolList& isFeaturePoint,
122  const label startEdgeI,
123  boolList& featVisited
124  ) const;
125 
126  //- Do point-edge walk to determine nearest (to edgeI). Stops if
127  // distance >= maxDistance. Used to determine edges close to seed
128  // point.
129  void markEdges
130  (
131  const label maxDistance,
132  const label edgeI,
133  const label distance,
134  labelList& minDistance,
135  DynamicList<label>& visited
136  ) const;
137 
138  //- Get index of polypatch by name
139  label findPatchID(const polyPatchList&, const word&) const;
140 
141  //- Get index of patch for face
142  label whichPatch(const polyPatchList&, const label) const;
143 
144  //- Gets labels of changed faces and propagates them to the edges.
145  // Returns labels of edges changed. Fills edgeRegion of visited edges
146  // with current region.
147  labelList faceToEdge
148  (
149  const boolList& regionEdge,
150  const label region,
151  const labelList& changedFaces,
152  labelList& edgeRegion
153  ) const;
154 
155  //- Reverse of faceToEdge: gets edges and returns faces
156  labelList edgeToFace
157  (
158  const label region,
159  const labelList& changedEdges,
160  labelList& faceRegion
161  ) const;
162 
163  //- Finds area, starting at facei, delimited by borderEdge. Marks all
164  // faces thus visited with currentZone.
165  void markZone
166  (
167  const boolList& borderEdge,
168  label facei,
169  label currentZone,
171  ) const;
172 
173 
174  //- Disallow default bitwise copy construct
175  boundaryMesh(const boundaryMesh&);
176 
177  //- Disallow default bitwise assignment
178  void operator=(const boundaryMesh&);
179 
180 
181 public:
182 
183  //- Runtime type information
184  ClassName("boundaryMesh");
185 
186 
187  // Constructors
188 
189  //- Construct null
190  boundaryMesh();
191 
192 
193  //- Destructor
194  ~boundaryMesh();
195 
196  void clearOut();
197 
198 
199  // Member Functions
200 
201  // Access
203  const bMesh& mesh() const
204  {
205  if (!meshPtr_)
206  {
208  << "No mesh available. Probably mesh not yet"
209  << " read." << abort(FatalError);
210  }
211  return *meshPtr_;
212  }
214  const PtrList<boundaryPatch>& patches() const
215  {
216  return patches_;
217  }
218 
219 
220  //- Label of original face in polyMesh (before patchify(...))
221  const labelList& meshFace() const
222  {
223  return meshFace_;
224  }
225 
226  //- Feature points.
227  const pointField& featurePoints() const
228  {
229  return featurePoints_;
230  }
231 
232  //- Feature edges. Indices into featurePoints.
233  const edgeList& featureEdges() const
234  {
235  return featureEdges_;
236  }
237 
238  //- From index into featureEdge to index into meshedges,
239  const labelList& featureToEdge() const
240  {
241  return featureToEdge_;
242  }
243 
244  //- From edge into featureEdges
245  const labelList& edgeToFeature() const
246  {
247  return edgeToFeature_;
248  }
249 
250  //- Lists of connected featureEdges. Indices into featureEdges.
251  const labelListList& featureSegments() const
252  {
253  return featureSegments_;
254  }
255 
256  //- Indices into edges of additional edges.
257  const labelList& extraEdges() const
258  {
259  return extraEdges_;
260  }
261 
262 
263  // Edit
264 
265  //- Read from boundaryMesh of polyMesh.
266  void read(const polyMesh&);
267 
268  //- Read from triSurface
269  void readTriSurface(const fileName&);
270 
271  //- Write to file.
272  void writeTriSurface(const fileName&) const;
273 
274  //- Get bMesh index of nearest face for every boundary face in
275  // pMesh. Gets passed initial search box. If not found
276  // returns -1 for the face.
278  (
279  const primitiveMesh& pMesh,
280  const vector& searchSpan
281  ) const;
282 
283  //- Take over patches onto polyMesh from nearest face in *this
284  // (from call to getNearest). Insert as
285  // -new set of patches (newMesh.addPatches)
286  // -topoChanges to change faces.
287  // nearest is list of nearest face in *this for every boundary
288  // face. oldPatches is list of existing patches in mesh.
289  // newMesh is the mesh to which the new patches are added.
290  // (so has to be constructed without patches).
291  void patchify
292  (
293  const labelList& nearest,
294  const polyBoundaryMesh& oldPatches,
295  polyMesh& newMesh
296  ) const;
297 
298  // Patches
299 
300  //- Get index of patch face is in
301  label whichPatch(const label facei) const;
302 
303  //- Get index of patch by name
304  label findPatchID(const word& patchName) const;
305 
306  //- Get names of patches
307  wordList patchNames() const;
308 
309  //- Add to back of patch list.
310  void addPatch(const word& patchName);
311 
312  //- Delete from patch list.
313  void deletePatch(const word& patchName);
314 
315  //- Change patch.
316  void changePatchType(const word& patchName, const word& type);
317 
318  //- Recalculate face ordering and patches. Return old to new
319  // mapping.
320  void changeFaces(const labelList& patchIDs, labelList& oldToNew);
321 
322 
323  // Edges
324 
325  //- Set featureEdges, edgeToFeature, featureSegments according
326  // to angle of faces across edge
327  void setFeatureEdges(const scalar minCos);
328 
329  //- Set extraEdges to edges 'near' to edgeI. Uses point-edge walk
330  // to determine 'near'.
331  void setExtraEdges(const label edgeI);
332 
333 
334  // Faces
335 
336  //- Simple triangulation of face subset. Returns number of triangles
337  // needed.
338  label getNTris(const label facei) const;
339 
340  //- Simple triangulation of face subset. TotalNTris is total number
341  // of triangles, nTris is per face number of triangles.
343  (
344  const label startFacei,
345  const label nFaces,
346  labelList& nTris
347  ) const;
348 
349  //- Simple triangulation of face subset. TotalNTris is total number
350  // of triangles (from call to getNTris)
351  // triVerts is triangle vertices, three per triangle.
352  void triangulate
353  (
354  const label startFacei,
355  const label nFaces,
356  const label totalNTris,
357  labelList& triVerts
358  ) const;
359 
360  //- Number of points used in face subset.
361  label getNPoints(const label startFacei, const label nFaces) const;
362 
363  //- Same as triangulate but in local vertex numbering.
364  // (Map returned).
365  void triangulateLocal
366  (
367  const label startFacei,
368  const label nFaces,
369  const label totalNTris,
370  labelList& triVerts,
371  labelList& localToGlobal
372  ) const;
373 
374  // Other
375 
376  // Flood filling without crossing protected edges.
377  void markFaces
378  (
379  const labelList& protectedEdges,
380  const label facei,
381  boolList& visited
382  ) const;
383 };
384 
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 } // End namespace Foam
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 #endif
393 
394 // ************************************************************************* //
void addPatch(const word &patchName)
Add to back of patch list.
const labelList & featureToEdge() const
From index into featureEdge to index into meshedges,.
Definition: boundaryMesh.H:238
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
const pointField & featurePoints() const
Feature points.
Definition: boundaryMesh.H:226
void read(const polyMesh &)
Read from boundaryMesh of polyMesh.
Definition: boundaryMesh.C:472
void setFeatureEdges(const scalar minCos)
Set featureEdges, edgeToFeature, featureSegments according.
error FatalError
void markFaces(const labelList &protectedEdges, const label facei, boolList &visited) const
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
const edgeList & featureEdges() const
Feature edges. Indices into featurePoints.
Definition: boundaryMesh.H:232
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
Definition: boundaryMesh.H:59
~boundaryMesh()
Destructor.
Definition: boundaryMesh.C:453
void triangulateLocal(const label startFacei, const label nFaces, const label totalNTris, labelList &triVerts, labelList &localToGlobal) const
Same as triangulate but in local vertex numbering.
scalar distance(const vector &p1, const vector &p2)
Definition: curveTools.C:12
wordList patchNames() const
Get names of patches.
Definition: boundaryMesh.C:271
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
A list of faces which address into the list of points.
ClassName("boundaryMesh")
Runtime type information.
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 writeTriSurface(const fileName &) const
Write to file.
Definition: boundaryMesh.C:771
A class for handling words, derived from string.
Definition: word.H:59
const labelList & meshFace() const
Label of original face in polyMesh (before patchify(...))
Definition: boundaryMesh.H:220
label getNTris(const label facei) const
Simple triangulation of face subset. Returns number of triangles.
const labelList & extraEdges() const
Indices into edges of additional edges.
Definition: boundaryMesh.H:256
const labelListList & featureSegments() const
Lists of connected featureEdges. Indices into featureEdges.
Definition: boundaryMesh.H:250
void patchify(const labelList &nearest, const polyBoundaryMesh &oldPatches, polyMesh &newMesh) const
Take over patches onto polyMesh from nearest face in *this.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::polyBoundaryMesh.
const bMesh & mesh() const
Definition: boundaryMesh.H:202
void triangulate(const label startFacei, const label nFaces, const label totalNTris, labelList &triVerts) const
Simple triangulation of face subset. TotalNTris is total number.
void setExtraEdges(const label edgeI)
Set extraEdges to edges &#39;near&#39; to edgeI. Uses point-edge walk.
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
label getNPoints(const label startFacei, const label nFaces) const
Number of points used in face subset.
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:62
Macro definitions for declaring ClassName(), NamespaceName(), etc.
const PtrList< boundaryPatch > & patches() const
Definition: boundaryMesh.H:213
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 labelList & edgeToFeature() const
From edge into featureEdges.
Definition: boundaryMesh.H:244
void changeFaces(const labelList &patchIDs, labelList &oldToNew)
Recalculate face ordering and patches. Return old to new.
Namespace for OpenFOAM.