Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/IO/MeditMeshReader.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 Medit mesh reader class definition
10 : : \details Medit mesh reader class definition. Only supports tetrahedra.
11 : : */
12 : : // *****************************************************************************
13 : :
14 : : #include <array>
15 : : #include <istream>
16 : : #include <string>
17 : : #include <vector>
18 : : #include <cstddef>
19 : :
20 : : #include "Types.hpp"
21 : : #include "Exception.hpp"
22 : : #include "UnsMesh.hpp"
23 : : #include "Reorder.hpp"
24 : : #include "DerivedData.hpp"
25 : : #include "MeditMeshReader.hpp"
26 : :
27 : : using tk::MeditMeshReader;
28 : :
29 : : void
30 : 2 : MeditMeshReader::readMesh( UnsMesh& mesh )
31 : : // *****************************************************************************
32 : : // Read Medit mesh
33 : : //! \param[in] mesh Unstructured mesh object
34 : : // *****************************************************************************
35 : : {
36 : 2 : std::size_t ntet = 0;
37 : : // cppcheck-suppress unreadVariable
38 : 2 : std::size_t triid = 0;
39 : :
40 [ + + ]: 35 : while (!m_inFile.eof()) {
41 : 33 : std::string s;
42 [ + - ]: 33 : m_inFile >> s;
43 : :
44 [ + - ][ + + ]: 33 : if (s == "Triangles") {
45 : :
46 : : int nel;
47 [ + - ]: 2 : m_inFile >> nel;
48 : : //std::cout << "ntri: " << nel << '\n';
49 [ - + ][ - - ]: 2 : ErrChk( nel > 0, "Number of triangles (surface elements) must be greater "
[ - - ][ - - ]
50 : : "than zero in file " + m_filename );
51 [ + + ]: 146 : for (int i=0; i<nel; ++i) {
52 : : int tag;
53 : : std::array< std::size_t, 3 > n;
54 [ + - ][ + - ]: 144 : m_inFile >> n[0] >> n[1] >> n[2] >> tag;
[ + - ][ + - ]
55 : 144 : auto& triinpoel = mesh.triinpoel();
56 [ + - ]: 144 : triinpoel.push_back( n[0] );
57 [ + - ]: 144 : triinpoel.push_back( n[1] );
58 [ + - ]: 144 : triinpoel.push_back( n[2] );
59 [ + - ][ + - ]: 144 : mesh.bface()[ tag ].push_back( triid++ );
60 [ + - ][ + - ]: 144 : mesh.faceid()[ tag ].push_back( 0 );
61 : : }
62 : :
63 [ + - ][ + + ]: 31 : } else if (s == "Tetrahedra") {
64 : :
65 : : int nel;
66 [ + - ]: 1 : m_inFile >> nel;
67 : : //std::cout << "ntet: " << nel << '\n';
68 [ - + ][ - - ]: 1 : ErrChk( nel > 0, "Number of tetrahedra (volume elements) must be greater "
[ - - ][ - - ]
69 : : "than zero in file " + m_filename );
70 : :
71 : : // Read in tetrahedra element tags and connectivity
72 [ + + ]: 87 : for (int i=0; i<nel; ++i) {
73 : : int tag;
74 : : std::array< std::size_t, 4 > n;
75 [ + - ][ + - ]: 86 : m_inFile >> n[0] >> n[1] >> n[2] >> n[3] >> tag;
[ + - ][ + - ]
[ + - ]
76 [ + - ]: 86 : mesh.tetinpoel().push_back( n[0] );
77 [ + - ]: 86 : mesh.tetinpoel().push_back( n[1] );
78 [ + - ]: 86 : mesh.tetinpoel().push_back( n[2] );
79 [ + - ]: 86 : mesh.tetinpoel().push_back( n[3] );
80 : 86 : ++ntet;
81 : : }
82 : :
83 [ + - ][ + + ]: 30 : } else if (s == "Vertices") {
84 : :
85 : : int nnode;
86 [ + - ]: 2 : m_inFile >> nnode;
87 : : //std::cout << "nnode: " << nnode << '\n';
88 [ - + ][ - - ]: 2 : ErrChk( nnode > 0,
[ - - ][ - - ]
89 : : "Number of nodes must be greater than zero in file " + m_filename );
90 : :
91 : : // Read in node coordinates: x-coord y-coord z-coord
92 : : int tag;
93 [ + + ]: 80 : for (int i=0; i<nnode; ++i) {
94 : : tk::real x, y, z;
95 [ + - ][ + - ]: 78 : m_inFile >> x >> y >> z >> tag;
[ + - ][ + - ]
96 [ + - ]: 78 : mesh.x().push_back( x );
97 [ + - ]: 78 : mesh.y().push_back( y );
98 [ + - ]: 78 : mesh.z().push_back( z );
99 : : }
100 : : }
101 : 33 : }
102 : :
103 : : // adjust boundary element ids in exo, since tets are written first
104 [ + + ]: 14 : for (auto& [sid,triangles] : mesh.bface()) {
105 [ + + ]: 156 : for (auto& tid : triangles) {
106 : : // cppcheck-suppress useStlAlgorithm
107 : 144 : tid += ntet;
108 : : }
109 : : }
110 : :
111 : : // Shift node IDs to start from zero
112 : 2 : shiftToZero( mesh.triinpoel() );
113 : :
114 : : // Shift node IDs to start from zero
115 : 2 : shiftToZero( mesh.tetinpoel() );
116 : 2 : }
|