PatchEdgeFaceWave.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::PatchEdgeFaceWave
26 
27 Description
28  Wave propagation of information along patch. Every iteration
29  information goes through one layer of faces. Templated on information
30  that is transferred.
31 
32 SourceFiles
33  PatchEdgeFaceWave.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef PatchEdgeFaceWave_H
38 #define PatchEdgeFaceWave_H
39 
40 #include "scalarField.H"
41 #include "PackedBoolList.H"
42 #include "PrimitivePatch.H"
43 #include "transformer.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward declaration of classes
51 class polyMesh;
52 
53 /*---------------------------------------------------------------------------*\
54  Class PatchEdgeFaceWaveName Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 TemplateName(PatchEdgeFaceWave);
58 
59 
60 /*---------------------------------------------------------------------------*\
61  Class PatchEdgeFaceWave Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 template
65 <
66  class PrimitivePatchType,
67  class Type,
68  class TrackingData = int
69 >
71 :
72  public PatchEdgeFaceWaveName
73 {
74  // Private static data
75 
76  //- Relative tolerance. Stop propagation if relative changes
77  // less than this tolerance (responsibility for checking this is
78  // up to Type implementation)
79  static scalar propagationTol_;
80 
81 
82  // Private Data
83 
84  //- Reference to mesh
85  const polyMesh& mesh_;
86 
87  //- Reference to patch
88  const PrimitivePatchType& patch_;
89 
90  //- Wall information for all edges
91  UList<Type>& allEdgeInfo_;
92 
93  //- Information on all patch faces
94  UList<Type>& allFaceInfo_;
95 
96  //- Additional data to be passed into container
97  TrackingData& td_;
98 
99  //- Has edge changed
100  PackedBoolList changedEdge_;
101 
102  //- List of changed edges
103  DynamicList<label> changedEdges_;
104 
105  //- Has face changed
106  PackedBoolList changedFace_;
107 
108  //- List of changed faces
109  DynamicList<label> changedFaces_;
110 
111  //- Number of evaluations
112  label nEvals_;
113 
114  //- Number of unvisited faces/edges
115  label nUnvisitedEdges_;
116  label nUnvisitedFaces_;
117 
118 
119  // Addressing between edges of patch_ and globalData.coupledPatch()
120  labelList patchEdges_;
121  labelList coupledEdges_;
122  PackedBoolList sameEdgeOrientation_;
123 
124 
125  // Private Member Functions
126 
127  //- Updates edgeInfo with information from neighbour. Updates all
128  // statistics.
129  bool updateEdge
130  (
131  const label edgeI,
132  const label neighbourFacei,
133  const Type& neighbourInfo,
134  Type& edgeInfo
135  );
136 
137  //- Updates faceInfo with information from neighbour. Updates all
138  // statistics.
139  bool updateFace
140  (
141  const label facei,
142  const label neighbourEdgeI,
143  const Type& neighbourInfo,
144  Type& faceInfo
145  );
146 
147  //- Update coupled edges
148  void syncEdges();
149 
150 
151 public:
152 
153  // Static Data
154 
155  //- Default tracking data to go with default template argument
156  static int defaultTrackingData_;
157 
158 
159  // Static Functions
160 
161  //- Access to tolerance
162  static scalar propagationTol()
163  {
164  return propagationTol_;
165  }
166 
167  //- Change tolerance
168  static void setPropagationTol(const scalar tol)
169  {
170  propagationTol_ = tol;
171  }
172 
173 
174  // Constructors
175 
176  //- Construct from patch, list of changed edges with the Type
177  // for these edges. Gets work arrays to operate on, one of size
178  // number of patch edges, the other number of patch faces.
179  // Iterates until nothing changes or maxIter reached.
180  // (maxIter can be 0)
182  (
183  const polyMesh& mesh,
184  const PrimitivePatchType& patch,
185  const labelList& initialEdges,
186  const List<Type>& initialEdgesInfo,
189  const label maxIter,
190  TrackingData& td = defaultTrackingData_
191  );
192 
193  //- Construct from patch. Use setEdgeInfo and iterate() to do
194  // actual calculation
196  (
197  const polyMesh& mesh,
198  const PrimitivePatchType& patch,
199  UList<Type>& allEdgeInfo,
200  UList<Type>& allFaceInfo,
201  TrackingData& td = defaultTrackingData_
202  );
203 
204  //- Disallow default bitwise copy construction
205  PatchEdgeFaceWave(const PatchEdgeFaceWave&) = delete;
206 
207 
208  // Member Functions
209 
210  //- Access allEdgeInfo
211  UList<Type>& allEdgeInfo() const
212  {
213  return allEdgeInfo_;
214  }
215 
216  //- Access allFaceInfo
217  UList<Type>& allFaceInfo() const
218  {
219  return allFaceInfo_;
220  }
221 
222  //- Additional data to be passed into container
223  const TrackingData& data() const
224  {
225  return td_;
226  }
227 
228  //- Get number of unvisited faces, i.e. faces that were not (yet)
229  // reached from walking across patch. This can happen from
230  // - not enough iterations done
231  // - a disconnected patch
232  // - a patch without walls in it
233  label getUnsetFaces() const;
234 
235  label getUnsetEdges() const;
236 
237  //- Copy initial data into allEdgeInfo_
238  void setEdgeInfo
239  (
240  const labelList& changedEdges,
241  const List<Type>& changedEdgesInfo
242  );
243 
244  //- Propagate from edge to face. Returns total number of faces
245  // (over all processors) changed.
246  label edgeToFace();
247 
248  //- Propagate from face to edge. Returns total number of edges
249  // (over all processors) changed.
250  label faceToEdge();
251 
252  //- Iterate until no changes or maxIter reached. Returns actual
253  // number of iterations.
254  label iterate(const label maxIter);
255 
256 
257  // Member Operators
258 
259  //- Disallow default bitwise assignment
260  void operator=(const PatchEdgeFaceWave&) = delete;
261 };
262 
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 //- Update operation
267 template
268 <
269  class PrimitivePatchType,
270  class Type,
271  class TrackingData = int
272 >
273 class updateOp
274 {
275  //- Additional data to be passed into container
276  const polyMesh& mesh_;
277  const PrimitivePatchType& patch_;
278  const scalar tol_;
279  TrackingData& td_;
280 
281 public:
283  (
284  const polyMesh& mesh,
285  const PrimitivePatchType& patch,
286  const scalar tol,
287  TrackingData& td
288  )
289  :
290  mesh_(mesh),
291  patch_(patch),
292  tol_(tol),
293  td_(td)
294  {}
296  void operator()(Type& x, const Type& y) const
297  {
298  if (y.valid(td_))
299  {
300  x.updateEdge(mesh_, patch_, y, true, tol_, td_);
301  }
302  }
303 };
304 
305 
306 //- Transform operation
307 template
308 <
309  class PrimitivePatchType,
310  class Type,
311  class TrackingData = int
312 >
313 class transformOp
314 {
315  //- Additional data to be passed into container
316  const polyMesh& mesh_;
317  const PrimitivePatchType& patch_;
318  const scalar tol_;
319  TrackingData& td_;
320 
321 public:
323  (
324  const polyMesh& mesh,
325  const PrimitivePatchType& patch,
326  const scalar tol,
327  TrackingData& td
328  )
329  :
330  mesh_(mesh),
331  patch_(patch),
332  tol_(tol),
333  td_(td)
334  {}
335 
336  void operator()
337  (
338  const transformer& vt,
339  const bool forward,
340  List<Type>& fld
341  ) const
342  {
343  if (forward)
344  {
345  forAll(fld, i)
346  {
347  fld[i].transform(mesh_, patch_, vt.T(), tol_, td_);
348  }
349  }
350  else
351  {
352  forAll(fld, i)
353  {
354  fld[i].transform(mesh_, patch_, vt.T().T(), tol_, td_);
355  }
356  }
357  }
358 };
359 
360 } // End namespace Foam
361 
362 
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 
365 #ifdef NoRepository
366  #include "PatchEdgeFaceWave.C"
367 #endif
368 
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 
371 #endif
372 
373 // ************************************************************************* //
Transform operation.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space...
Definition: transformer.H:83
const TrackingData & data() const
Additional data to be passed into container.
label getUnsetFaces() const
Get number of unvisited faces, i.e. faces that were not (yet)
PatchEdgeFaceWave(const polyMesh &mesh, const PrimitivePatchType &patch, const labelList &initialEdges, const List< Type > &initialEdgesInfo, UList< Type > &allEdgeInfo, UList< Type > &allFaceInfo, const label maxIter, TrackingData &td=defaultTrackingData_)
Construct from patch, list of changed edges with the Type.
static void setPropagationTol(const scalar tol)
Change tolerance.
Wave propagation of information along patch. Every iteration information goes through one layer of fa...
label faceToEdge()
Propagate from face to edge. Returns total number of edges.
label edgeToFace()
Propagate from edge to face. Returns total number of faces.
fvMesh & mesh
scalar y
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
TemplateName(FvFaceCellWave)
void operator=(const PatchEdgeFaceWave &)=delete
Disallow default bitwise assignment.
label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
static scalar propagationTol()
Access to tolerance.
void setEdgeInfo(const labelList &changedEdges, const List< Type > &changedEdgesInfo)
Copy initial data into allEdgeInfo_.
UList< Type > & allFaceInfo() const
Access allFaceInfo.
A bit-packed bool list.
Update operation.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
static int defaultTrackingData_
Default tracking data to go with default template argument.
Namespace for OpenFOAM.
UList< Type > & allEdgeInfo() const
Access allEdgeInfo.