1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 A surface geometry mesh with zone information, not to be confused with
29 the similarly named surfaceMesh, which actually refers to the cell faces
32 A MeshedSurface can have zero or more surface zones (roughly equivalent
33 to faceZones for a polyMesh). If surface zones are defined, they must
34 be contiguous and cover all of the faces.
36 The MeshedSurface is intended for surfaces from a variety of sources.
37 - A set of points and faces without any surface zone information.
38 - A set of points and faces with randomly ordered zone information.
39 This could arise, for example, from reading external file formats
45 \*---------------------------------------------------------------------------*/
47 #ifndef MeshedSurface_H
48 #define MeshedSurface_H
50 #include "PrimitivePatch.H"
51 #include "PatchTools.H"
52 #include "pointField.H"
56 #include "surfZoneList.H"
57 #include "surfaceFormatsCore.H"
58 #include "runTimeSelectionTables.H"
59 #include "memberFunctionSelectionTables.H"
62 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 // Forward declaration of friend functions and operators
71 class polyBoundaryMesh;
73 template<class Face> class MeshedSurface;
74 template<class Face> class MeshedSurfaceProxy;
75 template<class Face> class UnsortedMeshedSurface;
77 /*---------------------------------------------------------------------------*\
78 Class MeshedSurface Declaration
79 \*---------------------------------------------------------------------------*/
84 public PrimitivePatch<Face, ::Foam::List, pointField, point>,
85 public fileFormats::surfaceFormatsCore
87 // friends - despite different face representationsx
88 template<class Face2> friend class MeshedSurface;
89 template<class Face2> friend class UnsortedMeshedSurface;
90 friend class surfMesh;
95 // Private typedefs for convenience
97 typedef PrimitivePatch
106 typedef UnsortedMeshedSurface<Face> FriendType;
107 typedef MeshedSurfaceProxy<Face> ProxyType;
110 // Private Member Data
113 // (face ordering nFaces/startFace only used during reading/writing)
114 List<surfZone> zones_;
119 // Protected Member functions
121 //- Transfer points/zones and transcribe face -> triFace
122 void transcribe(MeshedSurface<face>&);
124 //- basic sanity check on zones
127 //- Non-const access to global points
128 pointField& storedPoints()
130 return const_cast<pointField&>(ParentType::points());
133 //- Non-const access to the faces
134 List<Face>& storedFaces()
136 return static_cast<List<Face> &>(*this);
139 //- Non-const access to the zones
140 surfZoneList& storedZones()
145 //- sort faces by zones and store sorted faces
146 void sortFacesAndStore
148 const Xfer<List<Face> >& unsortedFaces,
149 const Xfer<List<label> >& zoneIds,
153 //- Set new zones from faceMap
154 virtual void remapFaces(const labelUList& faceMap);
162 typedef Face FaceType;
164 //- Runtime type information
165 ClassName("MeshedSurface");
170 //- Face storage only handles triangulated faces
171 inline static bool isTri();
173 //- Can we read this file format?
174 static bool canRead(const fileName&, const bool verbose=false);
176 //- Can we read this file format?
177 static bool canReadType(const word& ext, const bool verbose=false);
179 //- Can we write this file format?
180 static bool canWriteType(const word& ext, const bool verbose=false);
182 static wordHashSet readTypes();
183 static wordHashSet writeTypes();
191 //- Construct by transferring components (points, faces, zones).
194 const Xfer<pointField>&,
195 const Xfer<List<Face> >&,
196 const Xfer<surfZoneList>&
199 //- Construct by transferring components (points, faces).
200 // Use zone information if available
203 const Xfer<pointField>&,
204 const Xfer<List<Face> >&,
205 const labelUList& zoneSizes = labelUList(),
206 const UList<word>& zoneNames = UList<word>()
209 //- Construct as copy
210 MeshedSurface(const MeshedSurface&);
212 //- Construct from a UnsortedMeshedSurface
213 MeshedSurface(const UnsortedMeshedSurface<Face>&);
215 //- Construct from a boundary mesh with local points/faces
218 const polyBoundaryMesh&,
219 const bool globalPoints=false
222 //- Construct from a surfMesh
223 MeshedSurface(const surfMesh&);
225 //- Construct by transferring the contents from a UnsortedMeshedSurface
226 MeshedSurface(const Xfer<UnsortedMeshedSurface<Face> >&);
228 //- Construct by transferring the contents from a MeshedSurface
229 MeshedSurface(const Xfer<MeshedSurface<Face> >&);
231 //- Construct from file name (uses extension to determine type)
232 MeshedSurface(const fileName&);
234 //- Construct from file name (uses extension to determine type)
235 MeshedSurface(const fileName&, const word& ext);
237 //- Construct from database
238 MeshedSurface(const Time&, const word& surfName="");
241 // Declare run-time constructor selection table
243 declareRunTimeSelectionTable
257 //- Select constructed from filename (explicit extension)
258 static autoPtr<MeshedSurface> New
264 //- Select constructed from filename (implicit extension)
265 static autoPtr<MeshedSurface> New(const fileName&);
269 virtual ~MeshedSurface();
272 // Member Function Selectors
274 declareMemberFunctionSelectionTable
277 UnsortedMeshedSurface,
281 const fileName& name,
282 const MeshedSurface<Face>& surf
288 static void write(const fileName&, const MeshedSurface<Face>&);
295 //- The surface size is the number of faces
298 return ParentType::size();
301 //- Return const access to the faces
302 inline const List<Face>& faces() const
304 return static_cast<const List<Face> &>(*this);
307 //- Const access to the surface zones.
308 // If zones are defined, they must be contiguous and cover the
310 const List<surfZone>& surfZones() const
315 //- Add surface zones
316 virtual void addZones
318 const UList<surfZone>&,
319 const bool cullEmpty=false
322 //- Add surface zones
323 virtual void addZones
325 const labelUList& sizes,
326 const UList<word>& names,
327 const bool cullEmpty=false
330 //- Add surface zones
331 virtual void addZones
333 const labelUList& sizes,
334 const bool cullEmpty=false
337 //- Remove surface zones
338 virtual void removeZones();
343 //- Clear all storage
344 virtual void clear();
347 virtual void movePoints(const pointField&);
349 //- Scale points. A non-positive factor is ignored
350 virtual void scalePoints(const scalar);
352 //- Reset primitive data (points, faces and zones)
353 // Note, optimized to avoid overwriting data (with Xfer::null)
356 const Xfer<pointField >& points,
357 const Xfer<List<Face> >& faces,
358 const Xfer<surfZoneList>& zones
361 //- Reset primitive data (points, faces and zones)
362 // Note, optimized to avoid overwriting data (with Xfer::null)
365 const Xfer<List<point> >& points,
366 const Xfer<List<Face> >& faces,
367 const Xfer<surfZoneList >& zones
370 //- Remove invalid faces
371 virtual void cleanup(const bool verbose);
373 virtual bool stitchFaces
375 const scalar tol=SMALL,
376 const bool verbose=false
379 virtual bool checkFaces
381 const bool verbose=false
384 //- Triangulate in-place, returning the number of triangles added
385 virtual label triangulate();
387 //- Triangulate in-place, returning the number of triangles added
388 // and setting a map of original face Ids.
389 // The faceMap is zero-sized when no triangulation was done.
390 virtual label triangulate(List<label>& faceMap);
393 //- Return new surface.
394 // Returns return pointMap, faceMap from subsetMeshMap
395 MeshedSurface subsetMesh
397 const labelHashSet& include,
402 //- Return new surface.
403 MeshedSurface subsetMesh
405 const labelHashSet& include
408 //- Transfer the contents of the argument and annul the argument
409 void transfer(MeshedSurface<Face>&);
411 //- Transfer the contents of the argument and annul the argument
412 void transfer(UnsortedMeshedSurface<Face>&);
414 //- Transfer contents to the Xfer container
415 Xfer<MeshedSurface<Face> > xfer();
420 //- Read from file. Chooses reader based on explicit extension
421 bool read(const fileName&, const word& ext);
423 //- Read from file. Chooses reader based on detected extension
424 virtual bool read(const fileName&);
429 void writeStats(Ostream& os) const;
431 //- Generic write routine. Chooses writer based on extension.
432 virtual void write(const fileName& name) const
437 //- Write to database
438 void write(const Time&, const word& surfName="") const;
443 void operator=(const MeshedSurface<Face>&);
445 //- Conversion operator to MeshedSurfaceProxy
446 operator MeshedSurfaceProxy<Face>() const;
450 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
452 //- Specialization for holding triangulated information
454 inline bool MeshedSurface<triFace>::isTri()
460 //- Specialization for holding triangulated information
462 inline label MeshedSurface<triFace>::triangulate()
468 //- Specialization for holding triangulated information
470 inline label MeshedSurface<triFace>::triangulate(List<label>& faceMap)
481 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
483 } // End namespace Foam
485 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
488 # include "MeshedSurface.C"
491 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
495 // ************************************************************************* //