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-2021 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 "dictionary.H"
50 #include "edgeMeshFormatsCore.H"
51 #include "runTimeSelectionTables.H"
53 #include "HashSet.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // Forward Declarations
61 class edgeMesh;
62 
63 Istream& operator>>(Istream& is, edgeMesh& em);
64 Ostream& operator<<(Ostream& os, const edgeMesh& em);
65 
66 /*---------------------------------------------------------------------------*\
67  Class edgeMesh Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 class edgeMesh
71 :
72  public fileFormats::edgeMeshFormatsCore
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 unique_ptr<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() noexcept;
98 
99  //- Non-const access to the edges
100  inline edgeList& storedEdges() noexcept;
101 
102 
103 public:
104 
105  //- Runtime type information
106  TypeName("edgeMesh");
107 
108 
109  // Static Member Functions
110 
111  //- Summary of supported read file types.
112  static wordHashSet readTypes();
113 
114  //- Summary of supported write file types.
115  static wordHashSet writeTypes();
116 
117  //- Can we read this file format?
118  static bool canReadType(const word& fileType, bool verbose=false);
119 
120  //- Can we write this file format type?
121  static bool canWriteType(const word& fileType, bool verbose=false);
122 
123  //- Can we read this file format?
124  static bool canRead(const fileName& name, bool verbose=false);
125 
126 
127  // Constructors
128 
129  //- Default construct
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  explicit edgeMesh(const fileName& name);
146 
147  //- Construct from file name with specified type
148  edgeMesh(const fileName& name, const word& fileType);
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  //- Read construct from filename with given format
168  static autoPtr<edgeMesh> New
169  (
170  const fileName& name,
171  const word& fileType
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  IOstreamOption streamOpt,
194  const dictionary& options
195  ),
196  (name, mesh, streamOpt, options)
197  );
198 
199  //- Write to file (format implicit in the extension)
200  static void write
201  (
202  const fileName& name,
203  const edgeMesh& mesh,
204  IOstreamOption streamOpt = IOstreamOption(),
205  const dictionary& options = dictionary::null
206  );
207 
208  //- Write to file, with given format
209  static void write
210  (
211  const fileName& name,
212  const word& fileType,
213  const edgeMesh& mesh,
214  IOstreamOption streamOpt = IOstreamOption(),
215  const dictionary& options = dictionary::null
216  );
217 
218 
219  // Member Functions
220 
221  //- Transfer the contents of the argument and annul the argument
222  void transfer(edgeMesh& mesh);
223 
224 
225  // Read
226 
227  //- Read from file. Chooses reader based on explicit extension
228  bool read(const fileName& name, const word& fileType);
229 
230  //- Read from file. Chooses reader based on detected extension
231  virtual bool read(const fileName& name);
232 
233 
234  // Access
235 
236  //- Return points
237  inline const pointField& points() const noexcept;
238 
239  //- Return edges
240  inline const edgeList& edges() const noexcept;
241 
242  //- Return edges
243  inline const labelListList& pointEdges() const;
244 
245  //- Find connected regions. Set region number per edge.
246  // Returns number of regions.
247  label regions(labelList& edgeRegion) const;
248 
249 
250  // Edit
251 
252  //- Clear all storage
253  virtual void clear();
254 
255  //- Scale points. A non-positive factor is ignored
256  virtual void scalePoints(const scalar scaleFactor);
257 
258  //- Geometric merge points (points within mergeDist) prior to
259  // automatically calling mergeEdges().
260  virtual void mergePoints(const scalar mergeDist);
261 
262  //- Merge duplicate edges and eliminate unused points.
263  virtual void mergeEdges();
264 
265 
266  // Write
267 
268  virtual void writeStats(Ostream&) const;
269 
270  //- Write to file, choosing writer based on the file extension.
271  virtual void write
272  (
273  const fileName& name,
274  IOstreamOption streamOpt = IOstreamOption(),
275  const dictionary& options = dictionary::null
276  ) const
277  {
278  write(name, *this, streamOpt, options);
279  }
280 
281  //- Write to file with given format type.
282  // If the format type is "", uses the file extension.
283  virtual void write
284  (
285  const fileName& name,
286  const word& fileType,
287  IOstreamOption streamOpt = IOstreamOption(),
288  const dictionary& options = dictionary::null
289  ) const
290  {
291  write(name, fileType, *this, streamOpt, options);
292  }
293 
294 
295  // Member Operators
296 
297  //- Copy assignment
298  inline void operator=(const edgeMesh& rhs);
299 
300  //- Move assignment
301  inline void operator=(edgeMesh&& rhs);
302 
303 
304  // Ostream Operator
305 
306  friend Ostream& operator<<(Ostream& os, const edgeMesh& em);
307  friend Istream& operator>>(Istream& is, edgeMesh& em);
308 };
309 
310 
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 
313 } // End namespace Foam
314 
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 
317 #include "edgeMeshI.H"
318 
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 
321 #endif
322 
323 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::edgeMesh::points
const pointField & points() const noexcept
Return points.
Definition: edgeMeshI.H:99
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:65
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:73
Foam::edgeMesh::declareMemberFunctionSelectionTable
declareMemberFunctionSelectionTable(void, edgeMesh, write, fileExtension,(const fileName &name, const edgeMesh &mesh, IOstreamOption streamOpt, const dictionary &options),(name, mesh, streamOpt, options))
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::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::write
static void write(const fileName &name, const edgeMesh &mesh, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null)
Write to file (format implicit in the extension)
Definition: edgeMeshIO.C:114
Foam::edgeMesh::storedPoints
pointField & storedPoints() noexcept
Non-const access to global points.
Definition: edgeMeshI.H:31
edgeMeshI.H
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:392
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::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::writeStats
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:125
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
HashSet.H
Foam::edgeMesh::pointEdges
const labelListList & pointEdges() const
Return edges.
Definition: edgeMeshI.H:111
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
edgeList.H
os
OBJstream os(runTime.globalPath()/outputName)
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::edgeMesh::edges
const edgeList & edges() const noexcept
Return edges.
Definition: edgeMeshI.H:105
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
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
dictionary.H
Foam::wordHashSet
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:77
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::edgeMesh::storedEdges
edgeList & storedEdges() noexcept
Non-const access to the edges.
Definition: edgeMeshI.H:37
memberFunctionSelectionTables.H
Macros to ease 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:53
edgeMeshFormatsCore.H
Foam::edgeMesh::transfer
void transfer(edgeMesh &mesh)
Transfer the contents of the argument and annul the argument.
Definition: edgeMesh.C:124