OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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