Xyst test code coverage report
Current view: top level - IO - RDGFLOMeshReader.cpp (source / functions) Coverage Total Hit
Commit: 1fb74642dd9d7732b67f32dec2f2762e238d3fa7 Lines: 94.7 % 76 72
Test Date: 2025-08-13 22:46:33 Functions: 100.0 % 4 4
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 37.5 % 152 57

             Branch data     Line data    Source code
       1                 :             : // *****************************************************************************
       2                 :             : /*!
       3                 :             :   \file      src/IO/RDGFLOMeshReader.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     RDGFLO mesh reader class declaration
      10                 :             :   \details   RDGFLO mesh reader class declaration. Mesh reader facilitating
      11                 :             :              reading a mesh from a simple text file used by Prof. Hong Luo at
      12                 :             :              North Carolina State University.
      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 "RDGFLOMeshReader.hpp"
      27                 :             : 
      28                 :             : using tk::RDGFLOMeshReader;
      29                 :             : 
      30                 :             : void
      31                 :           1 : RDGFLOMeshReader::readHeader()
      32                 :             : // *****************************************************************************
      33                 :             : //  Read RDGFLO mesh header
      34                 :             : // *****************************************************************************
      35                 :             : {
      36                 :             :   // read in header: "npoin, ntetr, npyra, npris, nhexa, ntria, nquad, time"
      37                 :           1 :   std::string s;
      38 [ +  - ][ +  + ]:           9 :   for (int i=0; i<8; ++i) m_inFile >> s;
      39                 :             : 
      40                 :             :   // number of points
      41         [ +  - ]:           1 :   m_inFile >> m_nnode;
      42                 :             : 
      43                 :             :   // number of tetrahedra
      44         [ +  - ]:           1 :   m_inFile >> m_ntet;
      45 [ -  + ][ -  - ]:           1 :   if (m_ntet == 0) Throw( "No tetrahedra in input mesh" );
         [ -  - ][ -  - ]
      46                 :             : 
      47                 :             :   // number of pyramids
      48                 :             :   std::size_t npyra;
      49         [ +  - ]:           1 :   m_inFile >> npyra;
      50         [ -  + ]:           1 :   if (npyra > 0)
      51 [ -  - ][ -  - ]:           0 :     Throw( "Pyramids not supported. Need a mesh with only tetrahedra." );
                 [ -  - ]
      52                 :             : 
      53                 :             :   // number of prisms
      54                 :             :   std::size_t npris;
      55         [ +  - ]:           1 :   m_inFile >> npris;
      56         [ -  + ]:           1 :   if (npris > 0)
      57 [ -  - ][ -  - ]:           0 :     Throw( "Prisms not supported. Need a mesh with only tetrahedra." );
                 [ -  - ]
      58                 :             : 
      59                 :             :   // number of hexahedra
      60                 :             :   std::size_t nhexa;
      61         [ +  - ]:           1 :   m_inFile >> nhexa;
      62         [ -  + ]:           1 :   if (nhexa > 0)
      63 [ -  - ][ -  - ]:           0 :     Throw( "Hexahedra not supported. Need a mesh with only tetrahedra." );
                 [ -  - ]
      64                 :             : 
      65                 :             :   // number of triangles
      66         [ +  - ]:           1 :   m_inFile >> m_ntri;
      67                 :             : 
      68                 :             :   // number of quads
      69                 :             :   std::size_t nquad;
      70         [ +  - ]:           1 :   m_inFile >> nquad;
      71         [ -  + ]:           1 :   if (nquad > 0)
      72 [ -  - ][ -  - ]:           0 :     Throw( "Quads not supported. Need a mesh with only tetrahedra." );
                 [ -  - ]
      73                 :             : 
      74                 :             :   // time
      75                 :             :   tk::real time;
      76         [ +  - ]:           1 :   m_inFile >> time;
      77                 :           1 : }
      78                 :             : 
      79                 :             : void
      80                 :           1 : RDGFLOMeshReader::readMesh( UnsMesh& mesh )
      81                 :             : // *****************************************************************************
      82                 :             : //  Read RDGFLO mesh
      83                 :             : //! \param[in] mesh Unstructured mesh object
      84                 :             : // *****************************************************************************
      85                 :             : {
      86                 :             :   // Read header
      87                 :           1 :   readHeader();
      88                 :             :   // Read elements
      89                 :           1 :   readElements( mesh );
      90                 :             :   // Read nodes
      91                 :           1 :   readNodes( mesh );
      92                 :           1 : }
      93                 :             : 
      94                 :             : void
      95                 :           1 : RDGFLOMeshReader::readNodes( UnsMesh& mesh )
      96                 :             : // *****************************************************************************
      97                 :             : //  Read nodes
      98                 :             : //! \param[in] mesh Unstructured mesh object
      99                 :             : // *****************************************************************************
     100                 :             : {
     101                 :           1 :   std::string s;
     102                 :             : 
     103         [ +  - ]:           1 :   std::getline( m_inFile, s );
     104         [ +  - ]:           1 :   std::getline( m_inFile, s );
     105 [ +  - ][ -  + ]:           1 :   Assert( s == " grid point coordinates",
         [ -  - ][ -  - ]
                 [ -  - ]
     106                 :             :           "Invalid keyword, expected: ' grid point coordinates'" );
     107                 :             : 
     108                 :             :   // Read in node coordinates: x-coord y-coord z-coord
     109                 :           1 :   auto& xcoord = mesh.x();
     110                 :           1 :   auto& ycoord = mesh.y();
     111                 :           1 :   auto& zcoord = mesh.z();
     112         [ +  - ]:           1 :   xcoord.resize( m_nnode );
     113         [ +  - ]:           1 :   ycoord.resize( m_nnode );
     114         [ +  - ]:           1 :   zcoord.resize( m_nnode );
     115         [ +  + ]:       11687 :   for (std::size_t i=0; i<m_nnode; ++i) {
     116                 :             :     std::size_t id;
     117                 :             :     tk::real x, y, z;
     118 [ +  - ][ +  - ]:       11686 :     m_inFile >> id >> x >> y >> z;
         [ +  - ][ +  - ]
     119                 :       11686 :     --id;       // convert to zero-based node ids
     120                 :       11686 :     xcoord[ id ] = x;
     121                 :       11686 :     ycoord[ id ] = y;
     122                 :       11686 :     zcoord[ id ] = z;
     123                 :             :   }
     124                 :           1 : }
     125                 :             : 
     126                 :             : void
     127                 :           1 : RDGFLOMeshReader::readElements( UnsMesh& mesh )
     128                 :             : // *****************************************************************************
     129                 :             : //  Read element connectivity
     130                 :             : //! \param[in] mesh Unstructured mesh object
     131                 :             : // *****************************************************************************
     132                 :             : {
     133                 :           1 :   std::string s;
     134                 :             : 
     135         [ +  - ]:           1 :   std::getline( m_inFile, s );
     136         [ +  - ]:           1 :   std::getline( m_inFile, s );
     137 [ +  - ][ -  + ]:           1 :   Assert( s == " element connectivity",
         [ -  - ][ -  - ]
                 [ -  - ]
     138                 :             :           "Invalid keyword, expected: ' element connectivity'" );
     139                 :             : 
     140                 :             :   // Read in tetrahedra element connectivity
     141                 :           1 :   auto& tetinpoel = mesh.tetinpoel();
     142         [ +  - ]:           1 :   tetinpoel.resize( m_ntet * 4 );
     143         [ +  + ]:       59687 :   for (std::size_t i=0; i<m_ntet; ++i) {
     144                 :             :     std::size_t id;
     145                 :             :     std::array< std::size_t, 4 > n;
     146                 :             :     // ignore cell id, a, b
     147 [ +  - ][ +  - ]:       59686 :     m_inFile >> id >> n[0] >> n[1] >> n[2] >> n[3];
         [ +  - ][ +  - ]
                 [ +  - ]
     148                 :       59686 :     --id;       // convert to zero-based element ids
     149                 :       59686 :     tetinpoel[ id*4+0 ] = n[0]-1;       // store zero-based node ids
     150                 :       59686 :     tetinpoel[ id*4+1 ] = n[1]-1;
     151                 :       59686 :     tetinpoel[ id*4+2 ] = n[2]-1;
     152                 :       59686 :     tetinpoel[ id*4+3 ] = n[3]-1;
     153                 :             :   }
     154                 :             : 
     155         [ -  + ]:           1 :   if (!m_ntri) return;
     156                 :             : 
     157         [ +  - ]:           1 :   std::getline( m_inFile, s );
     158         [ +  - ]:           1 :   std::getline( m_inFile, s );
     159 [ +  - ][ -  + ]:           1 :   Assert( s == " boundary conditions & connectivity for boundary faces",
         [ -  - ][ -  - ]
                 [ -  - ]
     160                 :             :           "Invalid keyword, expected: ' boundary conditions & connectivity "
     161                 :             :           "for boundary faces'" );
     162                 :             : 
     163                 :             :   // Read in triangle element connectivity and side set ids
     164                 :           1 :   auto& triinpoel = mesh.triinpoel();
     165                 :           1 :   auto& bface = mesh.bface();
     166                 :           1 :   auto& faceid = mesh.faceid();
     167         [ +  - ]:           1 :   triinpoel.resize( m_ntri * 3 );
     168         [ +  + ]:        6419 :   for (std::size_t i=0; i<m_ntri; ++i) {
     169                 :             :     std::array< std::size_t, 15 > n;
     170 [ +  - ][ +  + ]:      109106 :     for (std::size_t j=0; j<n.size(); ++j)  m_inFile >> n[j];
     171                 :        6418 :     --n[0];     // convert to zero-based node ids
     172                 :        6418 :     triinpoel[ n[0]*3+0 ] = n[6]-1;       // store zero-based node ids
     173                 :        6418 :     triinpoel[ n[0]*3+1 ] = n[7]-1;
     174                 :        6418 :     triinpoel[ n[0]*3+2 ] = n[8]-1;
     175                 :        6418 :     auto setid = static_cast< int >( n[1] );
     176 [ +  - ][ +  - ]:        6418 :     bface[ setid ].push_back( m_ntet + n[0] );  // tets written first
     177 [ +  - ][ +  - ]:        6418 :     faceid[ setid ].push_back( 0 );
     178                 :             :   }
     179         [ +  - ]:           1 : }
        

Generated by: LCOV version 2.0-1