Quinoa all test code coverage report
Current view: top level - IO - RDGFLOMeshReader.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 51 51 100.0 %
Date: 2024-04-29 14:42:33 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 37 126 29.4 %

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

Generated by: LCOV version 1.14