Xyst test code coverage report
Current view: top level - IO - ASCMeshReader.cpp (source / functions) Coverage Total Hit
Commit: 1fb74642dd9d7732b67f32dec2f2762e238d3fa7 Lines: 100.0 % 44 44
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: 33.8 % 136 46

             Branch data     Line data    Source code
       1                 :             : // *****************************************************************************
       2                 :             : /*!
       3                 :             :   \file      src/IO/ASCMeshReader.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     ASC mesh reader class definition
      10                 :             :   \details   ASC mesh reader class definition. Mesh reader facilitating reading
      11                 :             :              a mesh from a simple text file used by Jacob Waltz's Chicoma code.
      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 "ASCMeshReader.hpp"
      26                 :             : 
      27                 :             : using tk::ASCMeshReader;
      28                 :             : 
      29                 :             : void
      30                 :           4 : ASCMeshReader::readHeader()
      31                 :             : // *****************************************************************************
      32                 :             : //  Read ASC mesh header
      33                 :             : // *****************************************************************************
      34                 :             : {
      35                 :           4 :   std::string s;
      36                 :             : 
      37                 :             :   // ndim
      38         [ +  - ]:           4 :   m_inFile >> s;
      39 [ +  - ][ -  + ]:           4 :   Assert( s == "*ndim", "Invalid keyword, expected: '*ndim'" );
         [ -  - ][ -  - ]
                 [ -  - ]
      40                 :             :   int ndim;
      41         [ +  - ]:           4 :   m_inFile >> ndim;
      42 [ -  + ][ -  - ]:           4 :   Assert( ndim == 3, "Only 3D meshes are supported" );
         [ -  - ][ -  - ]
      43                 :             : 
      44                 :             :   // numNodeSets (throw away)
      45         [ +  - ]:           4 :   m_inFile >> s;
      46 [ +  - ][ -  + ]:           4 :   Assert( s == "*numNodeSets", "Invalid keyword, expected: '*numNodeSets'" );
         [ -  - ][ -  - ]
                 [ -  - ]
      47                 :             :   int nn;
      48         [ +  - ]:           4 :   m_inFile >> nn;
      49                 :             : 
      50                 :             :   // numSideSets (throw away)
      51         [ +  - ]:           4 :   m_inFile >> s;
      52 [ +  - ][ -  + ]:           4 :   Assert( s == "*numSideSets", "Invalid keyword, expected: '*numSideSets'" );
         [ -  - ][ -  - ]
                 [ -  - ]
      53                 :             :   int ns;
      54         [ +  - ]:           4 :   m_inFile >> ns;
      55                 :           4 : }
      56                 :             : 
      57                 :             : void
      58                 :           4 : ASCMeshReader::readMesh( UnsMesh& mesh )
      59                 :             : // *****************************************************************************
      60                 :             : //  Read ASC mesh
      61                 :             : //! \param[in] mesh Unstructured mesh object
      62                 :             : // *****************************************************************************
      63                 :             : {
      64                 :             :   // Read header
      65                 :           4 :   readHeader();
      66                 :             :   // Read nodes
      67                 :           4 :   readNodes( mesh );
      68                 :             :   // Read elements
      69                 :           4 :   readElements( mesh );
      70                 :           4 : }
      71                 :             : 
      72                 :             : void
      73                 :           4 : ASCMeshReader::readNodes( UnsMesh& mesh )
      74                 :             : // *****************************************************************************
      75                 :             : //  Read nodes
      76                 :             : //! \param[in] mesh Unstructured mesh object
      77                 :             : // *****************************************************************************
      78                 :             : {
      79                 :           4 :   std::string s;
      80                 :             : 
      81         [ +  - ]:           4 :   m_inFile >> s;
      82 [ +  - ][ -  + ]:           4 :   Assert( s == "*nodes", "Invalid keyword, expected: '*nodes'" );
         [ -  - ][ -  - ]
                 [ -  - ]
      83                 :             :   int nnode;
      84         [ +  - ]:           4 :   m_inFile >> nnode;
      85 [ -  + ][ -  - ]:           4 :   ErrChk( nnode > 0,
         [ -  - ][ -  - ]
      86                 :             :           "Number of nodes must be greater than zero in file " + m_filename  );
      87                 :             : 
      88                 :             :   // Read in node coordinates: x-coord y-coord z-coord, ignore node IDs, assume
      89                 :             :   // sorted
      90         [ +  + ]:       70308 :   for (int i=0; i<nnode; ++i) {
      91                 :             :     int n;
      92                 :             :     tk::real x, y, z;
      93 [ +  - ][ +  - ]:       70304 :     m_inFile >> n >> x >> y >> z;
         [ +  - ][ +  - ]
      94         [ +  - ]:       70304 :     mesh.x().push_back( x );
      95         [ +  - ]:       70304 :     mesh.y().push_back( y );
      96         [ +  - ]:       70304 :     mesh.z().push_back( z );
      97                 :             :   }
      98                 :           4 : }
      99                 :             : 
     100                 :             : void
     101                 :           4 : ASCMeshReader::readElements( UnsMesh& mesh )
     102                 :             : // *****************************************************************************
     103                 :             : //  Read element connectivity
     104                 :             : //! \param[in] mesh Unstructured mesh object
     105                 :             : // *****************************************************************************
     106                 :             : {
     107                 :           4 :   std::string s;
     108                 :             : 
     109         [ +  - ]:           4 :   m_inFile >> s;
     110 [ +  - ][ -  + ]:           4 :   Assert( s == "*cells", "Invalid keyword, expected: '*cells'" );
         [ -  - ][ -  - ]
                 [ -  - ]
     111                 :             : 
     112                 :             :   int nel;
     113         [ +  - ]:           4 :   m_inFile >> nel;
     114 [ -  + ][ -  - ]:           4 :   ErrChk( nel > 0,
         [ -  - ][ -  - ]
     115                 :             :           "Number of cells must be greater than zero in file " + m_filename  );
     116                 :             : 
     117                 :             :   // Read in tetrahedra element tags and connectivity
     118         [ +  + ]:      375004 :   for (int i=0; i<nel; ++i) {
     119                 :             :     int a, b, c;
     120                 :             :     std::array< std::size_t, 4 > n;
     121                 :             :     // ignore cell id, a, b
     122 [ +  - ][ +  - ]:      375000 :     m_inFile >> a >> b >> c >> n[3] >> n[0] >> n[1] >> n[2];
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     123         [ +  - ]:      375000 :     mesh.tetinpoel().push_back( n[0] );
     124         [ +  - ]:      375000 :     mesh.tetinpoel().push_back( n[1] );
     125                 :             :     // switch nodes 2 and 3 to enforce positive volume
     126         [ +  - ]:      375000 :     mesh.tetinpoel().push_back( n[3] );
     127         [ +  - ]:      375000 :     mesh.tetinpoel().push_back( n[2] );
     128                 :             :   }
     129                 :             : 
     130                 :             :   // Shift node IDs to start from zero
     131         [ +  - ]:           4 :   shiftToZero( mesh.tetinpoel() );
     132                 :           4 : }
        

Generated by: LCOV version 2.0-1