FreeFOAM The Cross-Platform CFD Toolkit
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) 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::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 ('chop' out 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/triSurface.H>
54 #include <OpenFOAM/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 
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  // Private data
85 
86  //- From new to old face + surface:
87  // >0 : to face on surface1
88  // <0 : to face on surface2. Negate and offset by one to get
89  // face2 (e.g. face2I = -faceMap[]-1)
90  labelList faceMap_;
91 
92  // Private Member Functions
93 
94  //- Check whether subset of faces (from markZones) reaches up to
95  // the intersection.
96  static void checkIncluded
97  (
98  const intersectedSurface& surf,
99  const labelList& faceZone,
100  const label includedFace
101  );
102 
103  //- Get label in elems of elem.
104  static label index(const labelList& elems, const label elem);
105 
106  //- Find index of edge e in subset edgeLabels.
107  static label findEdge
108  (
109  const edgeList& edges,
110  const labelList& edgeLabels,
111  const edge& e
112  );
113 
114  //- Get index of face in zoneI whose faceCentre is nearest farAwayPoint
115  static label findNearest
116  (
117  const triSurface& surf,
118  const labelList& faceZone,
119  const label zoneI
120  );
121 
122  //- Generate combined patchList (returned). Sets patchMap to map from
123  // surf region numbers into combined patchList
124  static geometricSurfacePatchList mergePatches
125  (
126  const triSurface& surf1,
127  const triSurface& surf2,
128  labelList& patchMap2
129  );
130 
131  //- On edgeI, coming from face prevFace, determines visibility/side of
132  // all the other faces using the edge.
133  static void propagateEdgeSide
134  (
135  const triSurface& surf,
136  const label prevVert0,
137  const label prevFaceI,
138  const label prevState,
139  const label edgeI,
140  labelList& side
141  );
142 
143  //- Given in/outside status of face determines status for all
144  // neighbouring faces.
145  static void propagateSide
146  (
147  const triSurface& surf,
148  const label prevState,
149  const label faceI,
150  labelList& side
151  );
152 
153 public:
154 
155  ClassName("booleanSurface");
156 
157 
158  // Data types
159 
160  //- Enumeration listing the possible volume operator types
162  {
163  OR, // Union of volumes
164  AND, // Intersection of volumes
165  XOR, // Difference of volumes
166  ALL // Special: does not subset combined surface. (Produces
167  // multiply connected surface)
168  };
169 
170 
171  // Constructors
172 
173  //- Construct null
174  booleanSurface();
175 
176  //- Construct from surfaces and face labels to keep.
177  // Walks from provided seed faces without crossing intersection line
178  // to determine faces to keep.
180  (
181  const triSurface& surf1,
182  const triSurface& surf2,
183  const surfaceIntersection& inter,
184  const label includeFace1,
185  const label includeFace2
186  );
187 
188  //- Construct from surfaces and operation. Surfaces need to be closed
189  // for this to make any sense since uses inside/outside to determine
190  // which part of combined surface to include.
192  (
193  const triSurface& surf1,
194  const triSurface& surf2,
195  const surfaceIntersection& inter,
196  const label booleanOp
197  );
198 
199 
200  // Member Functions
201 
202  //- new to old face map. >0: surface 1 face label. <0: surface 2. Negate
203  // and subtract 1 to get face label on surface 2.
204  const labelList& faceMap() const
205  {
206  return faceMap_;
207  }
208 
209  bool from1(const label faceI) const
210  {
211  return faceMap_[faceI] >= 0;
212  }
213 
214  bool surf1Face(const label faceI) const
215  {
216  if (!from1(faceI))
217  {
218  FatalErrorIn("booleanSurface::surf1Face(const label)")
219  << "face " << faceI << " not from surface 1"
220  << abort(FatalError);
221  }
222  return faceMap_[faceI];
223  }
224 
225  bool surf2Face(const label faceI) const
226  {
227  if (from1(faceI))
228  {
229  FatalErrorIn("booleanSurface::surf2Face(const label)")
230  << "face " << faceI << " not from surface 2"
231  << abort(FatalError);
232  }
233  return -faceMap_[faceI]-1;
234  }
235 
236 
237 };
238 
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 } // End namespace Foam
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 #endif
247 
248 // ************************ vim: set sw=4 sts=4 et: ************************ //