Walker test code coverage report
Current view: top level - IO - H5PartWriter.cpp (source / functions) Hit Total Coverage
Commit: test_coverage.info Lines: 7 17 41.2 %
Date: 2022-09-21 13:52:12 Functions: 1 2 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 152 4.6 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/IO/H5PartWriter.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     H5Part particles data writer
       9                 :            :   \details   H5Part particles data writer class definition, facilitating writing
      10                 :            :     particle coordinates and associated particle fields into HDF5-based H5Part
      11                 :            :     data files in parallel, using MPI-IO.
      12                 :            : */
      13                 :            : // *****************************************************************************
      14                 :            : 
      15                 :            : #include "H5PartWriter.hpp"
      16                 :            : #include "Exception.hpp"
      17                 :            : 
      18                 :            : #include "NoWarning/H5Part.hpp"
      19                 :            : 
      20                 :            : using tk::H5PartWriter;
      21                 :            : 
      22                 :        281 : H5PartWriter::H5PartWriter( const std::string& filename ) :
      23                 :        281 :   m_filename( filename )
      24                 :            : // *****************************************************************************
      25                 :            : //  Constructor: create/open H5Part file
      26                 :            : //! \param[in] filename File to open as H5Part file
      27                 :            : //! \details It is okay to call this constructor with empty filename. In that
      28                 :            : //!   case no IO will be performed. This is basically a punt to enable skipping
      29                 :            : //!   H5Part I/O. Particles are a highly experimental feature at this point.
      30                 :            : //! \note If the file exists, it will be truncated.
      31                 :            : // *****************************************************************************
      32                 :            : {
      33         [ +  - ]:        281 :   if (m_filename.empty()) return;
      34                 :            : 
      35                 :            :   #if defined(__clang__)
      36                 :            :     #pragma clang diagnostic push
      37                 :            :     #pragma clang diagnostic ignored "-Wold-style-cast"
      38                 :            :   #endif
      39                 :            : 
      40                 :            :   auto f =
      41         [ +  - ]:        281 :     H5PartOpenFileParallel(filename.c_str(), H5PART_WRITE, MPI_COMM_WORLD);
      42                 :            : 
      43                 :            :   #if defined(__clang__)
      44                 :            :     #pragma clang diagnostic pop
      45                 :            :   #endif
      46                 :            : 
      47 [ -  + ][ -  - ]:        281 :   ErrChk( f, "Failed to create/open H5Part file: " + filename );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
      48                 :            : 
      49 [ +  - ][ -  + ]:        281 :   ErrChk( H5PartWriteFileAttribString( f, "Origin", "Written by Walker" ) ==
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      50                 :            :           H5PART_SUCCESS, "Failed to write file attribute to " + filename );
      51                 :            : 
      52 [ +  - ][ -  + ]:        281 :   ErrChk( H5PartCloseFile( f ) == H5PART_SUCCESS,
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      53                 :            :           "Failed to close file " + filename );
      54                 :            : }
      55                 :            : 
      56                 :            : void
      57         [ -  - ]:          0 : H5PartWriter::writeCoords( uint64_t it,
      58                 :            :                            const std::vector< tk::real >& x,
      59                 :            :                            const std::vector< tk::real >& y,
      60                 :            :                            const std::vector< tk::real >& z ) const
      61                 :            : // *****************************************************************************
      62                 :            : //  Write particle coordinates to H5Part file
      63                 :            : //! \param[in] it Iteration number
      64                 :            : //! \param[in] x X coordinates of particles
      65                 :            : //! \param[in] y Y coordinates of particles
      66                 :            : //! \param[in] z Z coordinates of particles
      67                 :            : // *****************************************************************************
      68                 :            : {
      69         [ -  - ]:          0 :   if (m_filename.empty()) return;
      70                 :            : 
      71                 :            :   Assert( x.size() == y.size() && y.size() == z.size(),
      72                 :            :           "Particle coordinates array sizes mismatch" );
      73                 :            : 
      74                 :            :   #if defined(__clang__)
      75                 :            :     #pragma clang diagnostic push
      76                 :            :     #pragma clang diagnostic ignored "-Wold-style-cast"
      77                 :            :   #endif
      78                 :            : 
      79                 :            :   auto f =
      80                 :          0 :     H5PartOpenFileParallel(m_filename.c_str(), H5PART_APPEND, MPI_COMM_WORLD);
      81                 :            : 
      82                 :            :   #if defined(__clang__)
      83                 :            :     #pragma clang diagnostic pop
      84                 :            :   #endif
      85                 :            : 
      86 [ -  - ][ -  - ]:          0 :   ErrChk( f, "Failed to open H5Part file for appending: " + m_filename );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
      87                 :            : 
      88 [ -  - ][ -  - ]:          0 :   ErrChk( H5PartSetStep( f, static_cast<h5part_int64_t>(it) ) == H5PART_SUCCESS,
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
      89                 :            :           "Failed to set time step in file " + m_filename );
      90                 :            : 
      91 [ -  - ][ -  - ]:          0 :   ErrChk( H5PartSetNumParticles( f, static_cast<h5part_int64_t>(x.size()) ) ==
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
      92                 :            :           H5PART_SUCCESS, "Failed to set number of particles in file " +
      93                 :            :                              m_filename );
      94                 :            : 
      95 [ -  - ][ -  - ]:          0 :   ErrChk( H5PartWriteDataFloat64( f, "x", x.data() ) == H5PART_SUCCESS,
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
      96                 :            :           "Failed to write x particle coordinates to file " + m_filename );
      97 [ -  - ][ -  - ]:          0 :   ErrChk( H5PartWriteDataFloat64( f, "y", y.data() ) == H5PART_SUCCESS,
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
      98                 :            :           "Failed to write y particle coordinates to file " + m_filename );
      99 [ -  - ][ -  - ]:          0 :   ErrChk( H5PartWriteDataFloat64( f, "z", z.data() ) == H5PART_SUCCESS,
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
     100                 :            :           "Failed to write z particle coordinates to file " + m_filename );
     101                 :            : 
     102 [ -  - ][ -  - ]:          0 :   ErrChk( H5PartCloseFile( f ) == H5PART_SUCCESS,
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
     103                 :            :           "Failed to close file " + m_filename );
     104                 :            : }

Generated by: LCOV version 1.14