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

MeshedSurface.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::MeshedSurface
00026 
00027 Description
00028     A surface geometry mesh with zone information, not to be confused with
00029     the similarly named surfaceMesh, which actually refers to the cell faces
00030     of a volume mesh.
00031 
00032     A MeshedSurface can have zero or more surface zones (roughly equivalent
00033     to faceZones for a polyMesh). If surface zones are defined, they must
00034     be contiguous and cover all of the faces.
00035 
00036     The MeshedSurface is intended for surfaces from a variety of sources.
00037     - A set of points and faces without any surface zone information.
00038     - A set of points and faces with randomly ordered zone information.
00039       This could arise, for example, from reading external file formats
00040       such as STL, etc.
00041 
00042 SourceFiles
00043     MeshedSurface.C
00044 
00045 \*---------------------------------------------------------------------------*/
00046 
00047 #ifndef MeshedSurface_H
00048 #define MeshedSurface_H
00049 
00050 #include <OpenFOAM/PrimitivePatch_.H>
00051 #include <OpenFOAM/PatchTools.H>
00052 #include <OpenFOAM/pointField.H>
00053 #include <OpenFOAM/face.H>
00054 #include <OpenFOAM/triFace.H>
00055 
00056 #include <surfMesh/surfZoneList.H>
00057 #include <surfMesh/surfaceFormatsCore.H>
00058 #include <OpenFOAM/runTimeSelectionTables.H>
00059 #include <OpenFOAM/memberFunctionSelectionTables.H>
00060 #include <OpenFOAM/HashSet.H>
00061 
00062 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00063 
00064 namespace Foam
00065 {
00066 
00067 // Forward declaration of friend functions and operators
00068 
00069 class Time;
00070 class surfMesh;
00071 class polyBoundaryMesh;
00072 
00073 template<class Face> class MeshedSurface;
00074 template<class Face> class MeshedSurfaceProxy;
00075 template<class Face> class UnsortedMeshedSurface;
00076 
00077 /*---------------------------------------------------------------------------*\
00078                       Class MeshedSurface Declaration
00079 \*---------------------------------------------------------------------------*/
00080 
00081 template<class Face>
00082 class MeshedSurface
00083 :
00084     public PrimitivePatch<Face, ::Foam::List, pointField, point>,
00085     public fileFormats::surfaceFormatsCore
00086 {
00087     // friends - despite different face representationsx
00088     template<class Face2> friend class MeshedSurface;
00089     template<class Face2> friend class UnsortedMeshedSurface;
00090     friend class surfMesh;
00091 
00092 private:
00093 
00094     //- Private typedefs for convenience
00095 
00096         typedef PrimitivePatch
00097         <
00098             Face,
00099             ::Foam::List,
00100             pointField,
00101             point
00102         >
00103         ParentType;
00104 
00105         typedef UnsortedMeshedSurface<Face>  FriendType;
00106         typedef MeshedSurfaceProxy<Face>     ProxyType;
00107 
00108     // Private Member Data
00109 
00110         //- Zone information
00111         // (face ordering nFaces/startFace only used during reading/writing)
00112         List<surfZone> zones_;
00113 
00114 
00115     // Private member functions
00116 
00117 protected:
00118 
00119     // Protected Member functions
00120 
00121         //- Transfer points/zones and transcribe face -> triFace
00122         void transcribe(MeshedSurface<face>&);
00123 
00124         //- basic sanity check on zones
00125         void checkZones();
00126 
00127         //- Non-const access to global points
00128         pointField& storedPoints()
00129         {
00130             return const_cast<pointField&>(ParentType::points());
00131         }
00132 
00133         //- Non-const access to the faces
00134         List<Face>& storedFaces()
00135         {
00136             return static_cast<List<Face> &>(*this);
00137         }
00138 
00139         //- Non-const access to the zones
00140         surfZoneList& storedZones()
00141         {
00142             return zones_;
00143         }
00144 
00145         //- sort faces by zones and store sorted faces
00146         void sortFacesAndStore
00147         (
00148             const Xfer< List<Face> >& unsortedFaces,
00149             const Xfer< List<label> >& zoneIds,
00150             const bool sorted
00151         );
00152 
00153         //- Set new zones from faceMap
00154         virtual void remapFaces(const UList<label>& faceMap);
00155 
00156 public:
00157 
00158         //- Runtime type information
00159         ClassName("MeshedSurface");
00160 
00161     // Static
00162 
00163         //- Face storage only handles triangulated faces
00164         inline static bool isTri();
00165 
00166         //- Can we read this file format?
00167         static bool canRead(const fileName&, const bool verbose=false);
00168 
00169         //- Can we read this file format?
00170         static bool canReadType(const word& ext, const bool verbose=false);
00171 
00172         //- Can we write this file format?
00173         static bool canWriteType(const word& ext, const bool verbose=false);
00174 
00175         static wordHashSet readTypes();
00176         static wordHashSet writeTypes();
00177 
00178     // Constructors
00179 
00180         //- Construct null
00181         MeshedSurface();
00182 
00183         //- Construct by transferring components (points, faces, zones).
00184         MeshedSurface
00185         (
00186             const Xfer< pointField >&,
00187             const Xfer< List<Face> >&,
00188             const Xfer< surfZoneList >&
00189         );
00190 
00191         //- Construct by transferring components (points, faces).
00192         //  Use zone information if available
00193         MeshedSurface
00194         (
00195             const Xfer< pointField >&,
00196             const Xfer< List<Face> >&,
00197             const UList<label>& zoneSizes = UList<label>(),
00198             const UList<word>& zoneNames = UList<word>()
00199         );
00200 
00201         //- Construct as copy
00202         MeshedSurface(const MeshedSurface&);
00203 
00204         //- Construct from a UnsortedMeshedSurface
00205         MeshedSurface(const UnsortedMeshedSurface<Face>&);
00206 
00207         //- Construct from a boundary mesh with local points/faces
00208         MeshedSurface
00209         (
00210             const polyBoundaryMesh&,
00211             const bool globalPoints=false
00212         );
00213 
00214         //- Construct from a surfMesh
00215         MeshedSurface(const surfMesh&);
00216 
00217         //- Construct by transferring the contents from a UnsortedMeshedSurface
00218         MeshedSurface(const Xfer<UnsortedMeshedSurface<Face> >&);
00219 
00220         //- Construct by transferring the contents from a MeshedSurface
00221         MeshedSurface(const Xfer<MeshedSurface<Face> >&);
00222 
00223         //- Construct from file name (uses extension to determine type)
00224         MeshedSurface(const fileName&);
00225 
00226         //- Construct from file name (uses extension to determine type)
00227         MeshedSurface(const fileName&, const word& ext);
00228 
00229         //- Construct from database
00230         MeshedSurface(const Time&, const word& surfName="");
00231 
00232     // Declare run-time constructor selection table
00233 
00234         declareRunTimeSelectionTable
00235         (
00236             autoPtr,
00237             MeshedSurface,
00238             fileExtension,
00239             (
00240                 const fileName& name
00241             ),
00242             (name)
00243         );
00244 
00245     // Selectors
00246 
00247         //- Select constructed from filename (explicit extension)
00248         static autoPtr<MeshedSurface> New
00249         (
00250             const fileName&,
00251             const word& ext
00252         );
00253 
00254         //- Select constructed from filename (implicit extension)
00255         static autoPtr<MeshedSurface> New(const fileName&);
00256 
00257     // Destructor
00258 
00259         virtual ~MeshedSurface();
00260 
00261 
00262     // Member Function Selectors
00263 
00264         declareMemberFunctionSelectionTable
00265         (
00266             void,
00267             UnsortedMeshedSurface,
00268             write,
00269             fileExtension,
00270             (
00271                 const fileName& name,
00272                 const MeshedSurface<Face>& surf
00273             ),
00274             (name, surf)
00275         );
00276 
00277         //- Write to file
00278         static void write(const fileName&, const MeshedSurface<Face>&);
00279 
00280 
00281     // Member Functions
00282 
00283     // Access
00284 
00285         //- The surface size is the number of faces
00286         label size() const
00287         {
00288             return ParentType::size();
00289         }
00290 
00291         //- Return const access to the faces
00292         inline const List<Face>& faces() const
00293         {
00294             return static_cast<const List<Face> &>(*this);
00295         }
00296 
00297         //- Const access to the surface zones.
00298         //  If zones are defined, they must be contiguous and cover the entire
00299         //  surface.
00300         const List<surfZone>& surfZones() const
00301         {
00302             return zones_;
00303         }
00304 
00305         //- Add surface zones
00306         virtual void addZones
00307         (
00308             const UList<surfZone>&,
00309             const bool cullEmpty=false
00310         );
00311 
00312         //- Add surface zones
00313         virtual void addZones
00314         (
00315             const UList<label>& sizes,
00316             const UList<word>& names,
00317             const bool cullEmpty=false
00318         );
00319 
00320         //- Add surface zones
00321         virtual void addZones
00322         (
00323             const UList<label>& sizes,
00324             const bool cullEmpty=false
00325         );
00326 
00327         //- Remove surface zones
00328         virtual void removeZones();
00329 
00330 
00331     // Edit
00332 
00333         //- Clear all storage
00334         virtual void clear();
00335 
00336         //- Move points
00337         virtual void movePoints(const pointField&);
00338 
00339         //- Scale points. A non-positive factor is ignored
00340         virtual void scalePoints(const scalar&);
00341 
00342         //- Reset primitive data (points, faces and zones)
00343         //  Note, optimized to avoid overwriting data (with Xfer::null)
00344         virtual void reset
00345         (
00346             const Xfer< pointField >& points,
00347             const Xfer< List<Face> >& faces,
00348             const Xfer< surfZoneList >& zones
00349         );
00350 
00351         //- Reset primitive data (points, faces and zones)
00352         //  Note, optimized to avoid overwriting data (with Xfer::null)
00353         virtual void reset
00354         (
00355             const Xfer< List<point> >& points,
00356             const Xfer< List<Face> >& faces,
00357             const Xfer< surfZoneList >& zones
00358         );
00359 
00360         //- Remove invalid faces
00361         virtual void cleanup(const bool verbose);
00362 
00363         virtual bool stitchFaces
00364         (
00365             const scalar tol=SMALL,
00366             const bool verbose=false
00367         );
00368 
00369         virtual bool checkFaces
00370         (
00371             const bool verbose=false
00372         );
00373 
00374         //- Triangulate in-place, returning the number of triangles added
00375         virtual label triangulate();
00376 
00377         //- Triangulate in-place, returning the number of triangles added
00378         //  and setting a map of original face Ids.
00379         //  The faceMap is zero-sized when no triangulation was done.
00380         virtual label triangulate(List<label>& faceMap);
00381 
00382 
00383         //- Return new surface.
00384         //  Returns return pointMap, faceMap from subsetMeshMap
00385         MeshedSurface subsetMesh
00386         (
00387             const labelHashSet& include,
00388             labelList& pointMap,
00389             labelList& faceMap
00390         ) const;
00391 
00392         //- Return new surface.
00393         MeshedSurface subsetMesh
00394         (
00395             const labelHashSet& include
00396         ) const;
00397 
00398         //- Transfer the contents of the argument and annull the argument
00399         void transfer(MeshedSurface<Face>&);
00400 
00401         //- Transfer the contents of the argument and annull the argument
00402         void transfer(UnsortedMeshedSurface<Face>&);
00403 
00404         //- Transfer contents to the Xfer container
00405         Xfer< MeshedSurface<Face> > xfer();
00406 
00407     // Read
00408 
00409         //- Read from file. Chooses reader based on explicit extension
00410         bool read(const fileName&, const word& ext);
00411 
00412         //- Read from file. Chooses reader based on detected extension
00413         virtual bool read(const fileName&);
00414 
00415 
00416     // Write
00417 
00418         void writeStats(Ostream& os) const;
00419 
00420         //- Generic write routine. Chooses writer based on extension.
00421         virtual void write(const fileName& name) const
00422         {
00423             write(name, *this);
00424         }
00425 
00426         //- Write to database
00427         void write(const Time&, const word& surfName="") const;
00428 
00429 
00430     // Member operators
00431 
00432         void operator=(const MeshedSurface<Face>&);
00433 
00434         //- Conversion operator to MeshedSurfaceProxy
00435         operator MeshedSurfaceProxy<Face>() const;
00436 
00437 };
00438 
00439 
00440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00441 
00442 //- Specialization for holding triangulated information
00443 template<>
00444 inline bool MeshedSurface<triFace>::isTri()
00445 {
00446     return true;
00447 }
00448 
00449 //- Specialization for holding triangulated information
00450 template<>
00451 inline label MeshedSurface<triFace>::triangulate()
00452 {
00453     return 0;
00454 }
00455 
00456 //- Specialization for holding triangulated information
00457 template<>
00458 inline label MeshedSurface<triFace>::triangulate(List<label>& faceMap)
00459 {
00460     if (&faceMap)
00461     {
00462         faceMap.clear();
00463     }
00464 
00465     return 0;
00466 }
00467 
00468 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00469 
00470 } // End namespace Foam
00471 
00472 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00473 
00474 #ifdef NoRepository
00475 #   include "MeshedSurface.C"
00476 #endif
00477 
00478 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00479 
00480 #endif
00481 
00482 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines