initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / edgeFaceCirculator / edgeFaceCirculator.H
blob644b0e84a05a4caa1cf3c8df13d20063acac6422
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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::edgeFaceCirculator
28 Description
29     Walks from starting face around edge.
31     Implicit description of edge:
32     - face
33     - index in face. edge is always between f[index] and f[index+1]
34     - direction (cell to walk into)
36     -# Use in-place: \n
37         @code
38             edgeFaceCirculator circ(..);
39             // Optionally rotate to beginning: circ.setCanonical();
41             // Walk
42             do
43             {
44                 Info<< "face:" << circ.face() << endl;
45                 ++circ;
46             }
47             while (circ != circ.end());
48         @endcode
50     -# Use like STL iterator: \n
51         @code
52             edgeFaceCirculator circ(..);
53             for
54             (
55                 edgeFaceCirculator iter = circ.begin();
56                 iter != circ.end();
57                 ++iter
58             )
59             {
60                 Info<< "face:" << iter.face() << endl;
61             }
62         @endcode
65 SourceFiles
66     edgeFaceCirculator.C
68 \*---------------------------------------------------------------------------*/
70 #ifndef edgeFaceCirculator_H
71 #define edgeFaceCirculator_H
73 #include "face.H"
74 #include "ListOps.H"
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
78 namespace Foam
81 // Forward declaration of classes
82 class primitiveMesh;
84 /*---------------------------------------------------------------------------*\
85                            Class edgeFaceCirculator Declaration
86 \*---------------------------------------------------------------------------*/
88 class edgeFaceCirculator
90     // Static data members
92         //- end iterator
93         static const edgeFaceCirculator endConstIter;
96     // Private data
98         //- Mesh
99         const primitiveMesh& mesh_;
101         //- Current face
102         label faceLabel_;
104         //- Current side of face
105         bool ownerSide_;
107         //- Edge (between index and index+1 on faces[faceLabel_]
108         label index_;
110         //- Is boundary edge?
111         bool isBoundaryEdge_;
113         //- Starting face so we know when to stop. Used when circulating over
114         //  internal edges.
115         label startFaceLabel_;
118     // Private Member Functions
120         //- Set to end() iterator
121         inline void setEnd();
123         //- Check and set faceLabel_ and ownerSide_
124         inline void setFace(const label faceI, const label cellI);
126         //- Set faceLabel_ to be the other face on the cell that uses the
127         //  edge.
128         inline void otherFace(const label cellI);
131 public:
133     // Constructors
135         //- Construct from components
136         inline edgeFaceCirculator
137         (
138             const primitiveMesh& mesh,
139             const label faceLabel,
140             const bool ownerSide,
141             const label index,
142             const bool isBoundaryEdge
143         );
145         //- Construct as copy
146         inline edgeFaceCirculator(const edgeFaceCirculator&);
149     // Member Functions
151         //- Helper: find index in face of edge or -1. Index is such that edge is
152         //  between f[index] and f[index+1]
153         inline static label getMinIndex
154         (
155             const face& f,
156             const label v0,
157             const label v1
158         );
160         inline label faceLabel() const;
162         inline bool ownerSide() const;
164         inline label index() const;
166         //- Helper: get the neighbouring cell according to the ownerSide.
167         //  Returns -1 if on neighbourside of boundary face.
168         inline label cellLabel() const;
170         //- Helper: return true if normal of generated face points along
171         //  edge from v0 to v1. (v0 and v1 have to be on edge)
172         inline bool sameOrder(const label v0, const label v1) const;
174         //- Set edge to a unique state so different ones can be compared.
175         //  Internal edge: minimum face index.
176         //  Boundary edge: walk back until boundary face.
177         inline void setCanonical();
180     // Member Operators
182         inline void operator=(const edgeFaceCirculator& iter);
184         inline bool operator==(const edgeFaceCirculator& iter) const;
186         inline bool operator!=(const edgeFaceCirculator& iter) const;
188         //- Step to next face. Uses no edge addressing!
189         inline edgeFaceCirculator& operator++();
191         //- iterator set to the beginning face. For internal edges this is
192         //  the current face. For boundary edges this is the first boundary face
193         //  reached from walking back (i.e. in opposite direction to ++)
194         inline edgeFaceCirculator begin() const;
195         inline edgeFaceCirculator cbegin() const;
197         //- iterator set to beyond the end of the walk.
198         inline const edgeFaceCirculator& end() const;
199         inline const edgeFaceCirculator& cend() const;
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 } // End namespace Foam
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 #include "edgeFaceCirculatorI.H"
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 #endif
215 // ************************************************************************* //