Quinoa unit test code coverage report
Current view: top level - IO - MeshFactory.cpp (source / functions) Hit Total Coverage
Commit: Quinoa_v0.3-957-gb4f0efae0 Lines: 0 65 0.0 %
Date: 2021-11-09 12:13:43 Functions: 0 2 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 170 0.0 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/IO/MeshFactory.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     Unstructured mesh reader and writer factory
       9                 :            :   \details   Unstructured mesh reader and writer factory.
      10                 :            : */
      11                 :            : // *****************************************************************************
      12                 :            : 
      13                 :            : #include <string>
      14                 :            : 
      15                 :            : #include "MeshFactory.hpp"
      16                 :            : #include "MeshDetect.hpp"
      17                 :            : #include "Timer.hpp"
      18                 :            : #include "Reader.hpp"
      19                 :            : #include "GmshMeshReader.hpp"
      20                 :            : #include "NetgenMeshReader.hpp"
      21                 :            : #include "ExodusIIMeshReader.hpp"
      22                 :            : #include "HyperMeshReader.hpp"
      23                 :            : #include "UGRIDMeshReader.hpp"
      24                 :            : #include "RDGFLOMeshReader.hpp"
      25                 :            : #include "ASCMeshReader.hpp"
      26                 :            : #include "NetgenMeshWriter.hpp"
      27                 :            : #include "GmshMeshWriter.hpp"
      28                 :            : #include "ExodusIIMeshWriter.hpp"
      29                 :            : #include "DerivedData.hpp"
      30                 :            : #include "Reorder.hpp"
      31                 :            : #include "QuinoaBuildConfig.hpp"
      32                 :            : 
      33                 :            : #ifdef HAS_OMEGA_H
      34                 :            :   #include "Omega_h_MeshReader.hpp"
      35                 :            : #endif
      36                 :            : 
      37                 :            : namespace tk {
      38                 :            : 
      39                 :            : UnsMesh
      40                 :          0 : readUnsMesh( const tk::Print& print,
      41                 :            :              const std::string& filename,
      42                 :            :              std::pair< std::string, tk::real >& timestamp )
      43                 :            : // *****************************************************************************
      44                 :            : //  Read unstructured mesh from file
      45                 :            : //! \param[in] print Pretty printer
      46                 :            : //! \param[in] filename Filename to read mesh from
      47                 :            : //! \param[out] timestamp A time stamp consisting of a timer label (a string),
      48                 :            : //!   and a time state (a tk::real in seconds) measuring the mesh read time
      49                 :            : //! \return Unstructured mesh object
      50                 :            : // *****************************************************************************
      51                 :            : {
      52 [ -  - ][ -  - ]:          0 :   print.diagstart( "Reading mesh from file '" + filename + "' ..." );
         [ -  - ][ -  - ]
      53                 :            : 
      54                 :            :   // Read in mesh
      55                 :            :   tk::Timer t;
      56                 :            :  
      57                 :            :   //! Create unstructured mesh to store mesh
      58                 :          0 :   UnsMesh mesh;
      59                 :            : 
      60         [ -  - ]:          0 :   const auto meshtype = detectInput( filename );
      61                 :            : 
      62         [ -  - ]:          0 :   if (meshtype == MeshReaderType::GMSH)
      63 [ -  - ][ -  - ]:          0 :     GmshMeshReader( filename ).readMesh( mesh );
      64         [ -  - ]:          0 :   else if (meshtype == MeshReaderType::NETGEN)
      65         [ -  - ]:          0 :     NetgenMeshReader( filename ).readMesh( mesh );
      66         [ -  - ]:          0 :   else if (meshtype == MeshReaderType::EXODUSII)
      67 [ -  - ][ -  - ]:          0 :     ExodusIIMeshReader( filename ).readMesh( mesh );
      68         [ -  - ]:          0 :   else if (meshtype == MeshReaderType::ASC)
      69         [ -  - ]:          0 :     ASCMeshReader( filename ).readMesh( mesh );
      70         [ -  - ]:          0 :   else if (meshtype == MeshReaderType::UGRID)
      71         [ -  - ]:          0 :     UGRIDMeshReader( filename ).readMesh( mesh );
      72         [ -  - ]:          0 :   else if (meshtype == MeshReaderType::RDGFLO)
      73         [ -  - ]:          0 :     RDGFLOMeshReader( filename ).readMesh( mesh );
      74         [ -  - ]:          0 :   else if (meshtype == MeshReaderType::HYPER)
      75         [ -  - ]:          0 :     HyperMeshReader( filename ).readMesh( mesh );
      76                 :            : 
      77                 :            :   timestamp =
      78 [ -  - ][ -  - ]:          0 :     std::make_pair( "Read mesh from file '" + filename + '\'', t.dsec() );
         [ -  - ][ -  - ]
      79                 :            : 
      80 [ -  - ][ -  - ]:          0 :   print.diagend( "done" );
      81                 :            : 
      82                 :            :   // Return (move out) mesh object
      83                 :          0 :   return mesh;
      84                 :            : }
      85                 :            : 
      86                 :            : std::vector< std::pair< std::string, tk::real > >
      87                 :          0 : writeUnsMesh( const tk::Print& print,
      88                 :            :               const std::string& filename,
      89                 :            :               UnsMesh& mesh,
      90                 :            :               bool reorder )
      91                 :            : // *****************************************************************************
      92                 :            : //  Write unstructured mesh to file
      93                 :            : //! \param[in] print Pretty printer
      94                 :            : //! \param[in] filename Filename to write mesh to
      95                 :            : //! \param[in] mesh Unstructured mesh object to write from
      96                 :            : //! \param[in] reorder Whether to also reorder mesh nodes
      97                 :            : //! \return Vector of time stamps consisting of a timer label (a string), and a
      98                 :            : //!   time state (a tk::real in seconds) measuring the renumber and the mesh
      99                 :            : //!   write time
     100                 :            : // *****************************************************************************
     101                 :            : {
     102                 :            :   std::vector< std::pair< std::string, tk::real > > times;
     103                 :            : 
     104                 :            :   tk::Timer t;
     105                 :            : 
     106                 :            :   // If mesh has tetrahedra but no triangles, generate triangle connectivity
     107 [ -  - ][ -  - ]:          0 :   if (!mesh.tetinpoel().empty() && mesh.triinpoel().empty()) {
     108 [ -  - ][ -  - ]:          0 :     print.diagstart( "Generating missing surface mesh ..." );
                 [ -  - ]
     109                 :            : 
     110                 :            :     const auto& inpoel = mesh.tetinpoel();        // get tet connectivity
     111         [ -  - ]:          0 :     auto esup = tk::genEsup( inpoel, 4 );         // elements surrounding points
     112         [ -  - ]:          0 :     auto esuel = tk::genEsuelTet( inpoel, esup ); // elems surrounding elements
     113                 :            :     auto& triinpoel = mesh.triinpoel();
     114                 :            :     // collect boundary faces
     115         [ -  - ]:          0 :     for (std::size_t e=0; e<esuel.size()/4; ++e) {
     116                 :          0 :       auto mark = e*4;
     117         [ -  - ]:          0 :       for (std::size_t f=0; f<4; ++f) {
     118         [ -  - ]:          0 :         if (esuel[mark+f] == -1) {
     119                 :            :           // extract triangle element connectivity from tetrahedron
     120         [ -  - ]:          0 :           triinpoel.push_back( inpoel[ mark+tk::lpofa[f][0] ] );
     121         [ -  - ]:          0 :           triinpoel.push_back( inpoel[ mark+tk::lpofa[f][1] ] );
     122         [ -  - ]:          0 :           triinpoel.push_back( inpoel[ mark+tk::lpofa[f][2] ] );
     123                 :            :         }
     124                 :            :       }
     125                 :            :     }
     126                 :            : 
     127 [ -  - ][ -  - ]:          0 :     print.diagend( "done" );
     128 [ -  - ][ -  - ]:          0 :     times.emplace_back( "Generate surface mesh", t.dsec() );
     129                 :            :     t.zero();
     130                 :            :   }
     131                 :            : 
     132         [ -  - ]:          0 :   if (reorder) {
     133 [ -  - ][ -  - ]:          0 :     print.diagstart( "Reordering mesh nodes ..." );
                 [ -  - ]
     134                 :            : 
     135                 :            :     // If mesh has tetrahedra elements, reorder based on those
     136         [ -  - ]:          0 :     if (!mesh.tetinpoel().empty()) {
     137                 :            : 
     138                 :            :       auto& inpoel = mesh.tetinpoel();
     139 [ -  - ][ -  - ]:          0 :       const auto psup = tk::genPsup( inpoel, 4, tk::genEsup( inpoel, 4 ) );
     140         [ -  - ]:          0 :       auto map = tk::renumber( psup );
     141         [ -  - ]:          0 :       tk::remap( inpoel, map );
     142         [ -  - ]:          0 :       tk::remap( mesh.triinpoel(), map );
     143         [ -  - ]:          0 :       tk::remap( mesh.x(), map );
     144         [ -  - ]:          0 :       tk::remap( mesh.y(), map );
     145         [ -  - ]:          0 :       tk::remap( mesh.z(), map );
     146                 :            : 
     147                 :            :     // If mesh has no tetrahedra elements, reorder based on triangle mesh if any
     148         [ -  - ]:          0 :     } else if (!mesh.triinpoel().empty()) {
     149                 :            : 
     150                 :            :       auto& inpoel = mesh.triinpoel();
     151 [ -  - ][ -  - ]:          0 :       const auto psup = tk::genPsup( inpoel, 3, tk::genEsup( inpoel, 3 ) );
     152         [ -  - ]:          0 :       auto map = tk::renumber( psup );
     153         [ -  - ]:          0 :       tk::remap( inpoel, map );
     154         [ -  - ]:          0 :       tk::remap( mesh.x(), map );
     155         [ -  - ]:          0 :       tk::remap( mesh.y(), map );
     156         [ -  - ]:          0 :       tk::remap( mesh.z(), map );
     157                 :            :     }
     158                 :            : 
     159 [ -  - ][ -  - ]:          0 :     print.diagend( "done" );
     160         [ -  - ]:          0 :     times.emplace_back( "Reorder mesh", t.dsec() );
     161                 :            :     t.zero();
     162                 :            :   }
     163                 :            : 
     164 [ -  - ][ -  - ]:          0 :   print.diagstart( "Writing mesh to file '" + filename + "' ..." );
         [ -  - ][ -  - ]
                 [ -  - ]
     165                 :            : 
     166         [ -  - ]:          0 :   const auto meshtype = pickOutput( filename );
     167                 :            : 
     168         [ -  - ]:          0 :   if (meshtype == MeshWriterType::GMSH)
     169 [ -  - ][ -  - ]:          0 :     GmshMeshWriter( filename ).writeMesh( mesh );
     170         [ -  - ]:          0 :   else if (meshtype == MeshWriterType::NETGEN)
     171         [ -  - ]:          0 :     NetgenMeshWriter( filename ).writeMesh( mesh );
     172         [ -  - ]:          0 :   else if (meshtype== MeshWriterType::EXODUSII)
     173 [ -  - ][ -  - ]:          0 :     ExodusIIMeshWriter( filename, ExoWriter::CREATE ).writeMesh( mesh );
     174                 :            : 
     175 [ -  - ][ -  - ]:          0 :   print.diagend( "done" );
     176         [ -  - ]:          0 :   times.emplace_back( "Write mesh to file", t.dsec() );
     177                 :            : 
     178                 :          0 :   return times;
     179                 :            : }
     180                 :            : 
     181                 :            : } // tk::

Generated by: LCOV version 1.14