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-2022 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 "DynamicList.H"
55 #include "primitiveFieldsFwd.H"
56 #include "labelPair.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 // Forward Declarations
64 class polyMesh;
65 class polyPatch;
66 
67 /*---------------------------------------------------------------------------*\
68  Class FaceCellWaveBase Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 class FaceCellWaveBase
72 {
73 protected:
74 
75  // Protected Static Data
76 
77  static const scalar geomTol_;
78  static scalar propagationTol_;
79 
80 
81  // Protected Data
82 
83  //- Reference to mesh
84  const polyMesh& mesh_;
85 
86  //- Track if face has changed
88 
89  //- Track if cell has changed
91 
92  //- List of changed faces
94 
95  //- List of changed cells
97 
98  //- Current count of unvisited faces
99  label nUnvisitedFaces_;
100 
101  //- Current count of unvisited cells
102  label nUnvisitedCells_;
103 
104 
105 public:
107  //- Default trackData value (for default template argument)
108  static int dummyTrackData_;
109 
110 
111  //- Runtime type information
112  ClassName("FaceCellWave");
113 
114 
115  // Constructors
116 
117  //- Construct with mesh reference and set initial sizes
120 
121  // Static Functions
122 
123  //- Access to propagation tolerance
124  static scalar propagationTol() noexcept
125  {
126  return propagationTol_;
127  }
128 
129  //- Change propagation tolerance, return previous value
130  static scalar setPropagationTol(const scalar tol) noexcept
131  {
132  scalar old(propagationTol_);
133  propagationTol_ = tol;
134  return old;
135  }
136 
137 
138  // Member Functions
139 
140  //- Return access to the mesh
141  const polyMesh& mesh() const noexcept
142  {
143  return mesh_;
144  }
145 
146  //- Current number of changed cells
147  label nChangedCells() const noexcept { return changedCells_.size(); }
148 
149  //- Current number of changed faces
150  label nChangedFaces() const noexcept { return changedFaces_.size(); }
151 
152  //- Get number of unvisited cells,
153  //- i.e. cells that were not (yet) reached from walking across mesh.
154  // This can happen from
155  // - not enough iterations done
156  // - a disconnected mesh
157  // - a mesh without walls in it
158  label nUnvisitedCells() const noexcept { return nUnvisitedCells_; }
159 
160  //- Get number of unvisited faces
161  label nUnvisitedFaces() const noexcept { return nUnvisitedFaces_; }
162 };
163 
164 
165 /*---------------------------------------------------------------------------*\
166  Class FaceCellWave Declaration
167 \*---------------------------------------------------------------------------*/
168 
169 template<class Type, class TrackingData = int>
171 :
172  public FaceCellWaveBase
173 {
174 protected:
176  //- Information tagged with a source or destination id.
177  // With std::pair as lightweight, movable container.
178  typedef std::pair<label,Type> taggedInfoType;
179 
180 
181  // Protected Data
182 
183  //- Optional boundary faces that information should travel through
185 
186  //- Information for all faces
188 
189  //- Information for all cells
192  //- Additional data to be passed into container
193  TrackingData& td_;
194 
195  // Information exchange for explicit baffle connections
196  // Max capacity = 2x number of explicit connections
198 
199  //- Contains cyclics
200  const bool hasCyclicPatches_;
201 
202  //- Contains cyclicAMI
203  const bool hasCyclicAMIPatches_;
204 
205  //- Number of evaluations
206  label nEvals_;
207 
208 
209  // Protected Member Functions
210 
211  //- Updates cellInfo with information from neighbour.
212  // Updates all statistics.
213  bool updateCell
214  (
215  const label celli,
216  const label neighbourFacei,
217  const Type& neighbourInfo,
218  const scalar tol,
219  Type& cellInfo
220  );
221 
222  //- Updates faceInfo with information from neighbour.
223  // Updates all statistics.
225  (
226  const label facei,
227  const label neighbourCelli,
228  const Type& neighbourInfo,
229  const scalar tol,
230  Type& faceInfo
231  );
232 
233  //- Updates faceInfo with information from same face.
234  // Updates all statistics.
235  bool updateFace
236  (
237  const label facei,
238  const Type& neighbourInfo,
239  const scalar tol,
240  Type& faceInfo
241  );
242 
244  // Parallel, cyclic
245 
246  //- Debugging: check info on both sides of cyclic
247  void checkCyclic(const polyPatch& pPatch) const;
249  //- Has cyclic patch?
250  template<class PatchType>
251  bool hasPatch() const;
252 
253  //- Merge received patch data into global data
254  void mergeFaceInfo
255  (
256  const polyPatch& patch,
257  const label nFaces,
258  const labelUList& changedFaces,
259  const List<Type>& changedFacesInfo
260  );
261 
262  //- Extract info for single patch only
264  (
265  const polyPatch& patch,
266  const label startFacei,
267  const label nFaces,
268  labelList& changedPatchFaces,
269  List<Type>& changedPatchFacesInfo
270  ) const;
271 
272  //- Handle leaving domain. Implementation referred to Type
273  void leaveDomain
274  (
275  const polyPatch& patch,
276  const label nFaces,
277  const labelUList& faceLabels,
278  List<Type>& faceInfo
279  ) const;
280 
281  //- Handle leaving domain. Implementation referred to Type
282  void enterDomain
283  (
284  const polyPatch& patch,
285  const label nFaces,
286  const labelUList& faceLabels,
287  List<Type>& faceInfo
288  ) const;
289 
290  //- Offset face labels by constant value
291  static void offset
292  (
293  const polyPatch& patch,
294  const label off,
295  const label nFaces,
296  labelList& faces
297  );
298 
299  //- Apply transformation to Type
300  void transform
301  (
302  const tensorField& rotTensor,
303  const label nFaces,
304  List<Type>& faceInfo
305  );
306 
307  //- Merge data from across processor boundaries
308  // Transfer changed faces from neighbouring processors.
309  void handleProcPatches();
310 
311  //- Merge data from across cyclics
312  // Transfer changed faces across cyclic halves
313  void handleCyclicPatches();
314 
315  //- Merge data from across AMI cyclics
316  void handleAMICyclicPatches();
317 
318  //- Merge data across explicitly provided local connections
319  // These are usually baffles
321 
322 
323  //- No copy construct
324  FaceCellWave(const FaceCellWave&) = delete;
325 
326  //- No copy assignment
327  void operator=(const FaceCellWave&) = delete;
328 
329 
330 public:
331 
332  // Constructors
333 
334  //- Construct from mesh.
335  //- Use setFaceInfo and iterate() to do actual calculation.
337  (
338  const polyMesh& mesh,
341  TrackingData& td = FaceCellWaveBase::dummyTrackData_
342  );
343 
344  //- Construct from mesh and list of changed faces with the Type
345  // for these faces. Iterates until nothing changes or maxIter reached.
346  // (maxIter can be 0 or negative). 0 initializes, -1 does not
348  (
349  const polyMesh& mesh,
350  const labelUList& initialChangedFaces,
351  const List<Type>& changedFacesInfo,
354  const label maxIter,
355  TrackingData& td = FaceCellWaveBase::dummyTrackData_
356  );
357 
358  //- Construct from mesh and explicitly connected boundary faces
359  // and list of changed faces with the Type
360  // for these faces. Iterates until nothing changes or maxIter reached.
361  // (maxIter can be 0 or negative). 0 initializes, -1 does not
363  (
364  const polyMesh& mesh,
365  const labelPairList& explicitConnections,
366  const bool handleCyclicAMI,
367  const labelUList& initialChangedFaces,
368  const List<Type>& changedFacesInfo,
371  const label maxIter,
372  TrackingData& td = FaceCellWaveBase::dummyTrackData_
373  );
374 
375 
376  //- Destructor
377  virtual ~FaceCellWave() = default;
378 
379 
380  // Member Functions
381 
382  // Access
383 
384  //- Access allFaceInfo
386  {
387  return allFaceInfo_;
388  }
389 
390  //- Access allCellInfo
392  {
393  return allCellInfo_;
394  }
395 
396  //- Additional data to be passed into container
397  const TrackingData& data() const noexcept
398  {
399  return td_;
400  }
401 
402 
403  // Edit
404 
405  //- Set single initial changed face.
406  // This is a noop if the face had already been visited
407  void setFaceInfo(const label facei, const Type& faceInfo);
408 
409  //- Set initial changed faces
410  void setFaceInfo
411  (
412  const labelUList& changedFaces,
413  const List<Type>& changedFacesInfo
414  );
415 
416  //- Propagate from face to cell.
417  // \return total number of cells (over all processors) changed.
418  virtual label faceToCell();
419 
420  //- Propagate from cell to face.
421  // \return total number of faces (over all processors) changed.
422  // Note that faces on processor patches are counted twice.
423  virtual label cellToFace();
424 
425  //- Iterate until no changes or maxIter reached.
426  // \return the number of iterations taken.
427  virtual label iterate(const label maxIter);
428 };
429 
430 
431 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
432 
433 } // End namespace Foam
434 
435 
436 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
437 
438 #ifdef NoRepository
439  #include "FaceCellWave.C"
440 #endif
441 
442 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
443 
444 #endif
445 
446 // ************************************************************************* //
void handleAMICyclicPatches()
Merge data from across AMI cyclics.
Definition: FaceCellWave.C:715
const bool hasCyclicAMIPatches_
Contains cyclicAMI.
Definition: FaceCellWave.H:248
void handleExplicitConnections()
Merge data across explicitly provided local connections.
Definition: FaceCellWave.C:815
static int dummyTrackData_
Default trackData value (for default template argument)
Definition: FaceCellWave.H:119
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
bitSet changedFace_
Track if face has changed.
Definition: FaceCellWave.H:86
ClassName("FaceCellWave")
Runtime type information.
UList< Type > & allFaceInfo_
Information for all faces.
Definition: FaceCellWave.H:224
label nUnvisitedFaces() const noexcept
Get number of unvisited faces.
Definition: FaceCellWave.H:191
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:243
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:238
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:200
label nUnvisitedCells_
Current count of unvisited cells.
Definition: FaceCellWave.H:111
const TrackingData & data() const noexcept
Additional data to be passed into container.
Definition: FaceCellWave.H:500
label nEvals_
Number of evaluations.
Definition: FaceCellWave.H:253
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:229
void handleProcPatches()
Merge data from across processor boundaries.
Definition: FaceCellWave.C:515
static scalar propagationTol() noexcept
Access to propagation tolerance.
Definition: FaceCellWave.H:141
void operator=(const FaceCellWave &)=delete
No copy assignment.
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
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:162
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:91
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:72
std::pair< label, Type > taggedInfoType
Information tagged with a source or destination id.
Definition: FaceCellWave.H:211
static scalar setPropagationTol(const scalar tol) noexcept
Change propagation tolerance, return previous value.
Definition: FaceCellWave.H:149
DynamicList< label > changedCells_
List of changed cells.
Definition: FaceCellWave.H:101
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:73
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:96
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:186
void handleCyclicPatches()
Merge data from across cyclics.
Definition: FaceCellWave.C:631
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
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:106
const polyMesh & mesh_
Reference to mesh.
Definition: FaceCellWave.H:81
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:175
UList< Type > & allCellInfo() noexcept
Access allCellInfo.
Definition: FaceCellWave.H:492
UList< Type > & allFaceInfo() noexcept
Access allFaceInfo.
Definition: FaceCellWave.H:484
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:219
Namespace for OpenFOAM.
TrackingData & td_
Additional data to be passed into container.
Definition: FaceCellWave.H:234
virtual label faceToCell()
Propagate from face to cell.
label nChangedCells() const noexcept
Current number of changed cells.
Definition: FaceCellWave.H:170