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 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 FaceCellWave_H
51 #define 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 FaceCellWaveName Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 TemplateName(FaceCellWave);
72 
73 
74 /*---------------------------------------------------------------------------*\
75  Class FaceCellWave Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 template<class Type, class TrackingData = int>
79 class FaceCellWave
80 :
81  public FaceCellWaveName
82 {
83  // Private Member Functions
84 
85  //- No copy construct
86  FaceCellWave(const FaceCellWave&) = delete;
87 
88  //- No copy assignment
89  void operator=(const FaceCellWave&) = delete;
90 
91 
92 protected:
93 
94  //- Information tagged with a source or destination id.
95  // With std::pair as lightweight, moveable container.
96  typedef std::pair<label,Type> taggedInfoType;
97 
98 
99  // Protected Data
100 
101  //- Reference to mesh
102  const polyMesh& mesh_;
103 
104  //- Optional boundary faces that information should travel through
106 
107  //- Information for all faces
109 
110  //- Information for all cells
112 
113  //- Additional data to be passed into container
114  TrackingData& td_;
115 
116  //- Has face changed
118 
119  //- Has cell changed
121 
122  //- List of changed faces
124 
125  // Cells that have changed
127 
128  // Information exchange for explicit baffle connections
129  // Max capacity = 2x number of explicit connections
131 
132  //- Contains cyclics
133  const bool hasCyclicPatches_;
134 
135  //- Contains cyclicAMI
136  const bool hasCyclicAMIPatches_;
137 
138  //- Number of evaluations
139  label nEvals_;
140 
141  //- Number of unvisited cells/faces
144 
145 
146  // Protected Member Functions
147 
148  //- Updates cellInfo with information from neighbour.
149  // Updates all statistics.
150  bool updateCell
151  (
152  const label celli,
153  const label neighbourFacei,
154  const Type& neighbourInfo,
155  const scalar tol,
156  Type& cellInfo
157  );
158 
159  //- Updates faceInfo with information from neighbour.
160  // Updates all statistics.
161  bool updateFace
162  (
163  const label facei,
164  const label neighbourCelli,
165  const Type& neighbourInfo,
166  const scalar tol,
167  Type& faceInfo
168  );
169 
170  //- Updates faceInfo with information from same face.
171  // Updates all statistics.
172  bool updateFace
173  (
174  const label facei,
175  const Type& neighbourInfo,
176  const scalar tol,
177  Type& faceInfo
178  );
179 
180 
181  // Parallel, cyclic
182 
183  //- Debugging: check info on both sides of cyclic
184  void checkCyclic(const polyPatch& pPatch) const;
185 
186  //- Has cyclic patch?
187  template<class PatchType>
188  bool hasPatch() const;
189 
190  //- Merge received patch data into global data
191  void mergeFaceInfo
192  (
193  const polyPatch& patch,
194  const label nFaces,
195  const labelUList& changedFaces,
196  const List<Type>& changedFacesInfo
197  );
198 
199  //- Extract info for single patch only
201  (
202  const polyPatch& patch,
203  const label startFacei,
204  const label nFaces,
205  labelList& changedPatchFaces,
206  List<Type>& changedPatchFacesInfo
207  ) const;
208 
209  //- Handle leaving domain. Implementation referred to Type
210  void leaveDomain
211  (
212  const polyPatch& patch,
213  const label nFaces,
214  const labelUList& faceLabels,
215  List<Type>& faceInfo
216  ) const;
217 
218  //- Handle leaving domain. Implementation referred to Type
219  void enterDomain
220  (
221  const polyPatch& patch,
222  const label nFaces,
223  const labelUList& faceLabels,
224  List<Type>& faceInfo
225  ) const;
226 
227  //- Offset face labels by constant value
228  static void offset
229  (
230  const polyPatch& patch,
231  const label off,
232  const label nFaces,
233  labelList& faces
234  );
235 
236  //- Apply transformation to Type
237  void transform
238  (
239  const tensorField& rotTensor,
240  const label nFaces,
241  List<Type>& faceInfo
242  );
243 
244  //- Merge data from across processor boundaries
245  // Transfer changed faces from neighbouring processors.
246  void handleProcPatches();
247 
248  //- Merge data from across cyclics
249  // Transfer changed faces across cyclic halves
250  void handleCyclicPatches();
251 
252  //- Merge data from across AMI cyclics
253  void handleAMICyclicPatches();
254 
255  //- Merge data across explicitly provided local connections
256  // These are usually baffles
258 
259 
260  // Protected static data
261 
262  static const scalar geomTol_;
263  static scalar propagationTol_;
264 
265  //- Used as default trackdata value to satisfy default template
266  // argument.
267  static int dummyTrackData_;
268 
269 
270 public:
271 
272  // Static Functions
273 
274  //- Access to tolerance
275  static scalar propagationTol()
276  {
277  return propagationTol_;
278  }
279 
280  //- Change tolerance
281  static void setPropagationTol(const scalar tol)
282  {
283  propagationTol_ = tol;
284  }
285 
286 
287  // Constructors
288 
289  //- Construct from mesh.
290  //- Use setFaceInfo and iterate() to do actual calculation.
292  (
293  const polyMesh& mesh,
296  TrackingData& td = dummyTrackData_
297  );
298 
299  //- Construct from mesh and list of changed faces with the Type
300  // for these faces. Iterates until nothing changes or maxIter reached.
301  // (maxIter can be 0 or negative). 0 initializes, -1 does not
303  (
304  const polyMesh& mesh,
305  const labelUList& initialChangedFaces,
306  const List<Type>& changedFacesInfo,
309  const label maxIter,
310  TrackingData& td = dummyTrackData_
311  );
312 
313  //- Construct from mesh and explicitly connected boundary faces
314  // and list of changed faces with the Type
315  // for these faces. Iterates until nothing changes or maxIter reached.
316  // (maxIter can be 0 or negative). 0 initializes, -1 does not
318  (
319  const polyMesh& mesh,
320  const labelPairList& explicitConnections,
321  const bool handleCyclicAMI,
322  const labelUList& initialChangedFaces,
323  const List<Type>& changedFacesInfo,
326  const label maxIter,
327  TrackingData& td = dummyTrackData_
328  );
329 
330 
331  //- Destructor
332  virtual ~FaceCellWave() = default;
333 
334 
335  // Member Functions
336 
337  // Access
338 
339  //- Access allFaceInfo
341  {
342  return allFaceInfo_;
343  }
344 
345  //- Access allCellInfo
347  {
348  return allCellInfo_;
349  }
350 
351  //- Additional data to be passed into container
352  const TrackingData& data() const
353  {
354  return td_;
355  }
356 
357  //- Access mesh
358  const polyMesh& mesh() const
359  {
360  return mesh_;
361  }
362 
363  //- Get number of unvisited cells,
364  //- i.e. cells that were not (yet) reached from walking across mesh.
365  // This can happen from
366  // - not enough iterations done
367  // - a disconnected mesh
368  // - a mesh without walls in it
369  label nUnvisitedCells() const;
370 
371  //- Get number of unvisited faces
372  label nUnvisitedFaces() const;
373 
374 
375  // Edit
376 
377  //- Set single initial changed face.
378  // This is a noop if the face had already been visited
379  void setFaceInfo(const label facei, const Type& faceInfo);
380 
381  //- Set initial changed faces
382  void setFaceInfo
383  (
384  const labelUList& changedFaces,
385  const List<Type>& changedFacesInfo
386  );
387 
388  //- Propagate from face to cell.
389  // \return total number of cells (over all processors) changed.
390  virtual label faceToCell();
391 
392  //- Propagate from cell to face.
393  // \return total number of faces (over all processors) changed.
394  // Note that faces on processor patches are counted twice.
395  virtual label cellToFace();
396 
397  //- Iterate until no changes or maxIter reached.
398  // \return the number of iterations taken.
399  virtual label iterate(const label maxIter);
400 
401 };
402 
403 
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405 
406 } // End namespace Foam
407 
408 
409 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 
411 #ifdef NoRepository
412  #include "FaceCellWave.C"
413 #endif
414 
415 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
416 
417 #endif
418 
419 // ************************************************************************* //
Foam::FaceCellWave::updateCell
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:114
primitiveFieldsFwd.H
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
Foam::FaceCellWave::dummyTrackData_
static int dummyTrackData_
Used as default trackdata value to satisfy default template.
Definition: FaceCellWave.H:266
Foam::FaceCellWave::handleExplicitConnections
void handleExplicitConnections()
Merge data across explicitly provided local connections.
Definition: FaceCellWave.C:829
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::DynamicList< label >
FaceCellWave.C
Foam::FaceCellWave::enterDomain
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:459
Foam::FaceCellWave::updateFace
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:162
Foam::FaceCellWave::nUnvisitedFaces_
label nUnvisitedFaces_
Definition: FaceCellWave.H:142
Foam::FaceCellWave::hasCyclicPatches_
const bool hasCyclicPatches_
Contains cyclics.
Definition: FaceCellWave.H:132
Foam::FaceCellWave::data
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:351
Foam::FaceCellWave::allFaceInfo
UList< Type > & allFaceInfo()
Access allFaceInfo.
Definition: FaceCellWave.H:339
Foam::FaceCellWave::changedBaffles_
DynamicList< taggedInfoType > changedBaffles_
Definition: FaceCellWave.H:129
Foam::FaceCellWave::allCellInfo_
UList< Type > & allCellInfo_
Information for all cells.
Definition: FaceCellWave.H:110
Foam::FaceCellWave::iterate
virtual label iterate(const label maxIter)
Iterate until no changes or maxIter reached.
Definition: FaceCellWave.C:1226
bitSet.H
Foam::FaceCellWave::changedCell_
bitSet changedCell_
Has cell changed.
Definition: FaceCellWave.H:119
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::FaceCellWave::changedCells_
DynamicList< label > changedCells_
Definition: FaceCellWave.H:125
Foam::FaceCellWave::getChangedPatchFaces
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:404
Foam::FaceCellWave::checkCyclic
void checkCyclic(const polyPatch &pPatch) const
Debugging: check info on both sides of cyclic.
Definition: FaceCellWave.C:256
Foam::FaceCellWave::handleProcPatches
void handleProcPatches()
Merge data from across processor boundaries.
Definition: FaceCellWave.C:529
Foam::FaceCellWave::propagationTol_
static scalar propagationTol_
Definition: FaceCellWave.H:262
Foam::FaceCellWave::geomTol_
static const scalar geomTol_
Definition: FaceCellWave.H:261
Foam::FaceCellWave::nUnvisitedFaces
label nUnvisitedFaces() const
Get number of unvisited faces.
Definition: FaceCellWave.C:1066
Foam::FaceCellWave::hasPatch
bool hasPatch() const
Has cyclic patch?
Definition: FaceCellWave.C:302
Foam::FaceCellWave::hasCyclicAMIPatches_
const bool hasCyclicAMIPatches_
Contains cyclicAMI.
Definition: FaceCellWave.H:135
Foam::FaceCellWave::propagationTol
static scalar propagationTol()
Access to tolerance.
Definition: FaceCellWave.H:274
Foam::FaceCellWave::faceToCell
virtual label faceToCell()
Propagate from face to cell.
Definition: FaceCellWave.C:1073
Foam::FaceCellWave::setFaceInfo
void setFaceInfo(const label facei, const Type &faceInfo)
Set single initial changed face.
Definition: FaceCellWave.C:317
Foam::FaceCellWave::nUnvisitedCells
label nUnvisitedCells() const
Definition: FaceCellWave.C:1059
Foam::FaceCellWave::handleCyclicPatches
void handleCyclicPatches()
Merge data from across cyclics.
Definition: FaceCellWave.C:645
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::FaceCellWave::allFaceInfo_
UList< Type > & allFaceInfo_
Information for all faces.
Definition: FaceCellWave.H:107
Foam::Field< tensor >
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::FaceCellWave::taggedInfoType
std::pair< label, Type > taggedInfoType
Information tagged with a source or destination id.
Definition: FaceCellWave.H:95
Foam::TemplateName
TemplateName(blendedSchemeBase)
Foam::FaceCellWave::handleAMICyclicPatches
void handleAMICyclicPatches()
Merge data from across AMI cyclics.
Definition: FaceCellWave.C:729
Foam::FaceCellWave::explicitConnections_
const labelPairList explicitConnections_
Optional boundary faces that information should travel through.
Definition: FaceCellWave.H:104
Foam::FaceCellWave::cellToFace
virtual label cellToFace()
Propagate from cell to face.
Definition: FaceCellWave.C:1150
Foam::FaceCellWave::td_
TrackingData & td_
Additional data to be passed into container.
Definition: FaceCellWave.H:113
Foam::FaceCellWave::mesh_
const polyMesh & mesh_
Reference to mesh.
Definition: FaceCellWave.H:101
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::FaceCellWave::nEvals_
label nEvals_
Number of evaluations.
Definition: FaceCellWave.H:138
Foam::FaceCellWave
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:78
Foam::FaceCellWave::allCellInfo
UList< Type > & allCellInfo()
Access allCellInfo.
Definition: FaceCellWave.H:345
Foam::FaceCellWave::changedFace_
bitSet changedFace_
Has face changed.
Definition: FaceCellWave.H:116
Foam::cellInfo
Holds information regarding type of cell. Used in inside/outside determination in cellClassification.
Definition: cellInfo.H:64
Foam::FaceCellWave::mesh
const polyMesh & mesh() const
Access mesh.
Definition: FaceCellWave.H:357
Foam::FaceCellWave::transform
void transform(const tensorField &rotTensor, const label nFaces, List< Type > &faceInfo)
Apply transformation to Type.
Definition: FaceCellWave.C:482
Foam::FaceCellWave::changedFaces_
DynamicList< label > changedFaces_
List of changed faces.
Definition: FaceCellWave.H:122
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::FaceCellWave::setPropagationTol
static void setPropagationTol(const scalar tol)
Change tolerance.
Definition: FaceCellWave.H:280
Foam::FaceCellWave::mergeFaceInfo
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:370
Foam::UList< Type >
Foam::FaceCellWave::nUnvisitedCells_
label nUnvisitedCells_
Number of unvisited cells/faces.
Definition: FaceCellWave.H:141
DynamicList.H
Foam::FaceCellWave::offset
static void offset(const polyPatch &patch, const label off, const label nFaces, labelList &faces)
Offset face labels by constant value.
Definition: FaceCellWave.C:511
Foam::FaceCellWave::leaveDomain
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:436
labelPair.H
Foam::FaceCellWave::~FaceCellWave
virtual ~FaceCellWave()=default
Destructor.