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

UnsortedMeshedSurface.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::UnsortedMeshedSurface
00026 
00027 Description
00028     A surface geometry mesh, in which the surface zone information is
00029     conveyed by the 'zoneId' associated with each face.
00030 
00031     This form of surface description is particularly useful for reading in
00032     surface meshes from third-party formats (eg, obj, stl, gts, etc.). It
00033     can also be particularly useful for situations in which the surface
00034     many be adjusted in an arbitrary manner without worrying about needed
00035     to adjust the zone information (eg, surface refinement).
00036 
00037 See Also
00038     The Foam::MeshedSurface - which is organized as a surface mesh, but
00039     with independent zone information.
00040 
00041 SourceFiles
00042     UnsortedMeshedSurface.C
00043 
00044 \*---------------------------------------------------------------------------*/
00045 
00046 #ifndef UnsortedMeshedSurface_H
00047 #define UnsortedMeshedSurface_H
00048 
00049 #include <surfMesh/MeshedSurface.H>
00050 #include <surfMesh/surfZoneIdentifierList.H>
00051 #include <surfMesh/surfZoneList.H>
00052 #include <surfMesh/surfaceFormatsCore.H>
00053 #include <OpenFOAM/runTimeSelectionTables.H>
00054 #include <OpenFOAM/memberFunctionSelectionTables.H>
00055 #include <OpenFOAM/HashSet.H>
00056 
00057 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00058 
00059 namespace Foam
00060 {
00061 
00062 // Forward declaration of friend functions and operators
00063 
00064 class Time;
00065 class IFstream;
00066 
00067 template<class Face> class MeshedSurface;
00068 template<class Face> class MeshedSurfaceProxy;
00069 template<class Face> class UnsortedMeshedSurface;
00070 
00071 /*---------------------------------------------------------------------------*\
00072                    Class UnsortedMeshedSurface Declaration
00073 \*---------------------------------------------------------------------------*/
00074 
00075 template<class Face>
00076 class UnsortedMeshedSurface
00077 :
00078     public MeshedSurface<Face>
00079 {
00080     // friends - despite different face representationsx
00081     template<class Face2> friend class MeshedSurface;
00082     template<class Face2> friend class UnsortedMeshedSurface;
00083     friend class surfMesh;
00084 
00085 private:
00086 
00087     //- Private typedefs for convenience
00088 
00089         typedef MeshedSurface<Face>       ParentType;
00090         typedef MeshedSurface<Face>       FriendType;
00091         typedef MeshedSurfaceProxy<Face>  ProxyType;
00092 
00093 
00094     // Private Member Data
00095 
00096         //- The zone Id associated with each face
00097         labelList zoneIds_;
00098 
00099         //- Zone information (face ordering nFaces/startFace only used
00100         //  during reading and writing)
00101         List<surfZoneIdentifier> zoneToc_;
00102 
00103 
00104     // Private member functions
00105 
00106         //- Disable resize with value
00107         void resize(const label, const Face&);
00108 
00109         //- Disable setSize with value
00110         void setSize(const label, const Face&);
00111 
00112         //- Read OpenFOAM Surface format
00113         bool read(Istream&);
00114 
00115 
00116 protected:
00117 
00118     // Protected Member functions
00119 
00120         //- Return non-const access to the zone Ids
00121         List<label>& storedZoneIds()
00122         {
00123             return zoneIds_;
00124         }
00125 
00126         //- Return non-const access to the zone table-of-contents
00127         List<surfZoneIdentifier>& storedZoneToc()
00128         {
00129             return zoneToc_;
00130         }
00131 
00132         //- Set new zones from faceMap
00133         virtual void remapFaces(const UList<label>& faceMap);
00134 
00135 
00136 public:
00137 
00138         //- Runtime type information
00139         TypeName("UnsortedMeshedSurface");
00140 
00141 
00142     // Static
00143 
00144         //- Can we read this file format?
00145         static bool canReadType(const word& ext, const bool verbose=false);
00146 
00147         //- Can we read this file format?
00148         static bool canRead(const fileName&, const bool verbose=false);
00149 
00150         //- Can we write this file format?
00151         static bool canWriteType(const word& ext, const bool verbose=false);
00152 
00153         static wordHashSet readTypes();
00154         static wordHashSet writeTypes();
00155 
00156 
00157     // Constructors
00158 
00159         //- Construct null
00160         UnsortedMeshedSurface();
00161 
00162         //- Construct by transferring components
00163         //  (points, faces, zone ids, zone info).
00164         UnsortedMeshedSurface
00165         (
00166             const Xfer< pointField >&,
00167             const Xfer< List<Face> >&,
00168             const Xfer< List<label> >& zoneIds,
00169             const Xfer< surfZoneIdentifierList >&
00170         );
00171 
00172         //- Construct by transferring points, faces.
00173         //  Use zone information, or set single default zone
00174         UnsortedMeshedSurface
00175         (
00176             const Xfer<pointField>&,
00177             const Xfer<List<Face> >&,
00178             const UList<label>& zoneSizes = UList<label>(),
00179             const UList<word>& zoneNames = UList<word>()
00180         );
00181 
00182         //- Construct as copy
00183         UnsortedMeshedSurface(const UnsortedMeshedSurface<Face>&);
00184 
00185         //- Construct from a meshedSurface
00186         UnsortedMeshedSurface(const MeshedSurface<Face>&);
00187 
00188         //- Construct by transferring the contents from a UnsortedMeshedSurface
00189         UnsortedMeshedSurface(const Xfer<UnsortedMeshedSurface<Face> >&);
00190 
00191         //- Construct by transferring the contents from a meshedSurface
00192         UnsortedMeshedSurface(const Xfer<MeshedSurface<Face> >&);
00193 
00194         //- Construct from file name (uses extension to determine type)
00195         UnsortedMeshedSurface(const fileName&);
00196 
00197         //- Construct from file name (uses extension to determine type)
00198         UnsortedMeshedSurface(const fileName&, const word&);
00199 
00200         //- Construct from Istream
00201         UnsortedMeshedSurface(Istream&);
00202 
00203         //- Construct from objectRegistry and a named surface
00204         UnsortedMeshedSurface(const Time&, const word& surfName="");
00205 
00206 
00207     // Declare run-time constructor selection table
00208 
00209         declareRunTimeSelectionTable
00210         (
00211             autoPtr,
00212             UnsortedMeshedSurface,
00213             fileExtension,
00214             (
00215                 const fileName& name
00216             ),
00217             (name)
00218         );
00219 
00220 
00221     // Selectors
00222 
00223         //- Select constructed from filename (explicit extension)
00224         static autoPtr<UnsortedMeshedSurface> New
00225         (
00226             const fileName&,
00227             const word& ext
00228         );
00229 
00230         //- Select constructed from filename (implicit extension)
00231         static autoPtr<UnsortedMeshedSurface> New(const fileName&);
00232 
00233 
00234     // Destructor
00235 
00236         virtual ~UnsortedMeshedSurface();
00237 
00238 
00239     // Member Function Selectors
00240 
00241         declareMemberFunctionSelectionTable
00242         (
00243             void,
00244             UnsortedMeshedSurface,
00245             write,
00246             fileExtension,
00247             (
00248                 const fileName& name,
00249                 const UnsortedMeshedSurface<Face>& surf
00250             ),
00251             (name, surf)
00252         );
00253 
00254         //- Write to file
00255         static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
00256 
00257 
00258     // Member Functions
00259 
00260         // Access
00261 
00262             //- The surface size is the number of faces
00263             label size() const
00264             {
00265                 return ParentType::size();
00266             }
00267 
00268             //- Reset size of face and zone list
00269             void setSize(const label);
00270 
00271             //- Return const access to the zone ids
00272             const List<label>& zoneIds() const
00273             {
00274                 return zoneIds_;
00275             }
00276 
00277             //- Return const access to the zone table-of-contents
00278             const List<surfZoneIdentifier>& zoneToc() const
00279             {
00280                 return zoneToc_;
00281             }
00282 
00283             //- Sort faces according to zoneIds
00284             //  Returns a surfZoneList and sets faceMap to index within faces()
00285             surfZoneList sortedZones(labelList& faceMap) const;
00286 
00287             //- Set zones to 0 and set a single zone
00288             void setOneZone();
00289 
00290             //- Set zone ids and zones
00291             void setZones(const surfZoneList&);
00292 
00293             //- Set zone ids and zones
00294             void setZones(const UList<label>& sizes, const UList<word>& names);
00295 
00296             //- Set zone ids and zones with default names
00297             void setZones(const UList<label>& sizes);
00298 
00299 
00300         // Edit
00301 
00302             //- Clear all storage
00303             virtual void clear();
00304 
00305             //- Return new surface.
00306             //  Returns return pointMap, faceMap from subsetMeshMap
00307             UnsortedMeshedSurface subsetMesh
00308             (
00309                 const labelHashSet& include,
00310                 labelList& pointMap,
00311                 labelList& faceMap
00312             ) const;
00313 
00314             //- Return new surface.
00315             UnsortedMeshedSurface subsetMesh
00316             (
00317                 const labelHashSet& include
00318             ) const;
00319 
00320             //- Transfer components (points, faces, zone ids).
00321             virtual void reset
00322             (
00323                 const Xfer< pointField >&,
00324                 const Xfer< List<Face> >&,
00325                 const Xfer< List<label> >& zoneIds
00326             );
00327 
00328             //- Transfer components (points, faces, zone ids).
00329             virtual void reset
00330             (
00331                 const Xfer< List<point> >&,
00332                 const Xfer< List<Face> >&,
00333                 const Xfer< List<label> >& zoneIds
00334             );
00335 
00336             //- Transfer the contents of the argument and annull the argument
00337             void transfer(UnsortedMeshedSurface<Face>&);
00338 
00339             //- Transfer the contents of the argument and annull the argument
00340             void transfer(MeshedSurface<Face>&);
00341 
00342             //- Transfer contents to the Xfer container
00343             Xfer< UnsortedMeshedSurface<Face> > xfer();
00344 
00345 
00346         // Read
00347 
00348             //- Read from file. Chooses reader based on explicit extension
00349             bool read(const fileName&, const word& ext);
00350 
00351             //- Read from file. Chooses reader based on detected extension
00352             virtual bool read(const fileName&);
00353 
00354 
00355         // Write
00356 
00357             //- Generic write routine. Chooses writer based on extension.
00358             virtual void write(const fileName& name) const
00359             {
00360                 write(name, *this);
00361             }
00362 
00363             //- Write to database
00364             void write(const Time&, const word& surfName="") const;
00365 
00366 
00367         // Member operators
00368 
00369             void operator=(const UnsortedMeshedSurface<Face>&);
00370 
00371             //- Conversion operator to MeshedSurfaceProxy
00372             operator MeshedSurfaceProxy<Face>() const;
00373 };
00374 
00375 
00376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00377 
00378 } // End namespace Foam
00379 
00380 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00381 
00382 #ifdef NoRepository
00383 #   include "UnsortedMeshedSurface.C"
00384 #endif
00385 
00386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00387 
00388 #endif
00389 
00390 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines