OpenFOAM logo
Open Source CFD Toolkit

diagonalEdge.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     diagonalEdge
00027 
00028 Description
00029     Implicit description of diagonal edge (from tet decomposition).
00030     Diangonal edge is edge between two vertices of same face.
00031     Stores
00032         - face label
00033         - indices in face
00034 
00035 SourceFiles
00036 
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef diagonalEdge_H
00040 #define diagonalEdge_H
00041 
00042 #include "label.H"
00043 #include "primitiveMesh.H"
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 namespace Foam
00048 {
00049 
00050 /*---------------------------------------------------------------------------*\
00051                            Class diagonalEdge Declaration
00052 \*---------------------------------------------------------------------------*/
00053 
00054 class diagonalEdge
00055 {
00056     // Private data
00057 
00058         //- face label
00059         label faceLabel_;
00060 
00061         //- index in face
00062         label faceIndex0_;
00063 
00064         //- index in face
00065         label faceIndex1_;
00066 
00067 public:
00068 
00069     // Public classes
00070 
00071         // Hash function
00072         class diagonalEdgeHash
00073         {
00074 
00075         public:
00076 
00077             diagonalEdgeHash()
00078             {}
00079 
00080             //- simple hashing function of labels. Commutative on face indices
00081             //  since edge is same.
00082             label operator()(const diagonalEdge& de, const label tableSize)
00083                 const
00084             {
00085                 // Note: mag since multiply might overflow and produce
00086                 // negative numbers
00087                 return
00088                     mag
00089                     (
00090                         de.faceLabel()
00091                       + (de.faceLabel()*de.faceLabel())
00092                       + de.faceIndex0() * de.faceIndex1()
00093                       + (de.faceIndex0() + de.faceIndex1())
00094                     )
00095                   % tableSize;
00096             }
00097         };
00098 
00099 
00100     // Constructors
00101 
00102         //- Construct null
00103         inline diagonalEdge()
00104         :
00105             faceLabel_(-1),
00106             faceIndex0_(-1),
00107             faceIndex1_(-1)
00108         {}
00109 
00110         //- Construct from components
00111         inline diagonalEdge
00112         (
00113             const label faceLabel,
00114             const label faceIndex0,
00115             const label faceIndex1
00116         )
00117         :
00118             faceLabel_(faceLabel),
00119             faceIndex0_(faceIndex0),
00120             faceIndex1_(faceIndex1)
00121         {}
00122 
00123     // Member Functions
00124 
00125         label faceLabel() const
00126         {   
00127             return faceLabel_;
00128         }
00129 
00130         label faceIndex0() const
00131         {   
00132             return faceIndex0_;
00133         }
00134 
00135         label faceIndex1() const
00136         {   
00137             return faceIndex1_;
00138         }
00139 
00140         template <class T>
00141         T interpolate
00142         (
00143             const primitiveMesh& mesh,
00144             const Field<T>& vertField,
00145             const scalar weight
00146         ) const
00147         {
00148             const face& f = mesh.faces()[faceLabel_];
00149 
00150             return
00151                 (1-weight)*vertField[f[faceIndex0_]]
00152               + weight*vertField[f[faceIndex1_]];
00153         }
00154 
00155         point coord(const primitiveMesh& mesh, const scalar weight) const
00156         {
00157             return interpolate(mesh, mesh.points(), weight);
00158         }
00159 
00160 
00161     // Member Operators
00162 
00163         bool operator==(const diagonalEdge& de) const
00164         {
00165             return
00166                 (faceLabel() == de.faceLabel())
00167              && (faceIndex0() == de.faceIndex0())
00168              && (faceIndex1() == de.faceIndex1());
00169         }
00170 
00171 
00172     // IOstream Operators
00173 
00174         inline friend Ostream& operator<<(Ostream& os, const diagonalEdge& de)
00175         {
00176             os  << token::BEGIN_LIST
00177                 << de.faceLabel_ << token::SPACE
00178                 << de.faceIndex0_ << token::SPACE
00179                 << de.faceIndex1_
00180                 << token::END_LIST;
00181 
00182             // Check state of Ostream
00183             os.check("Ostream& operator<<(Ostream&, const diagonalEdge&)");
00184 
00185             return os;
00186         }
00187 };
00188 
00189 
00190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00191 
00192 } // End namespace Foam
00193 
00194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00195 
00196 #endif
00197 
00198 // ************************************************************************* //
For further information go to www.openfoam.org