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-2015 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 "boolList.H"
51 #include "labelList.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 data
81 
82  //- Reference to mesh
83  const polyMesh& mesh_;
84 
85  //- Optional boundary faces that information should travel through
87 
88  //- Information for all faces
90 
91  //- Information for all cells
93 
94  //- Additional data to be passed into container
95  TrackingData& td_;
96 
97  //- Has face changed
99 
100  //- List of changed faces
102 
103  //- Number of changed faces
105 
106  // Cells that have changed
110 
111  //- Contains cyclics
112  const bool hasCyclicPatches_;
113 
114  //- Contains cyclicAMI
115  const bool hasCyclicAMIPatches_;
116 
117  //- Number of evaluations
118  label nEvals_;
119 
120  //- Number of unvisited cells/faces
123 
124 
125  // Private Member Functions
126 
127  //- Disallow default bitwise copy construct
128  FaceCellWave(const FaceCellWave&);
129 
130  //- Disallow default bitwise assignment
131  void operator=(const FaceCellWave&);
132 
133 
134  //- Updates cellInfo with information from neighbour. Updates all
135  // statistics.
136  bool updateCell
137  (
138  const label cellI,
139  const label neighbourFaceI,
140  const Type& neighbourInfo,
141  const scalar tol,
142  Type& cellInfo
143  );
144 
145  //- Updates faceInfo with information from neighbour. Updates all
146  // statistics.
147  bool updateFace
148  (
149  const label faceI,
150  const label neighbourCellI,
151  const Type& neighbourInfo,
152  const scalar tol,
153  Type& faceInfo
154  );
155 
156  //- Updates faceInfo with information from same face. Updates all
157  // statistics.
158  bool updateFace
159  (
160  const label faceI,
161  const Type& neighbourInfo,
162  const scalar tol,
163  Type& faceInfo
164  );
165 
166 
167  // Parallel, cyclic
168 
169  //- Debugging: check info on both sides of cyclic
170  void checkCyclic(const polyPatch& pPatch) const;
171 
172  //- Has cyclic patch?
173  template<class PatchType>
174  bool hasPatch() const;
175 
176  //- Merge received patch data into global data
177  void mergeFaceInfo
178  (
179  const polyPatch& patch,
180  const label nFaces,
181  const labelList&,
182  const List<Type>&
183  );
184 
185  //- Extract info for single patch only
187  (
188  const polyPatch& patch,
189  const label startFaceI,
190  const label nFaces,
191  labelList& changedPatchFaces,
192  List<Type>& changedPatchFacesInfo
193  ) const;
194 
195  //- Handle leaving domain. Implementation referred to Type
196  void leaveDomain
197  (
198  const polyPatch& patch,
199  const label nFaces,
200  const labelList& faceLabels,
201  List<Type>& faceInfo
202  ) const;
203 
204  //- Handle leaving domain. Implementation referred to Type
205  void enterDomain
206  (
207  const polyPatch& patch,
208  const label nFaces,
209  const labelList& faceLabels,
210  List<Type>& faceInfo
211  ) const;
212 
213  //- Offset face labels by constant value
214  static void offset
215  (
216  const polyPatch& patch,
217  const label off,
218  const label nFaces,
219  labelList& faces
220  );
221 
222  //- Apply transformation to Type
223  void transform
224  (
225  const tensorField& rotTensor,
226  const label nFaces,
227  List<Type>& faceInfo
228  );
229 
230  //- Merge data from across processor boundaries
231  void handleProcPatches();
232 
233  //- Merge data from across cyclics
234  void handleCyclicPatches();
235 
236  //- Merge data from across AMI cyclics
237  void handleAMICyclicPatches();
238 
239  //- Merge data across explicitly provided local connections (usually
240  // baffles)
242 
243 
244  // Private static data
245 
246  static const scalar geomTol_;
247  static scalar propagationTol_;
248 
249  //- Used as default trackdata value to satisfy default template
250  // argument.
251  static int dummyTrackData_;
252 
253 
254 public:
255 
256  // Static Functions
257 
258  //- Access to tolerance
259  static scalar propagationTol()
260  {
261  return propagationTol_;
262  }
263 
264  //- Change tolerance
265  static void setPropagationTol(const scalar tol)
266  {
267  propagationTol_ = tol;
268  }
269 
270 
271  // Constructors
272 
273  // Construct from mesh. Use setFaceInfo and iterate() to do actual
274  // calculation.
276  (
277  const polyMesh&,
280  TrackingData& td = dummyTrackData_
281  );
282 
283  //- Construct from mesh and list of changed faces with the Type
284  // for these faces. Iterates until nothing changes or maxIter reached.
285  // (maxIter can be 0)
287  (
288  const polyMesh&,
289  const labelList& initialChangedFaces,
290  const List<Type>& changedFacesInfo,
293  const label maxIter,
294  TrackingData& td = dummyTrackData_
295  );
296 
297  //- Construct from mesh and explicitly connected boundary faces
298  // and list of changed faces with the Type
299  // for these faces. Iterates until nothing changes or maxIter reached.
300  // (maxIter can be 0)
302  (
303  const polyMesh&,
304  const List<labelPair>& explicitConnections,
305  const bool handleCyclicAMI,
306  const labelList& initialChangedFaces,
307  const List<Type>& changedFacesInfo,
310  const label maxIter,
311  TrackingData& td = dummyTrackData_
312  );
313 
314 
315  // Member Functions
316 
317  // Access
318 
319  //- Access allFaceInfo
321  {
322  return allFaceInfo_;
323  }
324 
325  //- Access allCellInfo
327  {
328  return allCellInfo_;
329  }
330 
331  //- Additional data to be passed into container
332  const TrackingData& data() const
333  {
334  return td_;
335  }
336 
337  //- Access mesh
338  const polyMesh& mesh() const
339  {
340  return mesh_;
341  }
342 
343  //- Get number of unvisited cells, i.e. cells that were not (yet)
344  // reached from walking across mesh. This can happen from
345  // - not enough iterations done
346  // - a disconnected mesh
347  // - a mesh without walls in it
348  label getUnsetCells() const;
349 
350  //- Get number of unvisited faces
351  label getUnsetFaces() const;
352 
353 
354  // Edit
355 
356  //- Set initial changed faces
357  void setFaceInfo
358  (
359  const labelList& changedFaces,
360  const List<Type>& changedFacesInfo
361  );
362 
363  //- Propagate from face to cell. Returns total number of cells
364  // (over all processors) changed.
365  label faceToCell();
366 
367  //- Propagate from cell to face. Returns total number of faces
368  // (over all processors) changed. (Faces on processorpatches are
369  // counted double)
370  label cellToFace();
371 
372  //- Iterate until no changes or maxIter reached. Returns actual
373  // number of iterations.
374  label iterate(const label maxIter);
375 
376 };
377 
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 } // End namespace Foam
382 
383 
384 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
385 
386 #ifdef NoRepository
387 # include "FaceCellWave.C"
388 #endif
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 #endif
393 
394 // ************************************************************************* //
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. Updates all.
Definition: FaceCellWave.C:116
primitiveFieldsFwd.H
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
Foam::FaceCellWave::dummyTrackData_
static int dummyTrackData_
Used as default trackdata value to satisfy default template.
Definition: FaceCellWave.H:250
boolList.H
Foam::FaceCellWave::handleExplicitConnections
void handleExplicitConnections()
Merge data across explicitly provided local connections (usually.
Definition: FaceCellWave.C:806
FaceCellWave.C
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. Updates all.
Definition: FaceCellWave.C:164
Foam::FaceCellWave::FaceCellWave
FaceCellWave(const FaceCellWave &)
Disallow default bitwise copy construct.
Foam::FaceCellWave::nUnvisitedFaces_
label nUnvisitedFaces_
Definition: FaceCellWave.H:121
Foam::FaceCellWave::hasCyclicPatches_
const bool hasCyclicPatches_
Contains cyclics.
Definition: FaceCellWave.H:111
Foam::FaceCellWave::data
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:331
Foam::FaceCellWave::allFaceInfo
UList< Type > & allFaceInfo()
Access allFaceInfo.
Definition: FaceCellWave.H:319
Foam::FaceCellWave::nChangedCells_
label nChangedCells_
Definition: FaceCellWave.H:108
Foam::FaceCellWave::explicitConnections_
const List< labelPair > explicitConnections_
Optional boundary faces that information should travel through.
Definition: FaceCellWave.H:85
Foam::FaceCellWave::allCellInfo_
UList< Type > & allCellInfo_
Information for all cells.
Definition: FaceCellWave.H:91
Foam::FaceCellWave::iterate
label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
Definition: FaceCellWave.C:1258
Foam::FaceCellWave::changedCell_
boolList changedCell_
Definition: FaceCellWave.H:106
Foam::FaceCellWave::getUnsetFaces
label getUnsetFaces() const
Get number of unvisited faces.
Definition: FaceCellWave.C:1078
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::FaceCellWave::checkCyclic
void checkCyclic(const polyPatch &pPatch) const
Debugging: check info on both sides of cyclic.
Definition: FaceCellWave.C:254
Foam::FaceCellWave::handleProcPatches
void handleProcPatches()
Merge data from across processor boundaries.
Definition: FaceCellWave.C:499
Foam::FaceCellWave::propagationTol_
static scalar propagationTol_
Definition: FaceCellWave.H:246
Foam::FaceCellWave::geomTol_
static const scalar geomTol_
Definition: FaceCellWave.H:245
Foam::FaceCellWave::hasPatch
bool hasPatch() const
Has cyclic patch?
Definition: FaceCellWave.C:299
Foam::FaceCellWave::hasCyclicAMIPatches_
const bool hasCyclicAMIPatches_
Contains cyclicAMI.
Definition: FaceCellWave.H:114
Foam::FaceCellWave::propagationTol
static scalar propagationTol()
Access to tolerance.
Definition: FaceCellWave.H:258
Foam::FaceCellWave::faceToCell
label faceToCell()
Propagate from face to cell. Returns total number of cells.
Definition: FaceCellWave.C:1087
Foam::FaceCellWave::enterDomain
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:433
Foam::FaceCellWave::handleCyclicPatches
void handleCyclicPatches()
Merge data from across cyclics.
Definition: FaceCellWave.C:618
Foam::label
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
Foam::FaceCellWave::allFaceInfo_
UList< Type > & allFaceInfo_
Information for all faces.
Definition: FaceCellWave.H:88
labelList.H
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::TemplateName
TemplateName(blendedSchemeBase)
Foam::FaceCellWave::handleAMICyclicPatches
void handleAMICyclicPatches()
Merge data from across AMI cyclics.
Definition: FaceCellWave.C:703
Foam::FaceCellWave::setFaceInfo
void setFaceInfo(const labelList &changedFaces, const List< Type > &changedFacesInfo)
Set initial changed faces.
Definition: FaceCellWave.C:315
Foam::FaceCellWave::cellToFace
label cellToFace()
Propagate from cell to face. Returns total number of faces.
Definition: FaceCellWave.C:1172
Foam::FaceCellWave::td_
TrackingData & td_
Additional data to be passed into container.
Definition: FaceCellWave.H:94
Foam::FaceCellWave::mesh_
const polyMesh & mesh_
Reference to mesh.
Definition: FaceCellWave.H:82
Foam::FaceCellWave::changedFace_
boolList changedFace_
Has face changed.
Definition: FaceCellWave.H:97
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::FaceCellWave::changedCells_
labelList changedCells_
Definition: FaceCellWave.H:107
Foam::FaceCellWave::nEvals_
label nEvals_
Number of evaluations.
Definition: FaceCellWave.H:117
Foam::FaceCellWave
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:75
Foam::FaceCellWave::allCellInfo
UList< Type > & allCellInfo()
Access allCellInfo.
Definition: FaceCellWave.H:325
Foam::cellInfo
Holds information regarding type of cell. Used in inside/outside determination in cellClassification.
Definition: cellInfo.H:54
Foam::FaceCellWave::mesh
const polyMesh & mesh() const
Access mesh.
Definition: FaceCellWave.H:337
Foam::FaceCellWave::transform
void transform(const tensorField &rotTensor, const label nFaces, List< Type > &faceInfo)
Apply transformation to Type.
Definition: FaceCellWave.C:455
Foam::FaceCellWave::operator=
void operator=(const FaceCellWave &)
Disallow default bitwise assignment.
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:59
Foam::FaceCellWave::setPropagationTol
static void setPropagationTol(const scalar tol)
Change tolerance.
Definition: FaceCellWave.H:264
Foam::UList< Type >
Foam::FaceCellWave::nUnvisitedCells_
label nUnvisitedCells_
Number of unvisited cells/faces.
Definition: FaceCellWave.H:120
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:483
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:381
Foam::FaceCellWave::nChangedFaces_
label nChangedFaces_
Number of changed faces.
Definition: FaceCellWave.H:103
Foam::FaceCellWave::mergeFaceInfo
void mergeFaceInfo(const polyPatch &patch, const label nFaces, const labelList &, const List< Type > &)
Merge received patch data into global data.
Definition: FaceCellWave.C:346
Foam::FaceCellWave::getUnsetCells
label getUnsetCells() const
Get number of unvisited cells, i.e. cells that were not (yet)
Definition: FaceCellWave.C:1071
Foam::FaceCellWave::leaveDomain
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:411
labelPair.H
Foam::FaceCellWave::changedFaces_
labelList changedFaces_
List of changed faces.
Definition: FaceCellWave.H:100