star.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2021-2023 OpenFOAM Foundation
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::star
26 
27 Description
28  Engine for constructing a star-shaped domain by walking
29 
30 SourceFiles
31  star.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef star_H
36 #define star_H
37 
38 #include "DynamicList.H"
39 #include "labelPair.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class star Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class star
51 {
52 public:
53 
54  // Public Classes
55 
56  //- Star-edge structure. Poor man's linked list link.
57  struct edgeLink
58  {
62  };
63 
64  //- Context class. Returned by populate and resets the star when it
65  // goes out of scope.
66  class context
67  {
68  private:
69 
70  // Private Data
71 
72  //- Reference to the star
73  star& star_;
74 
75 
76  public:
77 
78  // Constructors
79 
80  //- Construct from components
81  context(star& s);
82 
83 
84  // Destructor
85  ~context();
86  };
87 
88 
89 private:
90 
91  // Private Data
92 
93  //- For each star face, the external face index, or -1
94  DynamicList<label> starFaceFaces_;
95 
96  //- For each external face, the star face index, or -1
97  DynamicList<label> faceStarFaces_;
98 
99  //- For each star edge, the external edge index and the two adjacent
100  // star indices, or {-1, -1, -1}
101  DynamicList<edgeLink> starEdgeEdges_;
102 
103  //- For each external edge, the star edge index, or -1
104  DynamicList<label> edgeStarEdges_;
105 
106  //- Generic work array
107  DynamicList<label> work_;
108 
109 
110  // Private Member Functions
111 
112  //- Reset the contents of the star, ready for another populate
113  void reset();
114 
115  //- Swap the given star edges. The star connectivity remains the same.
116  // Used to change order of iteration.
117  void swapStarEdges(const label starEdgeiA, const label starEdgeiB);
118 
119  //- Expand the star by crossing a given edge into a given face
120  template<class FaceEdges>
121  void cross
122  (
123  const label edgei,
124  const label facei,
125  const UList<FaceEdges>& faceEdges
126  );
127 
128 
129 public:
130 
131  // Constructors
132 
133  //- Construct null
134  star();
135 
136 
137  // Destructor
138  ~star();
139 
140 
141  // Member Functions
142 
143  // Access
144 
145  //- Access the star-face-faces
146  const DynamicList<label>& starFaceFaces() const
147  {
148  return starFaceFaces_;
149  }
150 
151  //- Access the face-star-faces
152  const DynamicList<label>& faceStarFaces() const
153  {
154  return faceStarFaces_;
155  }
156 
157  //- Access the star-edge-edges
158  const DynamicList<edgeLink>& starEdgeEdges() const
159  {
160  return starEdgeEdges_;
161  }
162 
163  //- Access the edge-star-edges
164  const DynamicList<label>& edgeStarEdges() const
165  {
166  return edgeStarEdges_;
167  }
168 
169 
170  //- Populate the star given a seed face or edge, a function
171  // `canCross(edgei, facei)` to determine whether an edge may be cross,
172  // and face-edge and edge-face addressing. After this is called, the
173  // forAll... macros below can be user to iterate through the star
174  // faces, or around the edges of the star perimeter.
175  template<class CanCross, class FaceEdges>
177  (
178  const label faceOrEdgei,
179  const bool isFace,
180  CanCross canCross,
181  const UList<FaceEdges>& faceEdges,
182  const UList<labelPair>& edgeFaces,
183  const label maxIterations = labelMax
184  );
185 };
186 
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 inline bool operator==(const star::edgeLink& elA, const star::edgeLink& elB)
191 {
192  return
193  elA.starEdgei0_ == elB.starEdgei0_
194  && elA.edgei_ == elB.edgei_
195  && elA.starEdgei1_ == elB.starEdgei1_;
196 }
197 
198 
199 inline bool operator!=(const star::edgeLink& elA, const star::edgeLink& elB)
200 {
201  return !(elA == elB);
202 }
203 
204 
205 inline Ostream& operator<<(Ostream& os, const star::edgeLink& el)
206 {
207  return os
208  << '(' << el.starEdgei0_ << ')'
209  << ' ' << el.edgei_ << ' '
210  << '(' << el.starEdgei1_ << ')';
211 }
212 
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 } // End namespace Foam
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 #define forAllStarFaces(star, starFacei, facei) \
221  for \
222  ( \
223  label starFacei = 0, \
224  facei = \
225  ( \
226  star.starFaceFaces().size() > 0 \
227  ? (star).starFaceFaces()[starFacei] \
228  : -1 \
229  ); \
230  starFacei < star.starFaceFaces().size(); \
231  ++ starFacei, \
232  facei = \
233  ( \
234  starFacei < (star).starFaceFaces().size() \
235  ? (star).starFaceFaces()[starFacei] \
236  : -1 \
237  ) \
238  )
239 
240 
241 #define forAllStarEdges(star, i, starEdgei, edgei) \
242  for \
243  ( \
244  label i = 0, \
245  starEdgei = 0, \
246  edgei = \
247  ( \
248  (star).starEdgeEdges().size() > 0 \
249  ? (star).starEdgeEdges()[0].edgei_ \
250  : -1 \
251  ); \
252  i < (star).starEdgeEdges().size(); \
253  ++ i, \
254  starEdgei = (star).starEdgeEdges()[starEdgei].starEdgei1_, \
255  edgei = \
256  ( \
257  starEdgei != -1 \
258  ? (star).starEdgeEdges()[starEdgei].edgei_ \
259  : -1 \
260  ) \
261  )
262 
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 #ifdef NoRepository
267  #include "starTemplates.C"
268 #endif
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 #endif
273 
274 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
Context class. Returned by populate and resets the star when it.
Definition: star.H:66
context(star &s)
Construct from components.
Definition: star.C:96
Engine for constructing a star-shaped domain by walking.
Definition: star.H:50
star()
Construct null.
Definition: star.C:86
const DynamicList< label > & edgeStarEdges() const
Access the edge-star-edges.
Definition: star.H:163
const DynamicList< edgeLink > & starEdgeEdges() const
Access the star-edge-edges.
Definition: star.H:157
const DynamicList< label > & starFaceFaces() const
Access the star-face-faces.
Definition: star.H:145
const DynamicList< label > & faceStarFaces() const
Access the face-star-faces.
Definition: star.H:151
~star()
Definition: star.C:104
context populate(const label faceOrEdgei, const bool isFace, CanCross canCross, const UList< FaceEdges > &faceEdges, const UList< labelPair > &edgeFaces, const label maxIterations=labelMax)
Populate the star given a seed face or edge, a function.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
bool operator!=(const particle &, const particle &)
Definition: particle.C:1210
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
static const label labelMax
Definition: label.H:62