PrimitivePatch.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) 2016-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::PrimitivePatch
29
30Description
31 A list of faces which address into the list of points.
32
33 The class is templated on the face type (e.g. triangle, polygon etc.)
34 and on the list type of faces and points so that it can refer to
35 existing lists using UList and const pointField& or hold the storage
36 using List and pointField.
37
38SourceFiles
39 PrimitivePatch.C
40 PrimitivePatchAddressing.C
41 PrimitivePatchBdryFaces.C
42 PrimitivePatchBdryPoints.C
43 PrimitivePatchCheck.C
44 PrimitivePatchClear.C
45 PrimitivePatchEdgeLoops.C
46 PrimitivePatchLocalPointOrder.C
47 PrimitivePatchMeshData.C
48 PrimitivePatchMeshEdges.C
49 PrimitivePatchPointAddressing.C
50 PrimitivePatchProjectPoints.C
51
52\*---------------------------------------------------------------------------*/
53
54#ifndef Foam_PrimitivePatch_H
55#define Foam_PrimitivePatch_H
56
57#include "boolList.H"
58#include "labelList.H"
59#include "edgeList.H"
60#include "point.H"
61#include "intersection.H"
62#include "HashSet.H"
63#include "objectHit.H"
64#include "PrimitivePatchBase.H"
65
66// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67
68namespace Foam
69{
70
71// Forward Declarations
72class face;
73template<class T> class Map;
74
75/*---------------------------------------------------------------------------*\
76 Class PrimitivePatch Declaration
77\*---------------------------------------------------------------------------*/
78
79template<class FaceList, class PointField>
81:
82 public PrimitivePatchBase,
83 public FaceList
84{
85public:
86
87 // Public Typedefs
88
89 //- The face type
90 typedef typename
91 std::remove_reference<FaceList>::type::value_type face_type;
92
93 //- The point type
94 typedef typename
95 std::remove_reference<PointField>::type::value_type point_type;
96
97 //- The face list type
98 typedef FaceList FaceListType;
99
100 //- The point field type
102
103 //- Deprecated(2020-03) prefer face_type typedef
104 // \deprecated(2020-03) prefer face_type typedef
105 typedef face_type FaceType;
106
107
108 // Public Data Types
109
110 //- Enumeration defining the surface type. Used in check routines.
111 enum surfaceTopo
114 OPEN,
116 };
117
118private:
119
120 // Private Data
121
122 //- Reference to global list of points
123 PointField points_;
124
125
126 // Demand-driven Private Data
127
128 //- Edges of the patch; address into local point list;
129 // sorted with internal edges first in upper-triangular order
130 // and external edges last.
131 mutable std::unique_ptr<edgeList> edgesPtr_;
132
133 //- Which part of edgesPtr_ is internal edges.
134 mutable label nInternalEdges_;
135
136 //- Boundary point labels, addressing into local point list
137 mutable std::unique_ptr<labelList> boundaryPointsPtr_;
138
139 //- Face-face addressing
140 mutable std::unique_ptr<labelListList> faceFacesPtr_;
141
142 //- Edge-face addressing
143 mutable std::unique_ptr<labelListList> edgeFacesPtr_;
144
145 //- Face-edge addressing
146 mutable std::unique_ptr<labelListList> faceEdgesPtr_;
147
148 //- Point-edge addressing
149 mutable std::unique_ptr<labelListList> pointEdgesPtr_;
150
151 //- Point-face addressing
152 mutable std::unique_ptr<labelListList> pointFacesPtr_;
153
154 //- Faces addressing into local point list
155 mutable std::unique_ptr<List<face_type>> localFacesPtr_;
156
157 //- Labels of mesh points
158 mutable std::unique_ptr<labelList> meshPointsPtr_;
159
160 //- Mesh point map. Given the global point index find its
161 //- location in the patch
162 mutable std::unique_ptr<Map<label>> meshPointMapPtr_;
163
164 //- Outside edge loops
165 mutable std::unique_ptr<labelListList> edgeLoopsPtr_;
166
167 //- Points local to patch
168 mutable std::unique_ptr<Field<point_type>> localPointsPtr_;
169
170 //- Local point order for most efficient search
171 mutable std::unique_ptr<labelList> localPointOrderPtr_;
172
173 //- Face centres
174 mutable std::unique_ptr<Field<point_type>> faceCentresPtr_;
175
176 //- Face area vectors
177 mutable std::unique_ptr<Field<point_type>> faceAreasPtr_;
178
179 //- Mag face area
180 mutable std::unique_ptr<Field<scalar>> magFaceAreasPtr_;
181
182 //- Face unit normals
183 mutable std::unique_ptr<Field<point_type>> faceNormalsPtr_;
184
185 //- Point unit normals
186 mutable std::unique_ptr<Field<point_type>> pointNormalsPtr_;
187
188
189 // Private Member Functions
190
191 //- Calculate internal points on a patch
192 void calcInternPoints() const;
193
194 //- Calculate boundary points on a patch
195 void calcBdryPoints() const;
196
197 //- Calculate addressing
198 void calcAddressing() const;
199
200 //- Calculate point-edge addressing
201 void calcPointEdges() const;
202
203 //- Calculate point-face addressing
204 void calcPointFaces() const;
205
206 //- Calculate mesh addressing
207 void calcMeshData() const;
208
209 //- Calculate mesh point map
210 void calcMeshPointMap() const;
211
212 //- Calculate outside edge loops
213 void calcEdgeLoops() const;
214
215 //- Calculate local points
216 void calcLocalPoints() const;
217
218 //- Calculate local point order
219 void calcLocalPointOrder() const;
220
221 //- Calculate face centres
222 void calcFaceCentres() const;
223
224 //- Calculate face area vectors
225 void calcFaceAreas() const;
226
227 //- Calculate face area magnitudes
228 void calcMagFaceAreas() const;
229
230 //- Calculate unit face normals
231 void calcFaceNormals() const;
232
233 //- Calculate unit point normals
234 void calcPointNormals() const;
235
236
237 //- Face-edge-face walk while remaining on a patch point.
238 // Used to determine if surface multiply connected through point.
239 void visitPointRegion
240 (
241 const label pointi,
242 const labelList& pFaces,
243 const label startFacei,
244 const label startEdgeI,
245 boolList& pFacesHad
246 ) const;
247
248
249public:
250
251 // Constructors
252
253 //- Construct from components
255 (
256 const FaceList& faces,
257 const PointField& points
258 );
259
260 //- Construct from components, transferring faces
262 (
263 FaceList&& faces,
264 const PointField& points
265 );
266
267 //- Construct from components, reuse storage
269 (
270 FaceList& faces,
272 const bool reuse
273 );
274
275 //- Copy construct
277
278
279 //- Destructor
280 virtual ~PrimitivePatch();
281
282 void clearOut();
283
284 void clearGeom();
285
286 void clearTopology();
287
288 void clearPatchMeshAddr();
289
290
291 // Member Functions
292
293 //- Suppress direct swapping, since storage containers may be const
294 void swap(PrimitivePatch&) = delete;
295
296
297 // Access
298
299 //- Return reference to global points
300 const Field<point_type>& points() const noexcept
301 {
302 return points_;
303 }
304
305 //- Number of faces in the patch
306 label nFaces() const noexcept
307 {
308 return FaceList::size();
309 }
310
311
312 // Access functions for demand-driven data
313
314 // Topological data; no mesh required.
315
316 //- Number of points supporting patch faces
317 label nPoints() const
318 {
319 return meshPoints().size();
320 }
321
322 //- Number of edges in patch
323 label nEdges() const
324 {
325 return edges().size();
326 }
327
328 //- Return list of edges, address into LOCAL point list
329 const edgeList& edges() const;
330
331 //- Return sub-list of internal edges, address into LOCAL point list
332 const edgeList::subList internalEdges() const;
333
334 //- Return sub-list of boundary edges, address into LOCAL point list
335 const edgeList::subList boundaryEdges() const;
336
337 //- Number of internal edges
338 label nInternalEdges() const;
339
340 //- Number of boundary edges == (nEdges() - nInternalEdges())
341 label nBoundaryEdges() const;
342
343 //- Is internal edge?
344 bool isInternalEdge(const label edgei) const
345 {
346 return edgei < nInternalEdges();
347 }
348
349 //- Return list of boundary points, address into LOCAL point list
350 // Uses edge addressing (if it exists) or calculates directly
351 // from localFaces()
352 const labelList& boundaryPoints() const;
353
354 //- Return face-face addressing
355 const labelListList& faceFaces() const;
356
357 //- Return edge-face addressing
358 const labelListList& edgeFaces() const;
359
360 //- Return face-edge addressing
361 const labelListList& faceEdges() const;
362
363 //- Return point-edge addressing
364 const labelListList& pointEdges() const;
365
366 //- Return point-face addressing
367 const labelListList& pointFaces() const;
368
369 //- Return patch faces addressing into local point list
370 const List<face_type>& localFaces() const;
371
372 //- Extract list of local faces corresponding to
373 //- the boundary edges.
374 labelList boundaryFaces() const;
375
376 //- Extract sorted list of unique local faces associated with
377 //- the boundary edges.
379
380
381 // Addressing into mesh
382
383 //- Return labelList of mesh points in patch.
384 // They are constructed by walking through the faces in
385 // incremental order and not sorted anymore.
386 const labelList& meshPoints() const;
387
388 //- Mesh point map.
389 // Given the global point index find its location in the patch
390 const Map<label>& meshPointMap() const;
391
392 //- Return pointField of points in patch
393 const Field<point_type>& localPoints() const;
394
395 //- Return orders the local points for most efficient search
396 const labelList& localPointOrder() const;
397
398 //- Given a global point index, return the local point index.
399 // If the point is not found, return -1
400 label whichPoint(const label gp) const;
401
402 //- From patch edge to global edge using meshPoints.
403 edge meshEdge(const label edgei) const;
404
405 //- From patch edge to global edge using meshPoints.
406 edge meshEdge(const edge& e) const;
407
408 //- Search for edge (local point labels) and return its
409 //- index in the edge list or -1 if not found.
410 // Ignores invalid or out-of-range edges
411 label findEdge(const edge& e) const;
412
413 //- Return labels of patch edges in the global edge list using
414 //- cell addressing
416 (
417 const edgeList& allEdges,
418 const labelListList& cellEdges,
419 const labelList& faceCells
420 ) const;
421
422 //- Return labels of patch edges into the global edge list using
423 //- basic edge addressing.
425 (
426 const edgeList& allEdges,
428 ) const;
429
430 //- Return label of the local patch edge
431 //- into the global edge list using basic edge addressing.
432 label meshEdge
433 (
434 const label edgei,
435 const edgeList& allEdges,
437 ) const;
438
439 //- Return labels of specified patch edges
440 //- into the global edge list using basic edge addressing.
442 (
443 const labelUList& edgeLabels,
444 const edgeList& allEdges,
446 ) const;
447
448
449 //- Return face centres for patch
450 const Field<point_type>& faceCentres() const;
451
452 //- Return face area vectors for patch
453 const Field<point_type>& faceAreas() const;
454
455 //- Return face area magnitudes for patch
456 const Field<scalar>& magFaceAreas() const;
457
458 //- Return face unit normals for patch
459 const Field<point_type>& faceNormals() const;
460
461 //- Return point normals for patch
462 const Field<point_type>& pointNormals() const;
463
464
465 // Storage Management
467 bool hasFaceAreas() const { return bool(faceAreasPtr_); }
468 bool hasFaceCentres() const { return bool(faceCentresPtr_); }
469 bool hasFaceNormals() const { return bool(faceNormalsPtr_); }
470 bool hasPointNormals() const { return bool(pointNormalsPtr_); }
472 bool hasBoundaryPoints() const { return bool(boundaryPointsPtr_); }
473
474 // These ones are currently all calculated together:
475 // - edges(), faceFaces(), edgeFaces(), faceEdges()
477 bool hasEdges() const { return bool(edgesPtr_); }
478 bool hasFaceFaces() const { return bool(faceFacesPtr_); }
479 bool hasEdgeFaces() const { return bool(edgeFacesPtr_); }
480 bool hasFaceEdges() const { return bool(faceEdgesPtr_); }
482 bool hasPointEdges() const { return bool(pointEdgesPtr_); }
483 bool hasPointFaces() const { return bool(pointFacesPtr_); }
485 bool hasMeshPointMap() const { return bool(meshPointMapPtr_); }
486
487
488 // Other patch operations
489
490 //- Project vertices of patch onto another patch
491 template<class ToPatch>
493 (
494 const ToPatch& targetPatch,
495 const Field<point_type>& projectionDirection,
498 ) const;
499
500 //- Project vertices of patch onto another patch
501 template<class ToPatch>
503 (
504 const ToPatch& targetPatch,
505 const Field<point_type>& projectionDirection,
508 ) const;
509
510 //- Return list of closed loops of boundary vertices.
511 // Edge loops are given as ordered lists of vertices
512 // in local addressing
513 const labelListList& edgeLoops() const;
514
515
516 // Check
517
518 //- Calculate surface type formed by patch.
519 // Types:
520 // - all edges have two neighbours (manifold)
521 // - some edges have more than two neighbours (illegal)
522 // - other (open)
523 surfaceTopo surfaceType() const;
524
525 //- Check surface formed by patch for manifoldness (see above).
526 // Return true if any incorrect edges are found.
527 // Insert vertices of incorrect edges into set.
528 bool checkTopology
529 (
530 const bool report = false,
531 labelHashSet* setPtr = nullptr
532 ) const;
533
534 //- Checks primitivePatch for faces sharing point but not edge.
535 // This denotes a surface that is pinched at a single point
536 // (test for pinched at single edge is already in PrimitivePatch)
537 // Returns true if this situation found and puts conflicting
538 // (mesh)point in set. Based on all the checking routines in
539 // primitiveMesh.
541 (
542 const bool report = false,
543 labelHashSet* setPtr = nullptr
544 ) const;
545
546
547 // Edit
548
549 //- Correct patch after moving points
550 virtual void movePoints(const Field<point_type>&);
551
552
553 // Member Operators
554
555 //- Copy assign faces. Leave points alone (could be a reference).
557
558 //- Move assign faces. Leave points alone (could be a reference).
560
561
562 // Housekeeping
563
564 //- Identical to findEdge
565 label whichEdge(const edge& e) const { return this->findEdge(e); }
566};
567
568
569// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
570
571} // End namespace Foam
572
573// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
574
575#ifdef NoRepository
576 #include "PrimitivePatch.C"
577#endif
578
579// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
580
581#endif
582
583// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
Non-templated base elements for PrimitivePatch.
A list of faces which address into the list of points.
label nEdges() const
Number of edges in patch.
bool hasPointFaces() const
label nPoints() const
Number of points supporting patch faces.
label nFaces() const noexcept
Number of faces in the patch.
label nBoundaryEdges() const
Number of boundary edges == (nEdges() - nInternalEdges())
FaceList FaceListType
The face list type.
const labelListList & pointEdges() const
Return point-edge addressing.
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
label nInternalEdges() const
Number of internal edges.
bool hasBoundaryPoints() const
face_type FaceType
Deprecated(2020-03) prefer face_type typedef.
labelList meshEdges(const edgeList &allEdges, const labelListList &cellEdges, const labelList &faceCells) const
bool hasFaceNormals() const
const Map< label > & meshPointMap() const
Mesh point map.
const edgeList::subList internalEdges() const
Return sub-list of internal edges, address into LOCAL point list.
List< objectHit > projectFaceCentres(const ToPatch &targetPatch, const Field< point_type > &projectionDirection, const intersection::algorithm=intersection::FULL_RAY, const intersection::direction=intersection::VECTOR) const
Project vertices of patch onto another patch.
const labelList & meshPoints() const
Return labelList of mesh points in patch.
bool hasFaceAreas() const
edge meshEdge(const label edgei) const
From patch edge to global edge using meshPoints.
void operator=(const PrimitivePatch< FaceList, PointField > &rhs)
Copy assign faces. Leave points alone (could be a reference).
bool checkPointManifold(const bool report=false, labelHashSet *setPtr=nullptr) const
Checks primitivePatch for faces sharing point but not edge.
surfaceTopo surfaceType() const
Calculate surface type formed by patch.
bool hasFaceCentres() const
const Field< point_type > & localPoints() const
Return pointField of points in patch.
const Field< point_type > & faceNormals() const
Return face unit normals for patch.
const labelList & localPointOrder() const
Return orders the local points for most efficient search.
virtual ~PrimitivePatch()
Destructor.
const Field< point_type > & pointNormals() const
Return point normals for patch.
const edgeList::subList boundaryEdges() const
Return sub-list of boundary edges, address into LOCAL point list.
std::remove_reference< PointField >::type::value_type point_type
The point type.
bool hasMeshPointMap() const
labelList boundaryFaces() const
const Field< point_type > & points() const noexcept
Return reference to global points.
const Field< point_type > & faceAreas() const
Return face area vectors for patch.
PointField PointFieldType
The point field type.
label whichPoint(const label gp) const
Given a global point index, return the local point index.
const labelListList & edgeLoops() const
Return list of closed loops of boundary vertices.
virtual void movePoints(const Field< point_type > &)
Correct patch after moving points.
bool isInternalEdge(const label edgei) const
Is internal edge?
const labelList & boundaryPoints() const
Return list of boundary points, address into LOCAL point list.
const Field< point_type > & faceCentres() const
Return face centres for patch.
const labelListList & faceFaces() const
Return face-face addressing.
bool hasPointNormals() const
void swap(PrimitivePatch &)=delete
Suppress direct swapping, since storage containers may be const.
const labelListList & pointFaces() const
Return point-face addressing.
std::remove_reference< FaceList >::type::value_type face_type
The face type.
bool hasFaceEdges() const
const labelListList & edgeFaces() const
Return edge-face addressing.
bool checkTopology(const bool report=false, labelHashSet *setPtr=nullptr) const
Check surface formed by patch for manifoldness (see above).
const labelListList & faceEdges() const
Return face-edge addressing.
const Field< scalar > & magFaceAreas() const
Return face area magnitudes for patch.
List< objectHit > projectPoints(const ToPatch &targetPatch, const Field< point_type > &projectionDirection, const intersection::algorithm=intersection::FULL_RAY, const intersection::direction=intersection::VECTOR) const
Project vertices of patch onto another patch.
label whichEdge(const edge &e) const
Identical to findEdge.
bool hasEdgeFaces() const
label findEdge(const edge &e) const
const List< face_type > & localFaces() const
Return patch faces addressing into local point list.
bool hasPointEdges() const
surfaceTopo
Enumeration defining the surface type. Used in check routines.
bool hasFaceFaces() const
labelList uniqBoundaryFaces() const
A List obtained as a section of another List.
Definition: SubList.H:70
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:59
bool
Definition: EEqn.H:20
Namespace for OpenFOAM.
const direction noexcept
Definition: Scalar.H:223
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=cellModel::ref(cellModel::HEX);labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells].reset(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< SMALL) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &oldCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< SLList< face > > pFaces[nBCs]
Definition: readKivaGrid.H:235
volScalarField & e
Definition: createFields.H:11