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-2020 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 protected:
84 
85  //- Information tagged with a source or destination id.
86  // With std::pair as lightweight, movable container.
87  typedef std::pair<label,Type> taggedInfoType;
88 
89 
90  // Protected Static Data
91 
92  static const scalar geomTol_;
93  static scalar propagationTol_;
94 
95  //- Default trackdata value to satisfy default template argument.
96  static int dummyTrackData_;
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
142  label nUnvisitedCells_;
143  label nUnvisitedFaces_;
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  //- No copy construct
261  FaceCellWave(const FaceCellWave&) = delete;
262 
263  //- No copy assignment
264  void operator=(const FaceCellWave&) = delete;
265 
266 
267 public:
268 
269  // Static Functions
270 
271  //- Access to tolerance
272  static scalar propagationTol()
273  {
274  return propagationTol_;
275  }
276 
277  //- Change tolerance
278  static void setPropagationTol(const scalar tol)
279  {
280  propagationTol_ = tol;
281  }
282 
283 
284  // Constructors
285 
286  //- Construct from mesh.
287  //- Use setFaceInfo and iterate() to do actual calculation.
289  (
290  const polyMesh& mesh,
291  UList<Type>& allFaceInfo,
292  UList<Type>& allCellInfo,
293  TrackingData& td = dummyTrackData_
294  );
295 
296  //- Construct from mesh and list of changed faces with the Type
297  // for these faces. Iterates until nothing changes or maxIter reached.
298  // (maxIter can be 0 or negative). 0 initializes, -1 does not
300  (
301  const polyMesh& mesh,
302  const labelUList& initialChangedFaces,
303  const List<Type>& changedFacesInfo,
304  UList<Type>& allFaceInfo,
305  UList<Type>& allCellInfo,
306  const label maxIter,
307  TrackingData& td = dummyTrackData_
308  );
309 
310  //- Construct from mesh and explicitly connected boundary faces
311  // and list of changed faces with the Type
312  // for these faces. Iterates until nothing changes or maxIter reached.
313  // (maxIter can be 0 or negative). 0 initializes, -1 does not
315  (
316  const polyMesh& mesh,
317  const labelPairList& explicitConnections,
318  const bool handleCyclicAMI,
319  const labelUList& initialChangedFaces,
320  const List<Type>& changedFacesInfo,
321  UList<Type>& allFaceInfo,
322  UList<Type>& allCellInfo,
323  const label maxIter,
324  TrackingData& td = dummyTrackData_
325  );
326 
327 
328  //- Destructor
329  virtual ~FaceCellWave() = default;
330 
331 
332  // Member Functions
333 
334  // Access
335 
336  //- Access allFaceInfo
338  {
339  return allFaceInfo_;
340  }
341 
342  //- Access allCellInfo
344  {
345  return allCellInfo_;
346  }
347 
348  //- Additional data to be passed into container
349  const TrackingData& data() const
350  {
351  return td_;
352  }
353 
354  //- Access mesh
355  const polyMesh& mesh() const
356  {
357  return mesh_;
358  }
359 
360  //- Get number of unvisited cells,
361  //- i.e. cells that were not (yet) reached from walking across mesh.
362  // This can happen from
363  // - not enough iterations done
364  // - a disconnected mesh
365  // - a mesh without walls in it
366  label nUnvisitedCells() const;
367 
368  //- Get number of unvisited faces
369  label nUnvisitedFaces() const;
370 
371 
372  // Edit
373 
374  //- Set single initial changed face.
375  // This is a noop if the face had already been visited
376  void setFaceInfo(const label facei, const Type& faceInfo);
377 
378  //- Set initial changed faces
379  void setFaceInfo
380  (
381  const labelUList& changedFaces,
382  const List<Type>& changedFacesInfo
383  );
384 
385  //- Propagate from face to cell.
386  // \return total number of cells (over all processors) changed.
387  virtual label faceToCell();
388 
389  //- Propagate from cell to face.
390  // \return total number of faces (over all processors) changed.
391  // Note that faces on processor patches are counted twice.
392  virtual label cellToFace();
393 
394  //- Iterate until no changes or maxIter reached.
395  // \return the number of iterations taken.
396  virtual label iterate(const label maxIter);
397 };
398 
399 
400 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
401 
402 } // End namespace Foam
403 
404 
405 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406 
407 #ifdef NoRepository
408  #include "FaceCellWave.C"
409 #endif
410 
411 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
412 
413 #endif
414 
415 // ************************************************************************* //
Foam::FaceCellWave::updateCell
bool updateCell(const label celli, const label neighbourFacei, const Type &neighbourInfo, const scalar tol, Type &cellInfo)
Definition: FaceCellWave.C:108
primitiveFieldsFwd.H
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
Foam::FaceCellWave::dummyTrackData_
static int dummyTrackData_
Definition: FaceCellWave.H:91
Foam::FaceCellWave::handleExplicitConnections
void handleExplicitConnections()
Definition: FaceCellWave.C:823
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
Foam::DynamicList< label >
FaceCellWave.C
Foam::FaceCellWave::operator=
void operator=(const FaceCellWave &)=delete
Foam::FaceCellWave::enterDomain
void enterDomain(const polyPatch &patch, const label nFaces, const labelUList &faceLabels, List< Type > &faceInfo) const
Definition: FaceCellWave.C:453
Foam::labelPairList
List< labelPair > labelPairList
List of labelPairs.
Definition: labelPair.H:61
Foam::FaceCellWave::updateFace
bool updateFace(const label facei, const label neighbourCelli, const Type &neighbourInfo, const scalar tol, Type &faceInfo)
Definition: FaceCellWave.C:156
Foam::FaceCellWave::nUnvisitedFaces_
label nUnvisitedFaces_
Definition: FaceCellWave.H:138
Foam::FaceCellWave::hasCyclicPatches_
const bool hasCyclicPatches_
Definition: FaceCellWave.H:128
Foam::FaceCellWave::data
const TrackingData & data() const
Definition: FaceCellWave.H:344
Foam::FaceCellWave::allFaceInfo
UList< Type > & allFaceInfo()
Definition: FaceCellWave.H:332
Foam::FaceCellWave::changedBaffles_
DynamicList< taggedInfoType > changedBaffles_
Definition: FaceCellWave.H:125
Foam::FaceCellWave::allCellInfo_
UList< Type > & allCellInfo_
Definition: FaceCellWave.H:106
Foam::FaceCellWave::iterate
virtual label iterate(const label maxIter)
Definition: FaceCellWave.C:1220
bitSet.H
Foam::FaceCellWave::changedCell_
bitSet changedCell_
Definition: FaceCellWave.H:115
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
Foam::FaceCellWave::changedCells_
DynamicList< label > changedCells_
Definition: FaceCellWave.H:121
Foam::FaceCellWave::getChangedPatchFaces
label getChangedPatchFaces(const polyPatch &patch, const label startFacei, const label nFaces, labelList &changedPatchFaces, List< Type > &changedPatchFacesInfo) const
Definition: FaceCellWave.C:398
Foam::FaceCellWave::checkCyclic
void checkCyclic(const polyPatch &pPatch) const
Definition: FaceCellWave.C:250
Foam::FaceCellWave::handleProcPatches
void handleProcPatches()
Definition: FaceCellWave.C:523
Foam::FaceCellWave::propagationTol_
static scalar propagationTol_
Definition: FaceCellWave.H:88
Foam::FaceCellWave::geomTol_
static const scalar geomTol_
Definition: FaceCellWave.H:87
Foam::FaceCellWave::nUnvisitedFaces
label nUnvisitedFaces() const
Definition: FaceCellWave.C:1060
Foam::FaceCellWave::hasPatch
bool hasPatch() const
Definition: FaceCellWave.C:296
Foam::FaceCellWave::hasCyclicAMIPatches_
const bool hasCyclicAMIPatches_
Definition: FaceCellWave.H:131
Foam::FaceCellWave::propagationTol
static scalar propagationTol()
Definition: FaceCellWave.H:267
Foam::FaceCellWave::faceToCell
virtual label faceToCell()
Definition: FaceCellWave.C:1067
Foam::FaceCellWave::setFaceInfo
void setFaceInfo(const label facei, const Type &faceInfo)
Definition: FaceCellWave.C:311
Foam::FaceCellWave::nUnvisitedCells
label nUnvisitedCells() const
Definition: FaceCellWave.C:1053
Foam::FaceCellWave::handleCyclicPatches
void handleCyclicPatches()
Definition: FaceCellWave.C:639
Foam::FaceCellWave::allFaceInfo_
UList< Type > & allFaceInfo_
Definition: FaceCellWave.H:103
Foam::Field
Generic templated field type.
Definition: Field.H:59
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:64
Foam::FaceCellWave::taggedInfoType
std::pair< label, Type > taggedInfoType
Definition: FaceCellWave.H:82
Foam::TemplateName
TemplateName(blendedSchemeBase)
Foam::FaceCellWave::FaceCellWave
FaceCellWave(const FaceCellWave &)=delete
Foam::FaceCellWave::handleAMICyclicPatches
void handleAMICyclicPatches()
Definition: FaceCellWave.C:723
Foam::FaceCellWave::explicitConnections_
const labelPairList explicitConnections_
Definition: FaceCellWave.H:100
Foam::FaceCellWave::cellToFace
virtual label cellToFace()
Definition: FaceCellWave.C:1144
Foam::FaceCellWave::td_
TrackingData & td_
Definition: FaceCellWave.H:109
Foam::FaceCellWave::mesh_
const polyMesh & mesh_
Definition: FaceCellWave.H:97
Foam
Definition: atmBoundaryLayer.C:26
Foam::FaceCellWave::nEvals_
label nEvals_
Definition: FaceCellWave.H:134
Foam::FaceCellWave
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:74
Foam::FaceCellWave::allCellInfo
UList< Type > & allCellInfo()
Definition: FaceCellWave.H:338
Foam::FaceCellWave::changedFace_
bitSet changedFace_
Definition: FaceCellWave.H:112
Foam::cellInfo
Holds information regarding type of cell. Used in inside/outside determination in cellClassification.
Definition: cellInfo.H:60
Foam::FaceCellWave::mesh
const polyMesh & mesh() const
Definition: FaceCellWave.H:350
Foam::FaceCellWave::transform
void transform(const tensorField &rotTensor, const label nFaces, List< Type > &faceInfo)
Definition: FaceCellWave.C:476
Foam::FaceCellWave::changedFaces_
DynamicList< label > changedFaces_
Definition: FaceCellWave.H:118
Foam::foamVersion::patch
const std::string patch
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
Foam::FaceCellWave::setPropagationTol
static void setPropagationTol(const scalar tol)
Definition: FaceCellWave.H:273
Foam::FaceCellWave::mergeFaceInfo
void mergeFaceInfo(const polyPatch &patch, const label nFaces, const labelUList &changedFaces, const List< Type > &changedFacesInfo)
Definition: FaceCellWave.C:364
Foam::UList< Type >
Foam::FaceCellWave::nUnvisitedCells_
label nUnvisitedCells_
Definition: FaceCellWave.H:137
DynamicList.H
Foam::FaceCellWave::offset
static void offset(const polyPatch &patch, const label off, const label nFaces, labelList &faces)
Definition: FaceCellWave.C:505
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:81
Foam::FaceCellWave::leaveDomain
void leaveDomain(const polyPatch &patch, const label nFaces, const labelUList &faceLabels, List< Type > &faceInfo) const
Definition: FaceCellWave.C:430
labelPair.H
Foam::FaceCellWave::~FaceCellWave
virtual ~FaceCellWave()=default