initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / dynamicMesh / boundaryMesh / boundaryMesh.H
blob71b19ee9764c24769a0739d2ee2c6c8a46e3906b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::boundaryMesh
28 Description
29     Addressing for all faces on surface of mesh. Can either be read
30     from polyMesh or from triSurface. Used for repatching existing meshes.
32 SourceFiles
33     boundaryMesh.C
35 \*---------------------------------------------------------------------------*/
37 #ifndef boundaryMesh_H
38 #define boundaryMesh_H
40 #include "bMesh.H"
41 #include "boundaryPatch.H"
42 #include "PrimitivePatch.H"
43 #include "PtrList.H"
44 #include "polyPatchList.H"
45 #include "className.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 namespace Foam
52 // Forward declaration of classes
53 class Time;
54 class polyMesh;
55 class primitiveMesh;
57 /*---------------------------------------------------------------------------*\
58                            Class boundaryMesh Declaration
59 \*---------------------------------------------------------------------------*/
61 class boundaryMesh
63     // Static data
65         //- Normal along which to divide faces into categories
66         //  (used in getNearest)
67         static const vector splitNormal_;
69         //- Distance to face tolerance for getNearest. Triangles are considered
70         //  near if they are nearer than distanceTol_*typDim where typDim is
71         //  the largest distance from face centre to one of its vertices.
72         static const scalar distanceTol_;
74     // Private data
76         //- All boundary mesh data. Reconstructed every time faces are repatched
77         bMesh* meshPtr_;
79         //- Patches. Reconstructed every time faces are repatched.
80         PtrList<boundaryPatch> patches_;
82         //- For every face in mesh() gives corresponding polyMesh face
83         // (not sensible if mesh read from triSurface)
84         labelList meshFace_;
87         //
88         // Edge handling
89         //
91         //- points referenced by feature edges.
92         pointField featurePoints_;
94         //- feature edges. Indices into featurePoints.
95         edgeList featureEdges_;
97         //- from feature edge to mesh edge.
98         labelList featureToEdge_;
100         //- from mesh edges to featureEdges_;
101         labelList edgeToFeature_;
103         //- Feature 'segments'. Collections of connected featureEdges.
104         //  Indices into featureEdges_.
105         labelListList featureSegments_;
107         //- Additional edges (indices of mesh edges)
108         labelList extraEdges_;
111     // Private Member Functions
113         //- Number of connected feature edges.
114         label nFeatureEdges(label pointI) const;
116         //- Step to next feature edge
117         label nextFeatureEdge(const label edgeI, const label vertI) const;
119         //- Return connected list of feature edges.
120         labelList collectSegment
121         (
122             const boolList& isFeaturePoint,
123             const label startEdgeI,
124             boolList& featVisited
125         ) const;
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;
139         //- Get index of polypatch by name
140         label findPatchID(const polyPatchList&, const word&) const;
142         //- Get index of patch for face
143         label whichPatch(const polyPatchList&, const label) const;
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;
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;
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,
171             labelList& faceZone
172         ) const;
175         //- Disallow default bitwise copy construct
176         boundaryMesh(const boundaryMesh&);
178         //- Disallow default bitwise assignment
179         void operator=(const boundaryMesh&);
182 public:
184     //- Runtime type information
185     ClassName("boundaryMesh");
188     // Constructors
190         //- Construct null
191         boundaryMesh();
194     // Destructor
196         ~boundaryMesh();
198         void clearOut();
201     // Member Functions
203         // Access
205             const bMesh& mesh() const
206             {
207                 if (!meshPtr_)
208                 {
209                     FatalErrorIn("boundaryMesh::mesh()")
210                         << "No mesh available. Probably mesh not yet"
211                         << " read." << abort(FatalError);
212                 }
213                 return *meshPtr_;
214             }
216             const PtrList<boundaryPatch>& patches() const
217             {
218                 return patches_;
219             }
222             //- Label of original face in polyMesh (before patchify(...))
223             const labelList& meshFace() const
224             {
225                 return meshFace_;
226             }
228             //- Feature points.
229             const pointField& featurePoints() const
230             {
231                 return featurePoints_;
232             }
234             //- Feature edges. Indices into featurePoints.
235             const edgeList& featureEdges() const
236             {
237                 return featureEdges_;
238             }
240             //- From index into featureEdge to index into meshedges,
241             const labelList& featureToEdge() const
242             {
243                 return featureToEdge_;
244             }
246             //- From edge into featureEdges
247             const labelList& edgeToFeature() const
248             {
249                 return edgeToFeature_;
250             }
252             //- Lists of connected featureEdges. Indices into featureEdges.
253             const labelListList& featureSegments() const
254             {
255                 return featureSegments_;
256             }
258             //- Indices into edges of additional edges.
259             const labelList& extraEdges() const
260             {
261                 return extraEdges_;
262             }
265         // Edit
267             //- Read from boundaryMesh of polyMesh.
268             void read(const polyMesh&);
270             //- Read from triSurface
271             void readTriSurface(const fileName&);
273             //- Write to file.
274             void writeTriSurface(const fileName&) const;
276             //- Get bMesh index of nearest face for every boundary face in
277             //  pMesh. Gets passed initial search box. If not found
278             //  returns -1 for the face.
279             labelList getNearest
280             (
281                 const primitiveMesh& pMesh,
282                 const vector& searchSpan
283             ) const;
285             //- Take over patches onto polyMesh from nearest face in *this
286             //  (from call to getNearest). Insert as
287             //      -new set of patches (newMesh.addPatches)
288             //      -topoChanges to change faces.
289             // nearest is list of nearest face in *this for every boundary
290             // face. oldPatches is list of existing patches in mesh.
291             // newMesh is the mesh to which the new patches are added.
292             // (so has to be constructed without patches).
293             void patchify
294             (
295                 const labelList& nearest,
296                 const polyBoundaryMesh& oldPatches,
297                 polyMesh& newMesh
298             ) const;
300         // Patches
302             //- Get index of patch face is in
303             label whichPatch(const label faceI) const;
305             //- Get index of patch by name
306             label findPatchID(const word& patchName) const;
308             //- Get names of patches
309             wordList patchNames() const;
311             //- Add to back of patch list.
312             void addPatch(const word& patchName);
314             //- Delete from patch list.
315             void deletePatch(const word& patchName);
317             //- Change patch.
318             void changePatchType(const word& patchName, const word& type);
320             //- Recalculate face ordering and patches. Return old to new
321             //  mapping.
322             void changeFaces(const labelList& patchIDs, labelList& oldToNew);
325         // Edges
327             //- Set featureEdges, edgeToFeature, featureSegments according
328             //  to angle of faces across edge
329             void setFeatureEdges(const scalar minCos);
331             //- Set extraEdges to edges 'near' to edgeI. Uses point-edge walk
332             //  to determine 'near'.
333             void setExtraEdges(const label edgeI);
336         // Faces
338             //- Simple triangulation of face subset. Returns number of triangles
339             //  needed.
340             label getNTris(const label faceI) const;
342             //- Simple triangulation of face subset. TotalNTris is total number
343             //  of triangles, nTris is per face number of triangles.
344             label getNTris
345             (
346                 const label startFaceI,
347                 const label nFaces,
348                 labelList& nTris
349             ) const;
351             //- Simple triangulation of face subset. TotalNTris is total number
352             //  of triangles (from call to getNTris)
353             //  triVerts is triangle vertices, three per triangle.
354             void triangulate
355             (
356                 const label startFaceI,
357                 const label nFaces,
358                 const label totalNTris,
359                 labelList& triVerts
360             ) const;
362             //- Number of points used in face subset.
363             label getNPoints(const label startFaceI, const label nFaces) const;
365             //- Same as triangulate but in local vertex numbering.
366             //  (Map returned).
367             void triangulateLocal
368             (
369                 const label startFaceI,
370                 const label nFaces,
371                 const label totalNTris,
372                 labelList& triVerts,
373                 labelList& localToGlobal
374             ) const;
376         // Other
378             // Flood filling without crossing protected edges.
379             void markFaces
380             (
381                 const labelList& protectedEdges,
382                 const label faceI,
383                 boolList& visited
384             ) const;
388 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390 } // End namespace Foam
392 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
394 #endif
396 // ************************************************************************* //