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 std::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
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 // ************************************************************************* //
bool read(const fileName &name, const word &fileType)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:66
const pointField & points() const noexcept
Return points.
Definition: edgeMeshI.H:92
List< edge > edgeList
List of edge.
Definition: edgeList.H:32
static bool canReadType(const word &fileType, bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:54
virtual void scalePoints(const scalar scaleFactor)
Scale points. A non-positive factor is ignored.
Definition: edgeMesh.C:198
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:105
declareMemberFunctionSelectionTable(void, edgeMesh, write, fileExtension,(const fileName &name, const edgeMesh &mesh, IOstreamOption streamOpt, const dictionary &options),(name, mesh, streamOpt, options))
void operator=(const edgeMesh &rhs)
Copy assignment.
Definition: edgeMeshI.H:116
friend Ostream & operator<<(Ostream &os, const edgeMesh &em)
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
edgeMesh()
Default construct.
Definition: edgeMeshI.H:38
static wordHashSet writeTypes()
Summary of supported write file types.
Definition: edgeMesh.C:48
friend Istream & operator>>(Istream &is, edgeMesh &em)
pointField & storedPoints() noexcept
Non-const access to global points.
Definition: edgeMeshI.H:24
const labelListList & pointEdges() const
Return edges.
Definition: edgeMeshI.H:104
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
declareRunTimeSelectionTable(autoPtr, edgeMesh, fileExtension,(const fileName &name),(name))
Istream & operator>>(Istream &, directionInfo &)
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:474
virtual void mergePoints(const scalar mergeDist)
Geometric merge points (points within mergeDist) prior to.
Definition: edgeMesh.C:208
static wordHashSet readTypes()
Summary of supported read file types.
Definition: edgeMesh.C:42
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:73
const direction noexcept
Definition: Scalar.H:258
static bool canWriteType(const word &fileType, bool verbose=false)
Can we write this file format type?
Definition: edgeMesh.C:66
OBJstream os(runTime.globalPath()/outputName)
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:116
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
Macros to ease declaration of member function selection tables.
virtual void clear()
Clear all storage.
Definition: edgeMesh.C:111
virtual void mergeEdges()
Merge duplicate edges and eliminate unused points.
Definition: edgeMesh.C:235
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
const edgeList & edges() const noexcept
Return edges.
Definition: edgeMeshI.H:98
void transfer(edgeMesh &mesh)
Transfer the contents of the argument and annul the argument.
Definition: edgeMesh.C:119
static bool canRead(const fileName &name, bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:78
Macros to ease declaration of run-time selection tables.
List< label > labelList
A List of labels.
Definition: List.H:62
label regions(labelList &edgeRegion) const
Find connected regions. Set region number per edge.
Definition: edgeMesh.C:132
edgeList & storedEdges() noexcept
Non-const access to the edges.
Definition: edgeMeshI.H:30
static autoPtr< edgeMesh > New(const fileName &name, const word &fileType)
Read construct from filename with given format.
Definition: edgeMeshNew.C:27
TypeName("edgeMesh")
Runtime type information.
Namespace for OpenFOAM.