1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 | // *****************************************************************************
/*!
\file src/IO/UGRIDMeshReader.cpp
\copyright 2012-2015 J. Bakosi,
2016-2018 Los Alamos National Security, LLC.,
2019-2021 Triad National Security, LLC.
All rights reserved. See the LICENSE file for details.
\brief UGRID mesh reader class declaration
\details UGRID mesh reader class declaration. Mesh reader facilitating
reading a mesh from a simple text file used by NASA.
\see http://www.simcenter.msstate.edu/software/downloads/doc/ug_io/3d_grid_file_type_ugrid.html, http://www.simcenter.msstate.edu/software/downloads/doc/aflr3/aflr3_io_summary.html
*/
// *****************************************************************************
#include <array>
#include <istream>
#include <string>
#include <vector>
#include <cstddef>
#include "Types.hpp"
#include "Exception.hpp"
#include "UnsMesh.hpp"
#include "Reorder.hpp"
#include "UGRIDMeshReader.hpp"
using tk::UGRIDMeshReader;
void
UGRIDMeshReader::readHeader()
// *****************************************************************************
// Read UGRID mesh header
// *****************************************************************************
{
std::string s;<--- Unused variable: s
// Number_of_Nodes
m_inFile >> m_nnode;
// Number_of_Surf_Trias
m_inFile >> m_ntri;
// Number_of_Surf_Quads
int nquad;
m_inFile >> nquad;
// Number_of_Vol_Tets
m_inFile >> m_ntet;
// Number_of_Vol_Pents_5
int pent5;
m_inFile >> pent5;
// Number_of_Vol_Pents_6
int pent6;
m_inFile >> pent6;
// Number_of_Vol_Hexs
int nhex;
m_inFile >> nhex;
}
void
UGRIDMeshReader::readMesh( UnsMesh& mesh )
// *****************************************************************************
// Read UGRID mesh
//! \param[in] mesh Unstructured mesh object
// *****************************************************************************
{
// Read header
readHeader();
// Read nodes
readNodes( mesh );
// Read elements
readElements( mesh );
}
void
UGRIDMeshReader::readNodes( UnsMesh& mesh )
// *****************************************************************************
// Read nodes
//! \param[in] mesh Unstructured mesh object
// *****************************************************************************
{
// Read in node coordinates: x-coord y-coord z-coord
for (std::size_t i=0; i<m_nnode; ++i) {
tk::real x, y, z;
m_inFile >> x >> y >> z;
mesh.x().push_back( x );
mesh.y().push_back( y );
mesh.z().push_back( z );
}
}
void
UGRIDMeshReader::readElements( UnsMesh& mesh )
// *****************************************************************************
// Read element connectivity
//! \param[in] mesh Unstructured mesh object
// *****************************************************************************
{
// Read in triangle element connectivity
for (std::size_t i=0; i<m_ntri; ++i) {
std::array< std::size_t, 3 > n;
m_inFile >> n[0] >> n[1] >> n[2];
mesh.triinpoel().push_back( n[0] );
mesh.triinpoel().push_back( n[1] );
mesh.triinpoel().push_back( n[2] );
}
// Read side sets of triangle elements
for (std::size_t i=0; i<m_ntri; ++i) {
int setid;
m_inFile >> setid;
mesh.bface()[ setid ].push_back( m_ntet + i );
mesh.faceid()[ setid ].push_back( 0 );
}
// Read in tetrahedra element connectivity
for (std::size_t i=0; i<m_ntet; ++i) {
std::array< std::size_t, 4 > n;
m_inFile >> n[0] >> n[1] >> n[2] >> n[3];
mesh.tetinpoel().push_back( n[0] );
mesh.tetinpoel().push_back( n[1] );
mesh.tetinpoel().push_back( n[2] );
mesh.tetinpoel().push_back( n[3] );
}
// Shift node IDs to start from zero
shiftToZero( mesh.triinpoel() );
shiftToZero( mesh.tetinpoel() );
}
|