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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2014 OpenFOAM Foundation
9  Copyright (C) 2017-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::edgeMesh
29 
30 Description
31  Points connected by edges.
32 
33  Can be read from fileName based on extension. Uses ::New factory method
34  to select the reader and transfer the result.
35 
36 SourceFiles
37  edgeMeshI.H
38  edgeMesh.C
39  edgeMeshIO.C
40  edgeMeshNew.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef edgeMesh_H
45 #define edgeMesh_H
46 
47 #include "pointField.H"
48 #include "edgeList.H"
49 #include "edgeMeshFormatsCore.H"
50 #include "runTimeSelectionTables.H"
52 #include "HashSet.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 // Forward Declarations
60 class edgeMesh;
61 
62 Istream& operator>>(Istream& is, edgeMesh& em);
63 Ostream& operator<<(Ostream& os, const edgeMesh& em);
64 
65 /*---------------------------------------------------------------------------*\
66  Class edgeMesh Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class edgeMesh
70 :
71  public fileFormats::edgeMeshFormatsCore
72 {
73  // Private Data
74 
75  //- Vertices of the edges
76  pointField points_;
77 
78  //- The edges defining the boundary
79  edgeList edges_;
80 
81  //- From point to edges
82  mutable unique_ptr<labelListList> pointEdgesPtr_;
83 
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 Member Functions
109 
110  //- Summary of supported read file types.
111  static wordHashSet readTypes();
112 
113  //- Summary of supported write file types.
114  static wordHashSet writeTypes();
115 
116  //- Can we read this file format?
117  static bool canReadType(const word& fileType, bool verbose=false);
118 
119  //- Can we write this file format type?
120  static bool canWriteType(const word& fileType, bool verbose=false);
121 
122  //- Can we read this file format?
123  static bool canRead(const fileName& name, bool verbose=false);
124 
125 
126  // Constructors
127 
128  //- Default construct
129  inline edgeMesh();
130 
131  //- Copy construct
132  inline edgeMesh(const edgeMesh& em);
133 
134  //- Move construct
135  inline edgeMesh(edgeMesh&& em);
136 
137  //- Copy construct from components
138  inline edgeMesh(const pointField& points, const edgeList& edges);
139 
140  //- Move construct from components
141  inline edgeMesh(pointField&& pointLst, edgeList&& edgeLst);
142 
143  //- Construct from file name (uses extension to determine type)
144  edgeMesh(const fileName& name);
145 
146  //- Construct from file name with specified type
147  edgeMesh(const fileName& name, const word& fileType);
148 
149 
150  // Declare run-time constructor selection table
151 
153  (
154  autoPtr,
155  edgeMesh,
157  (
158  const fileName& name
159  ),
160  (name)
161  );
162 
163 
164  // Selectors
165 
166  //- Read construct from filename with given format
167  static autoPtr<edgeMesh> New
168  (
169  const fileName& name,
170  const word& fileType
171  );
172 
173  //- Select constructed from filename (implicit extension)
174  static autoPtr<edgeMesh> New(const fileName& name);
175 
176 
177  //- Destructor
178  virtual ~edgeMesh() = default;
179 
180 
181  // Member Function Selectors
182 
184  (
185  void,
186  edgeMesh,
187  write,
189  (
190  const fileName& name,
191  const edgeMesh& mesh
192  ),
193  (name, mesh)
194  );
195 
196  //- Write to file (format implicit in the extension)
197  static void write
198  (
199  const fileName& name,
200  const edgeMesh& mesh
201  );
202 
203  //- Write to file, with given format
204  static void write
205  (
206  const fileName& name,
207  const word& fileType,
208  const edgeMesh& mesh
209  );
210 
211 
212  // Member Functions
213 
214  //- Transfer the contents of the argument and annul the argument
215  void transfer(edgeMesh& mesh);
216 
217 
218  // Read
219 
220  //- Read from file. Chooses reader based on explicit extension
221  bool read(const fileName& name, const word& fileType);
222 
223  //- Read from file. Chooses reader based on detected extension
224  virtual bool read(const fileName& name);
225 
226 
227  // Access
228 
229  //- Return points
230  inline const pointField& points() const;
231 
232  //- Return edges
233  inline const edgeList& edges() const;
234 
235  //- Return edges
236  inline const labelListList& pointEdges() const;
237 
238  //- Find connected regions. Set region number per edge.
239  // Returns number of regions.
240  label regions(labelList& edgeRegion) const;
241 
242 
243  // Edit
244 
245  //- Clear all storage
246  virtual void clear();
247 
248  //- Scale points. A non-positive factor is ignored
249  virtual void scalePoints(const scalar scaleFactor);
250 
251  //- Geometric merge points (points within mergeDist) prior to
252  // automatically calling mergeEdges().
253  virtual void mergePoints(const scalar mergeDist);
254 
255  //- Merge duplicate edges and eliminate unused points.
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  //- Generic write routine. Chooses writer based on extension.
270  virtual void write(const fileName& name, const word& fileType) const
271  {
272  write(name, fileType, *this);
273  }
274 
275 
276  // Member Operators
277 
278  //- Copy assignment
279  inline void operator=(const edgeMesh& rhs);
280 
281  //- Move assignment
282  inline void operator=(edgeMesh&& rhs);
283 
284 
285  // Ostream Operator
286 
287  friend Ostream& operator<<(Ostream& os, const edgeMesh& em);
288  friend Istream& operator>>(Istream& is, edgeMesh& em);
289 };
290 
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 } // End namespace Foam
295 
296 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 
298 #include "edgeMeshI.H"
299 
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 
302 #endif
303 
304 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::edgeMesh::storedEdges
edgeList & storedEdges()
Non-const access to the edges.
Definition: edgeMeshI.H:37
Foam::edgeMesh::scalePoints
virtual void scalePoints(const scalar scaleFactor)
Scale points. A non-positive factor is ignored.
Definition: edgeMesh.C:203
Foam::edgeMesh::regions
label regions(labelList &edgeRegion) const
Find connected regions. Set region number per edge.
Definition: edgeMesh.C:137
Foam::edgeMesh::operator=
void operator=(const edgeMesh &rhs)
Copy assignment.
Definition: edgeMeshI.H:123
Foam::edgeList
List< edge > edgeList
A List of edges.
Definition: edgeList.H:63
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::edgeMesh::canReadType
static bool canReadType(const word &fileType, bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:61
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::edgeMesh::New
static autoPtr< edgeMesh > New(const fileName &name, const word &fileType)
Read construct from filename with given format.
Definition: edgeMeshNew.C:34
Foam::vtk::fileExtension
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
Foam::edgeMesh::storedPoints
pointField & storedPoints()
Non-const access to global points.
Definition: edgeMeshI.H:31
Foam::edgeMesh::edgeMesh
edgeMesh()
Default construct.
Definition: edgeMeshI.H:45
Foam::edgeMesh::read
bool read(const fileName &name, const word &fileType)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:75
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::edgeMesh::operator>>
friend Istream & operator>>(Istream &is, edgeMesh &em)
Foam::edgeMesh::~edgeMesh
virtual ~edgeMesh()=default
Destructor.
edgeMeshI.H
Foam::edgeMesh::write
static void write(const fileName &name, const edgeMesh &mesh)
Write to file (format implicit in the extension)
Definition: edgeMeshIO.C:112
Foam::edgeMesh::write
virtual void write(const fileName &name) const
Generic write routine. Chooses writer based on extension.
Definition: edgeMesh.H:263
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::edgeMesh::writeTypes
static wordHashSet writeTypes()
Summary of supported write file types.
Definition: edgeMesh.C:55
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::edgeMesh::operator<<
friend Ostream & operator<<(Ostream &os, const edgeMesh &em)
Foam::edgeMesh::readTypes
static wordHashSet readTypes()
Summary of supported read file types.
Definition: edgeMesh.C:49
Foam::edgeMesh::points
const pointField & points() const
Return points.
Definition: edgeMeshI.H:99
Foam::edgeMesh::writeStats
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:121
Foam::edgeMesh::declareMemberFunctionSelectionTable
declareMemberFunctionSelectionTable(void, edgeMesh, write, fileExtension,(const fileName &name, const edgeMesh &mesh),(name, mesh))
Foam::edgeMesh::edges
const edgeList & edges() const
Return edges.
Definition: edgeMeshI.H:105
HashSet.H
Foam::edgeMesh::pointEdges
const labelListList & pointEdges() const
Return edges.
Definition: edgeMeshI.H:111
edgeList.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::edgeMesh::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, edgeMesh, fileExtension,(const fileName &name),(name))
Foam::edgeMesh::mergeEdges
virtual void mergeEdges()
Merge duplicate edges and eliminate unused points.
Definition: edgeMesh.C:247
Foam::edgeMesh::canRead
static bool canRead(const fileName &name, bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:85
Foam::edgeMesh::clear
virtual void clear()
Clear all storage.
Definition: edgeMesh.C:116
Foam::edgeMesh::canWriteType
static bool canWriteType(const word &fileType, bool verbose=false)
Can we write this file format type?
Definition: edgeMesh.C:73
pointField.H
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
Foam::edgeMesh::mergePoints
virtual void mergePoints(const scalar mergeDist)
Geometric merge points (points within mergeDist) prior to.
Definition: edgeMesh.C:213
Foam::edgeMesh::write
virtual void write(const fileName &name, const word &fileType) const
Generic write routine. Chooses writer based on extension.
Definition: edgeMesh.H:269
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::wordHashSet
HashSet< word > wordHashSet
A HashSet with word keys.
Definition: HashSet.H:406
memberFunctionSelectionTables.H
Macros to enable the easy declaration of member function selection tables.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::edgeMesh::TypeName
TypeName("edgeMesh")
Runtime type information.
Foam::edgeMesh
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:52
edgeMeshFormatsCore.H
Foam::edgeMesh::transfer
void transfer(edgeMesh &mesh)
Transfer the contents of the argument and annul the argument.
Definition: edgeMesh.C:124