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-2018 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 
61 class edgeMesh;
62 class Istream;
63 class Ostream;
64 
65 Istream& operator>>(Istream& is, edgeMesh& em);
66 Ostream& operator<<(Ostream& os, const edgeMesh& em);
67 
68 
69 /*---------------------------------------------------------------------------*\
70  Class edgeMesh Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 class edgeMesh
74 :
75  public fileFormats::edgeMeshFormatsCore
76 {
77  // Private data
78 
79  //- Vertices of the edges
80  pointField points_;
81 
82  //- The edges defining the boundary
83  edgeList edges_;
84 
85  //- From point to edges
86  mutable autoPtr<labelListList> pointEdgesPtr_;
87 
88 
89  // Private Member Functions
90 
91  //- Calculate point-edge addressing (inverse of edges)
92  void calcPointEdges() const;
93 
94 
95 protected:
96 
97  // Protected Member Functions
98 
99  //- Non-const access to global points
100  inline pointField& storedPoints();
101 
102  //- Non-const access to the edges
103  inline edgeList& storedEdges();
104 
105 
106 public:
107 
108  //- Runtime type information
109  TypeName("edgeMesh");
110 
111 
112  // Static
113 
114  //- Can we read this file format?
115  static bool canRead(const fileName& name, bool verbose=false);
116 
117  //- Can we read this file format?
118  static bool canReadType(const word& ext, bool verbose=false);
119 
120  //- Can we write this file format type?
121  static bool canWriteType(const word& ext, bool verbose=false);
122 
123  static wordHashSet readTypes();
124  static wordHashSet writeTypes();
125 
126 
127  // Constructors
128 
129  //- Construct null
130  inline edgeMesh();
131 
132  //- Copy construct
133  inline edgeMesh(const edgeMesh& em);
134 
135  //- Move construct
136  inline edgeMesh(edgeMesh&& em);
137 
138  //- Copy construct from components
139  inline edgeMesh(const pointField& points, const edgeList& edges);
140 
141  //- Move construct from components
142  inline edgeMesh(pointField&& pointLst, edgeList&& edgeLst);
143 
144  //- Construct from file name (uses extension to determine type)
145  edgeMesh(const fileName& name);
146 
147  //- Construct from file name (uses extension to determine type)
148  edgeMesh(const fileName& name, const word& ext);
149 
150 
151  // Declare run-time constructor selection table
152 
154  (
155  autoPtr,
156  edgeMesh,
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& name,
171  const word& ext
172  );
173 
174  //- Select constructed from filename (implicit extension)
175  static autoPtr<edgeMesh> New(const fileName& name);
176 
177 
178  //- Destructor
179  virtual ~edgeMesh() = default;
180 
181 
182  // Member Function Selectors
183 
185  (
186  void,
187  edgeMesh,
188  write,
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& name, const edgeMesh& mesh);
199 
200 
201  // Member Functions
202 
203  //- Transfer the contents of the argument and annul the argument
204  void transfer(edgeMesh& mesh);
205 
206 
207  // Read
208 
209  //- Read from file. Chooses reader based on explicit extension
210  bool read(const fileName& name, const word& ext);
211 
212  //- Read from file. Chooses reader based on detected extension
213  virtual bool read(const fileName& name);
214 
215 
216  // Access
217 
218  //- Return points
219  inline const pointField& points() const;
220 
221  //- Return edges
222  inline const edgeList& edges() const;
223 
224  //- Return edges
225  inline const labelListList& pointEdges() const;
226 
227  //- Find connected regions. Set region number per edge.
228  // Returns number of regions.
229  label regions(labelList& edgeRegion) const;
230 
231 
232  // Edit
233 
234  //- Clear all storage
235  virtual void clear();
236 
237  //- Scale points. A non-positive factor is ignored
238  virtual void scalePoints(const scalar scaleFactor);
239 
240  //- Geometric merge points (points within mergeDist) prior to
241  // automatically calling mergeEdges().
242  virtual void mergePoints(const scalar mergeDist);
243 
244  //- Merge duplicate edges and eliminate unused points.
245  virtual void mergeEdges();
246 
247 
248  // Write
249 
250  virtual void writeStats(Ostream&) const;
251 
252  //- Generic write routine. Chooses writer based on extension.
253  virtual void write(const fileName& name) const
254  {
255  write(name, *this);
256  }
257 
258 
259  // Member Operators
260 
261  //- Copy assignment
262  inline void operator=(const edgeMesh& rhs);
263 
264  //- Move assignment
265  inline void operator=(edgeMesh&& rhs);
266 
267 
268  // Ostream Operator
269 
270  friend Ostream& operator<<(Ostream& os, const edgeMesh& em);
271  friend Istream& operator>>(Istream& is, edgeMesh& em);
272 
273 };
274 
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 } // End namespace Foam
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 #include "edgeMeshI.H"
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #endif
287 
288 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
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:196
Foam::edgeMesh::regions
label regions(labelList &edgeRegion) const
Find connected regions. Set region number per edge.
Definition: edgeMesh.C:131
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::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::vtk::fileExtension
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
Foam::edgeMesh::canReadType
static bool canReadType(const word &ext, bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:61
Foam::edgeMesh::storedPoints
pointField & storedPoints()
Non-const access to global points.
Definition: edgeMeshI.H:31
Foam::edgeMesh::edgeMesh
edgeMesh()
Construct null.
Definition: edgeMeshI.H:45
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:228
Foam::edgeMesh::operator>>
friend Istream & operator>>(Istream &is, edgeMesh &em)
Foam::edgeMesh::read
bool read(const fileName &name, const word &ext)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:76
Foam::edgeMesh::~edgeMesh
virtual ~edgeMesh()=default
Destructor.
edgeMeshI.H
Foam::edgeMesh::write
static void write(const fileName &name, const edgeMesh &mesh)
Write to file.
Definition: edgeMeshIO.C:88
Foam::edgeMesh::write
virtual void write(const fileName &name) const
Generic write routine. Chooses writer based on extension.
Definition: edgeMesh.H:252
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:62
Foam::edgeMesh::writeTypes
static wordHashSet writeTypes()
Definition: edgeMesh.C:53
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()
Definition: edgeMesh.C:47
Foam::edgeMesh::points
const pointField & points() const
Return points.
Definition: edgeMeshI.H:99
Foam::edgeMesh::writeStats
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:113
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:240
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:115
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:206
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::wordHashSet
HashSet< word > wordHashSet
A HashSet with word keys.
Definition: HashSet.H:412
Foam::edgeMesh::canWriteType
static bool canWriteType(const word &ext, bool verbose=false)
Can we write this file format type?
Definition: edgeMesh.C:73
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:123
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
Foam::edgeMesh::New
static autoPtr< edgeMesh > New(const fileName &name, const word &ext)
Select constructed from filename (explicit extension)
Definition: edgeMeshNew.C:33