edgeMesh.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) 2011-2013 OpenFOAM Foundation
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::edgeMesh
26 
27 Description
28  Points connected by edges.
29 
30  Can be read from fileName based on extension. Uses ::New factory method
31  to select the reader and transfer the result.
32 
33 SourceFiles
34  edgeMeshI.H
35  edgeMesh.C
36  edgeMeshIO.C
37  edgeMeshNew.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef edgeMesh_H
42 #define edgeMesh_H
43 
44 #include "pointField.H"
45 #include "edgeList.H"
46 #include "edgeMeshFormatsCore.H"
47 #include "runTimeSelectionTables.H"
49 #include "HashSet.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward declaration of classes
57 class Istream;
58 class Ostream;
59 
60 // Forward declaration of friend functions and operators
61 class edgeMesh;
62 Istream& operator>>(Istream&, edgeMesh&);
63 Ostream& operator<<(Ostream&, const edgeMesh&);
64 
65 
66 /*---------------------------------------------------------------------------*\
67  Class edgeMesh Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 class edgeMesh
71 :
73 {
74  // Private data
75 
76  //- Vertices of the edges
77  pointField points_;
78 
79  //- The edges defining the boundary
80  edgeList edges_;
81 
82  //- From point to edges
83  mutable autoPtr<labelListList> pointEdgesPtr_;
84 
85  // Private Member Functions
86 
87  //- Calculate point-edge addressing (inverse of edges)
88  void calcPointEdges() const;
89 
90 
91 protected:
92 
93  // Protected Member Functions
94 
95  //- Non-const access to global points
96  inline pointField& storedPoints();
97 
98  //- Non-const access to the edges
99  inline edgeList& storedEdges();
100 
101 
102 public:
103 
104  //- Runtime type information
105  TypeName("edgeMesh");
106 
107 
108  // Static
109 
110  //- Can we read this file format?
111  static bool canRead(const fileName&, const bool verbose=false);
112 
113  //- Can we read this file format?
114  static bool canReadType(const word& ext, const bool verbose=false);
115 
116  //- Can we write this file format type?
117  static bool canWriteType(const word& ext, const bool verbose=false);
118 
119  static wordHashSet readTypes();
120  static wordHashSet writeTypes();
121 
122 
123  // Constructors
124 
125  //- Construct null
126  edgeMesh();
127 
128  //- Construct from components
129  edgeMesh(const pointField&, const edgeList&);
130 
131  //- Construct by transferring components (points, edges).
132  edgeMesh
133  (
134  const Xfer<pointField>&,
135  const Xfer<edgeList>&
136  );
137 
138  //- Construct as copy
139  edgeMesh(const edgeMesh&);
140 
141  //- Construct from file name (uses extension to determine type)
142  edgeMesh(const fileName&);
143 
144  //- Construct from file name (uses extension to determine type)
145  edgeMesh(const fileName&, const word& ext);
146 
147  //- Construct from Istream
148  edgeMesh(Istream&);
149 
150 
151  // Declare run-time constructor selection table
152 
154  (
155  autoPtr,
156  edgeMesh,
157  fileExtension,
158  (
159  const fileName& name
160  ),
161  (name)
162  );
163 
164 
165  // Selectors
166 
167  //- Select constructed from filename (explicit extension)
168  static autoPtr<edgeMesh> New
169  (
170  const fileName&,
171  const word& ext
172  );
173 
174  //- Select constructed from filename (implicit extension)
175  static autoPtr<edgeMesh> New(const fileName&);
176 
177 
178  //- Destructor
179  virtual ~edgeMesh();
180 
181 
182  // Member Function Selectors
183 
185  (
186  void,
187  edgeMesh,
188  write,
189  fileExtension,
190  (
191  const fileName& name,
192  const edgeMesh& mesh
193  ),
194  (name, mesh)
195  );
196 
197  //- Write to file
198  static void write(const fileName&, const edgeMesh&);
199 
200 
201  // Member Functions
202 
203  //- Transfer the contents of the argument and annul the argument
204  void transfer(edgeMesh&);
205 
206  //- Transfer contents to the Xfer container
208 
209  // Read
210 
211  //- Read from file. Chooses reader based on explicit extension
212  bool read(const fileName&, const word& ext);
213 
214  //- Read from file. Chooses reader based on detected extension
215  virtual bool read(const fileName&);
216 
217 
218  // Access
219 
220  //- Return points
221  inline const pointField& points() const;
222 
223  //- Return edges
224  inline const edgeList& edges() const;
225 
226  //- Return edges
227  inline const labelListList& pointEdges() const;
228 
229  //- Find connected regions. Set region number per edge.
230  // Returns number of regions.
231  label regions(labelList& edgeRegion) const;
232 
233 
234  // Edit
235 
236  //- Clear all storage
237  virtual void clear();
238 
239  //- Reset primitive data (points, edges)
240  // Note, optimized to avoid overwriting data (with Xfer::null)
241  virtual void reset
242  (
243  const Xfer<pointField>& points,
244  const Xfer<edgeList>& edges
245  );
246 
247  //- Scale points. A non-positive factor is ignored
248  virtual void scalePoints(const scalar);
249 
250  //- Merge common points (points within mergeDist)
251  void mergePoints(const scalar mergeDist);
252 
253  //- Merge similar edges
254  void mergeEdges();
255 
256 
257  // Write
258 
259  virtual void writeStats(Ostream&) const;
260 
261  //- Generic write routine. Chooses writer based on extension.
262  virtual void write(const fileName& name) const
263  {
264  write(name, *this);
265  }
266 
267 
268  // Member Operators
269 
270  inline void operator=(const edgeMesh&);
271 
272  // Ostream Operator
273 
274  friend Ostream& operator<<(Ostream&, const edgeMesh&);
275  friend Istream& operator>>(Istream&, edgeMesh&);
276 
277 };
278 
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 } // End namespace Foam
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #include "edgeMeshI.H"
287 
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 
290 #endif
291 
292 // ************************************************************************* //
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
void transfer(edgeMesh &)
Transfer the contents of the argument and annul the argument.
Definition: edgeMesh.C:200
A HashTable with keys but without contents.
Definition: HashSet.H:59
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:69
static bool canReadType(const word &ext, const bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:58
edgeList & storedEdges()
Non-const access to the edges.
Definition: edgeMeshI.H:67
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:75
static autoPtr< edgeMesh > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
Definition: edgeMeshNew.C:31
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual void scalePoints(const scalar)
Scale points. A non-positive factor is ignored.
Definition: edgeMesh.C:279
static bool canRead(const fileName &, const bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:90
Xfer< edgeMesh > xfer()
Transfer contents to the Xfer container.
Definition: edgeMesh.C:208
void operator=(const edgeMesh &)
Definition: edgeMeshI.H:75
pointField & storedPoints()
Non-const access to global points.
Definition: edgeMeshI.H:61
edgeMesh()
Construct null.
Definition: edgeMesh.C:123
friend Istream & operator>>(Istream &, edgeMesh &)
static wordHashSet writeTypes()
Definition: edgeMesh.C:49
const pointField & points() const
Return points.
Definition: edgeMeshI.H:39
declareMemberFunctionSelectionTable(void, edgeMesh, write, fileExtension,(const fileName &name, const edgeMesh &mesh),(name, mesh))
dynamicFvMesh & mesh
declareRunTimeSelectionTable(autoPtr, edgeMesh, fileExtension,(const fileName &name),(name))
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
void mergePoints(const scalar mergeDist)
Merge common points (points within mergeDist)
Definition: edgeMesh.C:289
static wordHashSet readTypes()
Definition: edgeMesh.C:43
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:117
friend Ostream & operator<<(Ostream &, const edgeMesh &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Points connected by edges.
Definition: edgeMesh.H:69
virtual void reset(const Xfer< pointField > &points, const Xfer< edgeList > &edges)
Reset primitive data (points, edges)
Definition: edgeMesh.C:178
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
label regions(labelList &edgeRegion) const
Find connected regions. Set region number per edge.
Definition: edgeMesh.C:214
virtual void clear()
Clear all storage.
Definition: edgeMesh.C:169
void mergeEdges()
Merge similar edges.
Definition: edgeMesh.C:358
A collection of helper functions for reading/writing edge formats.
Ostream & operator<<(Ostream &, const ensightPart &)
const edgeList & edges() const
Return edges.
Definition: edgeMeshI.H:45
static void write(const fileName &, const edgeMesh &)
Write to file.
Definition: edgeMeshIO.C:87
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
Macros to ease declaration of run-time selection tables.
TypeName("edgeMesh")
Runtime type information.
virtual ~edgeMesh()
Destructor.
Definition: edgeMesh.C:163
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format type?
Definition: edgeMesh.C:74
Namespace for OpenFOAM.
const labelListList & pointEdges() const
Return edges.
Definition: edgeMeshI.H:51