FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/boolList.H>
55 #include <OpenFOAM/labelList.H>
56 #include <OpenFOAM/edgeList.H>
57 #include <OpenFOAM/point.H>
58 #include <OpenFOAM/intersection.H>
59 #include <OpenFOAM/HashSet.H>
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 namespace Foam
64 {
65 
66 class face;
67 class objectHit;
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 >
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.
107  {
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, reuse storage
248  (
249  FaceList<Face>& faces,
251  const bool reUse
252  );
253 
254  //- Construct as copy
256  (
258  );
259 
260 
261  // Destructor
262 
263  virtual ~PrimitivePatch();
264 
265  void clearOut();
266 
267  void clearGeom();
268 
269  void clearTopology();
270 
271  void clearPatchMeshAddr();
272 
273 
274  // Member Functions
275 
276  // Access
277 
278  //- Return reference to global points
279  const Field<PointType>& points() const
280  {
281  return points_;
282  }
283 
284 
285  // Access functions for demand driven data
286 
287  // Topological data; no mesh required.
288 
289  //- Return number of points supporting patch faces
290  label nPoints() const
291  {
292  return meshPoints().size();
293  }
294 
295  //- Return number of edges in patch
296  label nEdges() const
297  {
298  return edges().size();
299  }
300 
301  //- Return list of edges, address into LOCAL point list
302  const edgeList& edges() const;
303 
304  //- Number of internal edges
305  label nInternalEdges() const;
306 
307  //- Is internal edge?
308  bool isInternalEdge(const label edgeI) const
309  {
310  return edgeI < nInternalEdges();
311  }
312 
313  //- Return list of boundary points,
314  // address into LOCAL point list
315  const labelList& boundaryPoints() const;
316 
317  //- Return face-face addressing
318  const labelListList& faceFaces() const;
319 
320  //- Return edge-face addressing
321  const labelListList& edgeFaces() const;
322 
323  //- Return face-edge addressing
324  const labelListList& faceEdges() const;
325 
326  //- Return point-edge addressing
327  const labelListList& pointEdges() const;
328 
329  //- Return point-face addressing
330  const labelListList& pointFaces() const;
331 
332  //- Return patch faces addressing into local point list
333  const List<Face>& localFaces() const;
334 
335 
336  // Addressing into mesh
337 
338  //- Return labelList of mesh points in patch. They are constructed
339  // walking through the faces in incremental order and not sorted
340  // anymore.
341  const labelList& meshPoints() const;
342 
343  //- Mesh point map. Given the global point index find its
344  // location in the patch
345  const Map<label>& meshPointMap() const;
346 
347  //- Return pointField of points in patch
348  const Field<PointType>& localPoints() const;
349 
350  //- Return orders the local points for most efficient search
351  const labelList& localPointOrder() const;
352 
353  //- Given a global point index, return the local point index.
354  // If the point is not found, return -1
355  label whichPoint(const label gp) const;
356 
357  //- Given an edge in local point labels, return its
358  // index in the edge list. If the edge is not found, return -1
359  label whichEdge(const edge&) const;
360 
361  //- Return labels of patch edges in the global edge list using
362  // cell addressing
364  (
365  const edgeList& allEdges,
366  const labelListList& cellEdges,
367  const labelList& faceCells
368  ) const;
369 
370  //- Return labels of patch edges in the global edge list using
371  // basic edge addressing.
373  (
374  const edgeList& allEdges,
376  ) const;
377 
378  //- Return face centres for patch
379  const Field<PointType>& faceCentres() const;
380 
381  //- Return face normals for patch
382  const Field<PointType>& faceNormals() const;
383 
384  //- Return point normals for patch
385  const Field<PointType>& pointNormals() const;
386 
387 
388  // Other patch operations
389 
390  //- Project vertices of patch onto another patch
391  template <class ToPatch>
393  (
394  const ToPatch& targetPatch,
395  const Field<PointType>& projectionDirection,
398  ) const;
399 
400  //- Project vertices of patch onto another patch
401  template <class ToPatch>
403  (
404  const ToPatch& targetPatch,
405  const Field<PointType>& projectionDirection,
408  ) const;
409 
410  //- Return list of closed loops of boundary vertices.
411  // Edge loops are given as ordered lists of vertices
412  // in local addressing
413  const labelListList& edgeLoops() const;
414 
415 
416  // Check
417 
418  //- Calculate surface type formed by patch.
419  // - all edges have two neighbours (manifold)
420  // - some edges have more than two neighbours (illegal)
421  // - other (open)
422  surfaceTopo surfaceType() const;
423 
424  //- Check surface formed by patch for manifoldness (see above).
425  // Return true if any incorrect edges are found.
426  // Insert vertices of incorrect edges into set.
427  bool checkTopology
428  (
429  const bool report = false,
430  labelHashSet* setPtr = NULL
431  ) const;
432 
433  //- Checks primitivePatch for faces sharing point but not edge.
434  // This denotes a surface that is pinched at a single point
435  // (test for pinched at single edge is already in PrimitivePatch)
436  // Returns true if this situation found and puts conflicting
437  // (mesh)point in set. Based on all the checking routines in
438  // primitiveMesh.
439  bool checkPointManifold
440  (
441  const bool report = false,
442  labelHashSet* setPtr = NULL
443  ) const;
444 
445 
446  // Edit
447 
448  //- Correct patch after moving points
449  virtual void movePoints(const Field<PointType>&);
450 
451 
452  // Member operators
453 
454  //- Assignment
455  void operator=
456  (
458  );
459 };
460 
461 
462 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
463 
464 } // End namespace Foam
465 
466 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
467 
468 #ifdef NoRepository
469 # include "PrimitivePatch_.C"
470 #endif
471 
472 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
473 
474 #endif
475 
476 // ************************ vim: set sw=4 sts=4 et: ************************ //