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