Quinoa all test code coverage report
Current view: top level - IO - ASCMeshReader.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 35 35 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: 31 78 39.7 %

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

Generated by: LCOV version 1.14