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-2014 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
78 
79  //- The edges defining the boundary
81 
82  //- From point to edges
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). Return map from
251  // old to new points.
252  virtual void mergePoints(const scalar mergeDist, labelList&);
253 
254  //- Merge duplicate edges
255  virtual void mergeEdges();
256 
257 
258  // Write
259 
260  virtual void writeStats(Ostream&) const;
261 
262  //- Generic write routine. Chooses writer based on extension.
263  virtual void write(const fileName& name) const
264  {
265  write(name, *this);
266  }
267 
268 
269  // Member Operators
270 
271  inline void operator=(const edgeMesh&);
272 
273  // Ostream Operator
274 
275  friend Ostream& operator<<(Ostream&, const edgeMesh&);
276  friend Istream& operator>>(Istream&, edgeMesh&);
277 
278 };
279 
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 } // End namespace Foam
284 
285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286 
287 #include "edgeMeshI.H"
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 #endif
292 
293 // ************************************************************************* //
Foam::edgeMesh::~edgeMesh
virtual ~edgeMesh()
Destructor.
Definition: edgeMesh.C:163
Foam::edgeMesh::storedEdges
edgeList & storedEdges()
Non-const access to the edges.
Definition: edgeMeshI.H:67
Foam::edgeMesh::regions
label regions(labelList &edgeRegion) const
Find connected regions. Set region number per edge.
Definition: edgeMesh.C:214
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::edgeMesh::New
static autoPtr< edgeMesh > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
Definition: edgeMeshNew.C:31
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::edgeMesh::canWriteType
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format type?
Definition: edgeMesh.C:74
Foam::edgeMesh::canReadType
static bool canReadType(const word &ext, const bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:58
Foam::edgeMesh::points_
pointField points_
Vertices of the edges.
Definition: edgeMesh.H:76
Foam::edgeMesh::scalePoints
virtual void scalePoints(const scalar)
Scale points. A non-positive factor is ignored.
Definition: edgeMesh.C:279
Foam::edgeMesh::storedPoints
pointField & storedPoints()
Non-const access to global points.
Definition: edgeMeshI.H:61
Foam::edgeMesh::edgeMesh
edgeMesh()
Construct null.
Definition: edgeMesh.C:123
Foam::edgeMesh::xfer
Xfer< edgeMesh > xfer()
Transfer contents to the Xfer container.
Definition: edgeMesh.C:208
Foam::edgeMesh::mergePoints
virtual void mergePoints(const scalar mergeDist, labelList &)
Merge common points (points within mergeDist). Return map from.
Definition: edgeMesh.C:290
Foam::edgeMesh::pointEdgesPtr_
autoPtr< labelListList > pointEdgesPtr_
From point to edges.
Definition: edgeMesh.H:82
Foam::edgeMesh::read
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:75
Foam::HashSet
A HashTable with keys but without contents.
Definition: HashSet.H:59
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
edgeMeshI.H
Foam::edgeMesh::canRead
static bool canRead(const fileName &, const bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:90
Foam::edgeMesh::write
virtual void write(const fileName &name) const
Generic write routine. Chooses writer based on extension.
Definition: edgeMesh.H:262
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::edgeMesh::writeTypes
static wordHashSet writeTypes()
Definition: edgeMesh.C:49
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::edgeMesh::readTypes
static wordHashSet readTypes()
Definition: edgeMesh.C:43
Foam::edgeMesh::operator=
void operator=(const edgeMesh &)
Definition: edgeMeshI.H:75
Foam::edgeMesh::points
const pointField & points() const
Return points.
Definition: edgeMeshI.H:39
Foam::edgeMesh::writeStats
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:120
Foam::edgeMesh::operator>>
friend Istream & operator>>(Istream &, edgeMesh &)
Foam::edgeMesh::declareMemberFunctionSelectionTable
declareMemberFunctionSelectionTable(void, edgeMesh, write, fileExtension,(const fileName &name, const edgeMesh &mesh),(name, mesh))
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::edgeMesh::edges
const edgeList & edges() const
Return edges.
Definition: edgeMeshI.H:45
HashSet.H
Foam::edgeMesh::pointEdges
const labelListList & pointEdges() const
Return edges.
Definition: edgeMeshI.H:51
edgeList.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::edgeMesh::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, edgeMesh, fileExtension,(const fileName &name),(name))
Foam::edgeMesh::write
static void write(const fileName &, const edgeMesh &)
Write to file.
Definition: edgeMeshIO.C:87
Foam::edgeMesh::mergeEdges
virtual void mergeEdges()
Merge duplicate edges.
Definition: edgeMesh.C:365
Foam::edgeMesh::clear
virtual void clear()
Clear all storage.
Definition: edgeMesh.C:169
pointField.H
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::edgeMesh::reset
virtual void reset(const Xfer< pointField > &points, const Xfer< edgeList > &edges)
Reset primitive data (points, edges)
Definition: edgeMesh.C:178
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::edgeMesh::operator<<
friend Ostream & operator<<(Ostream &, const edgeMesh &)
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
memberFunctionSelectionTables.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::edgeMesh::transfer
void transfer(edgeMesh &)
Transfer the contents of the argument and annul the argument.
Definition: edgeMesh.C:200
Foam::edgeMesh::TypeName
TypeName("edgeMesh")
Runtime type information.
Foam::edgeMesh::edges_
edgeList edges_
The edges defining the boundary.
Definition: edgeMesh.H:79
Foam::edgeMesh
Points connected by edges.
Definition: edgeMesh.H:69
Foam::edgeMesh::calcPointEdges
void calcPointEdges() const
Calculate point-edge addressing (inverse of edges)
Definition: edgeMesh.C:106
Foam::fileFormats::edgeMeshFormatsCore
A collection of helper functions for reading/writing edge formats.
Definition: edgeMeshFormatsCore.H:58
edgeMeshFormatsCore.H
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47