PointEdgeWave.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::PointEdgeWave
28 
29 Description
30  Wave propagation of information through grid. Every iteration
31  information goes through one layer of edges.
32 
33  Templated on information that is transferred.
34 
35  Handles parallel and cyclics. Only parallel reasonably tested. Cyclics
36  hardly tested.
37 
38  Note: whether to propagate depends on the return value of Type::update
39  which returns true (i.e. propagate) if the value changes by more than a
40  certain tolerance.
41 
42  Note: parallel is done in two steps:
43  -# transfer patch points in offset notation, i.e. every patch
44  point is denoted by a patchface label and an index in this face.
45  Receiving end uses that fact that f[0] is shared and order is
46  reversed.
47  -# do all non-local shared points by means of reduce of data on them.
48 
49  Note: cyclics is with offset in patchface as well. Patch is divided into
50  two sub patches and the point-point addressing is never explicitly
51  calculated but instead use is made of the face-face correspondence.
52  (it probably is more efficient to calculate a point-point
53  correspondence at the start and then reuse this; task to be done)
54 
55 SourceFiles
56  PointEdgeWave.C
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #ifndef PointEdgeWave_H
61 #define PointEdgeWave_H
62 
63 #include "bitSet.H"
64 #include "scalarField.H"
65 #include "tensorField.H"
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 namespace Foam
70 {
71 
72 // Forward declaration of classes
73 class polyMesh;
74 class polyPatch;
75 
76 /*---------------------------------------------------------------------------*\
77  Class PointEdgeWaveName Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 TemplateName(PointEdgeWave);
81 
82 
83 /*---------------------------------------------------------------------------*\
84  Class PointEdgeWave Declaration
85 \*---------------------------------------------------------------------------*/
86 
87 template<class Type, class TrackingData = int>
88 class PointEdgeWave
89 :
90  public PointEdgeWaveName
91 {
92  // Private static data
93 
94  //- Relative tolerance. Stop propagation if relative changes
95  // less than this tolerance (responsibility for checking this is
96  // up to Type implementation)
97  static scalar propagationTol_;
98 
99  //- Used as default trackdata value to satisfy default template
100  // argument.
101  static int dummyTrackData_;
102 
103 
104  // Private data
105 
106  //- Reference to mesh
107  const polyMesh& mesh_;
108 
109  //- Wall information for all points
110  UList<Type>& allPointInfo_;
111 
112  //- Information on all mesh edges
113  UList<Type>& allEdgeInfo_;
114 
115  //- Additional data to be passed into container
116  TrackingData& td_;
117 
118  //- Has point changed
119  bitSet changedPoint_;
120 
121  //- List of changed points
122  labelList changedPoints_;
123 
124  //- Number of changed points
125  label nChangedPoints_;
126 
127  //- Edges that have changed
128  bitSet changedEdge_;
129 
130  labelList changedEdges_;
131  label nChangedEdges_;
132 
133  //- Number of cyclic patches
134  label nCyclicPatches_;
135 
136  //- Number of evaluations
137  label nEvals_;
138 
139  //- Number of unvisited edges/points
140  label nUnvisitedPoints_;
141  label nUnvisitedEdges_;
142 
143 
144  // Private Member Functions
145 
146  //- Adapt pointInfo for leaving domain
147  void leaveDomain
148  (
149  const polyPatch&,
150  const List<label>& patchPointLabels,
151  List<Type>& pointInfo
152  ) const;
153 
154  //- Adapt pointInfo for entering domain
155  void enterDomain
156  (
157  const polyPatch&,
158  const List<label>& patchPointLabels,
159  List<Type>& pointInfo
160  ) const;
161 
162  //- Transform. Implementation referred to Type
163  void transform
164  (
165  const polyPatch& patch,
166  const tensorField& rotTensor,
167  List<Type>& pointInfo
168  ) const;
169 
170  //- Updates pointInfo with information from neighbour. Updates all
171  // statistics.
172  bool updatePoint
173  (
174  const label pointi,
175  const label neighbourEdgeI,
176  const Type& neighbourInfo,
177  Type& pointInfo
178  );
179 
180  //- Updates pointInfo with information from same point. Updates all
181  // statistics.
182  bool updatePoint
183  (
184  const label pointi,
185  const Type& neighbourInfo,
186  Type& pointInfo
187  );
188 
189  //- Updates edgeInfo with information from neighbour. Updates all
190  // statistics.
191  bool updateEdge
192  (
193  const label edgeI,
194  const label neighbourPointi,
195  const Type& neighbourInfo,
196  Type& edgeInfo
197  );
198 
199  // Parallel, cyclic
200 
201  //- Has patches of certain type?
202  template<class PatchType>
203  label countPatchType() const;
204 
205  //- Merge data from across processor boundaries
206  void handleProcPatches();
207 
208  //- Merge data from across cyclic boundaries
209  void handleCyclicPatches();
210 
211  //- Explicitly sync all collocated points
212  label handleCollocatedPoints();
213 
214 
215  //- No copy construct
216  PointEdgeWave(const PointEdgeWave&) = delete;
217 
218  //- No copy assignment
219  void operator=(const PointEdgeWave&) = delete;
220 
221 
222 public:
223 
224  // Static Functions
225 
226  //- Access to tolerance
227  static scalar propagationTol()
228  {
229  return propagationTol_;
230  }
231 
232  //- Change tolerance
233  static void setPropagationTol(const scalar tol)
234  {
235  propagationTol_ = tol;
236  }
237 
238 
239  // Constructors
240 
241  //- Construct from mesh, list of changed points with the Type
242  // for these points. Gets work arrays to operate on, one of size
243  // number of mesh points, the other number of mesh edges.
244  // Iterates until nothing changes or maxIter reached.
245  // (maxIter can be 0)
247  (
248  const polyMesh& mesh,
249  const labelList& initialPoints,
250  const List<Type>& initialPointsInfo,
253  const label maxIter,
254  TrackingData& td = dummyTrackData_
255  );
256 
257  //- Construct from mesh. Use setPointInfo and iterate() to do
258  // actual calculation
260  (
261  const polyMesh& mesh,
264  TrackingData& td = dummyTrackData_
265  );
266 
267 
268  //- Destructor
269  ~PointEdgeWave();
270 
271 
272  // Member Functions
273 
274  //- Access allPointInfo
275  UList<Type>& allPointInfo() const
276  {
277  return allPointInfo_;
278  }
279 
280  //- Access allEdgeInfo
281  UList<Type>& allEdgeInfo() const
282  {
283  return allEdgeInfo_;
284  }
285 
286  //- Additional data to be passed into container
287  const TrackingData& data() const
288  {
289  return td_;
290  }
291 
292  //- Number of unvisited edges, i.e. edges that were not (yet)
293  // reached from walking across mesh. This can happen from
294  // - not enough iterations done
295  // - a disconnected mesh
296  // - a mesh without walls in it
297  label nUnvisitedEdges() const;
298 
299  label nUnvisitedPoints() const;
300 
301  //- Copy initial data into allPointInfo_
302  void setPointInfo
303  (
304  const labelList& changedPoints,
305  const List<Type>& changedPointsInfo
306  );
307 
308  //- Propagate from point to edge. Returns total number of edges
309  // (over all processors) changed.
310  label pointToEdge();
311 
312  //- Propagate from edge to point. Returns total number of points
313  // (over all processors) changed.
314  label edgeToPoint();
315 
316  //- Iterate until no changes or maxIter reached. Returns actual
317  // number of iterations.
318  label iterate(const label maxIter);
319 };
320 
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 /*---------------------------------------------------------------------------*\
325  Class listUpdateOp Declaration
326 \*---------------------------------------------------------------------------*/
327 
328 //- List update operation
329 template<class Type, class TrackingData = int>
330 class listUpdateOp
331 {
332  //- Additional data to be passed into container
333 
334  const scalar tol_;
335 
336  TrackingData& td_;
337 
338 public:
339  listUpdateOp(const scalar tol, TrackingData& td)
340  :
341  tol_(tol),
342  td_(td)
343  {}
344 
345  void operator()(List<Type>& x, const List<Type>& y) const
346  {
347  forAll(x, i)
348  {
349  if (y[i].valid(td_))
350  {
351  x[i].updatePoint(y[i], tol_, td_);
352  }
353  }
354  }
355 };
356 
357 } // End namespace Foam
358 
359 
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 
362 #ifdef NoRepository
363  #include "PointEdgeWave.C"
364 #endif
365 
366 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 
368 #endif
369 
370 // ************************************************************************* //
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::PointEdgeWave::pointToEdge
label pointToEdge()
Propagate from point to edge. Returns total number of edges.
Definition: PointEdgeWave.C:847
Foam::PointEdgeWave::setPointInfo
void setPointInfo(const labelList &changedPoints, const List< Type > &changedPointsInfo)
Copy initial data into allPointInfo_.
Definition: PointEdgeWave.C:735
scalarField.H
Foam::listUpdateOp::listUpdateOp
listUpdateOp(const scalar tol, TrackingData &td)
Definition: PointEdgeWave.H:338
Foam::PointEdgeWave::nUnvisitedEdges
label nUnvisitedEdges() const
Number of unvisited edges, i.e. edges that were not (yet)
Definition: PointEdgeWave.C:726
Foam::PointEdgeWave
Wave propagation of information through grid. Every iteration information goes through one layer of e...
Definition: PointEdgeWave.H:87
Foam::PointEdgeWave::propagationTol
static scalar propagationTol()
Access to tolerance.
Definition: PointEdgeWave.H:226
Foam::PointEdgeWave::allPointInfo
UList< Type > & allPointInfo() const
Access allPointInfo.
Definition: PointEdgeWave.H:274
Foam::PointEdgeWave::nUnvisitedPoints
label nUnvisitedPoints() const
Definition: PointEdgeWave.C:719
bitSet.H
Foam::listUpdateOp
List update operation.
Definition: PointEdgeWave.H:329
Foam::PointEdgeWave::edgeToPoint
label edgeToPoint()
Propagate from edge to point. Returns total number of points.
Definition: PointEdgeWave.C:771
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::label
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:62
Foam::Field< tensor >
Foam::PointEdgeWave::iterate
label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
Definition: PointEdgeWave.C:916
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::TemplateName
TemplateName(blendedSchemeBase)
PointEdgeWave.C
Foam::PointEdgeWave::~PointEdgeWave
~PointEdgeWave()
Destructor.
Definition: PointEdgeWave.C:711
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::PointEdgeWave::data
const TrackingData & data() const
Additional data to be passed into container.
Definition: PointEdgeWave.H:286
tensorField.H
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< label >
Foam::UList< Type >
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::PointEdgeWave::allEdgeInfo
UList< Type > & allEdgeInfo() const
Access allEdgeInfo.
Definition: PointEdgeWave.H:280
Foam::listUpdateOp::operator()
void operator()(List< Type > &x, const List< Type > &y) const
Definition: PointEdgeWave.H:344
Foam::PointEdgeWave::setPropagationTol
static void setPropagationTol(const scalar tol)
Change tolerance.
Definition: PointEdgeWave.H:232
y
scalar y
Definition: LISASMDCalcMethod1.H:14