PrimitivePatch.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-2024 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::PrimitivePatch
26 
27 Description
28  A list of faces which address into the list of points.
29 
30  The class is templated on the face type (e.g. triangle, polygon etc.)
31  and on the list type of faces and points so that it can refer to
32  existing lists using UList and const pointField& or hold the storage
33  using List and pointField.
34 
35 SourceFiles
36  PrimitivePatchAddressing.C
37  PrimitivePatchBdryPoints.C
38  PrimitivePatch.C
39  PrimitivePatchCheck.C
40  PrimitivePatchClear.C
41  PrimitivePatchEdgeLoops.C
42  PrimitivePatchLocalPointOrder.C
43  PrimitivePatchMeshData.C
44  PrimitivePatchMeshEdges.C
45  PrimitivePatchName.C
46  PrimitivePatchPointAddressing.C
47  PrimitivePatchProjectPoints.C
48 
49 \*---------------------------------------------------------------------------*/
50 
51 #ifndef PrimitivePatch_H
52 #define PrimitivePatch_H
53 
54 #include "boolList.H"
55 #include "labelList.H"
56 #include "edgeList.H"
57 #include "point.H"
58 #include "intersection.H"
59 #include "HashSet.H"
60 #include "Map.H"
61 #include "objectHit.H"
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
65 namespace Foam
66 {
67 
68 /*---------------------------------------------------------------------------*\
69  Class PrimitivePatchName Declaration
70 \*---------------------------------------------------------------------------*/
71 
73 
74 
75 /*---------------------------------------------------------------------------*\
76  Class PrimitivePatch Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class FaceList, class PointField>
80 class PrimitivePatch
81 :
82  public PrimitivePatchName,
83  public FaceList
84 {
85 
86 public:
87 
88  // Public Typedefs
89 
90  typedef FaceList FaceListType;
91 
92  typedef typename std::remove_reference<FaceList>::type::value_type
93  FaceType;
94 
95  typedef PointField PointFieldType;
96 
97  typedef typename std::remove_reference<PointField>::type::value_type
98  PointType;
99 
100 
101  // Public data types
102 
103  //- Enumeration defining the surface type. Used in check routines.
104  enum surfaceTopo
105  {
107  OPEN,
109  };
110 
111 private:
112 
113  // Private Data
114 
115  //- Reference to global list of points
116  PointField points_;
117 
118 
119  // Demand driven private data
120 
121  //- Edges of the patch; address into local point list;
122  // sorted with internal edges first in upper-triangular order
123  // and external edges last.
124  mutable edgeList* edgesPtr_;
125 
126  //- Which part of edgesPtr_ is internal edges.
127  mutable label nInternalEdges_;
128 
129  //- Boundary point labels, addressing into local point list
130  mutable labelList* boundaryPointsPtr_;
131 
132  //- Face-face addressing
133  mutable labelListList* faceFacesPtr_;
134 
135  //- Edge-face addressing
136  mutable labelListList* edgeFacesPtr_;
137 
138  //- Face-edge addressing
139  mutable labelListList* faceEdgesPtr_;
140 
141  //- Point-edge addressing
142  mutable labelListList* pointEdgesPtr_;
143 
144  //- Point-face addressing
145  mutable labelListList* pointFacesPtr_;
146 
147  //- Faces addressing into local point list
148  mutable List<FaceType>* localFacesPtr_;
149 
150  //- Labels of mesh points
151  mutable labelList* meshPointsPtr_;
152 
153  //- Mesh point map. Given the global point index find its
154  // location in the patch
155  mutable Map<label>* meshPointMapPtr_;
156 
157  //- Outside edge loops
158  mutable labelListList* edgeLoopsPtr_;
159 
160  //- Points local to patch
161  mutable Field<PointType>* localPointsPtr_;
162 
163  //- Local point order for most efficient search
164  mutable labelList* localPointOrderPtr_;
165 
166  //- Face centres
167  mutable Field<PointType>* faceCentresPtr_;
168 
169  //- Face areas
170  mutable Field<PointType>* faceAreasPtr_;
171 
172  //- Face unit normals
173  mutable Field<PointType>* faceNormalsPtr_;
174 
175  //- Point unit normals
176  mutable Field<PointType>* pointNormalsPtr_;
177 
178 
179  // Private Member Functions
180 
181  //- Calculate edges of the patch
182  void calcIntBdryEdges() const;
183 
184  //- Calculated boundary points on a patch
185  void calcBdryPoints() const;
186 
187  //- Calculate addressing
188  void calcAddressing() const;
189 
190  //- Calculate point-edge addressing
191  void calcPointEdges() const;
192 
193  //- Calculate point-face addressing
194  void calcPointFaces() const;
195 
196  //- Calculate mesh addressing
197  void calcMeshData() const;
198 
199  //- Calculate mesh point map
200  void calcMeshPointMap() const;
201 
202  //- Calculate outside edge loops
203  void calcEdgeLoops() const;
204 
205  //- Calculate local points
206  void calcLocalPoints() const;
207 
208  //- Calculate local point order
209  void calcLocalPointOrder() const;
210 
211  //- Calculate face centres
212  void calcFaceCentres() const;
213 
214  //- Calculate face areas
215  void calcFaceAreas() const;
216 
217  //- Calculate unit face normals
218  void calcFaceNormals() const;
219 
220  //- Calculate unit point normals
221  void calcPointNormals() const;
222 
223  //- Calculate edge owner
224  void calcEdgeOwner() const;
225 
226 
227  //- Face-edge-face walk while remaining on a patch point.
228  // Used to determine if surface multiply connected through point.
229  void visitPointRegion
230  (
231  const label pointi,
232  const labelList& pFaces,
233  const label startFacei,
234  const label startEdgeI,
235  boolList& pFacesHad
236  ) const;
237 
238 
239 public:
240 
241  // Constructors
242 
243  //- Construct from components
245  (
246  const FaceList& faces,
247  const Field<PointType>& points
248  );
249 
250  //- Move constructor from components
252  (
253  FaceList&& faces,
255  );
256 
257  //- Construct from components, reuse storage
259  (
260  FaceList& faces,
262  const bool reuse
263  );
264 
265  //- Copy constructor
267  (
269  );
270 
271  //- Move constructor
273  (
275  );
276 
277  //- Construct and return a clone
279  {
281  (
283  );
284  }
285 
286 
287  //- Destructor
288  ~PrimitivePatch();
289 
290 
291  // Member Functions
292 
293  // Access
294 
295  //- Return reference to global points
296  const Field<PointType>& points() const
297  {
298  return points_;
299  }
300 
301 
302  // Access functions for Topological data; no mesh required.
303 
304  //- Return number of points supporting patch faces
305  label nPoints() const
306  {
307  return meshPoints().size();
308  }
309 
310  //- Return number of edges in patch
311  label nEdges() const
312  {
313  return edges().size();
314  }
315 
316  //- Return list of edges, address into LOCAL point list
317  const edgeList& edges() const;
318 
319  //- Number of internal edges
320  label nInternalEdges() const;
321 
322  //- Is internal edge?
323  bool isInternalEdge(const label edgeI) const
324  {
325  return edgeI < nInternalEdges();
326  }
327 
328  //- Return list of boundary points,
329  // address into LOCAL point list
330  const labelList& boundaryPoints() const;
331 
332  //- Return face-face addressing
333  const labelListList& faceFaces() const;
334 
335  //- Return edge-face addressing
336  const labelListList& edgeFaces() const;
337 
338  //- Return face-edge addressing
339  const labelListList& faceEdges() const;
340 
341  //- Return point-edge addressing
342  const labelListList& pointEdges() const;
343 
344  //- Return point-face addressing
345  const labelListList& pointFaces() const;
346 
347  //- Return patch faces addressing into local point list
348  const List<FaceType>& localFaces() const;
349 
350 
351  // Addressing into mesh
352 
353  //- Return labelList of mesh points in patch. They are constructed
354  // walking through the faces in incremental order and not sorted
355  // anymore.
356  const labelList& meshPoints() const;
357 
358  //- Mesh point map. Given the global point index find its
359  // location in the patch
360  const Map<label>& meshPointMap() const;
361 
362  //- Return pointField of points in patch
363  const Field<PointType>& localPoints() const;
364 
365  //- Return orders the local points for most efficient search
366  const labelList& localPointOrder() const;
367 
368  //- Given a global point index, return the local point index.
369  // If the point is not found, return -1
370  label whichPoint(const label gp) const;
371 
372  //- Given an edge in local point labels, return its
373  // index in the edge list. If the edge is not found, return -1
374  label whichEdge(const edge&) const;
375 
376  //- Return labels of patch edges in the global edge list using
377  // cell addressing
379  (
380  const edgeList& allEdges,
381  const labelListList& cellEdges,
382  const labelList& faceCells
383  ) const;
384 
385  //- Return labels of patch edges in the global edge list using
386  // basic edge addressing.
388  (
389  const edgeList& allEdges,
391  ) const;
392 
393  //- Return face centres for patch
394  const Field<PointType>& faceCentres() const;
395 
396  //- Return face areas for patch
397  const Field<PointType>& faceAreas() const;
398 
399  //- Return face normals for patch
400  const Field<PointType>& faceNormals() const;
401 
402  //- Return point normals for patch
403  const Field<PointType>& pointNormals() const;
404 
405 
406  // Other patch operations
407 
408  //- Project vertices of patch onto another patch
409  template<class ToPatch>
411  (
412  const ToPatch& targetPatch,
413  const Field<PointType>& projectionDirection,
418  ) const;
419 
420  //- Project vertices of patch onto another patch
421  template<class ToPatch>
423  (
424  const ToPatch& targetPatch,
425  const Field<PointType>& projectionDirection,
430  ) const;
431 
432  //- Return list of closed loops of boundary vertices.
433  // Edge loops are given as ordered lists of vertices
434  // in local addressing
435  const labelListList& edgeLoops() const;
436 
437 
438  // Check
439 
440  //- Calculate surface type formed by patch.
441  // Types:
442  // - all edges have two neighbours (manifold)
443  // - some edges have more than two neighbours (illegal)
444  // - other (open)
445  surfaceTopo surfaceType() const;
446 
447  //- Check surface formed by patch for manifoldness (see above).
448  // Return true if any incorrect edges are found.
449  // Insert vertices of incorrect edges into set.
450  bool checkTopology
451  (
452  const bool report = false,
453  labelHashSet* setPtr = nullptr
454  ) const;
455 
456  //- Checks primitivePatch for faces sharing point but not edge.
457  // This denotes a surface that is pinched at a single point
458  // (test for pinched at single edge is already in PrimitivePatch)
459  // Returns true if this situation found and puts conflicting
460  // (mesh)point in set. Based on all the checking routines in
461  // primitiveMesh.
462  bool checkPointManifold
463  (
464  const bool report = false,
465  labelHashSet* setPtr = nullptr
466  ) const;
467 
468 
469  // Edit
470 
471  void clearOut();
472 
473  void clearGeom();
474 
475  void clearTopology();
476 
477  void clearPatchMeshAddr();
478 
479 
480  // Member Operators
481 
482  //- Assignment operator
483  void operator=
484  (
486  );
487 
488  //- Move assignment operator
489  void operator=
490  (
492  );
493 };
494 
495 
496 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
497 
498 } // End namespace Foam
499 
500 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
501 
502 #ifdef NoRepository
503  #include "PrimitivePatch.C"
504 #endif
505 
506 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
507 
508 #endif
509 
510 // ************************************************************************* //
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A list of faces which address into the list of points.
label nEdges() const
Return number of edges in patch.
label nPoints() const
Return number of points supporting patch faces.
const Field< PointType > & pointNormals() const
Return point normals for patch.
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.
autoPtr< PrimitivePatch< FaceList, PointField > > clone() const
Construct and return a clone.
label whichEdge(const edge &) const
Given an edge in local point labels, return its.
std::remove_reference< PointField >::type::value_type PointType
labelList meshEdges(const edgeList &allEdges, const labelListList &cellEdges, const labelList &faceCells) const
Return labels of patch edges in the global edge list using.
const Map< label > & meshPointMap() const
Mesh point map. Given the global point index find its.
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
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.
List< objectHit > projectPoints(const ToPatch &targetPatch, const Field< PointType > &projectionDirection, const intersection::algorithm=intersection::algorithm::fullRay, const intersection::direction=intersection::direction::vector) const
Project vertices of patch onto another patch.
const labelList & localPointOrder() const
Return orders the local points for most efficient search.
~PrimitivePatch()
Destructor.
const Field< PointType > & faceAreas() const
Return face areas for patch.
const Field< PointType > & points() const
Return reference to global points.
PointField PointFieldType
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.
const List< FaceType > & localFaces() const
Return patch faces addressing into local point list.
const labelList & boundaryPoints() const
Return list of boundary points,.
const labelListList & faceFaces() const
Return face-face addressing.
bool isInternalEdge(const label edgeI) const
Is internal edge?
std::remove_reference< FaceList >::type::value_type FaceType
const labelListList & pointFaces() const
Return point-face addressing.
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.
List< objectHit > projectFaceCentres(const ToPatch &targetPatch, const Field< PointType > &projectionDirection, const intersection::algorithm=intersection::algorithm::fullRay, const intersection::direction=intersection::direction::vector) const
Project vertices of patch onto another patch.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
const Field< PointType > & faceNormals() const
Return face normals for patch.
const Field< PointType > & faceCentres() const
Return face centres for patch.
PrimitivePatch(const FaceList &faces, const Field< PointType > &points)
Construct from components.
surfaceTopo
Enumeration defining the surface type. Used in check routines.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:61
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)
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=*(cellModeller::lookup("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]=cellShape(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, &mergedCyclicPolyPatch::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:229