ensightMeshReader.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) 2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::fileFormats::ensightMeshReader
28 
29 Description
30 
31 Notes
32 
33 SourceFiles
34  ensightMeshReader.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_ensightMeshReader_H
39 #define Foam_ensightMeshReader_H
40 
41 #include "meshReader.H"
42 //#include "ensightReadFile.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward Declarations
50 class ensightReadFile;
51 
52 namespace fileFormats
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class fileFormats::ensightMeshReader Declaration
57 \*---------------------------------------------------------------------------*/
58 
60 :
61  public meshReader
62 {
63  // Private Data
64 
65  //- Merge distance
66  const scalar mergeTol_;
67 
68  //- Check and correct handedness
69  const bool setHandedness_;
70 
71 
72 protected:
73 
74  // Protected Data
75 
76  //- mesh point to original node_id
78 
79  //- mesh cell to original element_id
81 
82 
83  // Protected Member Functions
84 
85  //- Rotate face so lowest vertex is first
86  const face& rotateFace
87  (
88  const face& f,
89  face& rotatedFace
90  ) const;
91 
92  //- Read set of vertices. Optional mapping
93  void readVerts
94  (
95  ensightReadFile& is,
96  const label nVerts,
97  const Map<label>& nodeIdToPoints,
98  DynamicList<label>& verts
99  ) const;
100 
101  //- Read set of element/node IDs
102  void readIDs
103  (
104  ensightReadFile& is,
105  const bool doRead,
106  const label nShapes,
107  labelList& foamToElem,
108  Map<label>& elemToFoam
109  ) const;
110 
111  //- Swap handedness of hex if needed
112  void setHandedness
113  (
114  const cellModel& model,
115  DynamicList<label>& verts,
116  const pointField& points
117  ) const;
118 
119  //- Read a single part until eof (return true) or until start of next
120  // part (return false)
121  bool readGoldPart
122  (
123  ensightReadFile& is,
124  const bool read_node_ids,
125  const bool read_elem_ids,
126 
128  labelList& pointToNodeIds,
129  Map<label>& nodeIdToPoints,
130 
131  // 3D-elems : cells (cell-to-faces)
132  faceListList& cellFaces,
133  labelList& cellToElemIds,
134  Map<label>& elemIdToCells,
135 
136  // 2D-elems : faces
137  faceList& faces,
138  labelList& faceToElemIDs,
139  Map<label>& elemIdToFaces
140  ) const;
141 
142  //- Read the mesh from the file(s)
143  virtual bool readGeometry(const scalar scaleFactor = 1.0);
144 
145 
146 public:
147 
148  //- Runtime type information
149  TypeName("ensightMeshReader");
150 
151 
152  // Constructors
153 
154  //- Construct from case name
156  (
157  const fileName& geomFile,
158  const objectRegistry& registry,
159  const scalar mergeTol = SMALL,
160  const scalar scaleFactor = 1.0,
161  const bool setHandedness = true
162  );
163 
164 
165  //- Destructor
166  virtual ~ensightMeshReader() = default;
167 
168 
169  // Access
170 
171  //- Original node id (if supplied) or -1
172  const labelList& nodeIds() const noexcept
173  {
174  return nodeIds_;
175  }
176 
177  //- Original element id (if supplied) or -1
178  const labelList& elementIds() const noexcept
179  {
180  return elementIds_;
181  }
182 };
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace fileFormats
188 } // End namespace Foam
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 #endif
193 
194 // ************************************************************************* //
TypeName("ensightMeshReader")
Runtime type information.
A class for handling file names.
Definition: fileName.H:71
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
void readIDs(ensightReadFile &is, const bool doRead, const label nShapes, labelList &foamToElem, Map< label > &elemToFoam) const
Read set of element/node IDs.
const face & rotateFace(const face &f, face &rotatedFace) const
Rotate face so lowest vertex is first.
void readVerts(ensightReadFile &is, const label nVerts, const Map< label > &nodeIdToPoints, DynamicList< label > &verts) const
Read set of vertices. Optional mapping.
const pointField & points
A variant of IFstream with specialised read() for strings, integers and floats. Correctly handles bin...
const labelList & nodeIds() const noexcept
Original node id (if supplied) or -1.
const direction noexcept
Definition: Scalar.H:258
labelList f(nPoints)
const labelList & elementIds() const noexcept
Original element id (if supplied) or -1.
ensightMeshReader(const fileName &geomFile, const objectRegistry &registry, const scalar mergeTol=SMALL, const scalar scaleFactor=1.0, const bool setHandedness=true)
Construct from case name.
void setHandedness(const cellModel &model, DynamicList< label > &verts, const pointField &points) const
Swap handedness of hex if needed.
bool readGoldPart(ensightReadFile &is, const bool read_node_ids, const bool read_elem_ids, pointField &points, labelList &pointToNodeIds, Map< label > &nodeIdToPoints, faceListList &cellFaces, labelList &cellToElemIds, Map< label > &elemIdToCells, faceList &faces, labelList &faceToElemIDs, Map< label > &elemIdToFaces) const
Read a single part until eof (return true) or until start of next.
virtual ~ensightMeshReader()=default
Destructor.
Maps a geometry to a set of cell primitives.
Definition: cellModel.H:68
labelList elementIds_
mesh cell to original element_id
virtual bool readGeometry(const scalar scaleFactor=1.0)
Read the mesh from the file(s)
Registry of regIOobjects.
labelList nodeIds_
mesh point to original node_id
This class supports creating polyMeshes with baffles.
Definition: meshReader.H:64
Namespace for OpenFOAM.