FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

booleanSurface.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::booleanSurface
00026 
00027 Description
00028     Surface-surface intersection. Given two surfaces construct combined surface.
00029 
00030     Called 'boolean' since the volume of resulting surface will encompass
00031     the volumes of the original surface according to some boolean operation:
00032     - all which is in surface1 AND in surface2 (intersection)
00033     - all which is in surface1 AND NOT in surface2 ('chop' out surface2)
00034     - all which is in surface1 OR in surface2 (union)
00035 
00036     Algorithm:
00037     -# find edge-surface intersection. Class 'surfaceIntersection'.
00038     -# combine intersection with both surfaces. Class 'intersectedSurface'.
00039     -# subset surfaces upto intersection. The 'side' of the surface to
00040        include is based on the faces that can be reached from a
00041        user-supplied face index.
00042     -# merge surfaces. Only the points on the intersection are shared.
00043 
00044 SourceFiles
00045     booleanSurface.C
00046 
00047 \*---------------------------------------------------------------------------*/
00048 
00049 #ifndef booleanSurface_H
00050 #define booleanSurface_H
00051 
00052 #include <triSurface/triSurface.H>
00053 #include <meshTools/surfaceIntersection.H>
00054 #include <OpenFOAM/typeInfo.H>
00055 
00056 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00057 
00058 namespace Foam
00059 {
00060 
00061 // Forward declaration of classes
00062 class triSurfaceSearch;
00063 class intersectedSurface;
00064 
00065 /*---------------------------------------------------------------------------*\
00066                            Class booleanSurface Declaration
00067 \*---------------------------------------------------------------------------*/
00068 
00069 class booleanSurface
00070 :
00071     public triSurface
00072 {
00073     // Data types
00074 
00075         //- Enumeration listing the status of a face (visible/invisible from
00076         //  outside)
00077         enum sideStat
00078         {
00079             UNVISITED,
00080             OUTSIDE,
00081             INSIDE
00082         };
00083 
00084     // Private data
00085 
00086         //- From new to old face + surface:
00087         //     >0 : to face on surface1
00088         //     <0 : to face on surface2. Negate and offset by one to get
00089         //          face2 (e.g. face2I = -faceMap[]-1)
00090         labelList faceMap_;
00091 
00092     // Private Member Functions
00093 
00094         //- Check whether subset of faces (from markZones) reaches up to
00095         //  the intersection.
00096         static void checkIncluded
00097         (
00098             const intersectedSurface& surf,
00099             const labelList& faceZone,
00100             const label includedFace
00101         );
00102 
00103         //- Get label in elems of elem.
00104         static label index(const labelList& elems, const label elem);
00105 
00106         //- Find index of edge e in subset edgeLabels.
00107         static label findEdge
00108         (
00109             const edgeList& edges,
00110             const labelList& edgeLabels,
00111             const edge& e
00112         );
00113 
00114         //- Get index of face in zoneI whose faceCentre is nearest farAwayPoint
00115         static label findNearest
00116         (
00117             const triSurface& surf,
00118             const labelList& faceZone,
00119             const label zoneI
00120         );
00121 
00122         //- Generate combined patchList (returned). Sets patchMap to map from
00123         // surf region numbers into combined patchList
00124         static geometricSurfacePatchList mergePatches
00125         (
00126             const triSurface& surf1,
00127             const triSurface& surf2,
00128             labelList& patchMap2
00129         );
00130 
00131         //- On edgeI, coming from face prevFace, determines visibility/side of
00132         // all the other faces using the edge.
00133         static void propagateEdgeSide
00134         (
00135             const triSurface& surf,
00136             const label prevVert0,
00137             const label prevFaceI,
00138             const label prevState,
00139             const label edgeI,
00140             labelList& side
00141         );
00142 
00143         //- Given in/outside status of face determines status for all
00144         //  neighbouring faces.
00145         static void propagateSide
00146         (
00147             const triSurface& surf,
00148             const label prevState,
00149             const label faceI,
00150             labelList& side
00151         );
00152 
00153 public:
00154 
00155     ClassName("booleanSurface");
00156 
00157 
00158     // Data types
00159 
00160         //- Enumeration listing the possible volume operator types
00161         enum booleanOpType
00162         {
00163             OR,     // Union of volumes
00164             AND,    // Intersection of volumes
00165             XOR,    // Difference of volumes
00166             ALL     // Special: does not subset combined surface. (Produces
00167                     // multiply connected surface)
00168         };
00169 
00170 
00171     // Constructors
00172 
00173         //- Construct null
00174         booleanSurface();
00175 
00176         //- Construct from surfaces and face labels to keep.
00177         //  Walks from provided seed faces without crossing intersection line 
00178         //  to determine faces to keep.
00179         booleanSurface
00180         (
00181             const triSurface& surf1,
00182             const triSurface& surf2,
00183             const surfaceIntersection& inter,
00184             const label includeFace1,
00185             const label includeFace2
00186         );
00187 
00188         //- Construct from surfaces and operation. Surfaces need to be closed
00189         //  for this to make any sense since uses inside/outside to determine
00190         //  which part of combined surface to include.
00191         booleanSurface
00192         (
00193             const triSurface& surf1,
00194             const triSurface& surf2,
00195             const surfaceIntersection& inter,
00196             const label booleanOp
00197         );
00198 
00199 
00200     // Member Functions
00201 
00202         //- new to old face map. >0: surface 1 face label. <0: surface 2. Negate
00203         //  and subtract 1 to get face label on surface 2.
00204         const labelList& faceMap() const
00205         {
00206             return faceMap_;
00207         }
00208 
00209         bool from1(const label faceI) const
00210         {
00211             return faceMap_[faceI] >= 0;
00212         }
00213 
00214         bool surf1Face(const label faceI) const
00215         {
00216             if (!from1(faceI))
00217             {
00218                 FatalErrorIn("booleanSurface::surf1Face(const label)")
00219                     << "face " << faceI << " not from surface 1"
00220                     << abort(FatalError);
00221             }
00222             return faceMap_[faceI];
00223         }
00224 
00225         bool surf2Face(const label faceI) const
00226         {
00227             if (from1(faceI))
00228             {
00229                 FatalErrorIn("booleanSurface::surf2Face(const label)")
00230                     << "face " << faceI << " not from surface 2"
00231                     << abort(FatalError);
00232             }
00233             return -faceMap_[faceI]-1;
00234         }
00235 
00236 
00237 };
00238 
00239 
00240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00241 
00242 } // End namespace Foam
00243 
00244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00245 
00246 #endif
00247 
00248 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines