Quinoa all test code coverage report
Current view: top level - IO - NetgenMeshWriter.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 33 33 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: 30 48 62.5 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/IO/NetgenMeshWriter.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 writer class definition
       9                 :            :   \details   Netgen mesh writer class definition. Only supports tetrahedra.
      10                 :            : */
      11                 :            : // *****************************************************************************
      12                 :            : 
      13                 :            : #include <iomanip>
      14                 :            : #include <ostream>
      15                 :            : #include <vector>
      16                 :            : #include <algorithm>
      17                 :            : #include <iterator>
      18                 :            : #include <utility>
      19                 :            : #include <cstddef>
      20                 :            : 
      21                 :            : #include "Types.hpp"
      22                 :            : #include "UnsMesh.hpp"
      23                 :            : #include "Exception.hpp"
      24                 :            : #include "NetgenMeshWriter.hpp"
      25                 :            : 
      26                 :            : using tk::NetgenMeshWriter;
      27                 :            : 
      28                 :            : void
      29                 :          5 : NetgenMeshWriter::writeMesh( const UnsMesh& mesh )
      30                 :            : // *****************************************************************************
      31                 :            : //  Public interface for writing Netgen mesh
      32                 :            : //! \param[in] mesh Unstructured mesh object
      33                 :            : // *****************************************************************************
      34                 :            : {
      35                 :          5 :   writeNodes( mesh );
      36                 :          5 :   writeElements( mesh );
      37                 :          5 : }
      38                 :            : 
      39                 :            : void
      40                 :          5 : NetgenMeshWriter::writeNodes( const UnsMesh& mesh )
      41                 :            : // *****************************************************************************
      42                 :            : //  Write nodes
      43                 :            : //! \param[in] mesh Unstructured mesh object
      44                 :            : // *****************************************************************************
      45                 :            : {
      46                 :            :   // Write out number of nodes
      47                 :          5 :   m_outFile << mesh.nnode() << std::endl;
      48                 :            : 
      49                 :            :   // Write node coordinates: x-coord y-coord z-coord
      50                 :            :   m_outFile << std::setprecision(6) << std::fixed;
      51         [ +  + ]:      17637 :   for ( std::size_t i=0; i<mesh.nnode(); ++i ) {
      52                 :      17632 :     m_outFile << '\t' << mesh.x()[i]
      53                 :      17632 :               << '\t' << mesh.y()[i]
      54                 :      17632 :               << '\t' << mesh.z()[i] << std::endl;
      55                 :            :   }
      56                 :          5 : }
      57                 :            : 
      58                 :            : void
      59         [ +  - ]:          5 : NetgenMeshWriter::writeElements( const UnsMesh& mesh )
      60                 :            : // *****************************************************************************
      61                 :            : //  Write elements, i.e., connectivity
      62                 :            : //! \param[in] mesh Unstructured mesh object
      63                 :            : // *****************************************************************************
      64                 :            : {
      65         [ +  - ]:          6 :   if (mesh.tetinpoel().empty()) return;
      66                 :            : 
      67                 :            :   // Make sure tetrahedron element connectivity starts with zero
      68                 :            :   Assert( *std::minmax_element( begin(mesh.tetinpoel()),
      69                 :            :                                 end(mesh.tetinpoel()) ).first == 0,
      70                 :            :           "tetrahedron node ids should start from zero" );
      71                 :            : 
      72                 :            :   // Get number of tetrahedra in mesh
      73                 :          5 :   auto n = mesh.tetinpoel().size()/4;  
      74                 :            : 
      75                 :            :   // Write out number of tetrahedra
      76                 :          5 :   m_outFile << n << std::endl;
      77                 :            : 
      78                 :            :   // Create empty tag vector
      79                 :          4 :   std::vector< std::vector< int > > tg;
      80         [ +  - ]:          5 :   tg.resize( n );
      81 [ +  + ][ +  - ]:      93851 :   for (auto& t : tg) t.push_back( 1 );
      82                 :            : 
      83                 :            :   // Write out tetrehadra element tags and connectivity
      84         [ +  + ]:      93851 :   for (std::size_t i=0; i<n; ++i) {
      85                 :            :     // tag n[1-4]
      86         [ +  - ]:      93846 :     m_outFile << '\t' << tg[i][0]
      87 [ +  - ][ +  - ]:     187692 :               << '\t' << mesh.tetinpoel()[i*4+3]+1
      88         [ +  - ]:      93846 :               << '\t' << mesh.tetinpoel()[i*4+0]+1
      89         [ +  - ]:      93846 :               << '\t' << mesh.tetinpoel()[i*4+1]+1
      90         [ +  - ]:      93846 :               << '\t' << mesh.tetinpoel()[i*4+2]+1 << std::endl;
      91                 :            :   }
      92                 :            : 
      93         [ +  + ]:          5 :   if (mesh.triinpoel().empty()) return;
      94                 :            : 
      95                 :            :   // Make sure triangle element connectivity starts with zero
      96                 :            :   Assert( *std::minmax_element( begin(mesh.triinpoel()),
      97                 :            :                                 end(mesh.triinpoel()) ).first == 0,
      98                 :            :           "triangle node ids should start from zero" );
      99                 :            : 
     100                 :            :   // Get number of triangles in mesh
     101         [ +  - ]:          4 :   n = mesh.triinpoel().size()/3;
     102                 :            : 
     103                 :            :   // Write out number of triangles
     104                 :            :   m_outFile << n << std::endl;
     105                 :            : 
     106                 :            :   // Create empty tag vector if there is no tag
     107                 :            :   tg.clear();
     108         [ +  - ]:          4 :   tg.resize( n );
     109 [ +  + ][ +  - ]:       7576 :   for (auto& t : tg) t.push_back( 1 );
     110                 :            : 
     111                 :            :   // Write out triangle element tags and connectivity
     112         [ +  + ]:       7576 :   for (std::size_t i=0; i<n; ++i) {
     113                 :            :     // tag n[1-4]
     114         [ +  - ]:       7572 :     m_outFile << '\t' << tg[i][0]
     115 [ +  - ][ +  - ]:      15144 :               << '\t' << mesh.triinpoel()[i*3+0]+1
     116         [ +  - ]:       7572 :               << '\t' << mesh.triinpoel()[i*3+1]+1
     117         [ +  - ]:       7572 :               << '\t' << mesh.triinpoel()[i*3+2]+1 << std::endl;
     118                 :            :   }
     119                 :            : }

Generated by: LCOV version 1.14