Loading...
Searching...
No Matches
FaceCellWave.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) 2018-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::FaceCellWave
29
30Description
31 Wave propagation of information through grid. Every iteration
32 information goes through one layer of cells. Templated on information
33 that is transferred.
34
35 Handles parallel and cyclics and non-parallel cyclics.
36
37 Note: whether to propagate depends on the return value of Type::update
38 which returns true (i.e. propagate) if the value changes by more than a
39 certain tolerance.
40 This tolerance can be very strict for normal face-cell and parallel
41 cyclics (we use a value of 0.01 just to limit propagation of small changes)
42 but for non-parallel cyclics this tolerance can be critical and if chosen
43 too small can lead to non-convergence.
44
45SourceFiles
46 FaceCellWave.C
47
48\*---------------------------------------------------------------------------*/
49
50#ifndef Foam_FaceCellWave_H
51#define Foam_FaceCellWave_H
52
53#include "bitSet.H"
54#include "labelPair.H"
55#include "DynamicList.H"
56#include "primitiveFieldsFwd.H"
57#include "PstreamBuffers.H"
58
59// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60
61namespace Foam
62{
63
64// Forward Declarations
65class polyMesh;
66class polyPatch;
68/*---------------------------------------------------------------------------*\
69 Class FaceCellWaveBase Declaration
70\*---------------------------------------------------------------------------*/
71
74protected:
75
76 // Protected Static Data
77
78 static const scalar geomTol_;
79 static scalar propagationTol_;
80
81
82 // Protected Data
83
84 //- Reference to mesh
85 const polyMesh& mesh_;
86
87 //- Buffers when updating processor patches
89
90 //- Track if face has changed
93 //- Track if cell has changed
95
96 //- List of changed faces
98
99 //- List of changed cells
101
102 //- Current count of unvisited faces
103 label nUnvisitedFaces_;
104
105 //- Current count of unvisited cells
106 label nUnvisitedCells_;
108
109public:
110
111 //- Default trackData value (for default template argument)
112 static int dummyTrackData_;
113
114
115 //- Runtime type information
116 ClassName("FaceCellWave");
118
119 // Constructors
120
121 //- Construct with mesh reference and set initial sizes
122 explicit FaceCellWaveBase(const polyMesh& mesh);
123
124
125 // Static Functions
126
127 //- Access to propagation tolerance
128 static scalar propagationTol() noexcept
129 {
130 return propagationTol_;
132
133 //- Change propagation tolerance, return previous value
134 static scalar setPropagationTol(const scalar tol) noexcept
135 {
136 scalar old(propagationTol_);
137 propagationTol_ = tol;
138 return old;
139 }
140
141
142 // Member Functions
143
144 //- Return access to the mesh
145 const polyMesh& mesh() const noexcept
146 {
147 return mesh_;
148 }
149
150 //- Current number of changed cells
151 label nChangedCells() const noexcept { return changedCells_.size(); }
152
153 //- Current number of changed faces
154 label nChangedFaces() const noexcept { return changedFaces_.size(); }
156 //- Get number of unvisited cells,
157 //- i.e. cells that were not (yet) reached from walking across mesh.
158 // This can happen from
159 // - not enough iterations done
160 // - a disconnected mesh
161 // - a mesh without walls in it
162 label nUnvisitedCells() const noexcept { return nUnvisitedCells_; }
163
164 //- Get number of unvisited faces
165 label nUnvisitedFaces() const noexcept { return nUnvisitedFaces_; }
166};
167
169/*---------------------------------------------------------------------------*\
170 Class FaceCellWave Declaration
171\*---------------------------------------------------------------------------*/
172
173template<class Type, class TrackingData = int>
174class FaceCellWave
175:
177{
178protected:
179
180 //- Information tagged with a source or destination id.
181 // With std::pair as lightweight, movable container.
182 typedef std::pair<label,Type> taggedInfoType;
183
184
185 // Protected Data
186
187 //- Optional boundary faces that information should travel through
189
190 //- Information for all faces
193 //- Information for all cells
195
196 //- Additional data to be passed into container
197 TrackingData& td_;
198
199 // Information exchange for explicit baffle connections
200 // Max capacity = 2x number of explicit connections
202
203 //- Contains cyclics
204 const bool hasCyclicPatches_;
205
206 //- Contains cyclicAMI
207 const bool hasCyclicAMIPatches_;
208
209 //- Number of evaluations
210 label nEvals_;
211
212
213 // Protected Member Functions
214
215 //- Updates cellInfo with information from neighbour.
216 // Updates all statistics.
218 (
219 const label celli,
220 const label neighbourFacei,
221 const Type& neighbourInfo,
222 const scalar tol,
223 Type& cellInfo
224 );
226 //- Updates faceInfo with information from neighbour.
227 // Updates all statistics.
228 bool updateFace
229 (
230 const label facei,
231 const label neighbourCelli,
232 const Type& neighbourInfo,
233 const scalar tol,
234 Type& faceInfo
235 );
236
237 //- Updates faceInfo with information from same face.
238 // Updates all statistics.
239 bool updateFace
241 const label facei,
242 const Type& neighbourInfo,
243 const scalar tol,
244 Type& faceInfo
245 );
246
247
248 // Parallel, cyclic
250 //- Debugging: check info on both sides of cyclic
251 void checkCyclic(const polyPatch& pPatch) const;
252
253 //- Has cyclic patch?
254 template<class PatchType>
255 bool hasPatch() const;
256
257 //- Merge received patch data into global data
258 void mergeFaceInfo
260 const polyPatch& patch,
261 const label nFaces,
262 const labelUList& changedFaces,
263 const UList<Type>& changedFacesInfo
264 );
265
266 //- Extract info for single patch only
268 (
269 const polyPatch& patch,
270 const label startFacei,
271 const label nFaces,
272 labelUList& changedPatchFaces,
273 UList<Type>& changedPatchFacesInfo
274 ) const;
275
276 //- Handle leaving domain. Implementation referred to Type
277 void leaveDomain
278 (
279 const polyPatch& patch,
280 const label nFaces,
281 const labelUList& faceLabels,
282 UList<Type>& faceInfo
283 ) const;
284
285 //- Handle leaving domain. Implementation referred to Type
286 void enterDomain
287 (
288 const polyPatch& patch,
289 const label nFaces,
290 const labelUList& faceLabels,
291 UList<Type>& faceInfo
292 ) const;
293
294 //- Offset face labels by constant value
295 static void offset
296 (
297 const polyPatch& patch,
298 const label off,
299 const label nFaces,
300 labelUList& faces
301 );
302
303 //- Apply transformation to Type
304 void transform
305 (
306 const tensorField& rotTensor,
307 const label nFaces,
308 UList<Type>& faceInfo
309 );
310
311 //- Merge data from across processor boundaries
312 // Transfer changed faces from neighbouring processors.
313 void handleProcPatches();
314
315 //- Merge data from across cyclics
316 // Transfer changed faces across cyclic halves
317 void handleCyclicPatches();
318
319 //- Merge data from across AMI cyclics
321
322 //- Merge data across explicitly provided local connections
323 // These are usually baffles
325
326
327 //- No copy construct
328 FaceCellWave(const FaceCellWave&) = delete;
329
330 //- No copy assignment
331 void operator=(const FaceCellWave&) = delete;
332
333
334public:
335
336 // Constructors
337
338 //- Construct from mesh.
339 //- Use setFaceInfo and iterate() to do actual calculation.
341 (
342 const polyMesh& mesh,
346 );
347
348 //- Construct from mesh and list of changed faces with the Type
349 // for these faces. Iterates until nothing changes or maxIter reached.
350 // (maxIter can be 0 or negative). 0 initializes, -1 does not
352 (
353 const polyMesh& mesh,
354 const labelUList& initialChangedFaces,
355 const UList<Type>& changedFacesInfo,
358 const label maxIter,
360 );
361
362 //- Construct from mesh and explicitly connected boundary faces
363 // and list of changed faces with the Type
364 // for these faces. Iterates until nothing changes or maxIter reached.
365 // (maxIter can be 0 or negative). 0 initializes, -1 does not
367 (
368 const polyMesh& mesh,
369 const UList<labelPair>& explicitConnections,
370 const bool handleCyclicAMI,
371 const labelUList& initialChangedFaces,
372 const UList<Type>& changedFacesInfo,
375 const label maxIter,
377 );
378
379
380 //- Destructor
381 virtual ~FaceCellWave() = default;
382
383
384 // Member Functions
385
386 // Access
387
388 //- Access allFaceInfo
390 {
391 return allFaceInfo_;
392 }
393
394 //- Access allCellInfo
396 {
397 return allCellInfo_;
398 }
399
400 //- Additional data to be passed into container
401 const TrackingData& data() const noexcept
402 {
403 return td_;
404 }
405
406
407 // Edit
408
409 //- Set single initial changed face.
410 // This is a noop if the face had already been visited
411 void setFaceInfo(const label facei, const Type& faceInfo);
412
413 //- Set initial changed faces
414 void setFaceInfo
416 const labelUList& changedFaces,
417 const UList<Type>& changedFacesInfo
418 );
419
420 //- Propagate from face to cell.
421 // \return total number of cells (over all processors) changed.
422 virtual label faceToCell();
423
424 //- Propagate from cell to face.
425 // \return total number of faces (over all processors) changed.
426 // Note that faces on processor patches are counted twice.
427 virtual label cellToFace();
428
429 //- Iterate until no changes or maxIter reached.
430 // \return the number of iterations taken.
431 virtual label iterate(const label maxIter);
432};
433
434
435// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
436
437} // End namespace Foam
438
439
440// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
441
442#ifdef NoRepository
443 #include "FaceCellWave.C"
444#endif
445
446// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
447
448#endif
449
450// ************************************************************************* //
labelList faceLabels(nFaceLabels)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
label nChangedFaces() const noexcept
Current number of changed faces.
DynamicList< label > changedCells_
List of changed cells.
static int dummyTrackData_
Default trackData value (for default template argument).
DynamicList< label > changedFaces_
List of changed faces.
ClassName("FaceCellWave")
Runtime type information.
bitSet changedFace_
Track if face has changed.
PstreamBuffers pBufs_
Buffers when updating processor patches.
static scalar propagationTol_
FaceCellWaveBase(const polyMesh &mesh)
Construct with mesh reference and set initial sizes.
static const scalar geomTol_
label nUnvisitedFaces_
Current count of unvisited faces.
label nChangedCells() const noexcept
Current number of changed cells.
static scalar setPropagationTol(const scalar tol) noexcept
Change propagation tolerance, return previous value.
label nUnvisitedFaces() const noexcept
Get number of unvisited faces.
label nUnvisitedCells_
Current count of unvisited cells.
bitSet changedCell_
Track if cell has changed.
const polyMesh & mesh() const noexcept
Return access to the mesh.
label nUnvisitedCells() const noexcept
Get number of unvisited cells, i.e. cells that were not (yet) reached from walking across mesh.
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 c...
virtual ~FaceCellWave()=default
Destructor.
void handleExplicitConnections()
Merge data across explicitly provided local connections.
UList< Type > & allCellInfo_
Information for all cells.
UList< Type > & allFaceInfo_
Information for all faces.
void mergeFaceInfo(const polyPatch &patch, const label nFaces, const labelUList &changedFaces, const UList< Type > &changedFacesInfo)
Merge received patch data into global data.
void handleProcPatches()
Merge data from across processor boundaries.
label nEvals_
Number of evaluations.
DynamicList< taggedInfoType > changedBaffles_
FaceCellWave(const FaceCellWave &)=delete
No copy construct.
void operator=(const FaceCellWave &)=delete
No copy assignment.
bool hasPatch() const
Has cyclic patch?
void leaveDomain(const polyPatch &patch, const label nFaces, const labelUList &faceLabels, UList< Type > &faceInfo) const
Handle leaving domain. Implementation referred to Type.
TrackingData & td_
Additional data to be passed into container.
const TrackingData & data() const noexcept
Additional data to be passed into container.
static void offset(const polyPatch &patch, const label off, const label nFaces, labelUList &faces)
Offset face labels by constant value.
void handleAMICyclicPatches()
Merge data from across AMI cyclics.
void checkCyclic(const polyPatch &pPatch) const
Debugging: check info on both sides of cyclic.
virtual label iterate(const label maxIter)
Iterate until no changes or maxIter reached.
void handleCyclicPatches()
Merge data from across cyclics.
void setFaceInfo(const label facei, const Type &faceInfo)
Set single initial changed face.
label getChangedPatchFaces(const polyPatch &patch, const label startFacei, const label nFaces, labelUList &changedPatchFaces, UList< Type > &changedPatchFacesInfo) const
Extract info for single patch only.
void enterDomain(const polyPatch &patch, const label nFaces, const labelUList &faceLabels, UList< Type > &faceInfo) const
Handle leaving domain. Implementation referred to Type.
bool updateCell(const label celli, const label neighbourFacei, const Type &neighbourInfo, const scalar tol, Type &cellInfo)
Updates cellInfo with information from neighbour.
const labelPairList explicitConnections_
Optional boundary faces that information should travel through.
void transform(const tensorField &rotTensor, const label nFaces, UList< Type > &faceInfo)
Apply transformation to Type.
const bool hasCyclicAMIPatches_
Contains cyclicAMI.
virtual label faceToCell()
Propagate from face to cell.
UList< Type > & allFaceInfo() noexcept
Access allFaceInfo.
bool updateFace(const label facei, const label neighbourCelli, const Type &neighbourInfo, const scalar tol, Type &faceInfo)
Updates faceInfo with information from neighbour.
std::pair< label, Type > taggedInfoType
Information tagged with a source or destination id.
virtual label cellToFace()
Propagate from cell to face.
UList< Type > & allCellInfo() noexcept
Access allCellInfo.
const bool hasCyclicPatches_
Contains cyclics.
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
Holds information regarding type of cell. Used in inside/outside determination in cellClassification.
Definition cellInfo.H:61
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< labelPair > labelPairList
List of labelPair.
Definition labelPair.H:33
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
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.