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
// *****************************************************************************
/*!
  \file      src/IO/MeditMeshReader.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     Medit mesh reader class definition
  \details   Medit 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 "DerivedData.hpp"<--- Include file: "DerivedData.hpp" not found.
#include "MeditMeshReader.hpp"

using tk::MeditMeshReader;

void
MeditMeshReader::readMesh( UnsMesh& mesh )
// *****************************************************************************
//  Read Medit mesh
//! \param[in] mesh Unstructured mesh object
// *****************************************************************************
{
  std::size_t ntet = 0;
  // cppcheck-suppress unreadVariable
  std::size_t triid = 0;

  while (!m_inFile.eof()) {
    std::string s;
    m_inFile >> s;

    if (s == "Triangles") {

      int nel;
      m_inFile >> nel;
      //std::cout << "ntri: " << nel << '\n';
      ErrChk( nel > 0, "Number of triangles (surface elements) must be greater "
                       "than zero in file " + m_filename );
      for (int i=0; i<nel; ++i) {
        int tag;
        std::array< std::size_t, 3 > n;
        m_inFile >> n[0] >> n[1] >> n[2] >> tag;
        auto& triinpoel = mesh.triinpoel();
        triinpoel.push_back( n[0] );
        triinpoel.push_back( n[1] );
        triinpoel.push_back( n[2] );
        mesh.bface()[ tag ].push_back( triid++ );
        mesh.faceid()[ tag ].push_back( 0 );
      }

    } else if (s == "Tetrahedra") {

      int nel;
      m_inFile >> nel;
      //std::cout << "ntet: " << nel << '\n';
      ErrChk( nel > 0, "Number of tetrahedra (volume elements) must be greater "
                       "than zero in file " + m_filename );

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

    } else if (s == "Vertices") {

      int nnode;
      m_inFile >> nnode;
      //std::cout << "nnode: " << nnode << '\n';
      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
      int tag;
      for (int i=0; i<nnode; ++i) {
        tk::real x, y, z;
        m_inFile >> x >> y >> z >> tag;
        mesh.x().push_back( x );
        mesh.y().push_back( y );
        mesh.z().push_back( z );
      }
    }
  }

  // adjust boundary element ids in exo, since tets are written first
  for (auto& [sid,triangles] : mesh.bface()) {
    for (auto& tid : triangles) {
      // cppcheck-suppress useStlAlgorithm
      tid += ntet;
    }
  }

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

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