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, moveable 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
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,
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,
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,
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)
Updates cellInfo with information from neighbour.
Definition: FaceCellWave.C:115
primitiveFieldsFwd.H
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
Foam::FaceCellWave::dummyTrackData_
static int dummyTrackData_
Default trackdata value to satisfy default template argument.
Definition: FaceCellWave.H:95
Foam::FaceCellWave::handleExplicitConnections
void handleExplicitConnections()
Merge data across explicitly provided local connections.
Definition: FaceCellWave.C:830
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::operator=
void operator=(const FaceCellWave &)=delete
No copy assignment.
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:460
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:163
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:348
Foam::FaceCellWave::allFaceInfo
UList< Type > & allFaceInfo()
Access allFaceInfo.
Definition: FaceCellWave.H:336
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:1227
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:405
Foam::FaceCellWave::checkCyclic
void checkCyclic(const polyPatch &pPatch) const
Debugging: check info on both sides of cyclic.
Definition: FaceCellWave.C:257
Foam::FaceCellWave::handleProcPatches
void handleProcPatches()
Merge data from across processor boundaries.
Definition: FaceCellWave.C:530
Foam::FaceCellWave::propagationTol_
static scalar propagationTol_
Definition: FaceCellWave.H:92
Foam::FaceCellWave::geomTol_
static const scalar geomTol_
Definition: FaceCellWave.H:91
Foam::FaceCellWave::nUnvisitedFaces
label nUnvisitedFaces() const
Get number of unvisited faces.
Definition: FaceCellWave.C:1067
Foam::FaceCellWave::hasPatch
bool hasPatch() const
Has cyclic patch?
Definition: FaceCellWave.C:303
Foam::FaceCellWave::hasCyclicAMIPatches_
const bool hasCyclicAMIPatches_
Contains cyclicAMI.
Definition: FaceCellWave.H:135
Foam::FaceCellWave::propagationTol
static scalar propagationTol()
Access to tolerance.
Definition: FaceCellWave.H:271
Foam::FaceCellWave::faceToCell
virtual label faceToCell()
Propagate from face to cell.
Definition: FaceCellWave.C:1074
Foam::FaceCellWave::setFaceInfo
void setFaceInfo(const label facei, const Type &faceInfo)
Set single initial changed face.
Definition: FaceCellWave.C:318
Foam::FaceCellWave::nUnvisitedCells
label nUnvisitedCells() const
Definition: FaceCellWave.C:1060
Foam::FaceCellWave::handleCyclicPatches
void handleCyclicPatches()
Merge data from across cyclics.
Definition: FaceCellWave.C:646
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:67
Foam::FaceCellWave::taggedInfoType
std::pair< label, Type > taggedInfoType
Information tagged with a source or destination id.
Definition: FaceCellWave.H:86
Foam::TemplateName
TemplateName(blendedSchemeBase)
Foam::FaceCellWave::FaceCellWave
FaceCellWave(const FaceCellWave &)=delete
No copy construct.
Foam::FaceCellWave::handleAMICyclicPatches
void handleAMICyclicPatches()
Merge data from across AMI cyclics.
Definition: FaceCellWave.C:730
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:1151
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:342
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:354
Foam::FaceCellWave::transform
void transform(const tensorField &rotTensor, const label nFaces, List< Type > &faceInfo)
Apply transformation to Type.
Definition: FaceCellWave.C:483
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:277
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:371
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:512
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:437
labelPair.H
Foam::FaceCellWave::~FaceCellWave
virtual ~FaceCellWave()=default
Destructor.