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