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