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-2017 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 
86  // Private Member Functions
87 
88  //- Calculate point-edge addressing (inverse of edges)
89  void calcPointEdges() const;
90 
91 
92 protected:
93 
94  // Protected Member Functions
95 
96  //- Non-const access to global points
97  inline pointField& storedPoints();
98 
99  //- Non-const access to the edges
100  inline edgeList& storedEdges();
101 
102 
103 public:
104 
105  //- Runtime type information
106  TypeName("edgeMesh");
107 
108 
109  // Static
110 
111  //- Can we read this file format?
112  static bool canRead(const fileName&, const bool verbose=false);
113 
114  //- Can we read this file format?
115  static bool canReadType(const word& ext, const bool verbose=false);
116 
117  //- Can we write this file format type?
118  static bool canWriteType(const word& ext, const bool verbose=false);
119 
120  static wordHashSet readTypes();
121  static wordHashSet writeTypes();
122 
123 
124  // Constructors
125 
126  //- Construct null
127  edgeMesh();
128 
129  //- Construct from components
130  edgeMesh(const pointField&, const edgeList&);
131 
132  //- Construct by transferring components (points, edges).
133  edgeMesh
134  (
135  const Xfer<pointField>&,
136  const Xfer<edgeList>&
137  );
138 
139  //- Construct as copy
140  edgeMesh(const edgeMesh&);
141 
142  //- Construct from file name (uses extension to determine type)
143  edgeMesh(const fileName&);
144 
145  //- Construct from file name (uses extension to determine type)
146  edgeMesh(const fileName&, const word& ext);
147 
148  //- Construct from Istream
149  edgeMesh(Istream&);
150 
151 
152  // Declare run-time constructor selection table
153 
155  (
156  autoPtr,
157  edgeMesh,
158  fileExtension,
159  (
160  const fileName& name
161  ),
162  (name)
163  );
164 
165 
166  // Selectors
167 
168  //- Select constructed from filename (explicit extension)
169  static autoPtr<edgeMesh> New
170  (
171  const fileName&,
172  const word& ext
173  );
174 
175  //- Select constructed from filename (implicit extension)
176  static autoPtr<edgeMesh> New(const fileName&);
177 
178 
179  //- Destructor
180  virtual ~edgeMesh();
181 
182 
183  // Member Function Selectors
184 
186  (
187  void,
188  edgeMesh,
189  write,
190  fileExtension,
191  (
192  const fileName& name,
193  const edgeMesh& mesh
194  ),
195  (name, mesh)
196  );
197 
198  //- Write to file
199  static void write(const fileName&, const edgeMesh&);
200 
201 
202  // Member Functions
203 
204  //- Transfer the contents of the argument and annul the argument
205  void transfer(edgeMesh&);
206 
207  //- Transfer contents to the Xfer container
209 
210  // Read
211 
212  //- Read from file. Chooses reader based on explicit extension
213  bool read(const fileName&, const word& ext);
214 
215  //- Read from file. Chooses reader based on detected extension
216  virtual bool read(const fileName&);
217 
218 
219  // Access
220 
221  //- Return points
222  inline const pointField& points() const;
223 
224  //- Return edges
225  inline const edgeList& edges() const;
226 
227  //- Return edges
228  inline const labelListList& pointEdges() const;
229 
230  //- Find connected regions. Set region number per edge.
231  // Returns number of regions.
232  label regions(labelList& edgeRegion) const;
233 
234 
235  // Edit
236 
237  //- Clear all storage
238  virtual void clear();
239 
240  //- Reset primitive data (points, edges)
241  // Note, optimized to avoid overwriting data (with Xfer::null)
242  virtual void reset
243  (
244  const Xfer<pointField>& points,
245  const Xfer<edgeList>& edges
246  );
247 
248  //- Scale points. A non-positive factor is ignored
249  virtual void scalePoints(const scalar);
250 
251  //- Merge common points (points within mergeDist). Return map from
252  // old to new points.
253  virtual void mergePoints(const scalar mergeDist, labelList&);
254 
255  //- Merge duplicate edges
256  virtual void mergeEdges();
257 
258 
259  // Write
260 
261  virtual void writeStats(Ostream&) const;
262 
263  //- Generic write routine. Chooses writer based on extension.
264  virtual void write(const fileName& name) const
265  {
266  write(name, *this);
267  }
268 
269 
270  // Member Operators
271 
272  inline void operator=(const edgeMesh&);
273 
274  // Ostream Operator
275 
276  friend Ostream& operator<<(Ostream&, const edgeMesh&);
277  friend Istream& operator>>(Istream&, edgeMesh&);
278 
279 };
280 
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 } // End namespace Foam
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 #include "edgeMeshI.H"
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 #endif
293 
294 // ************************************************************************* //
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:34
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:75
virtual void mergePoints(const scalar mergeDist, labelList &)
Merge common points (points within mergeDist). Return map from.
Definition: edgeMesh.C:290
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:77
pointField & storedPoints()
Non-const access to global points.
Definition: edgeMeshI.H:28
edgeMesh()
Construct null.
Definition: edgeMesh.C:123
friend Istream & operator>>(Istream &, edgeMesh &)
static wordHashSet writeTypes()
Definition: edgeMesh.C:49
declareMemberFunctionSelectionTable(void, edgeMesh, write, fileExtension,(const fileName &name, const edgeMesh &mesh),(name, mesh))
const labelListList & pointEdges() const
Return edges.
Definition: edgeMeshI.H:65
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 &)
const edgeList & edges() const
Return edges.
Definition: edgeMeshI.H:59
static wordHashSet readTypes()
Definition: edgeMesh.C:43
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
const pointField & points() const
Return points.
Definition: edgeMeshI.H:53
Points connected by edges.
Definition: edgeMesh.H:69
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:117
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
virtual void clear()
Clear all storage.
Definition: edgeMesh.C:169
virtual void mergeEdges()
Merge duplicate edges.
Definition: edgeMesh.C:366
A collection of helper functions for reading/writing edge formats.
Ostream & operator<<(Ostream &, const ensightPart &)
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:52
Macros to ease declaration of run-time selection tables.
label regions(labelList &edgeRegion) const
Find connected regions. Set region number per edge.
Definition: edgeMesh.C:214
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.