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