Quinoa all test code coverage report
Current view: top level - IO - NetgenMeshReader.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 36 36 100.0 %
Date: 2024-04-29 14:42:33 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 26 74 35.1 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/IO/NetgenMeshReader.cpp
       4                 :            :   \copyright 2012-2015 J. Bakosi,
       5                 :            :              2016-2018 Los Alamos National Security, LLC.,
       6                 :            :              2019-2021 Triad National Security, LLC.
       7                 :            :              All rights reserved. See the LICENSE file for details.
       8                 :            :   \brief     Netgen mesh reader class definition
       9                 :            :   \details   Netgen mesh reader class definition. Only supports tetrahedra.
      10                 :            : */
      11                 :            : // *****************************************************************************
      12                 :            : 
      13                 :            : #include <array>
      14                 :            : #include <istream>
      15                 :            : #include <string>
      16                 :            : #include <vector>
      17                 :            : #include <cstddef>
      18                 :            : 
      19                 :            : #include "Types.hpp"
      20                 :            : #include "Exception.hpp"
      21                 :            : #include "UnsMesh.hpp"
      22                 :            : #include "Reorder.hpp"
      23                 :            : #include "NetgenMeshReader.hpp"
      24                 :            : 
      25                 :            : using tk::NetgenMeshReader;
      26                 :            : 
      27                 :            : void
      28                 :          3 : NetgenMeshReader::readMesh( UnsMesh& mesh )
      29                 :            : // *****************************************************************************
      30                 :            : //  Read Netgen mesh
      31                 :            : //! \param[in] mesh Unstructured mesh object
      32                 :            : // *****************************************************************************
      33                 :            : {
      34                 :            :   // Read nodes
      35                 :          3 :   readNodes( mesh );
      36                 :            :   // Read elements
      37                 :          3 :   readElements( mesh );
      38                 :          3 : }
      39                 :            : 
      40                 :            : void
      41                 :          3 : NetgenMeshReader::readNodes( UnsMesh& mesh )
      42                 :            : // *****************************************************************************
      43                 :            : //  Read nodes
      44                 :            : //! \param[in] mesh Unstructured mesh object
      45                 :            : // *****************************************************************************
      46                 :            : {
      47                 :            :   int nnode;
      48                 :          3 :   m_inFile >> nnode;
      49 [ +  - ][ -  - ]:          3 :   ErrChk( nnode > 0,
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      50                 :            :           "Number of nodes must be greater than zero in file " + m_filename  );
      51                 :            : 
      52                 :            :   // Read in node coordinates: x-coord y-coord z-coord
      53         [ +  + ]:       1670 :   for (int i=0; i<nnode; ++i) {
      54                 :            :     tk::real x, y, z;
      55                 :            :     m_inFile >> x >> y >> z;
      56                 :       1667 :     mesh.x().push_back( x );
      57                 :       1667 :     mesh.y().push_back( y );
      58                 :       1667 :     mesh.z().push_back( z );
      59                 :            :   }
      60                 :            : 
      61                 :            :   std::string s;
      62         [ +  - ]:          3 :   getline( m_inFile, s );  // finish reading the last line
      63                 :          3 : }
      64                 :            : 
      65                 :            : void
      66                 :          3 : NetgenMeshReader::readElements( UnsMesh& mesh )
      67                 :            : // *****************************************************************************
      68                 :            : //  Read element connectivity
      69                 :            : //! \param[in] mesh Unstructured mesh object
      70                 :            : // *****************************************************************************
      71                 :            : {
      72                 :            :   int nel;
      73                 :            : 
      74                 :            :   // Read in number of tetrahedra
      75                 :          3 :   m_inFile >> nel;
      76         [ +  - ]:          3 :   if (!m_inFile.eof()) {
      77 [ -  + ][ -  - ]:          3 :     ErrChk( nel > 0, "Number of tetrahedra (volume elements) must be greater "
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      78                 :            :                      "than zero in file " + m_filename );
      79                 :            :     std::string s;
      80         [ +  - ]:          3 :     getline( m_inFile, s );  // finish reading the last line
      81                 :            : 
      82                 :            :     // Read in tetrahedra element tags and connectivity
      83         [ +  + ]:       5457 :     for (int i=0; i<nel; ++i) {
      84                 :            :       int tag;
      85                 :            :       std::array< std::size_t, 4 > n;
      86                 :            :       // tag n[1-4]
      87         [ +  - ]:       5454 :       m_inFile >> tag >> n[3] >> n[0] >> n[1] >> n[2];
      88         [ +  - ]:       5454 :       mesh.tetinpoel().push_back( n[0] );
      89         [ +  - ]:       5454 :       mesh.tetinpoel().push_back( n[1] );
      90         [ +  - ]:       5454 :       mesh.tetinpoel().push_back( n[2] );
      91         [ +  - ]:       5454 :       mesh.tetinpoel().push_back( n[3] );
      92                 :            :     }
      93                 :            : 
      94                 :            :     // Shift node IDs to start from zero
      95         [ +  - ]:          3 :     shiftToZero( mesh.tetinpoel() );
      96                 :            :   }
      97                 :            : 
      98                 :            :   // Read in number of triangles
      99                 :          3 :   m_inFile >> nel;
     100         [ +  + ]:          3 :   if (!m_inFile.eof()) {
     101 [ -  + ][ -  - ]:          2 :     ErrChk( nel > 0, "Number of triangles (surface elements) must be greater "
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     102                 :            :                      "than zero in file " + m_filename );
     103                 :            :     std::string s;
     104         [ +  - ]:          2 :     getline( m_inFile, s );  // finish reading the last line
     105                 :            : 
     106                 :            :     // Read in triangle element tags and connectivity
     107         [ +  + ]:       2606 :     for (int i=0; i<nel; ++i) {
     108                 :            :       int tag;
     109                 :            :       std::array< std::size_t, 3 > n;
     110                 :            :       // tag n[1-3]
     111         [ +  - ]:       2604 :       m_inFile >> tag >> n[0] >> n[1] >> n[2];
     112         [ +  - ]:       2604 :       mesh.triinpoel().push_back( n[0] );
     113         [ +  - ]:       2604 :       mesh.triinpoel().push_back( n[1] );
     114         [ +  - ]:       2604 :       mesh.triinpoel().push_back( n[2] );
     115                 :            :     }
     116                 :            : 
     117                 :            :     // Shift node IDs to start from zero
     118         [ +  - ]:          2 :     shiftToZero( mesh.triinpoel() );
     119                 :            :   }
     120                 :          3 : }

Generated by: LCOV version 1.14