FreeFOAM The Cross-Platform CFD Toolkit
edgeFaceCirculator.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::edgeFaceCirculator
26 
27 Description
28  Walks from starting face around edge.
29 
30  Implicit description of edge:
31  - face
32  - index in face. edge is always between f[index] and f[index+1]
33  - direction (cell to walk into)
34 
35  -# Use in-place: \n
36  @code
37  edgeFaceCirculator circ(..);
38  // Optionally rotate to beginning: circ.setCanonical();
39 
40  // Walk
41  do
42  {
43  Info<< "face:" << circ.face() << endl;
44  ++circ;
45  }
46  while (circ != circ.end());
47  @endcode
48 
49  -# Use like STL iterator: \n
50  @code
51  edgeFaceCirculator circ(..);
52  for
53  (
54  edgeFaceCirculator iter = circ.begin();
55  iter != circ.end();
56  ++iter
57  )
58  {
59  Info<< "face:" << iter.face() << endl;
60  }
61  @endcode
62 
63 
64 SourceFiles
65  edgeFaceCirculator.C
66 
67 \*---------------------------------------------------------------------------*/
68 
69 #ifndef edgeFaceCirculator_H
70 #define edgeFaceCirculator_H
71 
72 #include <OpenFOAM/face.H>
73 #include <OpenFOAM/ListOps.H>
74 
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 
77 namespace Foam
78 {
79 
80 // Forward declaration of classes
81 class primitiveMesh;
82 
83 /*---------------------------------------------------------------------------*\
84  Class edgeFaceCirculator Declaration
85 \*---------------------------------------------------------------------------*/
86 
88 {
89  // Static data members
90 
91  //- end iterator
92  static const edgeFaceCirculator endConstIter;
93 
94 
95  // Private data
96 
97  //- Mesh
98  const primitiveMesh& mesh_;
99 
100  //- Current face
101  label faceLabel_;
102 
103  //- Current side of face
104  bool ownerSide_;
105 
106  //- Edge (between index and index+1 on faces[faceLabel_]
107  label index_;
108 
109  //- Is boundary edge?
110  bool isBoundaryEdge_;
111 
112  //- Starting face so we know when to stop. Used when circulating over
113  // internal edges.
114  label startFaceLabel_;
115 
116 
117  // Private Member Functions
118 
119  //- Set to end() iterator
120  inline void setEnd();
121 
122  //- Check and set faceLabel_ and ownerSide_
123  inline void setFace(const label faceI, const label cellI);
124 
125  //- Set faceLabel_ to be the other face on the cell that uses the
126  // edge.
127  inline void otherFace(const label cellI);
128 
129 
130 public:
131 
132  // Constructors
133 
134  //- Construct from components
135  inline edgeFaceCirculator
136  (
137  const primitiveMesh& mesh,
138  const label faceLabel,
139  const bool ownerSide,
140  const label index,
141  const bool isBoundaryEdge
142  );
143 
144  //- Construct as copy
145  inline edgeFaceCirculator(const edgeFaceCirculator&);
146 
147 
148  // Member Functions
149 
150  //- Helper: find index in face of edge or -1. Index is such that edge is
151  // between f[index] and f[index+1]
152  inline static label getMinIndex
153  (
154  const face& f,
155  const label v0,
156  const label v1
157  );
158 
159  inline label faceLabel() const;
160 
161  inline bool ownerSide() const;
162 
163  inline label index() const;
164 
165  //- Helper: get the neighbouring cell according to the ownerSide.
166  // Returns -1 if on neighbourside of boundary face.
167  inline label cellLabel() const;
168 
169  //- Helper: return true if normal of generated face points along
170  // edge from v0 to v1. (v0 and v1 have to be on edge)
171  inline bool sameOrder(const label v0, const label v1) const;
172 
173  //- Set edge to a unique state so different ones can be compared.
174  // Internal edge: minimum face index.
175  // Boundary edge: walk back until boundary face.
176  inline void setCanonical();
177 
178 
179  // Member Operators
180 
181  inline void operator=(const edgeFaceCirculator& iter);
182 
183  inline bool operator==(const edgeFaceCirculator& iter) const;
184 
185  inline bool operator!=(const edgeFaceCirculator& iter) const;
186 
187  //- Step to next face. Uses no edge addressing!
188  inline edgeFaceCirculator& operator++();
189 
190  //- iterator set to the beginning face. For internal edges this is
191  // the current face. For boundary edges this is the first boundary face
192  // reached from walking back (i.e. in opposite direction to ++)
193  inline edgeFaceCirculator begin() const;
194  inline edgeFaceCirculator cbegin() const;
195 
196  //- iterator set to beyond the end of the walk.
197  inline const edgeFaceCirculator& end() const;
198  inline const edgeFaceCirculator& cend() const;
199 };
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 } // End namespace Foam
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #endif
213 
214 // ************************ vim: set sw=4 sts=4 et: ************************ //