FreeFOAM The Cross-Platform CFD Toolkit
UnsortedMeshedSurface.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::UnsortedMeshedSurface
26 
27 Description
28  A surface geometry mesh, in which the surface zone information is
29  conveyed by the 'zoneId' associated with each face.
30 
31  This form of surface description is particularly useful for reading in
32  surface meshes from third-party formats (eg, obj, stl, gts, etc.). It
33  can also be particularly useful for situations in which the surface
34  many be adjusted in an arbitrary manner without worrying about needed
35  to adjust the zone information (eg, surface refinement).
36 
37 See Also
38  The Foam::MeshedSurface - which is organized as a surface mesh, but
39  with independent zone information.
40 
41 SourceFiles
42  UnsortedMeshedSurface.C
43 
44 \*---------------------------------------------------------------------------*/
45 
46 #ifndef UnsortedMeshedSurface_H
47 #define UnsortedMeshedSurface_H
48 
49 #include <surfMesh/MeshedSurface.H>
51 #include <surfMesh/surfZoneList.H>
55 #include <OpenFOAM/HashSet.H>
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 // Forward declaration of friend functions and operators
63 
64 class Time;
65 class IFstream;
66 
67 template<class Face> class MeshedSurface;
68 template<class Face> class MeshedSurfaceProxy;
69 template<class Face> class UnsortedMeshedSurface;
70 
71 /*---------------------------------------------------------------------------*\
72  Class UnsortedMeshedSurface Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 template<class Face>
77 :
78  public MeshedSurface<Face>
79 {
80  // friends - despite different face representationsx
81  template<class Face2> friend class MeshedSurface;
82  template<class Face2> friend class UnsortedMeshedSurface;
83  friend class surfMesh;
84 
85 private:
86 
87  //- Private typedefs for convenience
88 
92 
93 
94  // Private Member Data
95 
96  //- The zone Id associated with each face
97  labelList zoneIds_;
98 
99  //- Zone information (face ordering nFaces/startFace only used
100  // during reading and writing)
101  List<surfZoneIdentifier> zoneToc_;
102 
103 
104  // Private member functions
105 
106  //- Disable resize with value
107  void resize(const label, const Face&);
108 
109  //- Disable setSize with value
110  void setSize(const label, const Face&);
111 
112  //- Read OpenFOAM Surface format
113  bool read(Istream&);
114 
115 
116 protected:
117 
118  // Protected Member functions
119 
120  //- Return non-const access to the zone Ids
122  {
123  return zoneIds_;
124  }
125 
126  //- Return non-const access to the zone table-of-contents
128  {
129  return zoneToc_;
130  }
131 
132  //- Set new zones from faceMap
133  virtual void remapFaces(const UList<label>& faceMap);
134 
135 
136 public:
137 
138  //- Runtime type information
139  TypeName("UnsortedMeshedSurface");
140 
141 
142  // Static
143 
144  //- Can we read this file format?
145  static bool canReadType(const word& ext, const bool verbose=false);
146 
147  //- Can we read this file format?
148  static bool canRead(const fileName&, const bool verbose=false);
149 
150  //- Can we write this file format?
151  static bool canWriteType(const word& ext, const bool verbose=false);
152 
153  static wordHashSet readTypes();
154  static wordHashSet writeTypes();
155 
156 
157  // Constructors
158 
159  //- Construct null
161 
162  //- Construct by transferring components
163  // (points, faces, zone ids, zone info).
165  (
166  const Xfer< pointField >&,
167  const Xfer< List<Face> >&,
168  const Xfer< List<label> >& zoneIds,
170  );
171 
172  //- Construct by transferring points, faces.
173  // Use zone information, or set single default zone
175  (
176  const Xfer<pointField>&,
177  const Xfer<List<Face> >&,
178  const UList<label>& zoneSizes = UList<label>(),
179  const UList<word>& zoneNames = UList<word>()
180  );
181 
182  //- Construct as copy
184 
185  //- Construct from a meshedSurface
187 
188  //- Construct by transferring the contents from a UnsortedMeshedSurface
190 
191  //- Construct by transferring the contents from a meshedSurface
193 
194  //- Construct from file name (uses extension to determine type)
196 
197  //- Construct from file name (uses extension to determine type)
198  UnsortedMeshedSurface(const fileName&, const word&);
199 
200  //- Construct from Istream
202 
203  //- Construct from objectRegistry and a named surface
204  UnsortedMeshedSurface(const Time&, const word& surfName="");
205 
206 
207  // Declare run-time constructor selection table
208 
210  (
211  autoPtr,
213  fileExtension,
214  (
215  const fileName& name
216  ),
217  (name)
218  );
219 
220 
221  // Selectors
222 
223  //- Select constructed from filename (explicit extension)
225  (
226  const fileName&,
227  const word& ext
228  );
229 
230  //- Select constructed from filename (implicit extension)
232 
233 
234  // Destructor
235 
236  virtual ~UnsortedMeshedSurface();
237 
238 
239  // Member Function Selectors
240 
242  (
243  void,
245  write,
246  fileExtension,
247  (
248  const fileName& name,
249  const UnsortedMeshedSurface<Face>& surf
250  ),
251  (name, surf)
252  );
253 
254  //- Write to file
255  static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
256 
257 
258  // Member Functions
259 
260  // Access
261 
262  //- The surface size is the number of faces
263  label size() const
264  {
265  return ParentType::size();
266  }
267 
268  //- Reset size of face and zone list
269  void setSize(const label);
270 
271  //- Return const access to the zone ids
272  const List<label>& zoneIds() const
273  {
274  return zoneIds_;
275  }
276 
277  //- Return const access to the zone table-of-contents
279  {
280  return zoneToc_;
281  }
282 
283  //- Sort faces according to zoneIds
284  // Returns a surfZoneList and sets faceMap to index within faces()
285  surfZoneList sortedZones(labelList& faceMap) const;
286 
287  //- Set zones to 0 and set a single zone
288  void setOneZone();
289 
290  //- Set zone ids and zones
291  void setZones(const surfZoneList&);
292 
293  //- Set zone ids and zones
294  void setZones(const UList<label>& sizes, const UList<word>& names);
295 
296  //- Set zone ids and zones with default names
297  void setZones(const UList<label>& sizes);
298 
299 
300  // Edit
301 
302  //- Clear all storage
303  virtual void clear();
304 
305  //- Return new surface.
306  // Returns return pointMap, faceMap from subsetMeshMap
308  (
309  const labelHashSet& include,
310  labelList& pointMap,
311  labelList& faceMap
312  ) const;
313 
314  //- Return new surface.
316  (
317  const labelHashSet& include
318  ) const;
319 
320  //- Transfer components (points, faces, zone ids).
321  virtual void reset
322  (
323  const Xfer< pointField >&,
324  const Xfer< List<Face> >&,
325  const Xfer< List<label> >& zoneIds
326  );
327 
328  //- Transfer components (points, faces, zone ids).
329  virtual void reset
330  (
331  const Xfer< List<point> >&,
332  const Xfer< List<Face> >&,
333  const Xfer< List<label> >& zoneIds
334  );
335 
336  //- Transfer the contents of the argument and annull the argument
338 
339  //- Transfer the contents of the argument and annull the argument
341 
342  //- Transfer contents to the Xfer container
344 
345 
346  // Read
347 
348  //- Read from file. Chooses reader based on explicit extension
349  bool read(const fileName&, const word& ext);
350 
351  //- Read from file. Chooses reader based on detected extension
352  virtual bool read(const fileName&);
353 
354 
355  // Write
356 
357  //- Generic write routine. Chooses writer based on extension.
358  virtual void write(const fileName& name) const
359  {
360  write(name, *this);
361  }
362 
363  //- Write to database
364  void write(const Time&, const word& surfName="") const;
365 
366 
367  // Member operators
368 
370 
371  //- Conversion operator to MeshedSurfaceProxy
372  operator MeshedSurfaceProxy<Face>() const;
373 };
374 
375 
376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
377 
378 } // End namespace Foam
379 
380 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
381 
382 #ifdef NoRepository
383 # include "UnsortedMeshedSurface.C"
384 #endif
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 #endif
389 
390 // ************************ vim: set sw=4 sts=4 et: ************************ //