All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
edgeMesh.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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  pointField&&,
136  edgeList&&
137  );
138 
139  //- Copy constructor
140  edgeMesh(const edgeMesh&);
141 
142  //- Move constructor
143  edgeMesh(edgeMesh&&);
144 
145  //- Construct from file name (uses extension to determine type)
146  edgeMesh(const fileName&);
147 
148  //- Construct from file name (uses extension to determine type)
149  edgeMesh(const fileName&, const word& ext);
150 
151  //- Construct from Istream
152  edgeMesh(Istream&);
153 
154 
155  // Declare run-time constructor selection table
156 
158  (
159  autoPtr,
160  edgeMesh,
161  fileExtension,
162  (
163  const fileName& name
164  ),
165  (name)
166  );
167 
168 
169  // Selectors
170 
171  //- Select constructed from filename (explicit extension)
172  static autoPtr<edgeMesh> New
173  (
174  const fileName&,
175  const word& ext
176  );
177 
178  //- Select constructed from filename (implicit extension)
179  static autoPtr<edgeMesh> New(const fileName&);
180 
181 
182  //- Destructor
183  virtual ~edgeMesh();
184 
185 
186  // Member Function Selectors
187 
189  (
190  void,
191  edgeMesh,
192  write,
193  fileExtension,
194  (
195  const fileName& name,
196  const edgeMesh& mesh
197  ),
198  (name, mesh)
199  );
200 
201  //- Write to file
202  static void write(const fileName&, const edgeMesh&);
203 
204 
205  // Member Functions
206 
207  //- Transfer the contents of the argument and annul the argument
208  void transfer(edgeMesh&);
209 
210 
211  // Read
212 
213  //- Read from file. Chooses reader based on explicit extension
214  bool read(const fileName&, const word& ext);
215 
216  //- Read from file. Chooses reader based on detected extension
217  virtual bool read(const fileName&);
218 
219 
220  // Access
221 
222  //- Return points
223  inline const pointField& points() const;
224 
225  //- Return edges
226  inline const edgeList& edges() const;
227 
228  //- Return edges
229  inline const labelListList& pointEdges() const;
230 
231  //- Find connected regions. Set region number per edge.
232  // Returns number of regions.
233  label regions(labelList& edgeRegion) const;
234 
235 
236  // Edit
237 
238  //- Clear all storage
239  virtual void clear();
240 
241  //- Reset primitive data (points, edges)
242  // Note, optimized to avoid overwriting data (with null)
243  virtual void reset
244  (
245  pointField&& points,
246  edgeList&& edges
247  );
248 
249  //- Scale points. A non-positive factor is ignored
250  virtual void scalePoints(const scalar);
251 
252  //- Merge common points (points within mergeDist). Return map from
253  // old to new points.
254  virtual void mergePoints(const scalar mergeDist, labelList&);
255 
256  //- Merge duplicate edges
257  virtual void mergeEdges();
258 
259 
260  // Write
261 
262  virtual void writeStats(Ostream&) const;
263 
264  //- Generic write routine. Chooses writer based on extension.
265  virtual void write(const fileName& name) const
266  {
267  write(name, *this);
268  }
269 
270 
271  // Member Operators
272 
273  inline void operator=(const edgeMesh&);
274  inline void operator=(edgeMesh&&);
275 
276 
277  // Ostream Operator
278 
279  friend Ostream& operator<<(Ostream&, const edgeMesh&);
280  friend Istream& operator>>(Istream&, edgeMesh&);
281 
282 };
283 
284 
285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286 
287 } // End namespace Foam
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 #include "edgeMeshI.H"
292 
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 
295 #endif
296 
297 // ************************************************************************* //
void transfer(edgeMesh &)
Transfer the contents of the argument and annul the argument.
Definition: edgeMesh.C:197
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:79
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:281
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:270
static bool canRead(const fileName &, const bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:90
void operator=(const edgeMesh &)
Definition: edgeMeshI.H:86
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:74
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:68
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:54
const pointField & points() const
Return points.
Definition: edgeMeshI.H:62
Points connected by edges.
Definition: edgeMesh.H:69
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:117
virtual void reset(pointField &&points, edgeList &&edges)
Reset primitive data (points, edges)
Definition: edgeMesh.C:175
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
virtual void clear()
Clear all storage.
Definition: edgeMesh.C:166
virtual void mergeEdges()
Merge duplicate edges.
Definition: edgeMesh.C:357
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:205
TypeName("edgeMesh")
Runtime type information.
virtual ~edgeMesh()
Destructor.
Definition: edgeMesh.C:160
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format type?
Definition: edgeMesh.C:74
Namespace for OpenFOAM.