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

edgeFaceCirculator.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 Class
00026     Foam::edgeFaceCirculator
00027 
00028 Description
00029     Walks from starting face around edge.
00030 
00031     Implicit description of edge:
00032     - face
00033     - index in face. edge is always between f[index] and f[index+1]
00034     - direction (cell to walk into)
00035 
00036     -# Use in-place: \n
00037         @code
00038             edgeFaceCirculator circ(..);
00039             // Optionally rotate to beginning: circ.setCanonical();
00040 
00041             // Walk
00042             do
00043             {
00044                 Info<< "face:" << circ.face() << endl;
00045                 ++circ;
00046             }
00047             while (circ != circ.end());
00048         @endcode
00049 
00050     -# Use like STL iterator: \n
00051         @code
00052             edgeFaceCirculator circ(..);
00053             for
00054             (
00055                 edgeFaceCirculator iter = circ.begin();
00056                 iter != circ.end();
00057                 ++iter
00058             )
00059             {
00060                 Info<< "face:" << iter.face() << endl;
00061             }
00062         @endcode
00063 
00064 
00065 SourceFiles
00066     edgeFaceCirculator.C
00067 
00068 \*---------------------------------------------------------------------------*/
00069 
00070 #ifndef edgeFaceCirculator_H
00071 #define edgeFaceCirculator_H
00072 
00073 #include "face.H"
00074 #include "ListOps.H"
00075 
00076 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00077 
00078 namespace Foam
00079 {
00080 
00081 // Forward declaration of classes
00082 class primitiveMesh;
00083 
00084 /*---------------------------------------------------------------------------*\
00085                            Class edgeFaceCirculator Declaration
00086 \*---------------------------------------------------------------------------*/
00087 
00088 class edgeFaceCirculator
00089 {
00090     // Static data members
00091 
00092         //- end iterator
00093         static const edgeFaceCirculator endConstIter;
00094 
00095 
00096     // Private data
00097 
00098         //- Mesh
00099         const primitiveMesh& mesh_;
00100 
00101         //- Current face
00102         label faceLabel_;
00103 
00104         //- Current side of face
00105         bool ownerSide_;
00106 
00107         //- Edge (between index and index+1 on faces[faceLabel_]
00108         label index_;
00109 
00110         //- Is boundary edge?
00111         bool isBoundaryEdge_;
00112 
00113         //- Starting face so we know when to stop. Used when circulating over
00114         //  internal edges.
00115         label startFaceLabel_;
00116 
00117 
00118     // Private Member Functions
00119 
00120         //- Set to end() iterator
00121         inline void setEnd();
00122 
00123         //- Check and set faceLabel_ and ownerSide_
00124         inline void setFace(const label faceI, const label cellI);
00125 
00126         //- Set faceLabel_ to be the other face on the cell that uses the
00127         //  edge.
00128         inline void otherFace(const label cellI);
00129 
00130 
00131 public:
00132 
00133     // Constructors
00134 
00135         //- Construct from components
00136         inline edgeFaceCirculator
00137         (
00138             const primitiveMesh& mesh,
00139             const label faceLabel,
00140             const bool ownerSide,
00141             const label index,
00142             const bool isBoundaryEdge
00143         );
00144 
00145         //- Construct as copy
00146         inline edgeFaceCirculator(const edgeFaceCirculator&);
00147 
00148 
00149     // Member Functions
00150 
00151         //- Helper: find index in face of edge or -1. Index is such that edge is
00152         //  between f[index] and f[index+1]
00153         inline static label getMinIndex
00154         (
00155             const face& f,
00156             const label v0,
00157             const label v1
00158         );
00159 
00160         inline label faceLabel() const;
00161 
00162         inline bool ownerSide() const;
00163 
00164         inline label index() const;
00165 
00166         //- Helper: get the neighbouring cell according to the ownerSide.
00167         //  Returns -1 if on neighbourside of boundary face.
00168         inline label cellLabel() const;
00169 
00170         //- Helper: return true if normal of generated face points along
00171         //  edge from v0 to v1. (v0 and v1 have to be on edge)
00172         inline bool sameOrder(const label v0, const label v1) const;
00173 
00174         //- Set edge to a unique state so different ones can be compared.
00175         //  Internal edge: minimum face index.
00176         //  Boundary edge: walk back until boundary face.
00177         inline void setCanonical();
00178 
00179 
00180     // Member Operators
00181 
00182         inline void operator=(const edgeFaceCirculator& iter);
00183 
00184         inline bool operator==(const edgeFaceCirculator& iter) const;
00185 
00186         inline bool operator!=(const edgeFaceCirculator& iter) const;
00187 
00188         //- Step to next face. Uses no edge addressing!
00189         inline edgeFaceCirculator& operator++();
00190 
00191         //- iterator set to the beginning face. For internal edges this is
00192         //  the current face. For boundary edges this is the first boundary face
00193         //  reached from walking back (i.e. in opposite direction to ++)
00194         inline edgeFaceCirculator begin() const;
00195         inline edgeFaceCirculator cbegin() const;
00196 
00197         //- iterator set to beyond the end of the walk.
00198         inline const edgeFaceCirculator& end() const;
00199         inline const edgeFaceCirculator& cend() const;
00200 };
00201 
00202 
00203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00204 
00205 } // End namespace Foam
00206 
00207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00208 
00209 #include "edgeFaceCirculatorI.H"
00210 
00211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00212 
00213 #endif
00214 
00215 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd