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-2020 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  //- Move constructor from components
261  (
262  FaceList&& faces,
264  );
265 
266  //- Construct from components, reuse storage
268  (
269  FaceList& faces,
271  const bool reuse
272  );
273 
274  //- Copy constructor
276  (
278  );
279 
280  //- Move constructor
282  (
284  );
285 
286  //- Construct and return a clone
288  {
290  (
292  );
293  }
294 
295  //- Construct from Istream
297  (
298  Istream&,
299  const Field<PointType>& points
300  );
302  class iNew
303  {
304  const Field<PointType>& points_;
305 
306  public:
308  iNew(const Field<PointType>& points)
309  :
310  points_(points)
311  {}
312 
314  (
315  Istream& is
316  ) const
317  {
319  (
320  new PrimitivePatch<FaceList, PointField>(is, points_)
321  );
322  }
323  };
324 
325 
326  //- Destructor
327  virtual ~PrimitivePatch();
328 
329 
330  // Member Functions
331 
332  // Access
333 
334  //- Return reference to global points
335  const Field<PointType>& points() const
336  {
337  return points_;
338  }
339 
340 
341  // Access functions for Topological data; no mesh required.
342 
343  //- Return number of points supporting patch faces
344  label nPoints() const
345  {
346  return meshPoints().size();
347  }
348 
349  //- Return number of edges in patch
350  label nEdges() const
351  {
352  return edges().size();
353  }
354 
355  //- Return list of edges, address into LOCAL point list
356  const edgeList& edges() const;
357 
358  //- Number of internal edges
359  label nInternalEdges() const;
360 
361  //- Is internal edge?
362  bool isInternalEdge(const label edgeI) const
363  {
364  return edgeI < nInternalEdges();
365  }
366 
367  //- Return list of boundary points,
368  // address into LOCAL point list
369  const labelList& boundaryPoints() const;
370 
371  //- Return face-face addressing
372  const labelListList& faceFaces() const;
373 
374  //- Return edge-face addressing
375  const labelListList& edgeFaces() const;
376 
377  //- Return face-edge addressing
378  const labelListList& faceEdges() const;
379 
380  //- Return point-edge addressing
381  const labelListList& pointEdges() const;
382 
383  //- Return point-face addressing
384  const labelListList& pointFaces() const;
385 
386  //- Return patch faces addressing into local point list
387  const List<FaceType>& localFaces() const;
388 
389 
390  // Addressing into mesh
391 
392  //- Return labelList of mesh points in patch. They are constructed
393  // walking through the faces in incremental order and not sorted
394  // anymore.
395  const labelList& meshPoints() const;
396 
397  //- Mesh point map. Given the global point index find its
398  // location in the patch
399  const Map<label>& meshPointMap() const;
400 
401  //- Return pointField of points in patch
402  const Field<PointType>& localPoints() const;
403 
404  //- Return orders the local points for most efficient search
405  const labelList& localPointOrder() const;
406 
407  //- Given a global point index, return the local point index.
408  // If the point is not found, return -1
409  label whichPoint(const label gp) const;
410 
411  //- Given an edge in local point labels, return its
412  // index in the edge list. If the edge is not found, return -1
413  label whichEdge(const edge&) const;
414 
415  //- Return labels of patch edges in the global edge list using
416  // cell addressing
418  (
419  const edgeList& allEdges,
420  const labelListList& cellEdges,
421  const labelList& faceCells
422  ) const;
423 
424  //- Return labels of patch edges in the global edge list using
425  // basic edge addressing.
427  (
428  const edgeList& allEdges,
429  const labelListList& pointEdges
430  ) const;
431 
432  //- Return face centres for patch
433  const Field<PointType>& faceCentres() const;
434 
435  //- Return face areas for patch
436  const Field<PointType>& faceAreas() const;
437 
438  //- Return face normals for patch
439  const Field<PointType>& faceNormals() const;
440 
441  //- Return point normals for patch
442  const Field<PointType>& pointNormals() const;
443 
444 
445  // Other patch operations
446 
447  //- Project vertices of patch onto another patch
448  template<class ToPatch>
450  (
451  const ToPatch& targetPatch,
452  const Field<PointType>& projectionDirection,
457  ) const;
458 
459  //- Project vertices of patch onto another patch
460  template<class ToPatch>
462  (
463  const ToPatch& targetPatch,
464  const Field<PointType>& projectionDirection,
469  ) const;
470 
471  //- Return list of closed loops of boundary vertices.
472  // Edge loops are given as ordered lists of vertices
473  // in local addressing
474  const labelListList& edgeLoops() const;
475 
476 
477  // Check
478 
479  //- Calculate surface type formed by patch.
480  // Types:
481  // - all edges have two neighbours (manifold)
482  // - some edges have more than two neighbours (illegal)
483  // - other (open)
484  surfaceTopo surfaceType() const;
485 
486  //- Check surface formed by patch for manifoldness (see above).
487  // Return true if any incorrect edges are found.
488  // Insert vertices of incorrect edges into set.
489  bool checkTopology
490  (
491  const bool report = false,
492  labelHashSet* setPtr = nullptr
493  ) const;
494 
495  //- Checks primitivePatch for faces sharing point but not edge.
496  // This denotes a surface that is pinched at a single point
497  // (test for pinched at single edge is already in PrimitivePatch)
498  // Returns true if this situation found and puts conflicting
499  // (mesh)point in set. Based on all the checking routines in
500  // primitiveMesh.
501  bool checkPointManifold
502  (
503  const bool report = false,
504  labelHashSet* setPtr = nullptr
505  ) const;
506 
507 
508  // Edit
509 
510  void clearOut();
511 
512  void clearGeom();
513 
514  void clearTopology();
515 
516  void clearPatchMeshAddr();
517 
518  //- Correct patch after moving points
519  virtual void movePoints(const Field<PointType>&);
520 
521 
522  // Member Operators
523 
524  //- Assignment operator
525  void operator=
526  (
528  );
529 
530  //- Move assignment operator
531  void operator=
532  (
534  );
535 };
536 
537 
538 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
539 
540 } // End namespace Foam
541 
542 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
543 
544 #ifdef NoRepository
545  #include "PrimitivePatch.C"
546 #endif
547 
548 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
549 
550 #endif
551 
552 // ************************************************************************* //
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: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.
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 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.
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.
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.
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
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.