1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 "PrimitivePatchTemplate.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;
94 //- Private typedefs for convenience
96 typedef PrimitivePatch
105 typedef UnsortedMeshedSurface<Face> FriendType;
106 typedef MeshedSurfaceProxy<Face> ProxyType;
108 // Private Member Data
111 // (face ordering nFaces/startFace only used during reading/writing)
112 List<surfZone> zones_;
115 // Private member functions
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 UList<label>& faceMap);
158 //- Runtime type information
159 ClassName("MeshedSurface");
163 //- Face storage only handles triangulated faces
164 inline static bool isTri();
166 //- Can we read this file format?
167 static bool canRead(const fileName&, const bool verbose=false);
169 //- Can we read this file format?
170 static bool canReadType(const word& ext, const bool verbose=false);
172 //- Can we write this file format?
173 static bool canWriteType(const word& ext, const bool verbose=false);
175 static wordHashSet readTypes();
176 static wordHashSet writeTypes();
183 //- Construct by transferring components (points, faces, zones).
186 const Xfer< pointField >&,
187 const Xfer< List<Face> >&,
188 const Xfer< surfZoneList >&
191 //- Construct by transferring components (points, faces).
192 // Use zone information if available
195 const Xfer< pointField >&,
196 const Xfer< List<Face> >&,
197 const UList<label>& zoneSizes = UList<label>(),
198 const UList<word>& zoneNames = UList<word>()
201 //- Construct as copy
202 MeshedSurface(const MeshedSurface&);
204 //- Construct from a UnsortedMeshedSurface
205 MeshedSurface(const UnsortedMeshedSurface<Face>&);
207 //- Construct from a boundary mesh with local points/faces
210 const polyBoundaryMesh&,
211 const bool globalPoints=false
214 //- Construct from a surfMesh
215 MeshedSurface(const surfMesh&);
217 //- Construct by transferring the contents from a UnsortedMeshedSurface
218 MeshedSurface(const Xfer<UnsortedMeshedSurface<Face> >&);
220 //- Construct by transferring the contents from a MeshedSurface
221 MeshedSurface(const Xfer<MeshedSurface<Face> >&);
223 //- Construct from file name (uses extension to determine type)
224 MeshedSurface(const fileName&);
226 //- Construct from file name (uses extension to determine type)
227 MeshedSurface(const fileName&, const word& ext);
229 //- Construct from database
230 MeshedSurface(const Time&, const word& surfName="");
232 // Declare run-time constructor selection table
234 declareRunTimeSelectionTable
247 //- Select constructed from filename (explicit extension)
248 static autoPtr<MeshedSurface> New
254 //- Select constructed from filename (implicit extension)
255 static autoPtr<MeshedSurface> New(const fileName&);
259 virtual ~MeshedSurface();
262 // Member Function Selectors
264 declareMemberFunctionSelectionTable
267 UnsortedMeshedSurface,
271 const fileName& name,
272 const MeshedSurface<Face>& surf
278 static void write(const fileName&, const MeshedSurface<Face>&);
285 //- The surface size is the number of faces
288 return ParentType::size();
291 //- Return const access to the faces
292 inline const List<Face>& faces() const
294 return static_cast<const List<Face> &>(*this);
297 //- Const access to the surface zones.
298 // If zones are defined, they must be contiguous and cover the entire
300 const List<surfZone>& surfZones() const
305 //- Add surface zones
306 virtual void addZones
308 const UList<surfZone>&,
309 const bool cullEmpty=false
312 //- Add surface zones
313 virtual void addZones
315 const UList<label>& sizes,
316 const UList<word>& names,
317 const bool cullEmpty=false
320 //- Add surface zones
321 virtual void addZones
323 const UList<label>& sizes,
324 const bool cullEmpty=false
327 //- Remove surface zones
328 virtual void removeZones();
333 //- Clear all storage
334 virtual void clear();
337 virtual void movePoints(const pointField&);
339 //- Scale points. A non-positive factor is ignored
340 virtual void scalePoints(const scalar&);
342 //- Reset primitive data (points, faces and zones)
343 // Note, optimized to avoid overwriting data (with Xfer::null)
346 const Xfer< pointField >& points,
347 const Xfer< List<Face> >& faces,
348 const Xfer< surfZoneList >& zones
351 //- Reset primitive data (points, faces and zones)
352 // Note, optimized to avoid overwriting data (with Xfer::null)
355 const Xfer< List<point> >& points,
356 const Xfer< List<Face> >& faces,
357 const Xfer< surfZoneList >& zones
360 //- Remove invalid faces
361 virtual void cleanup(const bool verbose);
363 virtual bool stitchFaces
365 const scalar tol=SMALL,
366 const bool verbose=false
369 virtual bool checkFaces
371 const bool verbose=false
374 //- Triangulate in-place, returning the number of triangles added
375 virtual label triangulate();
377 //- Triangulate in-place, returning the number of triangles added
378 // and setting a map of original face Ids.
379 // The faceMap is zero-sized when no triangulation was done.
380 virtual label triangulate(List<label>& faceMap);
383 //- Return new surface.
384 // Returns return pointMap, faceMap from subsetMeshMap
385 MeshedSurface subsetMesh
387 const labelHashSet& include,
392 //- Return new surface.
393 MeshedSurface subsetMesh
395 const labelHashSet& include
398 //- Transfer the contents of the argument and annull the argument
399 void transfer(MeshedSurface<Face>&);
401 //- Transfer the contents of the argument and annull the argument
402 void transfer(UnsortedMeshedSurface<Face>&);
404 //- Transfer contents to the Xfer container
405 Xfer< MeshedSurface<Face> > xfer();
409 //- Read from file. Chooses reader based on explicit extension
410 bool read(const fileName&, const word& ext);
412 //- Read from file. Chooses reader based on detected extension
413 virtual bool read(const fileName&);
418 void writeStats(Ostream& os) const;
420 //- Generic write routine. Chooses writer based on extension.
421 virtual void write(const fileName& name) const
426 //- Write to database
427 void write(const Time&, const word& surfName="") const;
432 void operator=(const MeshedSurface<Face>&);
434 //- Conversion operator to MeshedSurfaceProxy
435 operator MeshedSurfaceProxy<Face>() const;
440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
442 //- Specialization for holding triangulated information
444 inline bool MeshedSurface<triFace>::isTri()
449 //- Specialization for holding triangulated information
451 inline label MeshedSurface<triFace>::triangulate()
456 //- Specialization for holding triangulated information
458 inline label MeshedSurface<triFace>::triangulate(List<label>& faceMap)
460 if (!faceMap.empty())
468 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
470 } // End namespace Foam
472 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
475 # include "MeshedSurface.C"
478 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
482 // ************************************************************************* //