booleanSurface.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::booleanSurface
26 
27 Description
28  Surface-surface intersection. Given two surfaces construct combined surface.
29 
30  Called 'boolean' since the volume of resulting surface will encompass
31  the volumes of the original surface according to some boolean operation:
32  - all which is in surface1 AND in surface2 (intersection)
33  - all which is in surface1 AND NOT in surface2 (surface1 minus surface2)
34  - all which is in surface1 OR in surface2 (union)
35 
36  Algorithm:
37  -# find edge-surface intersection. Class 'surfaceIntersection'.
38  -# combine intersection with both surfaces. Class 'intersectedSurface'.
39  -# subset surfaces upto intersection. The 'side' of the surface to
40  include is based on the faces that can be reached from a
41  user-supplied face index.
42  -# merge surfaces. Only the points on the intersection are shared.
43 
44 SourceFiles
45  booleanSurface.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef booleanSurface_H
50 #define booleanSurface_H
51 
52 #include "triSurface.H"
53 #include "surfaceIntersection.H"
54 #include "typeInfo.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // Forward declaration of classes
62 class triSurfaceSearch;
63 class intersectedSurface;
64 
65 /*---------------------------------------------------------------------------*\
66  Class booleanSurface Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class booleanSurface
70 :
71  public triSurface
72 {
73  // Data types
74 
75  //- Enumeration listing the status of a face (visible/invisible from
76  // outside)
77  enum sideStat
78  {
79  UNVISITED,
80  OUTSIDE,
81  INSIDE
82  };
83 
84 
85  // Private data
86 
87  //- From new to old face + surface:
88  // >0 : to face on surface1
89  // <0 : to face on surface2. Negate and offset by one to get
90  // face2 (e.g. face2I = -faceMap[]-1)
91  labelList faceMap_;
92 
93 
94  // Private Member Functions
95 
96  //- Check whether subset of faces (from markZones) reaches up to
97  // the intersection.
98  static void checkIncluded
99  (
100  const intersectedSurface& surf,
101  const labelList& faceZone,
102  const label includedFace
103  );
104 
105  //- Get label in elems of elem.
106  static label index(const labelList& elems, const label elem);
107 
108  //- Find index of edge e in subset edgeLabels.
109  static label findEdge
110  (
111  const edgeList& edges,
112  const labelList& edgeLabels,
113  const edge& e
114  );
115 
116  //- Get index of face in zoneI whose faceCentre is nearest farAwayPoint
117  static label findNearest
118  (
119  const triSurface& surf,
120  const labelList& faceZone,
121  const label zoneI
122  );
123 
124  //- Generate combined patchList (returned). Sets patchMap to map from
125  // surf region numbers into combined patchList
126  static geometricSurfacePatchList mergePatches
127  (
128  const triSurface& surf1,
129  const triSurface& surf2,
130  labelList& patchMap2
131  );
132 
133  //- On edgeI, coming from face prevFace, determines visibility/side of
134  // all the other faces using the edge.
135  static void propagateEdgeSide
136  (
137  const triSurface& surf,
138  const label prevVert0,
139  const label prevFacei,
140  const label prevState,
141  const label edgeI,
142  labelList& side
143  );
144 
145  //- Given in/outside status of face determines status for all
146  // neighbouring faces.
147  static void propagateSide
148  (
149  const triSurface& surf,
150  const label prevState,
151  const label facei,
152  labelList& side
153  );
154 
155 
156 public:
157 
158  ClassName("booleanSurface");
159 
160 
161  // Data types
162 
163  //- Enumeration listing the possible volume operator types
164  enum booleanOpType
165  {
166  UNION, // Union of volumes
167  INTERSECTION, // Intersection of volumes
168  DIFFERENCE, // Difference of volumes
169  ALL // Special: does not subset combined
170  // surface. (Produces multiply connected surface)
171  };
172 
173 
174  // Constructors
175 
176  //- Construct null
177  booleanSurface();
178 
179  //- Construct from surfaces and face labels to keep.
180  // Walks from provided seed faces without crossing intersection line
181  // to determine faces to keep.
183  (
184  const triSurface& surf1,
185  const triSurface& surf2,
186  const surfaceIntersection& inter,
187  const label includeFace1,
188  const label includeFace2
189  );
190 
191  //- Construct from surfaces and operation. Surfaces need to be closed
192  // for this to make any sense since uses inside/outside to determine
193  // which part of combined surface to include.
195  (
196  const triSurface& surf1,
197  const triSurface& surf2,
198  const surfaceIntersection& inter,
199  const label booleanOp
200  );
201 
202 
203  // Member Functions
204 
205  //- New to old face map. >0: surface 1 face label. <0: surface 2. Negate
206  // and subtract 1 to get face label on surface 2.
207  const labelList& faceMap() const
208  {
209  return faceMap_;
210  }
212  bool from1(const label facei) const
213  {
214  return faceMap_[facei] >= 0;
215  }
217  bool surf1Face(const label facei) const
218  {
219  if (!from1(facei))
220  {
222  << "face " << facei << " not from surface 1"
223  << abort(FatalError);
224  }
225  return faceMap_[facei];
226  }
228  bool surf2Face(const label facei) const
229  {
230  if (from1(facei))
231  {
233  << "face " << facei << " not from surface 2"
234  << abort(FatalError);
235  }
236  return -faceMap_[facei]-1;
237  }
238 };
239 
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 } // End namespace Foam
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 #endif
248 
249 // ************************************************************************* //
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
booleanSurface()
Construct null.
const labelList & faceMap() const
New to old face map. >0: surface 1 face label. <0: surface 2. Negate.
const double e
Elementary charge.
Definition: doubleFloat.H:78
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Surface-surface intersection. Given two surfaces construct combined surface.
Basic surface-surface intersection description. Constructed from two surfaces it creates a descriptio...
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
bool surf2Face(const label facei) const
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
Given triSurface and intersection creates the intersected (properly triangulated) surface...
errorManip< error > abort(error &err)
Definition: errorManip.H:131
ClassName("booleanSurface")
bool surf1Face(const label facei) const
booleanOpType
Enumeration listing the possible volume operator types.
bool from1(const label facei) const
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Triangulated surface description with patch information.
Definition: triSurface.H:65
Namespace for OpenFOAM.