initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / surfMesh / UnsortedMeshedSurface / UnsortedMeshedSurface.H
blobbb4fa01b379a3080bb8a75459a7eb569073ce6bc
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::UnsortedMeshedSurface
28 Description
29     A surface geometry mesh, in which the surface zone information is
30     conveyed by the 'zoneId' associated with each face.
32     This form of surface description is particularly useful for reading in
33     surface meshes from third-party formats (eg, obj, stl, gts, etc.). It
34     can also be particularly useful for situations in which the surface
35     many be adjusted in an arbitrary manner without worrying about needed
36     to adjust the zone information (eg, surface refinement).
38 See Also
39     The Foam::MeshedSurface - which is organized as a surface mesh, but
40     with independent zone information.
42 SourceFiles
43     UnsortedMeshedSurface.C
45 \*---------------------------------------------------------------------------*/
47 #ifndef UnsortedMeshedSurface_H
48 #define UnsortedMeshedSurface_H
50 #include "MeshedSurface.H"
51 #include "surfZoneIdentifierList.H"
52 #include "surfZoneList.H"
53 #include "surfaceFormatsCore.H"
54 #include "runTimeSelectionTables.H"
55 #include "memberFunctionSelectionTables.H"
56 #include "HashSet.H"
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 namespace Foam
63 // Forward declaration of friend functions and operators
65 class Time;
66 class IFstream;
68 template<class Face> class MeshedSurface;
69 template<class Face> class MeshedSurfaceProxy;
70 template<class Face> class UnsortedMeshedSurface;
72 /*---------------------------------------------------------------------------*\
73                    Class UnsortedMeshedSurface Declaration
74 \*---------------------------------------------------------------------------*/
76 template<class Face>
77 class UnsortedMeshedSurface
79     public MeshedSurface<Face>
81     // friends - despite different face representationsx
82     template<class Face2> friend class MeshedSurface;
83     template<class Face2> friend class UnsortedMeshedSurface;
84     friend class surfMesh;
86 private:
88     //- Private typedefs for convenience
90         typedef MeshedSurface<Face>       ParentType;
91         typedef MeshedSurface<Face>       FriendType;
92         typedef MeshedSurfaceProxy<Face>  ProxyType;
95     // Private Member Data
97         //- The zone Id associated with each face
98         labelList zoneIds_;
100         //- Zone information (face ordering nFaces/startFace only used
101         //  during reading and writing)
102         List<surfZoneIdentifier> zoneToc_;
105     // Private member functions
107         //- Disable resize with value
108         void resize(const label, const Face&);
110         //- Disable setSize with value
111         void setSize(const label, const Face&);
113         //- Read OpenFOAM Surface format
114         bool read(Istream&);
117 protected:
119     // Protected Member functions
121         //- Return non-const access to the zone Ids
122         List<label>& storedZoneIds()
123         {
124             return zoneIds_;
125         }
127         //- Return non-const access to the zone table-of-contents
128         List<surfZoneIdentifier>& storedZoneToc()
129         {
130             return zoneToc_;
131         }
133         //- Set new zones from faceMap
134         virtual void remapFaces(const UList<label>& faceMap);
137 public:
139         //- Runtime type information
140         TypeName("UnsortedMeshedSurface");
143     // Static
145         //- Can we read this file format?
146         static bool canReadType(const word& ext, const bool verbose=false);
148         //- Can we read this file format?
149         static bool canRead(const fileName&, const bool verbose=false);
151         //- Can we write this file format?
152         static bool canWriteType(const word& ext, const bool verbose=false);
154         static wordHashSet readTypes();
155         static wordHashSet writeTypes();
158     // Constructors
160         //- Construct null
161         UnsortedMeshedSurface();
163         //- Construct by transferring components
164         //  (points, faces, zone ids, zone info).
165         UnsortedMeshedSurface
166         (
167             const Xfer< pointField >&,
168             const Xfer< List<Face> >&,
169             const Xfer< List<label> >& zoneIds,
170             const Xfer< surfZoneIdentifierList >&
171         );
173         //- Construct by transferring points, faces.
174         //  Use zone information, or set single default zone
175         UnsortedMeshedSurface
176         (
177             const Xfer<pointField>&,
178             const Xfer<List<Face> >&,
179             const UList<label>& zoneSizes = UList<label>(),
180             const UList<word>& zoneNames = UList<word>()
181         );
183         //- Construct as copy
184         UnsortedMeshedSurface(const UnsortedMeshedSurface<Face>&);
186         //- Construct from a meshedSurface
187         UnsortedMeshedSurface(const MeshedSurface<Face>&);
189         //- Construct by transferring the contents from a UnsortedMeshedSurface
190         UnsortedMeshedSurface(const Xfer<UnsortedMeshedSurface<Face> >&);
192         //- Construct by transferring the contents from a meshedSurface
193         UnsortedMeshedSurface(const Xfer<MeshedSurface<Face> >&);
195         //- Construct from file name (uses extension to determine type)
196         UnsortedMeshedSurface(const fileName&);
198         //- Construct from file name (uses extension to determine type)
199         UnsortedMeshedSurface(const fileName&, const word&);
201         //- Construct from Istream
202         UnsortedMeshedSurface(Istream&);
204         //- Construct from objectRegistry and a named surface
205         UnsortedMeshedSurface(const Time&, const word& surfName="");
208     // Declare run-time constructor selection table
210         declareRunTimeSelectionTable
211         (
212             autoPtr,
213             UnsortedMeshedSurface,
214             fileExtension,
215             (
216                 const fileName& name
217             ),
218             (name)
219         );
222     // Selectors
224         //- Select constructed from filename (explicit extension)
225         static autoPtr<UnsortedMeshedSurface> New
226         (
227             const fileName&,
228             const word& ext
229         );
231         //- Select constructed from filename (implicit extension)
232         static autoPtr<UnsortedMeshedSurface> New(const fileName&);
235     // Destructor
237         virtual ~UnsortedMeshedSurface();
240     // Member Function Selectors
242         declareMemberFunctionSelectionTable
243         (
244             void,
245             UnsortedMeshedSurface,
246             write,
247             fileExtension,
248             (
249                 const fileName& name,
250                 const UnsortedMeshedSurface<Face>& surf
251             ),
252             (name, surf)
253         );
255         //- Write to file
256         static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
259     // Member Functions
261         // Access
263             //- The surface size is the number of faces
264             label size() const
265             {
266                 return ParentType::size();
267             }
269             //- Reset size of face and zone list
270             void setSize(const label);
272             //- Return const access to the zone ids
273             const List<label>& zoneIds() const
274             {
275                 return zoneIds_;
276             }
278             //- Return const access to the zone table-of-contents
279             const List<surfZoneIdentifier>& zoneToc() const
280             {
281                 return zoneToc_;
282             }
284             //- Sort faces according to zoneIds
285             //  Returns a surfZoneList and sets faceMap to index within faces()
286             surfZoneList sortedZones(labelList& faceMap) const;
288             //- Set zones to 0 and set a single zone
289             void setOneZone();
291             //- Set zone ids and zones
292             void setZones(const surfZoneList&);
294             //- Set zone ids and zones
295             void setZones(const UList<label>& sizes, const UList<word>& names);
297             //- Set zone ids and zones with default names
298             void setZones(const UList<label>& sizes);
301         // Edit
303             //- Clear all storage
304             virtual void clear();
306             //- Return new surface.
307             //  Returns return pointMap, faceMap from subsetMeshMap
308             UnsortedMeshedSurface subsetMesh
309             (
310                 const labelHashSet& include,
311                 labelList& pointMap,
312                 labelList& faceMap
313             ) const;
315             //- Return new surface.
316             UnsortedMeshedSurface subsetMesh
317             (
318                 const labelHashSet& include
319             ) const;
321             //- Transfer components (points, faces, zone ids).
322             virtual void reset
323             (
324                 const Xfer< pointField >&,
325                 const Xfer< List<Face> >&,
326                 const Xfer< List<label> >& zoneIds
327             );
329             //- Transfer components (points, faces, zone ids).
330             virtual void reset
331             (
332                 const Xfer< List<point> >&,
333                 const Xfer< List<Face> >&,
334                 const Xfer< List<label> >& zoneIds
335             );
337             //- Transfer the contents of the argument and annull the argument
338             void transfer(UnsortedMeshedSurface<Face>&);
340             //- Transfer the contents of the argument and annull the argument
341             void transfer(MeshedSurface<Face>&);
343             //- Transfer contents to the Xfer container
344             Xfer< UnsortedMeshedSurface<Face> > xfer();
347         // Read
349             //- Read from file. Chooses reader based on explicit extension
350             bool read(const fileName&, const word& ext);
352             //- Read from file. Chooses reader based on detected extension
353             virtual bool read(const fileName&);
356         // Write
358             //- Generic write routine. Chooses writer based on extension.
359             virtual void write(const fileName& name) const
360             {
361                 write(name, *this);
362             }
364             //- Write to database
365             void write(const Time&, const word& surfName="") const;
368         // Member operators
370             void operator=(const UnsortedMeshedSurface<Face>&);
372             //- Conversion operator to MeshedSurfaceProxy
373             operator MeshedSurfaceProxy<Face>() const;
377 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
379 } // End namespace Foam
381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383 #ifdef NoRepository
384 #   include "UnsortedMeshedSurface.C"
385 #endif
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
389 #endif
391 // ************************************************************************* //