1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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
29 A surface geometry mesh with zone information, not to be confused with
30 the similarly named surfaceMesh, which actually refers to the cell faces
33 A MeshedSurface can have zero or more surface zones (roughly equivalent
34 to faceZones for a polyMesh). If surface zones are defined, they must
35 be contiguous and cover all of the faces.
37 The MeshedSurface is intended for surfaces from a variety of sources.
38 - A set of points and faces without any surface zone information.
39 - A set of points and faces with randomly ordered zone information.
40 This could arise, for example, from reading external file formats
46 \*---------------------------------------------------------------------------*/
48 #ifndef MeshedSurface_H
49 #define MeshedSurface_H
51 #include "PrimitivePatch.H"
52 #include "PatchTools.H"
53 #include "pointField.H"
57 #include "surfZoneList.H"
58 #include "surfaceFormatsCore.H"
59 #include "runTimeSelectionTables.H"
60 #include "memberFunctionSelectionTables.H"
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 // Forward declaration of friend functions and operators
72 class polyBoundaryMesh;
74 template<class Face> class MeshedSurface;
75 template<class Face> class MeshedSurfaceProxy;
76 template<class Face> class UnsortedMeshedSurface;
78 /*---------------------------------------------------------------------------*\
79 Class MeshedSurface Declaration
80 \*---------------------------------------------------------------------------*/
85 public PrimitivePatch<Face, ::Foam::List, pointField, point>,
86 public fileFormats::surfaceFormatsCore
88 // friends - despite different face representationsx
89 template<class Face2> friend class MeshedSurface;
90 template<class Face2> friend class UnsortedMeshedSurface;
91 friend class surfMesh;
95 //- Private typedefs for convenience
97 typedef PrimitivePatch
106 typedef UnsortedMeshedSurface<Face> FriendType;
107 typedef MeshedSurfaceProxy<Face> ProxyType;
109 // Private Member Data
112 // (face ordering nFaces/startFace only used during reading/writing)
113 List<surfZone> zones_;
116 // Private member functions
120 // Protected Member functions
122 //- Transfer points/zones and transcribe face -> triFace
123 void transcribe(MeshedSurface<face>&);
125 //- basic sanity check on zones
128 //- Non-const access to global points
129 pointField& storedPoints()
131 return const_cast<pointField&>(ParentType::points());
134 //- Non-const access to the faces
135 List<Face>& storedFaces()
137 return static_cast<List<Face> &>(*this);
140 //- Non-const access to the zones
141 surfZoneList& storedZones()
146 //- sort faces by zones and store sorted faces
147 void sortFacesAndStore
149 const Xfer< List<Face> >& unsortedFaces,
150 const Xfer< List<label> >& zoneIds,
154 //- Set new zones from faceMap
155 virtual void remapFaces(const UList<label>& faceMap);
159 //- Runtime type information
160 ClassName("MeshedSurface");
164 //- Face storage only handles triangulated faces
165 inline static bool isTri();
167 //- Can we read this file format?
168 static bool canRead(const fileName&, const bool verbose=false);
170 //- Can we read this file format?
171 static bool canReadType(const word& ext, const bool verbose=false);
173 //- Can we write this file format?
174 static bool canWriteType(const word& ext, const bool verbose=false);
176 static wordHashSet readTypes();
177 static wordHashSet writeTypes();
184 //- Construct by transferring components (points, faces, zones).
187 const Xfer< pointField >&,
188 const Xfer< List<Face> >&,
189 const Xfer< surfZoneList >&
192 //- Construct by transferring components (points, faces).
193 // Use zone information if available
196 const Xfer< pointField >&,
197 const Xfer< List<Face> >&,
198 const UList<label>& zoneSizes = UList<label>(),
199 const UList<word>& zoneNames = UList<word>()
202 //- Construct as copy
203 MeshedSurface(const MeshedSurface&);
205 //- Construct from a UnsortedMeshedSurface
206 MeshedSurface(const UnsortedMeshedSurface<Face>&);
208 //- Construct from a boundary mesh with local points/faces
211 const polyBoundaryMesh&,
212 const bool globalPoints=false
215 //- Construct from a surfMesh
216 MeshedSurface(const surfMesh&);
218 //- Construct by transferring the contents from a UnsortedMeshedSurface
219 MeshedSurface(const Xfer<UnsortedMeshedSurface<Face> >&);
221 //- Construct by transferring the contents from a MeshedSurface
222 MeshedSurface(const Xfer<MeshedSurface<Face> >&);
224 //- Construct from file name (uses extension to determine type)
225 MeshedSurface(const fileName&);
227 //- Construct from file name (uses extension to determine type)
228 MeshedSurface(const fileName&, const word& ext);
230 //- Construct from database
231 MeshedSurface(const Time&, const word& surfName="");
233 // Declare run-time constructor selection table
235 declareRunTimeSelectionTable
248 //- Select constructed from filename (explicit extension)
249 static autoPtr<MeshedSurface> New
255 //- Select constructed from filename (implicit extension)
256 static autoPtr<MeshedSurface> New(const fileName&);
260 virtual ~MeshedSurface();
263 // Member Function Selectors
265 declareMemberFunctionSelectionTable
268 UnsortedMeshedSurface,
272 const fileName& name,
273 const MeshedSurface<Face>& surf
279 static void write(const fileName&, const MeshedSurface<Face>&);
286 //- The surface size is the number of faces
289 return ParentType::size();
292 //- Return const access to the faces
293 inline const List<Face>& faces() const
295 return static_cast<const List<Face> &>(*this);
298 //- Const access to the surface zones.
299 // If zones are defined, they must be contiguous and cover the entire
301 const List<surfZone>& surfZones() const
306 //- Add surface zones
307 virtual void addZones
309 const UList<surfZone>&,
310 const bool cullEmpty=false
313 //- Add surface zones
314 virtual void addZones
316 const UList<label>& sizes,
317 const UList<word>& names,
318 const bool cullEmpty=false
321 //- Add surface zones
322 virtual void addZones
324 const UList<label>& sizes,
325 const bool cullEmpty=false
328 //- Remove surface zones
329 virtual void removeZones();
334 //- Clear all storage
335 virtual void clear();
338 virtual void movePoints(const pointField&);
340 //- Scale points. A non-positive factor is ignored
341 virtual void scalePoints(const scalar&);
343 //- Reset primitive data (points, faces and zones)
344 // Note, optimized to avoid overwriting data (with Xfer::null)
347 const Xfer< pointField >& points,
348 const Xfer< List<Face> >& faces,
349 const Xfer< surfZoneList >& zones
352 //- Reset primitive data (points, faces and zones)
353 // Note, optimized to avoid overwriting data (with Xfer::null)
356 const Xfer< List<point> >& points,
357 const Xfer< List<Face> >& faces,
358 const Xfer< surfZoneList >& zones
361 //- Remove invalid faces
362 virtual void cleanup(const bool verbose);
364 virtual bool stitchFaces
366 const scalar tol=SMALL,
367 const bool verbose=false
370 virtual bool checkFaces
372 const bool verbose=false
375 //- Triangulate in-place, returning the number of triangles added
376 virtual label triangulate();
378 //- Triangulate in-place, returning the number of triangles added
379 // and setting a map of original face Ids.
380 // The faceMap is zero-sized when no triangulation was done.
381 virtual label triangulate(List<label>& faceMap);
384 //- Return new surface.
385 // Returns return pointMap, faceMap from subsetMeshMap
386 MeshedSurface subsetMesh
388 const labelHashSet& include,
393 //- Return new surface.
394 MeshedSurface subsetMesh
396 const labelHashSet& include
399 //- Transfer the contents of the argument and annull the argument
400 void transfer(MeshedSurface<Face>&);
402 //- Transfer the contents of the argument and annull the argument
403 void transfer(UnsortedMeshedSurface<Face>&);
405 //- Transfer contents to the Xfer container
406 Xfer< MeshedSurface<Face> > xfer();
410 //- Read from file. Chooses reader based on explicit extension
411 bool read(const fileName&, const word& ext);
413 //- Read from file. Chooses reader based on detected extension
414 virtual bool read(const fileName&);
419 void writeStats(Ostream& os) const;
421 //- Generic write routine. Chooses writer based on extension.
422 virtual void write(const fileName& name) const
427 //- Write to database
428 void write(const Time&, const word& surfName="") const;
433 void operator=(const MeshedSurface<Face>&);
435 //- Conversion operator to MeshedSurfaceProxy
436 operator MeshedSurfaceProxy<Face>() const;
441 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
443 //- Specialization for holding triangulated information
445 inline bool MeshedSurface<triFace>::isTri()
450 //- Specialization for holding triangulated information
452 inline label MeshedSurface<triFace>::triangulate()
457 //- Specialization for holding triangulated information
459 inline label MeshedSurface<triFace>::triangulate(List<label>& faceMap)
469 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
471 } // End namespace Foam
473 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
476 # include "MeshedSurface.C"
479 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
483 // ************************************************************************* //