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-2022 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 static data
84 
85  //- ...
86  static const scalar geomTol_;
87 
88  //- ...
89  static scalar propagationTol_;
90 
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  //- 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
132 
133  //- Number of unvisited faces
135 
136 
137  // Protected member functions
138 
139  //- Updates cellInfo with information from neighbour. Updates all
140  // statistics.
141  bool updateCell
142  (
143  const label celli,
144  const label neighbourFacei,
145  const Type& neighbourInfo,
146  const scalar tol,
147  Type& cellInfo
148  );
149 
150  //- Updates faceInfo with information from neighbour. Updates all
151  // statistics.
152  bool updateFace
153  (
154  const label facei,
155  const label neighbourCelli,
156  const Type& neighbourInfo,
157  const scalar tol,
158  Type& faceInfo
159  );
160 
161  //- Updates faceInfo with information from same face. Updates all
162  // statistics.
163  bool updateFace
164  (
165  const label facei,
166  const Type& neighbourInfo,
167  const scalar tol,
168  Type& faceInfo
169  );
170 
171 
172  // Parallel, cyclic
173 
174  //- Debugging: check info on both sides of cyclic
175  void checkCyclic(const polyPatch& pPatch) const;
176 
177  //- Has cyclic patch?
178  template<class PatchType>
179  bool hasPatch() const;
180 
181  //- Merge received patch data into global data
182  void mergeFaceInfo
183  (
184  const polyPatch& patch,
185  const label nFaces,
186  const labelList&,
187  const List<Type>&
188  );
189 
190  //- Extract info for single patch only
192  (
193  const polyPatch& patch,
194  const label startFacei,
195  const label nFaces,
196  labelList& changedPatchFaces,
197  List<Type>& changedPatchFacesInfo
198  ) const;
199 
200  //- Transform across an interface. Implementation referred to Type
201  void transform
202  (
203  const polyPatch& patch,
204  const label nFaces,
205  const labelList& faceLabels,
206  const transformer& transform,
207  List<Type>& faceInfo
208  );
209 
210  //- Merge data from across processor boundaries
211  void handleProcPatches();
212 
213  //- Merge data from across cyclics
214  void handleCyclicPatches();
215 
216  //- Merge data from across AMI cyclics
217  void handleAMICyclicPatches();
218 
219  //- Merge data across explicitly provided local connections (usually
220  // baffles)
222 
223 
224 public:
225 
226  // Static Data
227 
228  //- Default tracking data to go with default template argument
229  static int defaultTrackingData_;
230 
231 
232  // Static Functions
233 
234  //- Access to tolerance
235  static scalar propagationTol()
236  {
237  return propagationTol_;
238  }
239 
240  //- Change tolerance
241  static void setPropagationTol(const scalar tol)
242  {
243  propagationTol_ = tol;
244  }
245 
246 
247  // Constructors
248 
249  // Construct from mesh. Use setFaceInfo and iterate() to do actual
250  // calculation.
252  (
253  const polyMesh&,
256  TrackingData& td = defaultTrackingData_
257  );
258 
259  //- Construct from mesh and list of changed faces with the Type
260  // for these faces. Iterates until nothing changes or maxIter reached.
261  // (maxIter can be 0)
263  (
264  const polyMesh&,
265  const labelList& initialChangedFaces,
266  const List<Type>& changedFacesInfo,
267  UList<Type>& allFaceInfo,
268  UList<Type>& allCellInfo,
269  const label maxIter,
270  TrackingData& td = defaultTrackingData_
271  );
272 
273  //- Construct from mesh and explicitly connected boundary faces
274  // and list of changed faces with the Type
275  // for these faces. Iterates until nothing changes or maxIter reached.
276  // (maxIter can be 0)
278  (
279  const polyMesh&,
280  const labelPairList& explicitConnections,
281  const bool handleCyclicAMI,
282  const labelList& initialChangedFaces,
283  const List<Type>& changedFacesInfo,
284  UList<Type>& allFaceInfo,
285  UList<Type>& allCellInfo,
286  const label maxIter,
287  TrackingData& td = defaultTrackingData_
288  );
289 
290  //- Disallow default bitwise copy construction
291  FaceCellWave(const FaceCellWave&) = delete;
292 
293 
294  //- Destructor
295  virtual ~FaceCellWave()
296  {}
297 
298 
299  // Member Functions
300 
301  // Access
302 
303  //- Access allFaceInfo
305  {
306  return allFaceInfo_;
307  }
308 
309  //- Access allCellInfo
311  {
312  return allCellInfo_;
313  }
314 
315  //- Additional data to be passed into container
316  const TrackingData& data() const
317  {
318  return td_;
319  }
320 
321  //- Additional data to be passed into container
322  TrackingData& data()
323  {
324  return td_;
325  }
326 
327  //- Access mesh
328  const polyMesh& mesh() const
329  {
330  return mesh_;
331  }
332 
333  //- Get number of unvisited cells, i.e. cells that were not (yet)
334  // reached from walking across mesh. This can happen from
335  // - not enough iterations done
336  // - a disconnected mesh
337  // - a mesh without walls in it
338  label getUnsetCells() const;
339 
340  //- Get number of unvisited faces
341  label getUnsetFaces() const;
342 
343 
344  // Edit
345 
346  //- Set initial changed faces
347  void setFaceInfo
348  (
349  const labelList& changedFaces,
350  const List<Type>& changedFacesInfo
351  );
352 
353  //- Propagate from face to cell. Returns total number of cells
354  // (over all processors) changed.
355  virtual label faceToCell();
356 
357  //- Propagate from cell to face. Returns total number of faces
358  // (over all processors) changed. (Faces on processorpatches are
359  // counted double)
360  virtual label cellToFace();
361 
362  //- Iterate until no changes or maxIter reached. Returns actual
363  // number of iterations.
364  virtual label iterate(const label maxIter);
365 
366 
367  // Member Operators
368 
369  //- Disallow default bitwise assignment
370  void operator=(const FaceCellWave&) = delete;
371 };
372 
373 
374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
375 
376 } // End namespace Foam
377 
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 #ifdef NoRepository
382  #include "FaceCellWave.C"
383 #endif
384 
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
386 
387 #endif
388 
389 // ************************************************************************* //
void handleAMICyclicPatches()
Merge data from across AMI cyclics.
Definition: FaceCellWave.C:540
void mergeFaceInfo(const polyPatch &patch, const label nFaces, const labelList &, const List< Type > &)
Merge received patch data into global data.
Definition: FaceCellWave.C:291
const bool hasCyclicAMIPatches_
Contains cyclicAMI.
Definition: FaceCellWave.H:124
void handleExplicitConnections()
Merge data across explicitly provided local connections (usually.
Definition: FaceCellWave.C:737
UList< Type > & allFaceInfo_
Information for all faces.
Definition: FaceCellWave.H:100
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: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:261
virtual ~FaceCellWave()
Destructor.
Definition: FaceCellWave.H:294
virtual label cellToFace()
Propagate from cell to face. Returns total number of faces.
const bool hasCyclicPatches_
Contains cyclics.
Definition: FaceCellWave.H:121
void transform(const polyPatch &patch, const label nFaces, const labelList &faceLabels, const transformer &transform, List< Type > &faceInfo)
Transform across an interface. Implementation referred to Type.
Definition: FaceCellWave.C:357
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:234
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:303
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:66
const polyMesh & mesh() const
Access mesh.
Definition: FaceCellWave.H:327
UList< Type > & allCellInfo_
Information for all cells.
Definition: FaceCellWave.H:103
void handleProcPatches()
Merge data from across processor boundaries.
Definition: FaceCellWave.C:373
label nUnvisitedFaces_
Number of unvisited faces.
Definition: FaceCellWave.H:133
void operator=(const FaceCellWave &)=delete
Disallow default bitwise assignment.
PackedBoolList changedCell_
Has cell changed.
Definition: FaceCellWave.H:115
static const scalar geomTol_
...
Definition: FaceCellWave.H:85
label getUnsetFaces() const
Get number of unvisited faces.
Definition: FaceCellWave.C:997
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
bool hasPatch() const
Has cyclic patch?
Definition: FaceCellWave.C:246
TemplateName(FvFaceCellWave)
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:104
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:55
DynamicList< label > changedFaces_
List of changed faces.
Definition: FaceCellWave.H:112
static void setPropagationTol(const scalar tol)
Change tolerance.
Definition: FaceCellWave.H:240
FaceCellWave(const polyMesh &, UList< Type > &allFaceInfo, UList< Type > &allCellInfo, TrackingData &td=defaultTrackingData_)
Definition: FaceCellWave.C:813
A bit-packed bool list.
static int defaultTrackingData_
Default tracking data to go with default template argument.
Definition: FaceCellWave.H:228
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:325
label nUnvisitedCells_
Number of unvisited cells.
Definition: FaceCellWave.H:130
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:315
UList< Type > & allCellInfo()
Access allCellInfo.
Definition: FaceCellWave.H:309
void checkCyclic(const polyPatch &pPatch) const
Debugging: check info on both sides of cyclic.
Definition: FaceCellWave.C:200
void handleCyclicPatches()
Merge data from across cyclics.
Definition: FaceCellWave.C:475
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
static scalar propagationTol_
...
Definition: FaceCellWave.H:88
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
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)
Definition: FaceCellWave.C:990