Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::PatchEdgeFaceWave
29
30Description
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
35SourceFiles
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"
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
51{
52
53// Forward Declarations
54class polyMesh;
56/*---------------------------------------------------------------------------*\
57 Class PatchEdgeFaceWaveBase Declaration
58\*---------------------------------------------------------------------------*/
59
61{
62protected:
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
76
77 //- Track if edge has changed
79
80 //- Track if face has changed
82
83 //- List of changed edges
86 //- List of changed faces
88
89 //- Number of unvisited edges
91
92 //- Number of unvisited faces
93 label nUnvisitedFaces_;
94
96public:
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\*---------------------------------------------------------------------------*/
162template
163<
164 class PrimitivePatchType,
165 class Type,
166 class TrackingData = label
167>
169:
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
227public:
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)
237 PatchEdgeFaceWave
238 (
239 const polyMesh& mesh,
240 const PrimitivePatchType& patch,
241 const labelList& initialEdges,
242 const List<Type>& initialEdgesInfo,
245 const label maxIter,
247 );
248
249 //- Construct from patch.
250 // Use setEdgeInfo() and iterate() to do actual calculation
251 PatchEdgeFaceWave
252 (
253 const polyMesh& mesh,
254 const PrimitivePatchType& patch,
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 labelUList& changedEdges,
285 const UList<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
305template
306<
307 class PrimitivePatchType,
308 class Type,
309 class TrackingData = int
310>
311class 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
319public:
320
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 }
342};
343
344
345//- Transform operation
346template
347<
348 class PrimitivePatchType,
349 class Type,
350 class TrackingData = int
351>
352class 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
360public:
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 UList<Type>& fld
381 ) const
382 {
383 const tensor rot(forward ? vt.R() : vt.R().T());
384
385 for (auto& val : fld)
386 {
387 val.transform(mesh_, patch_, rot, tol_, td_);
388 }
390};
391
392} // End namespace Foam
393
394
395// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
396
397#ifdef NoRepository
398 #include "PatchEdgeFaceWave.C"
399#endif
400
401// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
402
403#endif
404
405// ************************************************************************* //
scalar y
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
label nChangedFaces() const noexcept
Current number of changed faces.
DynamicList< label > changedFaces_
List of changed faces.
bitSet changedFace_
Track if face has changed.
DynamicList< label > changedEdges_
List of changed edges.
static scalar propagationTol_
Relative tolerance.
label nUnvisitedEdges() const noexcept
static label dummyTrackData_
Default trackData value (for default template argument).
label nChangedEdges() const noexcept
Current number of changed edges.
label nUnvisitedFaces_
Number of unvisited faces.
PatchEdgeFaceWaveBase(const polyMesh &mesh, const label nEdges, const label nFaces)
Construct with mesh reference and set initial sizes.
static scalar setPropagationTol(const scalar tol) noexcept
Change propagation tolerance, return previous value.
label nUnvisitedEdges_
Number of unvisited edges.
bitSet changedEdge_
Track if edge has changed.
label nUnvisitedFaces() const noexcept
Number of unvisited faces, i.e. faces that were not (yet) reached from walking across patch.
const polyMesh & mesh() const noexcept
Return access to the mesh.
const polyMesh & mesh_
Reference to mesh.
ClassName("PatchEdgeFaceWave")
Runtime type information.
static scalar propagationTol() noexcept
Access to propagation tolerance.
Wave propagation of information along patch. Every iteration information goes through one layer of fa...
UList< Type > & allFaceInfo() const noexcept
Access allFaceInfo.
label edgeToFace()
Propagate from edge to face.
UList< Type > & allEdgeInfo() const noexcept
Access allEdgeInfo.
const TrackingData & data() const noexcept
Additional data to be passed into container.
label iterate(const label maxIter)
Iterate until no changes or maxIter reached.
label faceToEdge()
Propagate from face to edge.
void setEdgeInfo(const labelUList &changedEdges, const UList< Type > &changedEdgesInfo)
Copy initial data into allEdgeInfo_.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
transformOp(const polyMesh &mesh, const PrimitivePatchType &patch, const scalar tol, TrackingData &td)
Update operation.
updateOp(const polyMesh &mesh, const PrimitivePatchType &patch, const scalar tol, TrackingData &td)
void operator()(Type &x, const Type &y) const
Vector-tensor class used to perform translations and rotations in 3D space.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74
dynamicFvMesh & mesh
wallPoints::trackData td(isBlockedFace, regionToBlockSize)
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
Tensor< scalar > tensor
Definition symmTensor.H:57
const direction noexcept
Definition scalarImpl.H:265
UList< label > labelUList
A UList of labels.
Definition UList.H:75