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 
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  //- Number of evaluations
125  label nEvals_;
126 
127  //- Number of unvisited cells
129 
130  //- Number of unvisited faces
132 
133 
134  // Protected member functions
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  //- Transform across an interface. Implementation referred to Type
198  void transform
199  (
200  const polyPatch& patch,
201  const label nFaces,
202  const labelList& faceLabels,
203  const transformer& transform,
204  List<Type>& faceInfo
205  );
206 
207  //- Merge data from across processor boundaries
208  void handleProcPatches();
209 
210  //- Merge data from across cyclics
211  void handleCyclicPatches();
212 
213  //- Merge data across explicitly provided local connections (usually
214  // baffles)
216 
217 
218 public:
219 
220  // Static Data
221 
222  //- Default tracking data to go with default template argument
223  static int defaultTrackingData_;
224 
225 
226  // Static Functions
227 
228  //- Access to tolerance
229  static scalar propagationTol()
230  {
231  return propagationTol_;
232  }
233 
234  //- Change tolerance
235  static void setPropagationTol(const scalar tol)
236  {
237  propagationTol_ = tol;
238  }
239 
240 
241  // Constructors
242 
243  // Construct from mesh. Use setFaceInfo and iterate() to do actual
244  // calculation.
246  (
247  const polyMesh&,
250  TrackingData& td = defaultTrackingData_
251  );
252 
253  //- Construct from mesh and list of changed faces with the Type
254  // for these faces. Iterates until nothing changes or maxIter reached.
255  // (maxIter can be 0)
257  (
258  const polyMesh&,
259  const labelList& initialChangedFaces,
260  const List<Type>& changedFacesInfo,
263  const label maxIter,
264  TrackingData& td = defaultTrackingData_
265  );
266 
267  //- Construct from mesh and explicitly connected boundary faces
268  // and list of changed faces with the Type
269  // for these faces. Iterates until nothing changes or maxIter reached.
270  // (maxIter can be 0)
272  (
273  const polyMesh&,
274  const labelPairList& explicitConnections,
275  const labelList& initialChangedFaces,
276  const List<Type>& changedFacesInfo,
279  const label maxIter,
280  TrackingData& td = defaultTrackingData_
281  );
282 
283  //- Disallow default bitwise copy construction
284  FaceCellWave(const FaceCellWave&) = delete;
285 
286 
287  //- Destructor
288  virtual ~FaceCellWave()
289  {}
290 
291 
292  // Member Functions
293 
294  // Access
295 
296  //- Access allFaceInfo
298  {
299  return allFaceInfo_;
300  }
301 
302  //- Access allCellInfo
304  {
305  return allCellInfo_;
306  }
307 
308  //- Additional data to be passed into container
309  const TrackingData& data() const
310  {
311  return td_;
312  }
313 
314  //- Additional data to be passed into container
315  TrackingData& data()
316  {
317  return td_;
318  }
319 
320  //- Access mesh
321  const polyMesh& mesh() const
322  {
323  return mesh_;
324  }
325 
326  //- Get number of unvisited cells, i.e. cells that were not (yet)
327  // reached from walking across mesh. This can happen from
328  // - not enough iterations done
329  // - a disconnected mesh
330  // - a mesh without walls in it
331  label getUnsetCells() const;
332 
333  //- Get number of unvisited faces
334  label getUnsetFaces() const;
335 
336 
337  // Edit
338 
339  //- Set initial changed faces
340  void setFaceInfo
341  (
342  const labelList& changedFaces,
343  const List<Type>& changedFacesInfo
344  );
345 
346  //- Propagate from face to cell. Returns total number of cells
347  // (over all processors) changed.
348  virtual label faceToCell();
349 
350  //- Propagate from cell to face. Returns total number of faces
351  // (over all processors) changed. (Faces on processorpatches are
352  // counted double)
353  virtual label cellToFace();
354 
355  //- Iterate until no changes or maxIter reached. Returns actual
356  // number of iterations.
357  virtual label iterate(const label maxIter);
358 
359 
360  // Member Operators
361 
362  //- Disallow default bitwise assignment
363  void operator=(const FaceCellWave&) = delete;
364 };
365 
366 
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
368 
369 } // End namespace Foam
370 
371 
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
373 
374 #ifdef NoRepository
375  #include "FaceCellWave.C"
376 #endif
377 
378 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
379 
380 #endif
381 
382 // ************************************************************************* //
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:79
UList< Type > & allCellInfo()
Access allCellInfo.
Definition: FaceCellWave.H:302
DynamicList< label > changedCells_
Definition: FaceCellWave.H:118
void handleExplicitConnections()
Merge data across explicitly provided local connections (usually.
Definition: FaceCellWave.C:539
UList< Type > & allCellInfo_
Information for all cells.
Definition: FaceCellWave.H:103
UList< Type > & allFaceInfo_
Information for all faces.
Definition: FaceCellWave.H:100
DynamicList< label > changedFaces_
List of changed faces.
Definition: FaceCellWave.H:112
void handleProcPatches()
Merge data from across processor boundaries.
Definition: FaceCellWave.C:372
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:308
label nEvals_
Number of evaluations.
Definition: FaceCellWave.H:124
label getUnsetCells() const
Get number of unvisited cells, i.e. cells that were not (yet)
Definition: FaceCellWave.C:778
PackedBoolList changedCell_
Has cell changed.
Definition: FaceCellWave.H:115
static scalar propagationTol()
Access to tolerance.
Definition: FaceCellWave.H:228
virtual ~FaceCellWave()
Destructor.
Definition: FaceCellWave.H:287
void setFaceInfo(const labelList &changedFaces, const List< Type > &changedFacesInfo)
Set initial changed faces.
Definition: FaceCellWave.C:260
void operator=(const FaceCellWave &)=delete
Disallow default bitwise assignment.
static scalar propagationTol_
...
Definition: FaceCellWave.H:88
bool hasPatch() const
Has cyclic patch?
Definition: FaceCellWave.C:245
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:356
TrackingData & td_
Additional data to be passed into container.
Definition: FaceCellWave.H:106
void mergeFaceInfo(const polyPatch &patch, const label nFaces, const labelList &, const List< Type > &)
Merge received patch data into global data.
Definition: FaceCellWave.C:290
static const scalar geomTol_
...
Definition: FaceCellWave.H:85
UList< Type > & allFaceInfo()
Access allFaceInfo.
Definition: FaceCellWave.H:296
label getUnsetFaces() const
Get number of unvisited faces.
Definition: FaceCellWave.C:785
void checkCyclic(const polyPatch &pPatch) const
Debugging: check info on both sides of cyclic.
Definition: FaceCellWave.C:199
static int defaultTrackingData_
Default tracking data to go with default template argument.
Definition: FaceCellWave.H:222
label nUnvisitedFaces_
Number of unvisited faces.
Definition: FaceCellWave.H:130
virtual label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
Definition: FaceCellWave.C:951
void handleCyclicPatches()
Merge data from across cyclics.
Definition: FaceCellWave.C:474
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:54
label nUnvisitedCells_
Number of unvisited cells.
Definition: FaceCellWave.H:127
const labelPairList explicitConnections_
Optional boundary faces that information should travel through.
Definition: FaceCellWave.H:97
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:324
virtual label faceToCell()
Propagate from face to cell. Returns total number of cells.
Definition: FaceCellWave.C:792
PackedBoolList changedFace_
Has face changed.
Definition: FaceCellWave.H:109
const polyMesh & mesh_
Reference to mesh.
Definition: FaceCellWave.H:94
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:103
const polyMesh & mesh() const
Access mesh.
Definition: FaceCellWave.H:320
virtual label cellToFace()
Propagate from cell to face. Returns total number of faces.
Definition: FaceCellWave.C:873
FaceCellWave(const polyMesh &, UList< Type > &allFaceInfo, UList< Type > &allCellInfo, TrackingData &td=defaultTrackingData_)
Definition: FaceCellWave.C:615
static void setPropagationTol(const scalar tol)
Change tolerance.
Definition: FaceCellWave.H:234
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: List.H:91
A bit-packed bool list.
Holds information regarding type of cell. Used in inside/outside determination in cellClassification.
Definition: cellInfo.H:67
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space.
Definition: transformer.H:84
Namespace for OpenFOAM.
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
TemplateName(FvFaceCellWave)
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.