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-2019 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 unit normals
172  mutable Field<PointType>* faceNormalsPtr_;
173 
174  //- Point unit normals
175  mutable Field<PointType>* pointNormalsPtr_;
176 
177 
178  // Private Member Functions
179 
180  //- Calculate edges of the patch
181  void calcIntBdryEdges() const;
182 
183  //- Calculated boundary points on a patch
184  void calcBdryPoints() const;
185 
186  //- Calculate addressing
187  void calcAddressing() const;
188 
189  //- Calculate point-edge addressing
190  void calcPointEdges() const;
191 
192  //- Calculate point-face addressing
193  void calcPointFaces() const;
194 
195  //- Calculate mesh addressing
196  void calcMeshData() const;
197 
198  //- Calculate mesh point map
199  void calcMeshPointMap() const;
200 
201  //- Calculate outside edge loops
202  void calcEdgeLoops() const;
203 
204  //- Calculate local points
205  void calcLocalPoints() const;
206 
207  //- Calculate local point order
208  void calcLocalPointOrder() const;
209 
210  //- Calculate face centres
211  void calcFaceCentres() const;
212 
213  //- Calculate unit face normals
214  void calcFaceNormals() const;
215 
216  //- Calculate unit point normals
217  void calcPointNormals() const;
218 
219  //- Calculate edge owner
220  void calcEdgeOwner() const;
221 
222 
223  //- Face-edge-face walk while remaining on a patch point.
224  // Used to determine if surface multiply connected through point.
225  void visitPointRegion
226  (
227  const label pointi,
228  const labelList& pFaces,
229  const label startFacei,
230  const label startEdgeI,
231  boolList& pFacesHad
232  ) const;
233 
234 
235 public:
236 
237  // Constructors
238 
239  //- Construct from components
241  (
242  const FaceList& faces,
243  const Field<PointType>& points
244  );
245 
246  //- Move constructor from components
248  (
249  FaceList&& faces,
251  );
252 
253  //- Move constructor from components
255  (
256  FaceList&& faces,
258  );
259 
260  //- Construct from components, reuse storage
262  (
263  FaceList& faces,
265  const bool reuse
266  );
267 
268  //- Copy constructor
270  (
272  );
273 
274  //- Move constructor
276  (
278  );
279 
280  //- Construct and return a clone
282  {
284  (
286  );
287  }
288 
289  //- Construct from Istream
291  (
292  Istream&,
293  const Field<PointType>& points
294  );
296  class iNew
297  {
298  const Field<PointType>& points_;
299 
300  public:
302  iNew(const Field<PointType>& points)
303  :
304  points_(points)
305  {}
306 
308  (
309  Istream& is
310  ) const
311  {
313  (
314  new PrimitivePatch<FaceList, PointField>(is, points_)
315  );
316  }
317  };
318 
319 
320  //- Destructor
321  virtual ~PrimitivePatch();
322 
323 
324  // Member Functions
325 
326  // Access
327 
328  //- Return reference to global points
329  const Field<PointType>& points() const
330  {
331  return points_;
332  }
333 
334 
335  // Access functions for Topological data; no mesh required.
336 
337  //- Return number of points supporting patch faces
338  label nPoints() const
339  {
340  return meshPoints().size();
341  }
342 
343  //- Return number of edges in patch
344  label nEdges() const
345  {
346  return edges().size();
347  }
348 
349  //- Return list of edges, address into LOCAL point list
350  const edgeList& edges() const;
351 
352  //- Number of internal edges
353  label nInternalEdges() const;
354 
355  //- Is internal edge?
356  bool isInternalEdge(const label edgeI) const
357  {
358  return edgeI < nInternalEdges();
359  }
360 
361  //- Return list of boundary points,
362  // address into LOCAL point list
363  const labelList& boundaryPoints() const;
364 
365  //- Return face-face addressing
366  const labelListList& faceFaces() const;
367 
368  //- Return edge-face addressing
369  const labelListList& edgeFaces() const;
370 
371  //- Return face-edge addressing
372  const labelListList& faceEdges() const;
373 
374  //- Return point-edge addressing
375  const labelListList& pointEdges() const;
376 
377  //- Return point-face addressing
378  const labelListList& pointFaces() const;
379 
380  //- Return patch faces addressing into local point list
381  const List<FaceType>& localFaces() const;
382 
383 
384  // Addressing into mesh
385 
386  //- Return labelList of mesh points in patch. They are constructed
387  // walking through the faces in incremental order and not sorted
388  // anymore.
389  const labelList& meshPoints() const;
390 
391  //- Mesh point map. Given the global point index find its
392  // location in the patch
393  const Map<label>& meshPointMap() const;
394 
395  //- Return pointField of points in patch
396  const Field<PointType>& localPoints() const;
397 
398  //- Return orders the local points for most efficient search
399  const labelList& localPointOrder() const;
400 
401  //- Given a global point index, return the local point index.
402  // If the point is not found, return -1
403  label whichPoint(const label gp) const;
404 
405  //- Given an edge in local point labels, return its
406  // index in the edge list. If the edge is not found, return -1
407  label whichEdge(const edge&) const;
408 
409  //- Return labels of patch edges in the global edge list using
410  // cell addressing
412  (
413  const edgeList& allEdges,
414  const labelListList& cellEdges,
415  const labelList& faceCells
416  ) const;
417 
418  //- Return labels of patch edges in the global edge list using
419  // basic edge addressing.
421  (
422  const edgeList& allEdges,
423  const labelListList& pointEdges
424  ) const;
425 
426  //- Return face centres for patch
427  const Field<PointType>& faceCentres() const;
428 
429  //- Return face normals for patch
430  const Field<PointType>& faceNormals() const;
431 
432  //- Return point normals for patch
433  const Field<PointType>& pointNormals() const;
434 
435 
436  // Other patch operations
437 
438  //- Project vertices of patch onto another patch
439  template<class ToPatch>
441  (
442  const ToPatch& targetPatch,
443  const Field<PointType>& projectionDirection,
448  ) const;
449 
450  //- Project vertices of patch onto another patch
451  template<class ToPatch>
453  (
454  const ToPatch& targetPatch,
455  const Field<PointType>& projectionDirection,
460  ) const;
461 
462  //- Return list of closed loops of boundary vertices.
463  // Edge loops are given as ordered lists of vertices
464  // in local addressing
465  const labelListList& edgeLoops() const;
466 
467 
468  // Check
469 
470  //- Calculate surface type formed by patch.
471  // Types:
472  // - all edges have two neighbours (manifold)
473  // - some edges have more than two neighbours (illegal)
474  // - other (open)
475  surfaceTopo surfaceType() const;
476 
477  //- Check surface formed by patch for manifoldness (see above).
478  // Return true if any incorrect edges are found.
479  // Insert vertices of incorrect edges into set.
480  bool checkTopology
481  (
482  const bool report = false,
483  labelHashSet* setPtr = nullptr
484  ) const;
485 
486  //- Checks primitivePatch for faces sharing point but not edge.
487  // This denotes a surface that is pinched at a single point
488  // (test for pinched at single edge is already in PrimitivePatch)
489  // Returns true if this situation found and puts conflicting
490  // (mesh)point in set. Based on all the checking routines in
491  // primitiveMesh.
492  bool checkPointManifold
493  (
494  const bool report = false,
495  labelHashSet* setPtr = nullptr
496  ) const;
497 
498 
499  // Edit
500 
501  void clearOut();
502 
503  void clearGeom();
504 
505  void clearTopology();
506 
507  void clearPatchMeshAddr();
508 
509  //- Correct patch after moving points
510  virtual void movePoints(const Field<PointType>&);
511 
512 
513  // Member Operators
514 
515  //- Assignment operator
516  void operator=
517  (
519  );
520 
521  //- Move assignment operator
522  void operator=
523  (
525  );
526 };
527 
528 
529 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
530 
531 } // End namespace Foam
532 
533 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
534 
535 #ifdef NoRepository
536  #include "PrimitivePatch.C"
537 #endif
538 
539 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
540 
541 #endif
542 
543 // ************************************************************************* //
TemplateName(blendedSchemeBase)
const labelListList & pointEdges() const
Return point-edge addressing.
label nPoints() const
Return number of points supporting patch faces.
virtual void movePoints(const Field< PointType > &)
Correct patch after moving points.
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
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.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
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.
virtual autoPtr< PrimitivePatch< FaceList, PointField > > clone() const
Construct and return a clone.
const labelListList & edgeLoops() const
Return list of closed loops of boundary vertices.
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.
iNew(const Field< PointType > &points)
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?
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.
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.
virtual ~PrimitivePatch()
Destructor.
const Field< PointType > & pointNormals() const
Return point normals for patch.
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
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, &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
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.