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
// *****************************************************************************
/*!
  \file      src/IO/NetgenMeshReader.cpp
  \copyright 2012-2015 J. Bakosi,
             2016-2018 Los Alamos National Security, LLC.,
             2019-2021 Triad National Security, LLC.,
             2022-2025 J. Bakosi
             All rights reserved. See the LICENSE file for details.
  \brief     Netgen mesh reader class definition
  \details   Netgen mesh reader class definition. Only supports tetrahedra.
*/
// *****************************************************************************

#include <array><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <istream><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <vector><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <cstddef><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "Types.hpp"
#include "Exception.hpp"
#include "UnsMesh.hpp"<--- Include file: "UnsMesh.hpp" not found.
#include "Reorder.hpp"<--- Include file: "Reorder.hpp" not found.
#include "NetgenMeshReader.hpp"

using tk::NetgenMeshReader;

void
NetgenMeshReader::readMesh( UnsMesh& mesh )
// *****************************************************************************
//  Read Netgen mesh
//! \param[in] mesh Unstructured mesh object
// *****************************************************************************
{
  // Read nodes
  readNodes( mesh );
  // Read elements
  readElements( mesh );
}

void
NetgenMeshReader::readNodes( UnsMesh& mesh )
// *****************************************************************************
//  Read nodes
//! \param[in] mesh Unstructured mesh object
// *****************************************************************************
{
  int nnode;
  m_inFile >> nnode;
  ErrChk( nnode > 0,
          "Number of nodes must be greater than zero in file " + m_filename  );

  // Read in node coordinates: x-coord y-coord z-coord
  for (int i=0; i<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 );
  }

  std::string s;
  getline( m_inFile, s );  // finish reading the last line
}

void
NetgenMeshReader::readElements( UnsMesh& mesh )
// *****************************************************************************
//  Read element connectivity
//! \param[in] mesh Unstructured mesh object
// *****************************************************************************
{
  int nel;

  // Read in number of tetrahedra
  m_inFile >> nel;
  if (!m_inFile.eof()) {
    ErrChk( nel > 0, "Number of tetrahedra (volume elements) must be greater "
                     "than zero in file " + m_filename );
    std::string s;
    getline( m_inFile, s );  // finish reading the last line

    // Read in tetrahedra element tags and connectivity
    for (int i=0; i<nel; ++i) {
      int tag;
      std::array< std::size_t, 4 > n;
      // tag n[1-4]
      m_inFile >> tag >> n[3] >> n[0] >> n[1] >> n[2];
      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.tetinpoel() );
  }

  // Read in number of triangles
  m_inFile >> nel;
  if (!m_inFile.eof()) {
    ErrChk( nel > 0, "Number of triangles (surface elements) must be greater "
                     "than zero in file " + m_filename );
    std::string s;
    getline( m_inFile, s );  // finish reading the last line

    // Read in triangle element tags and connectivity
    for (int i=0; i<nel; ++i) {
      int tag;
      std::array< std::size_t, 3 > n;
      // tag n[1-3]
      m_inFile >> tag >> n[0] >> n[1] >> n[2];
      mesh.triinpoel().push_back( n[0] );
      mesh.triinpoel().push_back( n[1] );
      mesh.triinpoel().push_back( n[2] );
    }

    // Shift node IDs to start from zero
    shiftToZero( mesh.triinpoel() );
  }
}