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-2022 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, optimised 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 duplicate edges
253  virtual void mergeEdges();
254 
255 
256  // Write
257 
258  virtual void writeStats(Ostream&) const;
259 
260  //- Generic write routine. Chooses writer based on extension.
261  virtual void write(const fileName& name) const
262  {
263  write(name, *this);
264  }
265 
266 
267  // Member Operators
268 
269  inline void operator=(const edgeMesh&);
270  inline void operator=(edgeMesh&&);
271 
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 // ************************************************************************* //
A HashTable with keys but without contents.
Definition: HashSet.H:62
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Points connected by edges.
Definition: edgeMesh.H:72
void operator=(const edgeMesh &)
Definition: edgeMeshI.H:86
virtual void scalePoints(const scalar)
Scale points. A non-positive factor is ignored.
Definition: edgeMesh.C:269
virtual void mergeEdges()
Merge duplicate edges.
Definition: edgeMesh.C:279
virtual ~edgeMesh()
Destructor.
Definition: edgeMesh.C:159
const labelListList & pointEdges() const
Return edges.
Definition: edgeMeshI.H:74
const edgeList & edges() const
Return edges.
Definition: edgeMeshI.H:68
friend Istream & operator>>(Istream &, edgeMesh &)
static autoPtr< edgeMesh > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
Definition: edgeMeshNew.C:31
virtual void reset(pointField &&points, edgeList &&edges)
Reset primitive data (points, edges)
Definition: edgeMesh.C:174
static wordHashSet writeTypes()
Definition: edgeMesh.C:48
edgeMesh()
Construct null.
Definition: edgeMesh.C:122
void transfer(edgeMesh &)
Transfer the contents of the argument and annul the argument.
Definition: edgeMesh.C:196
friend Ostream & operator<<(Ostream &, const edgeMesh &)
declareRunTimeSelectionTable(autoPtr, edgeMesh, fileExtension,(const fileName &name),(name))
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
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format type?
Definition: edgeMesh.C:73
label regions(labelList &edgeRegion) const
Find connected regions. Set region number per edge.
Definition: edgeMesh.C:204
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:117
TypeName("edgeMesh")
Runtime type information.
static bool canRead(const fileName &, const bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:89
declareMemberFunctionSelectionTable(void, edgeMesh, write, fileExtension,(const fileName &name, const edgeMesh &mesh),(name, mesh))
static bool canReadType(const word &ext, const bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:57
const pointField & points() const
Return points.
Definition: edgeMeshI.H:62
pointField & storedPoints()
Non-const access to global points.
Definition: edgeMeshI.H:28
virtual void clear()
Clear all storage.
Definition: edgeMesh.C:165
static void write(const fileName &, const edgeMesh &)
Write to file.
Definition: edgeMeshIO.C:87
static wordHashSet readTypes()
Definition: edgeMesh.C:42
A collection of helper functions for reading/writing edge formats.
A class for handling file names.
Definition: fileName.H:82
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
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
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
Istream & operator>>(Istream &, pistonPointEdgeData &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
Macros to ease declaration of run-time selection tables.