OpenFOAM logo
Open Source CFD Toolkit

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