PatchEdgeFaceWave.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::PatchEdgeFaceWave
29 
30 Description
31  Wave propagation of information along patch. Every iteration
32  information goes through one layer of faces. Templated on information
33  that is transferred.
34 
35 SourceFiles
36  PatchEdgeFaceWave.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Foam_PatchEdgeFaceWave_H
41 #define Foam_PatchEdgeFaceWave_H
42 
43 #include "bitSet.H"
44 #include "scalarField.H"
45 #include "primitivePatch.H"
46 #include "vectorTensorTransform.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward Declarations
54 class polyMesh;
55 
56 /*---------------------------------------------------------------------------*\
57  Class PatchEdgeFaceWaveBase Declaration
58 \*---------------------------------------------------------------------------*/
59 
61 {
62 protected:
63 
64  // Protected Static Data
65 
66  //- Relative tolerance.
67  // Stop propagation if relative changes less than this tolerance
68  // (responsibility for checking this is up to Type implementation)
69  static scalar propagationTol_;
70 
71 
72  // Protected Data
73 
74  //- Reference to mesh
75  const polyMesh& mesh_;
76 
77  //- Track if edge has changed
79 
80  //- Track if face has changed
82 
83  //- List of changed edges
85 
86  //- List of changed faces
88 
89  //- Number of unvisited edges
91 
92  //- Number of unvisited faces
93  label nUnvisitedFaces_;
94 
95 
96 public:
97 
98  //- Default trackData value (for default template argument)
99  static label dummyTrackData_;
101 
102  //- Runtime type information
103  ClassName("PatchEdgeFaceWave");
104 
106  // Constructors
107 
108  //- Construct with mesh reference and set initial sizes
110  (
111  const polyMesh& mesh,
112  const label nEdges,
113  const label nFaces
114  );
115 
116 
117  // Static Functions
118 
119  //- Access to propagation tolerance
120  static scalar propagationTol() noexcept
121  {
122  return propagationTol_;
123  }
124 
125  //- Change propagation tolerance, return previous value
126  static scalar setPropagationTol(const scalar tol) noexcept
127  {
128  scalar old(propagationTol_);
129  propagationTol_ = tol;
130  return old;
131  }
132 
133 
134  // Member Functions
135 
136  //- Return access to the mesh
137  const polyMesh& mesh() const noexcept { return mesh_; }
138 
139  //- Current number of changed edges
140  label nChangedEdges() const noexcept { return changedEdges_.size(); }
141 
142  //- Current number of changed faces
143  label nChangedFaces() const noexcept { return changedFaces_.size(); }
144 
145  //- Number of unvisited faces, i.e. faces that were not (yet)
146  //- reached from walking across patch.
147  //
148  // This can happen from
149  // - not enough iterations done
150  // - a disconnected patch
151  // - a patch without walls in it
152  label nUnvisitedFaces() const noexcept { return nUnvisitedFaces_; }
153 
154  label nUnvisitedEdges() const noexcept { return nUnvisitedEdges_; }
155 };
156 
157 
158 /*---------------------------------------------------------------------------*\
159  Class PatchEdgeFaceWave Declaration
160 \*---------------------------------------------------------------------------*/
162 template
163 <
164  class PrimitivePatchType,
165  class Type,
166  class TrackingData = label
167 >
168 class PatchEdgeFaceWave
169 :
170  public PatchEdgeFaceWaveBase
171 {
172  // Private Data
173 
174  //- Reference to patch
175  const PrimitivePatchType& patch_;
176 
177  //- Wall information for all edges
178  UList<Type>& allEdgeInfo_;
179 
180  //- Information on all patch faces
181  UList<Type>& allFaceInfo_;
182 
183  //- Additional data to be passed into container
184  TrackingData& td_;
186  //- Number of evaluations
187  label nEvals_;
188 
189  // Addressing between edges of patch_ and globalData.coupledPatch()
190  labelList patchEdges_;
191  labelList coupledEdges_;
192  bitSet sameEdgeOrientation_;
193 
194 
195  // Private Member Functions
196 
197  //- Updates edgeInfo with information from neighbour.
198  // Updates all statistics.
199  bool updateEdge
200  (
201  const label edgeI,
202  const label neighbourFacei,
203  const Type& neighbourInfo,
204  Type& edgeInfo
205  );
206 
207  //- Updates faceInfo with information from neighbour.
208  // Updates all statistics.
209  bool updateFace
210  (
211  const label facei,
212  const label neighbourEdgeI,
213  const Type& neighbourInfo,
214  Type& faceInfo
215  );
216 
217  //- Update coupled edges
218  void syncEdges();
219 
220  //- No copy construct
221  PatchEdgeFaceWave(const PatchEdgeFaceWave&) = delete;
222 
223  //- No copy assignment
224  void operator=(const PatchEdgeFaceWave&) = delete;
225 
226 
227 public:
228 
229  // Constructors
230 
231  //- Construct from patch, list of changed edges with the Type
232  //- for these edges.
233  // Obtains work arrays to operate on, one of size
234  // number of patch edges, the other number of patch faces.
235  // Iterates until nothing changes or maxIter reached.
236  // (maxIter can be 0)
238  (
239  const polyMesh& mesh,
240  const PrimitivePatchType& patch,
241  const labelList& initialEdges,
242  const List<Type>& initialEdgesInfo,
245  const label maxIter,
246  TrackingData& td = PatchEdgeFaceWaveBase::dummyTrackData_
247  );
248 
249  //- Construct from patch.
250  // Use setEdgeInfo() and iterate() to do actual calculation
252  (
253  const polyMesh& mesh,
254  const PrimitivePatchType& patch,
257  TrackingData& td = PatchEdgeFaceWaveBase::dummyTrackData_
258  );
259 
260 
261  // Member Functions
262 
263  //- Access allEdgeInfo
265  {
266  return allEdgeInfo_;
267  }
268 
269  //- Access allFaceInfo
271  {
272  return allFaceInfo_;
273  }
274 
275  //- Additional data to be passed into container
276  const TrackingData& data() const noexcept
277  {
278  return td_;
279  }
280 
281  //- Copy initial data into allEdgeInfo_
282  void setEdgeInfo
283  (
284  const labelList& changedEdges,
285  const List<Type>& changedEdgesInfo
286  );
287 
288  //- Propagate from edge to face.
289  // \return total number of faces (over all processors) changed.
290  label edgeToFace();
291 
292  //- Propagate from face to edge.
293  // \return total number of edges (over all processors) changed.
294  label faceToEdge();
295 
296  //- Iterate until no changes or maxIter reached.
297  // \return actual number of iterations.
298  label iterate(const label maxIter);
299 };
300 
301 
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 
304 //- Update operation
305 template
306 <
307  class PrimitivePatchType,
308  class Type,
309  class TrackingData = int
310 >
311 class updateOp
312 {
313  //- Additional data to be passed into container
314  const polyMesh& mesh_;
315  const PrimitivePatchType& patch_;
316  const scalar tol_;
317  TrackingData& td_;
318 
319 public:
320 
321  updateOp
322  (
323  const polyMesh& mesh,
324  const PrimitivePatchType& patch,
325  const scalar tol,
326  TrackingData& td
327  )
328  :
329  mesh_(mesh),
330  patch_(patch),
331  tol_(tol),
332  td_(td)
333  {}
334 
335  void operator()(Type& x, const Type& y) const
336  {
337  if (y.valid(td_))
338  {
339  x.updateEdge(mesh_, patch_, y, true, tol_, td_);
340  }
341  }
342 };
343 
344 
345 //- Transform operation
346 template
347 <
348  class PrimitivePatchType,
349  class Type,
350  class TrackingData = int
351 >
352 class transformOp
353 {
354  //- Additional data to be passed into container
355  const polyMesh& mesh_;
356  const PrimitivePatchType& patch_;
357  const scalar tol_;
358  TrackingData& td_;
359 
360 public:
361 
363  (
364  const polyMesh& mesh,
365  const PrimitivePatchType& patch,
366  const scalar tol,
367  TrackingData& td
368  )
369  :
370  mesh_(mesh),
371  patch_(patch),
372  tol_(tol),
373  td_(td)
374  {}
375 
376  void operator()
377  (
378  const vectorTensorTransform& vt,
379  const bool forward,
380  List<Type>& fld
381  ) const
382  {
383  if (forward)
384  {
385  forAll(fld, i)
386  {
387  fld[i].transform(mesh_, patch_, vt.R(), tol_, td_);
388  }
389  }
390  else
391  {
392  forAll(fld, i)
393  {
394  fld[i].transform(mesh_, patch_, vt.R().T(), tol_, td_);
395  }
396  }
397  }
398 };
399 
400 } // End namespace Foam
401 
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
404 
405 #ifdef NoRepository
406  #include "PatchEdgeFaceWave.C"
407 #endif
408 
409 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 
411 #endif
412 
413 // ************************************************************************* //
PatchEdgeFaceWaveBase(const polyMesh &mesh, const label nEdges, const label nFaces)
Construct with mesh reference and set initial sizes.
bitSet changedFace_
Track if face has changed.
const polyMesh & mesh_
Reference to mesh.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
label nUnvisitedFaces() const noexcept
Number of unvisited faces, i.e. faces that were not (yet) reached from walking across patch...
Wave propagation of information along patch. Every iteration information goes through one layer of fa...
void operator()(Type &x, const Type &y) const
label faceToEdge()
Propagate from face to edge.
label edgeToFace()
Propagate from edge to face.
const polyMesh & mesh() const noexcept
Return access to the mesh.
label nUnvisitedEdges_
Number of unvisited edges.
transformOp(const polyMesh &mesh, const PrimitivePatchType &patch, const scalar tol, TrackingData &td)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
label nUnvisitedFaces_
Number of unvisited faces.
scalar y
UList< Type > & allFaceInfo() const noexcept
Access allFaceInfo.
DynamicList< label > changedEdges_
List of changed edges.
dynamicFvMesh & mesh
static scalar setPropagationTol(const scalar tol) noexcept
Change propagation tolerance, return previous value.
label nChangedFaces() const noexcept
Current number of changed faces.
static scalar propagationTol() noexcept
Access to propagation tolerance.
static scalar propagationTol_
Relative tolerance.
UList< Type > & allEdgeInfo() const noexcept
Access allEdgeInfo.
label nUnvisitedEdges() const noexcept
const direction noexcept
Definition: Scalar.H:258
label iterate(const label maxIter)
Iterate until no changes or maxIter reached.
void setEdgeInfo(const labelList &changedEdges, const List< Type > &changedEdgesInfo)
Copy initial data into allEdgeInfo_.
const TrackingData & data() const noexcept
Additional data to be passed into container.
updateOp(const polyMesh &mesh, const PrimitivePatchType &patch, const scalar tol, TrackingData &td)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
ClassName("PatchEdgeFaceWave")
Runtime type information.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
const std::string patch
OpenFOAM patch number as a std::string.
label nChangedEdges() const noexcept
Current number of changed edges.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
static label dummyTrackData_
Default trackData value (for default template argument)
DynamicList< label > changedFaces_
List of changed faces.
Namespace for OpenFOAM.
bitSet changedEdge_
Track if edge has changed.