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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::FaceCellWave
29 
30 Description
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 
45 SourceFiles
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 
61 namespace Foam
62 {
63 
64 // Forward Declarations
65 class polyMesh;
66 class polyPatch;
67 
68 /*---------------------------------------------------------------------------*\
69  Class FaceCellWaveBase Declaration
70 \*---------------------------------------------------------------------------*/
71 
72 class FaceCellWaveBase
73 {
74 protected:
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
92 
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 
109 public:
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_;
131  }
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 
173 template<class Type, class TrackingData = int>
174 class FaceCellWave
175 :
177 {
178 protected:
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
240  (
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
259  (
260  const polyPatch& patch,
261  const label nFaces,
262  const labelUList& changedFaces,
263  const List<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  labelList& changedPatchFaces,
273  List<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  List<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  List<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  labelList& faces
301  );
302 
303  //- Apply transformation to Type
304  void transform
305  (
306  const tensorField& rotTensor,
307  const label nFaces,
308  List<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
320  void handleAMICyclicPatches();
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 
334 public:
335 
336  // Constructors
337 
338  //- Construct from mesh.
339  //- Use setFaceInfo and iterate() to do actual calculation.
341  (
342  const polyMesh& mesh,
345  TrackingData& td = FaceCellWaveBase::dummyTrackData_
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 List<Type>& changedFacesInfo,
358  const label maxIter,
359  TrackingData& td = FaceCellWaveBase::dummyTrackData_
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 labelPairList& explicitConnections,
370  const bool handleCyclicAMI,
371  const labelUList& initialChangedFaces,
372  const List<Type>& changedFacesInfo,
375  const label maxIter,
376  TrackingData& td = FaceCellWaveBase::dummyTrackData_
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
415  (
416  const labelUList& changedFaces,
417  const List<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 // ************************************************************************* //
void handleAMICyclicPatches()
Merge data from across AMI cyclics.
Definition: FaceCellWave.C:743
PstreamBuffers pBufs_
Buffers when updating processor patches.
Definition: FaceCellWave.H:87
const bool hasCyclicAMIPatches_
Contains cyclicAMI.
Definition: FaceCellWave.H:254
void handleExplicitConnections()
Merge data across explicitly provided local connections.
Definition: FaceCellWave.C:844
static int dummyTrackData_
Default trackData value (for default template argument)
Definition: FaceCellWave.H:125
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
bitSet changedFace_
Track if face has changed.
Definition: FaceCellWave.H:92
ClassName("FaceCellWave")
Runtime type information.
UList< Type > & allFaceInfo_
Information for all faces.
Definition: FaceCellWave.H:230
label nUnvisitedFaces() const noexcept
Get number of unvisited faces.
Definition: FaceCellWave.H:197
virtual label iterate(const label maxIter)
Iterate until no changes or maxIter reached.
virtual label cellToFace()
Propagate from cell to face.
const bool hasCyclicPatches_
Contains cyclics.
Definition: FaceCellWave.H:249
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
DynamicList< taggedInfoType > changedBaffles_
Definition: FaceCellWave.H:244
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:206
label nUnvisitedCells_
Current count of unvisited cells.
Definition: FaceCellWave.H:117
const TrackingData & data() const noexcept
Additional data to be passed into container.
Definition: FaceCellWave.H:506
label nEvals_
Number of evaluations.
Definition: FaceCellWave.H:259
Holds information regarding type of cell. Used in inside/outside determination in cellClassification...
Definition: cellInfo.H:60
UList< Type > & allCellInfo_
Information for all cells.
Definition: FaceCellWave.H:235
labelList faceLabels(nFaceLabels)
void handleProcPatches()
Merge data from across processor boundaries.
Definition: FaceCellWave.C:515
static scalar propagationTol() noexcept
Access to propagation tolerance.
Definition: FaceCellWave.H:147
void operator=(const FaceCellWave &)=delete
No copy assignment.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
void leaveDomain(const polyPatch &patch, const label nFaces, const labelUList &faceLabels, List< Type > &faceInfo) const
Handle leaving domain. Implementation referred to Type.
Definition: FaceCellWave.C:422
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
bool hasPatch() const
Has cyclic patch?
Definition: FaceCellWave.C:288
FaceCellWaveBase(const polyMesh &mesh)
Construct with mesh reference and set initial sizes.
void transform(const tensorField &rotTensor, const label nFaces, List< Type > &faceInfo)
Apply transformation to Type.
Definition: FaceCellWave.C:468
virtual ~FaceCellWave()=default
Destructor.
const polyMesh & mesh() const noexcept
Return access to the mesh.
Definition: FaceCellWave.H:168
void mergeFaceInfo(const polyPatch &patch, const label nFaces, const labelUList &changedFaces, const List< Type > &changedFacesInfo)
Merge received patch data into global data.
Definition: FaceCellWave.C:356
bitSet changedCell_
Track if cell has changed.
Definition: FaceCellWave.H:97
const direction noexcept
Definition: Scalar.H:258
bool updateFace(const label facei, const label neighbourCelli, const Type &neighbourInfo, const scalar tol, Type &faceInfo)
Updates faceInfo with information from neighbour.
Definition: FaceCellWave.C:148
bool updateCell(const label celli, const label neighbourFacei, const Type &neighbourInfo, const scalar tol, Type &cellInfo)
Updates cellInfo with information from neighbour.
Definition: FaceCellWave.C:100
static const scalar geomTol_
Definition: FaceCellWave.H:73
std::pair< label, Type > taggedInfoType
Information tagged with a source or destination id.
Definition: FaceCellWave.H:217
Buffers for inter-processor communications streams (UOPstream, UIPstream).
static scalar setPropagationTol(const scalar tol) noexcept
Change propagation tolerance, return previous value.
Definition: FaceCellWave.H:155
DynamicList< label > changedCells_
List of changed cells.
Definition: FaceCellWave.H:107
void enterDomain(const polyPatch &patch, const label nFaces, const labelUList &faceLabels, List< Type > &faceInfo) const
Handle leaving domain. Implementation referred to Type.
Definition: FaceCellWave.C:445
static scalar propagationTol_
Definition: FaceCellWave.H:74
label getChangedPatchFaces(const polyPatch &patch, const label startFacei, const label nFaces, labelList &changedPatchFaces, List< Type > &changedPatchFacesInfo) const
Extract info for single patch only.
Definition: FaceCellWave.C:390
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
const std::string patch
OpenFOAM patch number as a std::string.
DynamicList< label > changedFaces_
List of changed faces.
Definition: FaceCellWave.H:102
void checkCyclic(const polyPatch &pPatch) const
Debugging: check info on both sides of cyclic.
Definition: FaceCellWave.C:242
label nUnvisitedCells() const noexcept
Get number of unvisited cells, i.e. cells that were not (yet) reached from walking across mesh...
Definition: FaceCellWave.H:192
void handleCyclicPatches()
Merge data from across cyclics.
Definition: FaceCellWave.C:660
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
FaceCellWave(const FaceCellWave &)=delete
No copy construct.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
label nUnvisitedFaces_
Current count of unvisited faces.
Definition: FaceCellWave.H:112
const polyMesh & mesh_
Reference to mesh.
Definition: FaceCellWave.H:82
static void offset(const polyPatch &patch, const label off, const label nFaces, labelList &faces)
Offset face labels by constant value.
Definition: FaceCellWave.C:497
label nChangedFaces() const noexcept
Current number of changed faces.
Definition: FaceCellWave.H:181
UList< Type > & allCellInfo() noexcept
Access allCellInfo.
Definition: FaceCellWave.H:498
UList< Type > & allFaceInfo() noexcept
Access allFaceInfo.
Definition: FaceCellWave.H:490
void setFaceInfo(const label facei, const Type &faceInfo)
Set single initial changed face.
Definition: FaceCellWave.C:303
const labelPairList explicitConnections_
Optional boundary faces that information should travel through.
Definition: FaceCellWave.H:225
Namespace for OpenFOAM.
TrackingData & td_
Additional data to be passed into container.
Definition: FaceCellWave.H:240
virtual label faceToCell()
Propagate from face to cell.
label nChangedCells() const noexcept
Current number of changed cells.
Definition: FaceCellWave.H:176