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