FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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