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-2018 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 vectorTensorTransform;
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  // Private Member Functions
82 
83  //- Disallow default bitwise copy construct
84  FaceCellWave(const FaceCellWave&);
85 
86  //- Disallow default bitwise assignment
87  void operator=(const FaceCellWave&);
88 
89 
90 protected:
91 
92  // Protected data
93 
94  //- Reference to mesh
95  const polyMesh& mesh_;
96 
97  //- Optional boundary faces that information should travel through
99 
100  //- Information for all faces
102 
103  //- Information for all cells
105 
106  //- Additional data to be passed into container
107  TrackingData& td_;
108 
109  //- Has face changed
111 
112  //- List of changed faces
114 
115  //- Has cell changed
117 
118  // Cells that have changed
120 
121 
122  //- Contains cyclics
123  const bool hasCyclicPatches_;
124 
125  //- Contains cyclicAMI
126  const bool hasCyclicAMIPatches_;
127 
128  //- Number of evaluations
129  label nEvals_;
130 
131  //- Number of unvisited cells/faces
134 
135 
136  //- Updates cellInfo with information from neighbour. Updates all
137  // statistics.
138  bool updateCell
139  (
140  const label celli,
141  const label neighbourFacei,
142  const Type& neighbourInfo,
143  const scalar tol,
144  Type& cellInfo
145  );
146 
147  //- Updates faceInfo with information from neighbour. Updates all
148  // statistics.
149  bool updateFace
150  (
151  const label facei,
152  const label neighbourCelli,
153  const Type& neighbourInfo,
154  const scalar tol,
155  Type& faceInfo
156  );
157 
158  //- Updates faceInfo with information from same face. Updates all
159  // statistics.
160  bool updateFace
161  (
162  const label facei,
163  const Type& neighbourInfo,
164  const scalar tol,
165  Type& faceInfo
166  );
167 
168 
169  // Parallel, cyclic
170 
171  //- Debugging: check info on both sides of cyclic
172  void checkCyclic(const polyPatch& pPatch) const;
173 
174  //- Has cyclic patch?
175  template<class PatchType>
176  bool hasPatch() const;
177 
178  //- Merge received patch data into global data
179  void mergeFaceInfo
180  (
181  const polyPatch& patch,
182  const label nFaces,
183  const labelList&,
184  const List<Type>&
185  );
186 
187  //- Extract info for single patch only
189  (
190  const polyPatch& patch,
191  const label startFacei,
192  const label nFaces,
193  labelList& changedPatchFaces,
194  List<Type>& changedPatchFacesInfo
195  ) const;
196 
197  //- Handle leaving domain. Implementation referred to Type
198  void leaveDomain
199  (
200  const polyPatch& patch,
201  const label nFaces,
202  const labelList& faceLabels,
203  List<Type>& faceInfo
204  ) const;
205 
206  //- Handle leaving domain. Implementation referred to Type
207  void enterDomain
208  (
209  const polyPatch& patch,
210  const label nFaces,
211  const labelList& faceLabels,
212  List<Type>& faceInfo
213  ) const;
214 
215  //- Offset face labels by constant value
216  static void offset
217  (
218  const polyPatch& patch,
219  const label off,
220  const label nFaces,
221  labelList& faces
222  );
223 
224  //- Apply transformation to Type
225  void transform
226  (
227  const tensorField& rotTensor,
228  const label nFaces,
229  List<Type>& faceInfo
230  );
231 
232  //- Apply transformation to Type
233  void transform
234  (
236  const label nFaces,
237  List<Type>& faceInfo
238  );
239 
240  //- Merge data from across processor boundaries
241  void handleProcPatches();
242 
243  //- Merge data from across cyclics
244  void handleCyclicPatches();
245 
246  //- Merge data from across AMI cyclics
247  void handleAMICyclicPatches();
248 
249  //- Merge data across explicitly provided local connections (usually
250  // baffles)
252 
253 
254  // Protected static data
256  static const scalar geomTol_;
257  static scalar propagationTol_;
258 
259  //- Used as default trackdata value to satisfy default template
260  // argument.
261  static int dummyTrackData_;
262 
263 
264 public:
265 
266  // Static Functions
267 
268  //- Access to tolerance
269  static scalar propagationTol()
270  {
271  return propagationTol_;
272  }
273 
274  //- Change tolerance
275  static void setPropagationTol(const scalar tol)
276  {
277  propagationTol_ = tol;
278  }
279 
280 
281  // Constructors
282 
283  // Construct from mesh. Use setFaceInfo and iterate() to do actual
284  // calculation.
285  FaceCellWave
286  (
287  const polyMesh&,
290  TrackingData& td = dummyTrackData_
291  );
292 
293  //- Construct from mesh and list of changed faces with the Type
294  // for these faces. Iterates until nothing changes or maxIter reached.
295  // (maxIter can be 0)
296  FaceCellWave
297  (
298  const polyMesh&,
299  const labelList& initialChangedFaces,
300  const List<Type>& changedFacesInfo,
301  UList<Type>& allFaceInfo,
302  UList<Type>& allCellInfo,
303  const label maxIter,
304  TrackingData& td = dummyTrackData_
305  );
306 
307  //- Construct from mesh and explicitly connected boundary faces
308  // and list of changed faces with the Type
309  // for these faces. Iterates until nothing changes or maxIter reached.
310  // (maxIter can be 0)
311  FaceCellWave
312  (
313  const polyMesh&,
314  const labelPairList& explicitConnections,
315  const bool handleCyclicAMI,
316  const labelList& initialChangedFaces,
317  const List<Type>& changedFacesInfo,
318  UList<Type>& allFaceInfo,
319  UList<Type>& allCellInfo,
320  const label maxIter,
321  TrackingData& td = dummyTrackData_
322  );
323 
324 
325  //- Destructor
326  virtual ~FaceCellWave()
327  {}
328 
329 
330  // Member Functions
331 
332  // Access
333 
334  //- Access allFaceInfo
336  {
337  return allFaceInfo_;
338  }
339 
340  //- Access allCellInfo
342  {
343  return allCellInfo_;
344  }
345 
346  //- Additional data to be passed into container
347  const TrackingData& data() const
348  {
349  return td_;
350  }
351 
352  //- Access mesh
353  const polyMesh& mesh() const
354  {
355  return mesh_;
356  }
357 
358  //- Get number of unvisited cells, i.e. cells that were not (yet)
359  // reached from walking across mesh. This can happen from
360  // - not enough iterations done
361  // - a disconnected mesh
362  // - a mesh without walls in it
363  label getUnsetCells() const;
364 
365  //- Get number of unvisited faces
366  label getUnsetFaces() const;
367 
368 
369  // Edit
370 
371  //- Set initial changed faces
372  void setFaceInfo
373  (
374  const labelList& changedFaces,
375  const List<Type>& changedFacesInfo
376  );
377 
378  //- Propagate from face to cell. Returns total number of cells
379  // (over all processors) changed.
380  virtual label faceToCell();
381 
382  //- Propagate from cell to face. Returns total number of faces
383  // (over all processors) changed. (Faces on processorpatches are
384  // counted double)
385  virtual label cellToFace();
386 
387  //- Iterate until no changes or maxIter reached. Returns actual
388  // number of iterations.
389  virtual label iterate(const label maxIter);
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:732
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:125
void handleExplicitConnections()
Merge data across explicitly provided local connections (usually.
Definition: FaceCellWave.C:870
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:100
const polyMesh & mesh_
Reference to mesh.
Definition: FaceCellWave.H:94
virtual label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
PackedBoolList changedFace_
Has face changed.
Definition: FaceCellWave.H:109
void setFaceInfo(const labelList &changedFaces, const List< Type > &changedFacesInfo)
Set initial changed faces.
Definition: FaceCellWave.C:317
virtual ~FaceCellWave()
Destructor.
Definition: FaceCellWave.H:325
virtual label cellToFace()
Propagate from cell to face. Returns total number of faces.
const bool hasCyclicPatches_
Contains cyclics.
Definition: FaceCellWave.H:122
Vector-tensor class used to perform translations and rotations in 3D space.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
static scalar propagationTol()
Access to tolerance.
Definition: FaceCellWave.H:268
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:76
DynamicList< label > changedCells_
Definition: FaceCellWave.H:118
UList< Type > & allFaceInfo()
Access allFaceInfo.
Definition: FaceCellWave.H:334
label nEvals_
Number of evaluations.
Definition: FaceCellWave.H:128
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:352
UList< Type > & allCellInfo_
Information for all cells.
Definition: FaceCellWave.H:103
void handleProcPatches()
Merge data from across processor boundaries.
Definition: FaceCellWave.C:526
PackedBoolList changedCell_
Has cell changed.
Definition: FaceCellWave.H:115
static const scalar geomTol_
Definition: FaceCellWave.H:255
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 tensorField &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:112
static void setPropagationTol(const scalar tol)
Change tolerance.
Definition: FaceCellWave.H:274
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:131
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:346
UList< Type > & allCellInfo()
Access allCellInfo.
Definition: FaceCellWave.H:340
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:646
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static scalar propagationTol_
Definition: FaceCellWave.H:256
static int dummyTrackData_
Used as default trackdata value to satisfy default template.
Definition: FaceCellWave.H:260
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:508
const labelPairList explicitConnections_
Optional boundary faces that information should travel through.
Definition: FaceCellWave.H:97
Namespace for OpenFOAM.
TrackingData & td_
Additional data to be passed into container.
Definition: FaceCellWave.H:106
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)