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 | Copyright (C) 2011-2016 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 
64 /*---------------------------------------------------------------------------*\
65  Class FaceCellWaveName Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 TemplateName(FaceCellWave);
69 
70 
71 /*---------------------------------------------------------------------------*\
72  Class FaceCellWave Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 template<class Type, class TrackingData = int>
76 class FaceCellWave
77 :
78  public FaceCellWaveName
79 {
80  // Private Member Functions
81 
82  //- Disallow default bitwise copy construct
83  FaceCellWave(const FaceCellWave&);
84 
85  //- Disallow default bitwise assignment
86  void operator=(const FaceCellWave&);
87 
88 
89 protected:
90 
91  // Protected data
92 
93  //- Reference to mesh
94  const polyMesh& mesh_;
95 
96  //- Optional boundary faces that information should travel through
98 
99  //- Information for all faces
101 
102  //- Information for all cells
104 
105  //- Additional data to be passed into container
106  TrackingData& td_;
107 
108  //- Has face changed
110 
111  //- List of changed faces
113 
114  //- Has cell changed
116 
117  // Cells that have changed
119 
120 
121  //- Contains cyclics
122  const bool hasCyclicPatches_;
123 
124  //- Contains cyclicAMI
125  const bool hasCyclicAMIPatches_;
126 
127  //- Number of evaluations
128  label nEvals_;
129 
130  //- Number of unvisited cells/faces
133 
134 
135  //- Updates cellInfo with information from neighbour. Updates all
136  // statistics.
137  bool updateCell
138  (
139  const label celli,
140  const label neighbourFacei,
141  const Type& neighbourInfo,
142  const scalar tol,
143  Type& cellInfo
144  );
145 
146  //- Updates faceInfo with information from neighbour. Updates all
147  // statistics.
148  bool updateFace
149  (
150  const label facei,
151  const label neighbourCelli,
152  const Type& neighbourInfo,
153  const scalar tol,
154  Type& faceInfo
155  );
156 
157  //- Updates faceInfo with information from same face. Updates all
158  // statistics.
159  bool updateFace
160  (
161  const label facei,
162  const Type& neighbourInfo,
163  const scalar tol,
164  Type& faceInfo
165  );
166 
167 
168  // Parallel, cyclic
169 
170  //- Debugging: check info on both sides of cyclic
171  void checkCyclic(const polyPatch& pPatch) const;
172 
173  //- Has cyclic patch?
174  template<class PatchType>
175  bool hasPatch() const;
176 
177  //- Merge received patch data into global data
178  void mergeFaceInfo
179  (
180  const polyPatch& patch,
181  const label nFaces,
182  const labelList&,
183  const List<Type>&
184  );
185 
186  //- Extract info for single patch only
188  (
189  const polyPatch& patch,
190  const label startFacei,
191  const label nFaces,
192  labelList& changedPatchFaces,
193  List<Type>& changedPatchFacesInfo
194  ) const;
195 
196  //- Handle leaving domain. Implementation referred to Type
197  void leaveDomain
198  (
199  const polyPatch& patch,
200  const label nFaces,
201  const labelList& faceLabels,
202  List<Type>& faceInfo
203  ) const;
204 
205  //- Handle leaving domain. Implementation referred to Type
206  void enterDomain
207  (
208  const polyPatch& patch,
209  const label nFaces,
210  const labelList& faceLabels,
211  List<Type>& faceInfo
212  ) const;
213 
214  //- Offset face labels by constant value
215  static void offset
216  (
217  const polyPatch& patch,
218  const label off,
219  const label nFaces,
220  labelList& faces
221  );
222 
223  //- Apply transformation to Type
224  void transform
225  (
226  const tensorField& rotTensor,
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.
276  FaceCellWave
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)
287  FaceCellWave
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)
302  FaceCellWave
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 
316  //- Destructor
317  virtual ~FaceCellWave()
318  {}
319 
320 
321  // Member Functions
322 
323  // Access
324 
325  //- Access allFaceInfo
327  {
328  return allFaceInfo_;
329  }
330 
331  //- Access allCellInfo
333  {
334  return allCellInfo_;
335  }
336 
337  //- Additional data to be passed into container
338  const TrackingData& data() const
339  {
340  return td_;
341  }
342 
343  //- Access mesh
344  const polyMesh& mesh() const
345  {
346  return mesh_;
347  }
348 
349  //- Get number of unvisited cells, i.e. cells that were not (yet)
350  // reached from walking across mesh. This can happen from
351  // - not enough iterations done
352  // - a disconnected mesh
353  // - a mesh without walls in it
354  label getUnsetCells() const;
355 
356  //- Get number of unvisited faces
357  label getUnsetFaces() const;
358 
359 
360  // Edit
361 
362  //- Set initial changed faces
363  void setFaceInfo
364  (
365  const labelList& changedFaces,
366  const List<Type>& changedFacesInfo
367  );
368 
369  //- Propagate from face to cell. Returns total number of cells
370  // (over all processors) changed.
371  virtual label faceToCell();
372 
373  //- Propagate from cell to face. Returns total number of faces
374  // (over all processors) changed. (Faces on processorpatches are
375  // counted double)
376  virtual label cellToFace();
377 
378  //- Iterate until no changes or maxIter reached. Returns actual
379  // number of iterations.
380  virtual label iterate(const label maxIter);
381 };
382 
383 
384 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
385 
386 } // End namespace Foam
387 
388 
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390 
391 #ifdef NoRepository
392  #include "FaceCellWave.C"
393 #endif
394 
395 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
396 
397 #endif
398 
399 // ************************************************************************* //
void handleAMICyclicPatches()
Merge data from across AMI cyclics.
Definition: FaceCellWave.C:712
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:124
void handleExplicitConnections()
Merge data across explicitly provided local connections (usually.
Definition: FaceCellWave.C:817
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:99
const polyMesh & mesh_
Reference to mesh.
Definition: FaceCellWave.H:93
virtual label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
PackedBoolList changedFace_
Has face changed.
Definition: FaceCellWave.H:108
void setFaceInfo(const labelList &changedFaces, const List< Type > &changedFacesInfo)
Set initial changed faces.
Definition: FaceCellWave.C:317
virtual ~FaceCellWave()
Destructor.
Definition: FaceCellWave.H:316
virtual label cellToFace()
Propagate from cell to face. Returns total number of faces.
const bool hasCyclicPatches_
Contains cyclics.
Definition: FaceCellWave.H:121
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:259
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:75
DynamicList< label > changedCells_
Definition: FaceCellWave.H:117
UList< Type > & allFaceInfo()
Access allFaceInfo.
Definition: FaceCellWave.H:325
label nEvals_
Number of evaluations.
Definition: FaceCellWave.H:127
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:343
UList< Type > & allCellInfo_
Information for all cells.
Definition: FaceCellWave.H:102
void handleProcPatches()
Merge data from across processor boundaries.
Definition: FaceCellWave.C:506
PackedBoolList changedCell_
Has cell changed.
Definition: FaceCellWave.H:114
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 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:111
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:130
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:337
UList< Type > & allCellInfo()
Access allCellInfo.
Definition: FaceCellWave.H:331
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:626
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:488
const labelPairList explicitConnections_
Optional boundary faces that information should travel through.
Definition: FaceCellWave.H:96
Namespace for OpenFOAM.
TrackingData & td_
Additional data to be passed into container.
Definition: FaceCellWave.H:105
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)