PointEdgeWave.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) 2011-2022 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::PointEdgeWave
26 
27 Description
28  Wave propagation of information through grid. Every iteration
29  information goes through one layer of edges.
30 
31  Templated on information that is transferred.
32 
33  Handles parallel and cyclics. Only parallel reasonably tested. Cyclics
34  hardly tested.
35 
36  Note: whether to propagate depends on the return value of Type::update
37  which returns true (i.e. propagate) if the value changes by more than a
38  certain tolerance.
39 
40  Note: parallel is done in two steps:
41  -# transfer patch points in offset notation, i.e. every patch
42  point is denoted by a patchface label and an index in this face.
43  Receiving end uses that fact that f[0] is shared and order is
44  reversed.
45  -# do all non-local shared points by means of reduce of data on them.
46 
47  Note: cyclics is with offset in patchface as well. Patch is divided into
48  two sub patches and the point-point addressing is never explicitly
49  calculated but instead use is made of the face-face correspondence.
50  (it probably is more efficient to calculate a point-point
51  correspondence at the start and then reuse this; task to be done)
52 
53 SourceFiles
54  PointEdgeWave.C
55 
56 \*---------------------------------------------------------------------------*/
57 
58 #ifndef PointEdgeWave_H
59 #define PointEdgeWave_H
60 
61 #include "boolList.H"
62 #include "scalarField.H"
63 #include "tensorField.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 
70 // Forward declaration of classes
71 class polyMesh;
72 class polyPatch;
73 class transformer;
74 
75 /*---------------------------------------------------------------------------*\
76  Class PointEdgeWaveName Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 TemplateName(PointEdgeWave);
80 
81 
82 /*---------------------------------------------------------------------------*\
83  Class PointEdgeWave Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 template<class Type, class TrackingData = int>
87 class PointEdgeWave
88 :
89  public PointEdgeWaveName
90 {
91  // Private static data
92 
93  //- Relative tolerance. Stop propagation if relative changes
94  // less than this tolerance (responsibility for checking this is
95  // up to Type implementation)
96  static scalar propagationTol_;
97 
98 
99  // Private Data
100 
101  //- Reference to mesh
102  const polyMesh& mesh_;
103 
104  //- Wall information for all points
105  UList<Type>& allPointInfo_;
106 
107  //- Information on all mesh edges
108  UList<Type>& allEdgeInfo_;
109 
110  //- Additional data to be passed into container
111  TrackingData& td_;
112 
113  //- Has point changed
114  boolList changedPoint_;
115 
116  //- List of changed points
117  labelList changedPoints_;
118 
119  //- Number of changed points
120  label nChangedPoints_;
121 
122  //- Edges that have changed
123  boolList changedEdge_;
124  labelList changedEdges_;
125  label nChangedEdges_;
126 
127  //- Number of cyclic patches
128  label nCyclicPatches_;
129 
130  //- Number of evaluations
131  label nEvals_;
132 
133  //- Number of unvisited edges/points
134  label nUnvisitedPoints_;
135  label nUnvisitedEdges_;
136 
137 
138  // Private Member Functions
139 
140  //- Transform across an interface. Implementation referred to Type
141  void transform
142  (
143  const polyPatch& patch,
144  const List<label>& patchPointLabels,
145  const transformer& transform,
146  List<Type>& pointInfo
147  ) const;
148 
149  //- Updates pointInfo with information from neighbour. Updates all
150  // statistics.
151  bool updatePoint
152  (
153  const label pointi,
154  const label neighbourEdgeI,
155  const Type& neighbourInfo,
156  Type& pointInfo
157  );
158 
159  //- Updates pointInfo with information from same point. Updates all
160  // statistics.
161  bool updatePoint
162  (
163  const label pointi,
164  const Type& neighbourInfo,
165  Type& pointInfo
166  );
167 
168  //- Updates edgeInfo with information from neighbour. Updates all
169  // statistics.
170  bool updateEdge
171  (
172  const label edgeI,
173  const label neighbourPointi,
174  const Type& neighbourInfo,
175  Type& edgeInfo
176  );
177 
178  // Parallel, cyclic
179 
180  //- Has patches of certain type?
181  template<class PatchType>
182  label countPatchType() const;
183 
184  //- Merge data from across processor boundaries
185  void handleProcPatches();
186 
187  //- Merge data from across cyclic boundaries
188  void handleCyclicPatches();
189 
190  //- Explicitly sync all collocated points
191  label handleCollocatedPoints();
192 
193 
194 public:
195 
196  // Static Data
197 
198  //- Default tracking data to go with default template argument
199  static int defaultTrackingData_;
200 
201 
202  // Static Functions
203 
204  //- Access to tolerance
205  static scalar propagationTol()
206  {
207  return propagationTol_;
208  }
209 
210  //- Change tolerance
211  static void setPropagationTol(const scalar tol)
212  {
213  propagationTol_ = tol;
214  }
215 
216 
217  // Constructors
218 
219  //- Construct from mesh, list of changed points with the Type
220  // for these points. Gets work arrays to operate on, one of size
221  // number of mesh points, the other number of mesh edges.
222  // Iterates until nothing changes or maxIter reached.
223  // (maxIter can be 0)
225  (
226  const polyMesh& mesh,
227  const labelList& initialPoints,
228  const List<Type>& initialPointsInfo,
231  const label maxIter,
232  TrackingData& td = defaultTrackingData_
233  );
234 
235  //- Construct from mesh. Use setPointInfo and iterate() to do
236  // actual calculation
238  (
239  const polyMesh& mesh,
240  UList<Type>& allPointInfo,
241  UList<Type>& allEdgeInfo,
242  TrackingData& td = defaultTrackingData_
243  );
244 
245  //- Disallow default bitwise copy construction
246  PointEdgeWave(const PointEdgeWave&) = delete;
247 
248 
249  //- Destructor
250  ~PointEdgeWave();
251 
252 
253  // Member Functions
254 
255  //- Access allPointInfo
256  UList<Type>& allPointInfo() const
257  {
258  return allPointInfo_;
259  }
260 
261  //- Access allEdgeInfo
262  UList<Type>& allEdgeInfo() const
263  {
264  return allEdgeInfo_;
265  }
266 
267  //- Additional data to be passed into container
268  const TrackingData& data() const
269  {
270  return td_;
271  }
272 
273  //- Get number of unvisited edges, i.e. edges that were not (yet)
274  // reached from walking across mesh. This can happen from
275  // - not enough iterations done
276  // - a disconnected mesh
277  // - a mesh without walls in it
278  label getUnsetEdges() const;
279 
280  label getUnsetPoints() const;
281 
282  //- Copy initial data into allPointInfo_
283  void setPointInfo
284  (
285  const labelList& changedPoints,
286  const List<Type>& changedPointsInfo
287  );
288 
289  //- Propagate from point to edge. Returns total number of edges
290  // (over all processors) changed.
291  label pointToEdge();
292 
293  //- Propagate from edge to point. Returns total number of points
294  // (over all processors) changed.
295  label edgeToPoint();
296 
297  //- Iterate until no changes or maxIter reached. Returns actual
298  // number of iterations.
299  label iterate(const label maxIter);
300 
301 
302  // Member Operators
303 
304  //- Disallow default bitwise assignment
305  void operator=(const PointEdgeWave&) = delete;
306 };
307 
308 
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 
311 /*---------------------------------------------------------------------------*\
312  Class listUpdateOp Declaration
313 \*---------------------------------------------------------------------------*/
314 
315 //- List update operation
316 template<class Type, class TrackingData = int>
317 class listUpdateOp
318 {
319  //- Additional data to be passed into container
320 
321  const scalar tol_;
322 
323  TrackingData& td_;
324 
325 public:
326  listUpdateOp(const scalar tol, TrackingData& td)
327  :
328  tol_(tol),
329  td_(td)
330  {}
332  void operator()(List<Type>& x, const List<Type>& y) const
333  {
334  forAll(x, i)
335  {
336  if (y[i].valid(td_))
337  {
338  x[i].updatePoint(y[i], tol_, td_);
339  }
340  }
341  }
342 };
343 
344 } // End namespace Foam
345 
346 
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 
349 #ifdef NoRepository
350  #include "PointEdgeWave.C"
351 #endif
352 
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 
355 #endif
356 
357 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space...
Definition: transformer.H:83
label pointToEdge()
Propagate from point to edge. Returns total number of edges.
UList< Type > & allEdgeInfo() const
Access allEdgeInfo.
label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
label edgeToPoint()
Propagate from edge to point. Returns total number of points.
UList< Type > & allPointInfo() const
Access allPointInfo.
~PointEdgeWave()
Destructor.
void setPointInfo(const labelList &changedPoints, const List< Type > &changedPointsInfo)
Copy initial data into allPointInfo_.
fvMesh & mesh
void operator=(const PointEdgeWave &)=delete
Disallow default bitwise assignment.
scalar y
static void setPropagationTol(const scalar tol)
Change tolerance.
TemplateName(FvFaceCellWave)
static int defaultTrackingData_
Default tracking data to go with default template argument.
PointEdgeWave(const polyMesh &mesh, const labelList &initialPoints, const List< Type > &initialPointsInfo, UList< Type > &allPointInfo, UList< Type > &allEdgeInfo, const label maxIter, TrackingData &td=defaultTrackingData_)
Construct from mesh, list of changed points with the Type.
const TrackingData & data() const
Additional data to be passed into container.
List update operation.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
label getUnsetPoints() const
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Wave propagation of information through grid. Every iteration information goes through one layer of e...
Definition: PointEdgeWave.H:86
static scalar propagationTol()
Access to tolerance.
label getUnsetEdges() const
Get number of unvisited edges, i.e. edges that were not (yet)
Namespace for OpenFOAM.