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 | Copyright (C) 2011-2016 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
82 <
83  class Face,
84  template<class> class FaceList,
85  class PointField,
86  class PointType=point
87 >
88 class PrimitivePatch
89 :
90  public PrimitivePatchName,
91  public FaceList<Face>
92 {
93 
94 public:
95 
96  // Public typedefs
97 
98  typedef Face FaceType;
99  typedef FaceList<Face> FaceListType;
100  typedef PointField PointFieldType;
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<Face>* 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<Face>& faces,
243  const Field<PointType>& points
244  );
245 
246  //- Construct from components
248  (
249  const Xfer<FaceList<Face>>& faces,
250  const Xfer<List<PointType>>& points
251  );
252 
253  //- Construct from components, reuse storage
255  (
256  FaceList<Face>& faces,
258  const bool reuse
259  );
260 
261  //- Construct as copy
263  (
265  );
266 
267 
268  //- Destructor
269  virtual ~PrimitivePatch();
270 
271  void clearOut();
272 
273  void clearGeom();
274 
275  void clearTopology();
276 
277  void clearPatchMeshAddr();
278 
279 
280  // Member Functions
281 
282  // Access
283 
284  //- Return reference to global points
285  const Field<PointType>& points() const
286  {
287  return points_;
288  }
289 
290 
291  // Access functions for demand driven data
292 
293  // Topological data; no mesh required.
294 
295  //- Return number of points supporting patch faces
296  label nPoints() const
297  {
298  return meshPoints().size();
299  }
300 
301  //- Return number of edges in patch
302  label nEdges() const
303  {
304  return edges().size();
305  }
306 
307  //- Return list of edges, address into LOCAL point list
308  const edgeList& edges() const;
309 
310  //- Number of internal edges
311  label nInternalEdges() const;
312 
313  //- Is internal edge?
314  bool isInternalEdge(const label edgeI) const
315  {
316  return edgeI < nInternalEdges();
317  }
318 
319  //- Return list of boundary points,
320  // address into LOCAL point list
321  const labelList& boundaryPoints() const;
322 
323  //- Return face-face addressing
324  const labelListList& faceFaces() const;
325 
326  //- Return edge-face addressing
327  const labelListList& edgeFaces() const;
328 
329  //- Return face-edge addressing
330  const labelListList& faceEdges() const;
331 
332  //- Return point-edge addressing
333  const labelListList& pointEdges() const;
334 
335  //- Return point-face addressing
336  const labelListList& pointFaces() const;
337 
338  //- Return patch faces addressing into local point list
339  const List<Face>& localFaces() const;
340 
341 
342  // Addressing into mesh
343 
344  //- Return labelList of mesh points in patch. They are constructed
345  // walking through the faces in incremental order and not sorted
346  // anymore.
347  const labelList& meshPoints() const;
348 
349  //- Mesh point map. Given the global point index find its
350  // location in the patch
351  const Map<label>& meshPointMap() const;
352 
353  //- Return pointField of points in patch
354  const Field<PointType>& localPoints() const;
355 
356  //- Return orders the local points for most efficient search
357  const labelList& localPointOrder() const;
358 
359  //- Given a global point index, return the local point index.
360  // If the point is not found, return -1
361  label whichPoint(const label gp) const;
362 
363  //- Given an edge in local point labels, return its
364  // index in the edge list. If the edge is not found, return -1
365  label whichEdge(const edge&) const;
366 
367  //- Return labels of patch edges in the global edge list using
368  // cell addressing
370  (
371  const edgeList& allEdges,
372  const labelListList& cellEdges,
373  const labelList& faceCells
374  ) const;
375 
376  //- Return labels of patch edges in the global edge list using
377  // basic edge addressing.
379  (
380  const edgeList& allEdges,
381  const labelListList& pointEdges
382  ) const;
383 
384  //- Return face centres for patch
385  const Field<PointType>& faceCentres() const;
386 
387  //- Return face normals for patch
388  const Field<PointType>& faceNormals() const;
389 
390  //- Return point normals for patch
391  const Field<PointType>& pointNormals() const;
392 
393 
394  // Other patch operations
395 
396  //- Project vertices of patch onto another patch
397  template<class ToPatch>
399  (
400  const ToPatch& targetPatch,
401  const Field<PointType>& projectionDirection,
404  ) const;
405 
406  //- Project vertices of patch onto another patch
407  template<class ToPatch>
409  (
410  const ToPatch& targetPatch,
411  const Field<PointType>& projectionDirection,
414  ) const;
415 
416  //- Return list of closed loops of boundary vertices.
417  // Edge loops are given as ordered lists of vertices
418  // in local addressing
419  const labelListList& edgeLoops() const;
420 
421 
422  // Check
423 
424  //- Calculate surface type formed by patch.
425  // Types:
426  // - all edges have two neighbours (manifold)
427  // - some edges have more than two neighbours (illegal)
428  // - other (open)
429  surfaceTopo surfaceType() const;
430 
431  //- Check surface formed by patch for manifoldness (see above).
432  // Return true if any incorrect edges are found.
433  // Insert vertices of incorrect edges into set.
434  bool checkTopology
435  (
436  const bool report = false,
437  labelHashSet* setPtr = nullptr
438  ) const;
439 
440  //- Checks primitivePatch for faces sharing point but not edge.
441  // This denotes a surface that is pinched at a single point
442  // (test for pinched at single edge is already in PrimitivePatch)
443  // Returns true if this situation found and puts conflicting
444  // (mesh)point in set. Based on all the checking routines in
445  // primitiveMesh.
446  bool checkPointManifold
447  (
448  const bool report = false,
449  labelHashSet* setPtr = nullptr
450  ) const;
451 
452 
453  // Edit
454 
455  //- Correct patch after moving points
456  virtual void movePoints(const Field<PointType>&);
457 
458 
459  // Member operators
460 
461  //- Assignment
462  void operator=
463  (
465  );
466 };
467 
468 
469 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
470 
471 } // End namespace Foam
472 
473 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
474 
475 #ifdef NoRepository
476  #include "PrimitivePatch.C"
477 #endif
478 
479 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
480 
481 #endif
482 
483 // ************************************************************************* //
TemplateName(blendedSchemeBase)
const labelListList & pointEdges() const
Return point-edge addressing.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
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.
FaceList< Face > FaceListType
const Field< PointType > & pointNormals() const
Return point normals for patch.
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.
const Field< PointType > & faceCentres() const
Return face centres for patch.
const Field< PointType > & faceNormals() const
Return face normals for patch.
bool checkPointManifold(const bool report=false, labelHashSet *setPtr=nullptr) const
Checks primitivePatch for faces sharing point but not edge.
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).
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
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
bool isInternalEdge(const label edgeI) const
Is internal edge?
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
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.
PrimitivePatch(const FaceList< Face > &faces, const Field< PointType > &points)
Construct from components.
List< objectHit > projectFaceCentres(const ToPatch &targetPatch, const Field< PointType > &projectionDirection, const intersection::algorithm=intersection::FULL_RAY, const intersection::direction=intersection::VECTOR) const
Project vertices of patch onto another 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.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
label nEdges() const
Return number of edges in patch.
virtual ~PrimitivePatch()
Destructor.
List< objectHit > projectPoints(const ToPatch &targetPatch, const Field< PointType > &projectionDirection, const intersection::algorithm=intersection::FULL_RAY, const intersection::direction=intersection::VECTOR) const
Project vertices of patch onto another patch.
vector point
Point is a vector.
Definition: point.H:41
labelList meshEdges(const edgeList &allEdges, const labelListList &cellEdges, const labelList &faceCells) const
Return labels of patch edges in the global edge list using.
surfaceTopo surfaceType() const
Calculate surface type formed by patch.
const labelListList & faceEdges() const
Return face-edge addressing.
PointField PointFieldType
Namespace for OpenFOAM.