OpenFOAM logo
Open Source CFD Toolkit

boundaryMesh.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     boundaryMesh
00027 
00028 Description
00029     Addressing for all faces on surface of mesh. Can either be read
00030     from polyMesh or from triSurface. Used for repatching existing meshes.
00031 
00032 SourceFiles
00033     boundaryMesh.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef boundaryMesh_H
00038 #define boundaryMesh_H
00039 
00040 #include "bMesh.H"
00041 #include "boundaryPatch.H"
00042 #include "PrimitivePatch.H"
00043 #include "PtrList.H"
00044 #include "polyPatchList.H"
00045 #include "className.H"
00046 
00047 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00048 
00049 namespace Foam
00050 {
00051 
00052 // Class forward declarations
00053 class Time;
00054 class polyMesh;
00055 class primitiveMesh;
00056 
00057 /*---------------------------------------------------------------------------*\
00058                            Class boundaryMesh Declaration
00059 \*---------------------------------------------------------------------------*/
00060 
00061 class boundaryMesh
00062 {
00063     // Static data
00064 
00065         //- Normal along which to divide faces into categories
00066         //  (used in getNearest)
00067         static const vector splitNormal_;
00068 
00069         //- Distance to face tolerance for getNearest. Triangles are considered
00070         //  near if they are nearer than distanceTol_*typDim where typDim is
00071         //  the largest distance from face centre to one of its vertices.
00072         static const scalar distanceTol_;
00073 
00074     // Private data
00075 
00076         //- All boundary mesh data. Reconstructed every time faces are repatched
00077         bMesh* meshPtr_;
00078 
00079         //- Patches. Reconstructed every time faces are repatched.
00080         PtrList<boundaryPatch> patches_;
00081 
00082         //- For every face in mesh() gives corresponding polyMesh face
00083         // (not sensible if mesh read from triSurface)
00084         labelList meshFace_;
00085 
00086 
00087         //
00088         // Edge handling
00089         //
00090 
00091         //- points referenced by feature edges.
00092         pointField featurePoints_;
00093 
00094         //- feature edges. Indices into featurePoints.
00095         edgeList featureEdges_;
00096 
00097         //- from feature edge to mesh edge.
00098         labelList featureToEdge_;
00099 
00100         //- from mesh edges to featureEdges_;
00101         labelList edgeToFeature_;
00102 
00103         //- Feature 'segments'. Collections of connected featureEdges.
00104         //  Indices into featureEdges_.
00105         labelListList featureSegments_;
00106 
00107         //- Additional edges (indices of mesh edges)
00108         labelList extraEdges_;
00109 
00110 
00111     // Private Member Functions
00112 
00113         //- Number of connected feature edges.
00114         label nFeatureEdges(label pointI) const;
00115 
00116         //- Step to next feature edge
00117         label nextFeatureEdge(const label edgeI, const label vertI) const;
00118 
00119         //- Return connected list of feature edges.
00120         labelList collectSegment
00121         (
00122             const boolList& isFeaturePoint,
00123             const label startEdgeI,
00124             boolList& featVisited
00125         ) const;
00126 
00127         //- Do point-edge walk to determine nearest (to edgeI). Stops if
00128         //  distance >= maxDistance. Used to determine edges close to seed
00129         //  point.
00130         void markEdges
00131         (
00132             const label maxDistance,
00133             const label edgeI,
00134             const label distance,
00135             labelList& minDistance,
00136             DynamicList<label>& visited
00137         ) const;
00138 
00139         //- Get index of polypatch by name
00140         label findPatchID(const polyPatchList&, const word&) const;
00141 
00142         //- Get index of patch for face
00143         label whichPatch(const polyPatchList&, const label) const;
00144 
00145         //- Gets labels of changed faces and propagates them to the edges.
00146         //  Returns labels of edges changed. Fills edgeRegion of visited edges
00147         //  with current region.
00148         labelList faceToEdge
00149         (
00150             const boolList& regionEdge,
00151             const label region,
00152             const labelList& changedFaces,
00153             labelList& edgeRegion
00154         ) const;
00155 
00156         //- Reverse of faceToEdge: gets edges and returns faces
00157         labelList edgeToFace
00158         (
00159             const label region,
00160             const labelList& changedEdges,
00161             labelList& faceRegion
00162         ) const;
00163 
00164         //- Finds area, starting at faceI, delimited by borderEdge. Marks all
00165         //  faces thus visited with currentZone.
00166         void markZone
00167         (
00168             const boolList& borderEdge,
00169             label faceI,
00170             label currentZone,
00171             labelList& faceZone
00172         ) const;
00173  
00174 
00175         //- Disallow default bitwise copy construct
00176         boundaryMesh(const boundaryMesh&);
00177 
00178         //- Disallow default bitwise assignment
00179         void operator=(const boundaryMesh&);
00180 
00181 
00182 public:
00183 
00184     //- Runtime type information
00185     ClassName("boundaryMesh");
00186 
00187 
00188     // Constructors
00189 
00190         //- Construct null
00191         boundaryMesh();
00192 
00193 
00194     // Destructor
00195 
00196         ~boundaryMesh();
00197 
00198         void clearOut();
00199 
00200 
00201     // Member Functions
00202 
00203         // Access
00204 
00205             const bMesh& mesh() const
00206             {
00207                 if (!meshPtr_)
00208                 {
00209                     FatalErrorIn("boundaryMesh::mesh()")
00210                         << "No mesh available. Probably mesh not yet"
00211                         << " read." << abort(FatalError);
00212                 }
00213                 return *meshPtr_;
00214             }
00215 
00216             const PtrList<boundaryPatch>& patches() const
00217             {
00218                 return patches_;
00219             }
00220 
00221 
00222             //- Label of original face in polyMesh (before patchify(...))
00223             const labelList& meshFace() const
00224             {
00225                 return meshFace_;
00226             }
00227 
00228             //- Feature points.
00229             const pointField& featurePoints() const
00230             {
00231                 return featurePoints_;
00232             }
00233 
00234             //- Feature edges. Indices into featurePoints.
00235             const edgeList& featureEdges() const
00236             {
00237                 return featureEdges_;
00238             }
00239 
00240             //- From index into featureEdge to index into meshedges,
00241             const labelList& featureToEdge() const
00242             {
00243                 return featureToEdge_;
00244             }
00245 
00246             //- From edge into featureEdges
00247             const labelList& edgeToFeature() const
00248             {
00249                 return edgeToFeature_;
00250             }
00251 
00252             //- Lists of connected featureEdges. Indices into featureEdges.
00253             const labelListList& featureSegments() const
00254             {
00255                 return featureSegments_;
00256             }
00257 
00258             //- Indices into edges of additional edges.
00259             const labelList& extraEdges() const
00260             {
00261                 return extraEdges_;
00262             }
00263 
00264 
00265         // Check
00266 
00267         // Edit
00268 
00269             //- Read from boundaryMesh of polyMesh.
00270             void read(const polyMesh&);
00271 
00272             //- Read from triSurface
00273             void readTriSurface(const fileName&);
00274 
00275             //- Write to file.
00276             void writeTriSurface(const fileName&) const;
00277 
00278             //- Get bMesh index of nearest face for every boundary face in
00279             //  pMesh. Gets passed initial search box. If not found
00280             //  returns -1 for the face.
00281             labelList getNearest
00282             (
00283                 const primitiveMesh& pMesh,
00284                 const vector& searchSpan
00285             ) const;
00286 
00287             //- Take over patches onto polyMesh from nearest face in *this
00288             //  (from call to getNearest). Insert as
00289             //      -new set of patches (newMesh.addPatches)
00290             //      -topoChanges to change faces.
00291             // nearest is list of nearest face in *this for every boundary
00292             // face. oldPatches is list of existing patches in mesh.
00293             // newMesh is the mesh to which the new patches are added.
00294             // (so has to be constructed without patches).
00295             void patchify
00296             (
00297                 const labelList& nearest,
00298                 const polyBoundaryMesh& oldPatches,
00299                 polyMesh& newMesh
00300             ) const;
00301 
00302         // Patches
00303 
00304             //- Get index of patch face is in
00305             label whichPatch(const label faceI) const;
00306 
00307             //- Get index of patch by name
00308             label findPatchID(const word& patchName) const;
00309 
00310             //- Get names of patches
00311             wordList patchNames() const;
00312 
00313             //- Add to back of patch list.
00314             void addPatch(const word& patchName);
00315 
00316             //- Delete from patch list.
00317             void deletePatch(const word& patchName);
00318 
00319             //- Change patch.
00320             void changePatchType(const word& patchName, const word& type);
00321 
00322             //- Recalculate face ordering and patches. Return old to new
00323             //  mapping.
00324             void changeFaces(const labelList& patchIDs, labelList& oldToNew);
00325 
00326 
00327         // Edges
00328 
00329             //- Set featureEdges, edgeToFeature, featureSegments according
00330             //  to angle of faces across edge
00331             void setFeatureEdges(const scalar minCos);
00332 
00333             //- Set extraEdges to edges 'near' to edgeI. Uses point-edge walk
00334             //  to determine 'near'.
00335             void setExtraEdges(const label edgeI);
00336 
00337 
00338         // Faces
00339 
00340             //- Simple triangulation of face subset. Returns number of triangles
00341             //  needed.
00342             label getNTris(const label faceI) const;
00343 
00344             //- Simple triangulation of face subset. TotalNTris is total number
00345             //  of triangles, nTris is per face number of triangles.
00346             label getNTris
00347             (
00348                 const label startFaceI,
00349                 const label nFaces,
00350                 labelList& nTris
00351             ) const;
00352 
00353             //- Simple triangulation of face subset. TotalNTris is total number
00354             //  of triangles (from call to getNTris)
00355             //  triVerts is triangle vertices, three per triangle.
00356             void triangulate
00357             (
00358                 const label startFaceI,
00359                 const label nFaces,
00360                 const label totalNTris,
00361                 labelList& triVerts
00362             ) const;
00363 
00364             //- Number of points used in face subset.
00365             label getNPoints(const label startFaceI, const label nFaces) const;
00366 
00367             //- Same as triangulate but in local vertex numbering.
00368             //  (Map returned).
00369             void triangulateLocal
00370             (
00371                 const label startFaceI,
00372                 const label nFaces,
00373                 const label totalNTris,
00374                 labelList& triVerts,
00375                 labelList& localToGlobal
00376             ) const;
00377 
00378         // Other
00379 
00380             // Flood filling without crossing protected edges.
00381             void markFaces
00382             (
00383                 const labelList& protectedEdges,
00384                 const label faceI,
00385                 boolList& visited
00386             ) const;
00387 
00388 
00389 };
00390 
00391 
00392 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00393 
00394 } // End namespace Foam
00395 
00396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00397 
00398 #endif
00399 
00400 // ************************************************************************* //
For further information go to www.openfoam.org