OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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