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

meshTools.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 Namespace
00025     Foam::meshTools
00026 
00027 Description
00028     Collection of static functions to do various simple mesh related things.
00029 
00030 SourceFiles
00031     meshTools.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef meshTools_H
00036 #define meshTools_H
00037 
00038 #include <OpenFOAM/label.H>
00039 #include <OpenFOAM/vector.H>
00040 #include <OpenFOAM/labelList.H>
00041 #include <OpenFOAM/pointField.H>
00042 #include <OpenFOAM/faceList.H>
00043 #include <OpenFOAM/cellList.H>
00044 #include <OpenFOAM/primitivePatch.H>
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace Foam
00049 {
00050 
00051 class primitiveMesh;
00052 class polyMesh;
00053 
00054 /*---------------------------------------------------------------------------*\
00055                         Namespace meshTools Declaration
00056 \*---------------------------------------------------------------------------*/
00057 
00058 namespace meshTools
00059 {
00060     // Bit identifiers for octants (p=plus, m=min e.g. plusXminYminZ)
00061 
00062     static const label mXmYmZ = 0;
00063     static const label pXmYmZ = 1;
00064     static const label mXpYmZ = 2;
00065     static const label pXpYmZ = 3;
00066 
00067     static const label mXmYpZ = 4;
00068     static const label pXmYpZ = 5;
00069     static const label mXpYpZ = 6;
00070     static const label pXpYpZ = 7;
00071 
00072     static const label mXmYmZMask = 1 << mXmYmZ;
00073     static const label pXmYmZMask = 1 << pXmYmZ;
00074     static const label mXpYmZMask = 1 << mXpYmZ;
00075     static const label pXpYmZMask = 1 << pXpYmZ;
00076 
00077     static const label mXmYpZMask = 1 << mXmYpZ;
00078     static const label pXmYpZMask = 1 << pXmYpZ;
00079     static const label mXpYpZMask = 1 << mXpYpZ;
00080     static const label pXpYpZMask = 1 << pXpYpZ;
00081 
00082 
00083     // Normal handling
00084 
00085         //- Check if n is in same direction as normals of all faceLabels
00086         bool visNormal
00087         (
00088             const vector& n,
00089             const vectorField& faceNormals,
00090             const labelList& faceLabels
00091         );
00092 
00093         //- Calculate point normals on a 'box' mesh (all edges aligned with
00094         //  coordinate axes)
00095         vectorField calcBoxPointNormals(const primitivePatch& pp);
00096 
00097         //- Normalized edge vector
00098         vector normEdgeVec(const primitiveMesh&, const label edgeI);
00099 
00100 
00101     // OBJ writing
00102 
00103         //- Write obj representation of point
00104         void writeOBJ
00105         (
00106             Ostream& os,
00107             const point& pt
00108         );
00109 
00110         //- Write obj representation of faces subset
00111         void writeOBJ
00112         (
00113             Ostream& os,
00114             const faceList&,
00115             const pointField&,
00116             const labelList& faceLabels
00117         );
00118 
00119         //- Write obj representation of faces
00120         void writeOBJ
00121         (
00122             Ostream& os,
00123             const faceList&,
00124             const pointField&
00125         );
00126 
00127         //- Write obj representation of cell subset
00128         void writeOBJ
00129         (
00130             Ostream& os,
00131             const cellList&,
00132             const faceList&,
00133             const pointField&,
00134             const labelList& cellLabels
00135         );
00136 
00137 
00138     // Cell/face/edge walking
00139 
00140         //- Is edge used by cell
00141         bool edgeOnCell
00142         (
00143             const primitiveMesh&,
00144             const label cellI,
00145             const label edgeI
00146         );
00147 
00148         //- Is edge used by face
00149         bool edgeOnFace
00150         (
00151             const primitiveMesh&,
00152             const label faceI,
00153             const label edgeI
00154         );
00155 
00156         //- Is face used by cell
00157         bool faceOnCell
00158         (
00159             const primitiveMesh&,
00160             const label cellI,
00161             const label faceI
00162         );
00163 
00164         //- Return edge among candidates that uses the two vertices.
00165         label findEdge
00166         (
00167             const edgeList& edges,
00168             const labelList& candidates,
00169             const label v0,
00170             const label v1
00171         );
00172 
00173         //- Return edge between two vertices. Returns -1 if no edge.
00174         label findEdge
00175         (
00176             const primitiveMesh&,
00177             const label v0,
00178             const label v1
00179         );
00180 
00181         //- Return edge shared by two faces. Throws error if no edge found.
00182         label getSharedEdge
00183         (
00184             const primitiveMesh&,
00185             const label f0,
00186             const label f1
00187         );
00188 
00189         //- Return face shared by two cells. Throws error if none found.
00190         label getSharedFace
00191         (
00192             const primitiveMesh&,
00193             const label cell0,
00194             const label cell1
00195         );
00196 
00197         //- Get faces on cell using edgeI. Throws error if no two found.
00198         void getEdgeFaces
00199         (
00200             const primitiveMesh&,
00201             const label cellI,
00202             const label edgeI,
00203             label& face0,
00204             label& face1
00205         );
00206 
00207         //- Return label of other edge (out of candidates edgeLabels)
00208         //  connected to vertex but not edgeI. Throws error if none found.
00209         label otherEdge
00210         (
00211             const primitiveMesh&,
00212             const labelList& edgeLabels,
00213             const label edgeI,
00214             const label vertI
00215         );
00216 
00217         //- Return face on cell using edgeI but not faceI. Throws error
00218         //  if none found.
00219         label otherFace
00220         (
00221             const primitiveMesh&,
00222             const label cellI,
00223             const label faceI,
00224             const label edgeI
00225         );
00226 
00227         //- Return cell on other side of face. Throws error
00228         //  if face not internal.
00229         label otherCell
00230         (
00231             const primitiveMesh&,
00232             const label cellI,
00233             const label faceI
00234         );
00235 
00236         //- Returns label of edge nEdges away from startEdge (in the direction
00237         // of startVertI)
00238         label walkFace
00239         (
00240             const primitiveMesh&,
00241             const label faceI,
00242             const label startEdgeI,
00243             const label startVertI,
00244             const label nEdges
00245         );
00246 
00247 
00248     // Constraints on position
00249 
00250         //- Set the constrained components of position to mesh centre
00251         void constrainToMeshCentre
00252         (
00253             const polyMesh& mesh,
00254             point& pt
00255         );
00256         void constrainToMeshCentre
00257         (
00258             const polyMesh& mesh,
00259             pointField& pt
00260         );
00261 
00262         //- Set the constrained components of directions/velocity to zero
00263         void constrainDirection
00264         (
00265             const polyMesh& mesh,
00266             const Vector<label>& dirs,
00267             vector& d
00268         );
00269         void constrainDirection
00270         (
00271             const polyMesh& mesh,
00272             const Vector<label>& dirs,
00273             vectorField& d
00274         );
00275 
00276 
00277     // Hex only functionality.
00278 
00279         //- Given edge on hex find other 'parallel', non-connected edges.
00280         void getParallelEdges
00281         (
00282             const primitiveMesh&,
00283             const label cellI,
00284             const label e0,
00285             label&,
00286             label&,
00287             label&
00288         );
00289 
00290         //- Given edge on hex find all 'parallel' (i.e. non-connected)
00291         //  edges and average direction of them
00292         vector edgeToCutDir
00293         (
00294             const primitiveMesh&,
00295             const label cellI,
00296             const label edgeI
00297         );
00298 
00299         //- Reverse of edgeToCutDir: given direction find edge bundle and
00300         //  return one of them.
00301         label cutDirToEdge
00302         (
00303             const primitiveMesh&,
00304             const label cellI,
00305             const vector& cutDir
00306         );
00307 
00308 } // End namespace meshTools
00309 
00310 
00311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00312 
00313 } // End namespace Foam
00314 
00315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00316 
00317 #endif
00318 
00319 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines