initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / finiteVolume / fvMesh / fvMeshCutSurface / tetEdges / faceEdge.H
blob6676862c7cb3832afb8c4a5bb77a83300c697584
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::faceEdge
28 Description
29     Implicit description of face edge (from tet decomposition).
30     Face edge is edge between vertex of face and face centre.
32     Stores
33         - face label
34         - index in face (gives the mesh vertex)
37 SourceFiles
39 \*---------------------------------------------------------------------------*/
41 #ifndef faceEdge_H
42 #define faceEdge_H
44 #include "label.H"
45 #include "primitiveMesh.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 namespace Foam
52 // Forward declaration of classes
54 /*---------------------------------------------------------------------------*\
55                            Class faceEdge Declaration
56 \*---------------------------------------------------------------------------*/
58 class faceEdge
60     // Private data
62         //- face label
63         label faceLabel_;
65         //- index in face
66         label faceIndex_;
68 public:
70     // Public classes
72         //- Hash function
73         class faceEdgeHash
74         {
76         public:
78             faceEdgeHash()
79             {}
81             //- simple hashing function of labels
82             label operator()(const faceEdge& fe, const label tableSize)
83                 const
84             {
85                 // Note: mag since multiply might overflow and produce
86                 // negative numbers
87                 return
88                     mag
89                     (
90                         fe.faceLabel()
91                       + (fe.faceLabel() * fe.faceLabel())
92                       + fe.faceIndex()
93                       + (fe.faceIndex() * fe.faceIndex())
94                     )
95                   % tableSize;
96             }
97         };
100     // Constructors
102         //- Construct null
103         inline faceEdge()
104         :
105             faceLabel_(-1),
106             faceIndex_(-1)
107         {}
109         //- Construct from components
110         inline faceEdge(const label faceLabel, const label faceIndex)
111         :
112             faceLabel_(faceLabel),
113             faceIndex_(faceIndex)
114         {}
116     // Member Functions
118         label faceLabel() const
119         {
120             return faceLabel_;
121         }
123         label faceIndex() const
124         {
125             return faceIndex_;
126         }
128         template <class T>
129         T interpolate
130         (
131             const primitiveMesh& mesh,
132             const Field<T>& faceField,
133             const Field<T>& vertField,
134             const scalar weight
135         ) const
136         {
137             const face& f = mesh.faces()[faceLabel_];
139             return
140                 (1-weight)*vertField[f[faceIndex_]]
141               + weight*faceField[faceLabel_];
142         }
145         point coord(const primitiveMesh& mesh, const scalar weight) const
146         {
147             return interpolate(mesh, mesh.faceCentres(), mesh.points(), weight);
148         }
151     // Member Operators
153         bool operator==(const faceEdge& fe) const
154         {
155             return
156                 (faceLabel() == fe.faceLabel())
157              && (faceIndex() == fe.faceIndex());
158         }
161     // IOstream Operators
163         inline friend Ostream& operator<<(Ostream& os, const faceEdge& fe)
164         {
165             os  << token::BEGIN_LIST
166                 << fe.faceLabel_ << token::SPACE
167                 << fe.faceIndex_
168                 << token::END_LIST;
170             // Check state of Ostream
171             os.check("Ostream& operator<<(Ostream&, const faceEdge&)");
173             return os;
174         }
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 } // End namespace Foam
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 #endif
186 // ************************************************************************* //