FaceCellWave.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::FaceCellWave
26 
27 Description
28  Wave propagation of information through grid. Every iteration
29  information goes through one layer of cells. Templated on information
30  that is transferred.
31 
32  Handles parallel and cyclics and non-parallel cyclics.
33 
34  Note: whether to propagate depends on the return value of Type::update
35  which returns true (i.e. propagate) if the value changes by more than a
36  certain tolerance.
37  This tolerance can be very strict for normal face-cell and parallel
38  cyclics (we use a value of 0.01 just to limit propagation of small changes)
39  but for non-parallel cyclics this tolerance can be critical and if chosen
40  too small can lead to non-convergence.
41 
42 SourceFiles
43  FaceCellWave.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef FaceCellWave_H
48 #define FaceCellWave_H
49 
50 #include "PackedBoolList.H"
51 #include "DynamicList.H"
52 #include "primitiveFieldsFwd.H"
53 #include "labelPair.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // Forward declaration of classes
61 class polyMesh;
62 class polyPatch;
63 class transformer;
64 
65 /*---------------------------------------------------------------------------*\
66  Class FaceCellWaveName Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 TemplateName(FaceCellWave);
70 
71 
72 /*---------------------------------------------------------------------------*\
73  Class FaceCellWave Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 template<class Type, class TrackingData = int>
77 class FaceCellWave
78 :
79  public FaceCellWaveName
80 {
81 protected:
82 
83  // Protected data
84 
85  //- Reference to mesh
86  const polyMesh& mesh_;
87 
88  //- Optional boundary faces that information should travel through
90 
91  //- Information for all faces
93 
94  //- Information for all cells
96 
97  //- Additional data to be passed into container
98  TrackingData& td_;
99 
100  //- Has face changed
102 
103  //- List of changed faces
105 
106  //- Has cell changed
108 
109  // Cells that have changed
111 
112 
113  //- Contains cyclics
114  const bool hasCyclicPatches_;
115 
116  //- Contains cyclicAMI
117  const bool hasCyclicAMIPatches_;
118 
119  //- Number of evaluations
120  label nEvals_;
121 
122  //- Number of unvisited cells/faces
125 
126 
127  //- Updates cellInfo with information from neighbour. Updates all
128  // statistics.
129  bool updateCell
130  (
131  const label celli,
132  const label neighbourFacei,
133  const Type& neighbourInfo,
134  const scalar tol,
135  Type& cellInfo
136  );
137 
138  //- Updates faceInfo with information from neighbour. Updates all
139  // statistics.
140  bool updateFace
141  (
142  const label facei,
143  const label neighbourCelli,
144  const Type& neighbourInfo,
145  const scalar tol,
146  Type& faceInfo
147  );
148 
149  //- Updates faceInfo with information from same face. Updates all
150  // statistics.
151  bool updateFace
152  (
153  const label facei,
154  const Type& neighbourInfo,
155  const scalar tol,
156  Type& faceInfo
157  );
158 
159 
160  // Parallel, cyclic
161 
162  //- Debugging: check info on both sides of cyclic
163  void checkCyclic(const polyPatch& pPatch) const;
164 
165  //- Has cyclic patch?
166  template<class PatchType>
167  bool hasPatch() const;
168 
169  //- Merge received patch data into global data
170  void mergeFaceInfo
171  (
172  const polyPatch& patch,
173  const label nFaces,
174  const labelList&,
175  const List<Type>&
176  );
177 
178  //- Extract info for single patch only
180  (
181  const polyPatch& patch,
182  const label startFacei,
183  const label nFaces,
184  labelList& changedPatchFaces,
185  List<Type>& changedPatchFacesInfo
186  ) const;
187 
188  //- Handle leaving domain. Implementation referred to Type
189  void leaveDomain
190  (
191  const polyPatch& patch,
192  const label nFaces,
193  const labelList& faceLabels,
194  List<Type>& faceInfo
195  ) const;
196 
197  //- Handle leaving domain. Implementation referred to Type
198  void enterDomain
199  (
200  const polyPatch& patch,
201  const label nFaces,
202  const labelList& faceLabels,
203  List<Type>& faceInfo
204  ) const;
205 
206  //- Offset face labels by constant value
207  static void offset
208  (
209  const polyPatch& patch,
210  const label off,
211  const label nFaces,
212  labelList& faces
213  );
214 
215  //- Apply transformation to Type
216  void transform
217  (
218  const tensor& rotTensor,
219  const label nFaces,
220  List<Type>& faceInfo
221  );
222 
223  //- Apply transformation to Type
224  void transform
225  (
226  const transformer& trans,
227  const label nFaces,
228  List<Type>& faceInfo
229  );
230 
231  //- Merge data from across processor boundaries
232  void handleProcPatches();
233 
234  //- Merge data from across cyclics
235  void handleCyclicPatches();
236 
237  //- Merge data from across AMI cyclics
238  void handleAMICyclicPatches();
239 
240  //- Merge data across explicitly provided local connections (usually
241  // baffles)
243 
244 
245  // Protected static data
247  static const scalar geomTol_;
248  static scalar propagationTol_;
249 
250  //- Used as default trackdata value to satisfy default template
251  // argument.
252  static int dummyTrackData_;
253 
254 
255 public:
256 
257  // Static Functions
258 
259  //- Access to tolerance
260  static scalar propagationTol()
261  {
262  return propagationTol_;
263  }
264 
265  //- Change tolerance
266  static void setPropagationTol(const scalar tol)
267  {
268  propagationTol_ = tol;
269  }
270 
271 
272  // Constructors
273 
274  // Construct from mesh. Use setFaceInfo and iterate() to do actual
275  // calculation.
277  (
278  const polyMesh&,
281  TrackingData& td = dummyTrackData_
282  );
283 
284  //- Construct from mesh and list of changed faces with the Type
285  // for these faces. Iterates until nothing changes or maxIter reached.
286  // (maxIter can be 0)
288  (
289  const polyMesh&,
290  const labelList& initialChangedFaces,
291  const List<Type>& changedFacesInfo,
292  UList<Type>& allFaceInfo,
293  UList<Type>& allCellInfo,
294  const label maxIter,
295  TrackingData& td = dummyTrackData_
296  );
297 
298  //- Construct from mesh and explicitly connected boundary faces
299  // and list of changed faces with the Type
300  // for these faces. Iterates until nothing changes or maxIter reached.
301  // (maxIter can be 0)
303  (
304  const polyMesh&,
305  const labelPairList& explicitConnections,
306  const bool handleCyclicAMI,
307  const labelList& initialChangedFaces,
308  const List<Type>& changedFacesInfo,
309  UList<Type>& allFaceInfo,
310  UList<Type>& allCellInfo,
311  const label maxIter,
312  TrackingData& td = dummyTrackData_
313  );
314 
315  //- Disallow default bitwise copy construction
316  FaceCellWave(const FaceCellWave&) = delete;
317 
318 
319  //- Destructor
320  virtual ~FaceCellWave()
321  {}
322 
323 
324  // Member Functions
325 
326  // Access
327 
328  //- Access allFaceInfo
330  {
331  return allFaceInfo_;
332  }
333 
334  //- Access allCellInfo
336  {
337  return allCellInfo_;
338  }
339 
340  //- Additional data to be passed into container
341  const TrackingData& data() const
342  {
343  return td_;
344  }
345 
346  //- Access mesh
347  const polyMesh& mesh() const
348  {
349  return mesh_;
350  }
351 
352  //- Get number of unvisited cells, i.e. cells that were not (yet)
353  // reached from walking across mesh. This can happen from
354  // - not enough iterations done
355  // - a disconnected mesh
356  // - a mesh without walls in it
357  label getUnsetCells() const;
358 
359  //- Get number of unvisited faces
360  label getUnsetFaces() const;
361 
362 
363  // Edit
364 
365  //- Set initial changed faces
366  void setFaceInfo
367  (
368  const labelList& changedFaces,
369  const List<Type>& changedFacesInfo
370  );
371 
372  //- Propagate from face to cell. Returns total number of cells
373  // (over all processors) changed.
374  virtual label faceToCell();
375 
376  //- Propagate from cell to face. Returns total number of faces
377  // (over all processors) changed. (Faces on processorpatches are
378  // counted double)
379  virtual label cellToFace();
380 
381  //- Iterate until no changes or maxIter reached. Returns actual
382  // number of iterations.
383  virtual label iterate(const label maxIter);
384 
385 
386  // Member Operators
387 
388  //- Disallow default bitwise assignment
389  void operator=(const FaceCellWave&) = delete;
390 };
391 
392 
393 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
394 
395 } // End namespace Foam
396 
397 
398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
399 
400 #ifdef NoRepository
401  #include "FaceCellWave.C"
402 #endif
403 
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405 
406 #endif
407 
408 // ************************************************************************* //
void handleAMICyclicPatches()
Merge data from across AMI cyclics.
Definition: FaceCellWave.C:718
void mergeFaceInfo(const polyPatch &patch, const label nFaces, const labelList &, const List< Type > &)
Merge received patch data into global data.
Definition: FaceCellWave.C:347
TemplateName(blendedSchemeBase)
const bool hasCyclicAMIPatches_
Contains cyclicAMI.
Definition: FaceCellWave.H:116
void handleExplicitConnections()
Merge data across explicitly provided local connections (usually.
Definition: FaceCellWave.C:856
dimensionSet trans(const dimensionSet &)
Definition: dimensionSet.C:450
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:59
UList< Type > & allFaceInfo_
Information for all faces.
Definition: FaceCellWave.H:91
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space...
Definition: transformer.H:83
const polyMesh & mesh_
Reference to mesh.
Definition: FaceCellWave.H:85
virtual label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
PackedBoolList changedFace_
Has face changed.
Definition: FaceCellWave.H:100
void setFaceInfo(const labelList &changedFaces, const List< Type > &changedFacesInfo)
Set initial changed faces.
Definition: FaceCellWave.C:317
virtual ~FaceCellWave()
Destructor.
Definition: FaceCellWave.H:319
virtual label cellToFace()
Propagate from cell to face. Returns total number of faces.
const bool hasCyclicPatches_
Contains cyclics.
Definition: FaceCellWave.H:113
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
static scalar propagationTol()
Access to tolerance.
Definition: FaceCellWave.H:259
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:76
FaceCellWave(const polyMesh &, UList< Type > &allFaceInfo, UList< Type > &allCellInfo, TrackingData &td=dummyTrackData_)
Definition: FaceCellWave.C:932
DynamicList< label > changedCells_
Definition: FaceCellWave.H:109
UList< Type > & allFaceInfo()
Access allFaceInfo.
Definition: FaceCellWave.H:328
label nEvals_
Number of evaluations.
Definition: FaceCellWave.H:119
Holds information regarding type of cell. Used in inside/outside determination in cellClassification...
Definition: cellInfo.H:63
const polyMesh & mesh() const
Access mesh.
Definition: FaceCellWave.H:346
UList< Type > & allCellInfo_
Information for all cells.
Definition: FaceCellWave.H:94
void handleProcPatches()
Merge data from across processor boundaries.
Definition: FaceCellWave.C:512
void operator=(const FaceCellWave &)=delete
Disallow default bitwise assignment.
PackedBoolList changedCell_
Has cell changed.
Definition: FaceCellWave.H:106
static const scalar geomTol_
Definition: FaceCellWave.H:246
label getUnsetFaces() const
Get number of unvisited faces.
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
void enterDomain(const polyPatch &patch, const label nFaces, const labelList &faceLabels, List< Type > &faceInfo) const
Handle leaving domain. Implementation referred to Type.
Definition: FaceCellWave.C:436
bool hasPatch() const
Has cyclic patch?
Definition: FaceCellWave.C:302
void transform(const tensor &rotTensor, const label nFaces, List< Type > &faceInfo)
Apply transformation to Type.
Definition: FaceCellWave.C:459
bool updateFace(const label facei, const label neighbourCelli, const Type &neighbourInfo, const scalar tol, Type &faceInfo)
Updates faceInfo with information from neighbour. Updates all.
Definition: FaceCellWave.C:160
bool updateCell(const label celli, const label neighbourFacei, const Type &neighbourInfo, const scalar tol, Type &cellInfo)
Updates cellInfo with information from neighbour. Updates all.
Definition: FaceCellWave.C:111
DynamicList< label > changedFaces_
List of changed faces.
Definition: FaceCellWave.H:103
static void setPropagationTol(const scalar tol)
Change tolerance.
Definition: FaceCellWave.H:265
A bit-packed bool list.
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:381
label nUnvisitedCells_
Number of unvisited cells/faces.
Definition: FaceCellWave.H:122
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:340
UList< Type > & allCellInfo()
Access allCellInfo.
Definition: FaceCellWave.H:334
void checkCyclic(const polyPatch &pPatch) const
Debugging: check info on both sides of cyclic.
Definition: FaceCellWave.C:256
void handleCyclicPatches()
Merge data from across cyclics.
Definition: FaceCellWave.C:632
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static scalar propagationTol_
Definition: FaceCellWave.H:247
static int dummyTrackData_
Used as default trackdata value to satisfy default template.
Definition: FaceCellWave.H:251
void leaveDomain(const polyPatch &patch, const label nFaces, const labelList &faceLabels, List< Type > &faceInfo) const
Handle leaving domain. Implementation referred to Type.
Definition: FaceCellWave.C:413
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
static void offset(const polyPatch &patch, const label off, const label nFaces, labelList &faces)
Offset face labels by constant value.
Definition: FaceCellWave.C:494
const labelPairList explicitConnections_
Optional boundary faces that information should travel through.
Definition: FaceCellWave.H:88
Namespace for OpenFOAM.
TrackingData & td_
Additional data to be passed into container.
Definition: FaceCellWave.H:97
virtual label faceToCell()
Propagate from face to cell. Returns total number of cells.
label getUnsetCells() const
Get number of unvisited cells, i.e. cells that were not (yet)