Walker test code coverage report
Current view: top level - IO - TxtStatWriter.cpp (source / functions) Hit Total Coverage
Commit: test_coverage.info Lines: 37 39 94.9 %
Date: 2022-09-21 18:57:21 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 60 114 52.6 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/IO/TxtStatWriter.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     Text statistics writer declaration
       9                 :            :   \details   This file declares the ASCII statistics writer class that
      10                 :            :      facilitates outputing statistics to text files.
      11                 :            : */
      12                 :            : // *****************************************************************************
      13                 :            : 
      14                 :            : #include <iostream>
      15                 :            : #include <iomanip>
      16                 :            : 
      17                 :            : #include "TxtStatWriter.hpp"
      18                 :            : 
      19                 :            : using tk::TxtStatWriter;
      20                 :            : 
      21                 :     398632 : TxtStatWriter::TxtStatWriter( const std::string& filename,
      22                 :            :                               ctr::TxtFloatFormatType format,
      23                 :            :                               kw::precision::info::expect::type precision,
      24                 :     398632 :                               std::ios_base::openmode mode ) :
      25                 :            :   Writer( filename, mode ),
      26                 :            :   m_precision( static_cast<int>(precision) ),
      27                 :     398632 :   m_width( std::max( 20, m_precision+8 ) )
      28                 :            : // *****************************************************************************
      29                 :            : //  Constructor
      30                 :            : //! \param[in] filename Output filename to which output the statistics
      31                 :            : //! \param[in] format Configure floating-point output format ASCII output
      32                 :            : //! \param[in] precision Configure precision for floating-point ASCII output
      33                 :            : //! \param[in] mode Configure file open mode
      34                 :            : // *****************************************************************************
      35                 :            : {
      36                 :            :   // Set floating-point format for output file stream
      37         [ +  + ]:     398632 :   if (format == ctr::TxtFloatFormatType::DEFAULT)
      38                 :            :     {} //m_outFile << std::defaultfloat;   GCC does not yet support this
      39         [ -  + ]:       2055 :   else if (format == ctr::TxtFloatFormatType::FIXED)
      40         [ -  - ]:          0 :     m_outFile << std::fixed;
      41         [ +  - ]:       2055 :   else if (format == ctr::TxtFloatFormatType::SCIENTIFIC)
      42         [ +  - ]:       2055 :     m_outFile << std::scientific;
      43 [ -  - ][ -  - ]:          0 :   else Throw( "Text floating-point format not recognized." );
                 [ -  - ]
      44                 :            : 
      45                 :            :   // Set numeric precision for output file stream if the input makes sense
      46 [ +  - ][ +  - ]:     398632 :   if (precision > 0 && precision < std::numeric_limits< tk::real >::digits10+2)
      47         [ +  - ]:     398632 :     m_outFile << std::setprecision( static_cast<int>(precision) );
      48                 :     398632 : }
      49                 :            : 
      50                 :            : void
      51                 :         97 : TxtStatWriter::header( const std::vector< std::string >& nameOrd,
      52                 :            :                        const std::vector< std::string >& nameCen,
      53                 :            :                        const std::vector< std::string >& nameExt ) const
      54                 :            : // *****************************************************************************
      55                 :            : //  Write out statistics file header
      56                 :            : //! \param[in] nameOrd Vector of strings with the names of ordinary moments
      57                 :            : //! \param[in] nameCen Vector of strings with the names of central moments
      58                 :            : //! \param[in] nameExt Vector of strings with the names of extra data
      59                 :            : // *****************************************************************************
      60                 :            : {
      61 [ +  - ][ +  - ]:         97 :   m_outFile << "#" << std::setw(9) << "1:it";
                 [ +  - ]
      62 [ +  - ][ +  - ]:         97 :   m_outFile << std::setw(m_width) << "2:t";
      63         [ +  - ]:        194 :   std::stringstream out;
      64                 :            : 
      65                 :            :   // Output names of ordinary moments
      66                 :         97 :   std::size_t column = 3;
      67         [ +  + ]:        711 :   for (const auto& n : nameOrd) {
      68 [ +  - ][ +  - ]:        614 :     out << column++ << ":<" << n << ">";
         [ +  - ][ +  - ]
      69 [ +  - ][ +  - ]:        614 :     m_outFile << std::setw(m_width) << out.str();
                 [ +  - ]
      70 [ +  - ][ +  - ]:        614 :     out.str("");
      71                 :            :   }
      72                 :            : 
      73                 :            :   // Output name of central moments
      74         [ +  + ]:        884 :   for (const auto& c : nameCen) {
      75 [ +  - ][ +  - ]:        787 :     out << column++ << ":<" << c << ">";
         [ +  - ][ +  - ]
      76 [ +  - ][ +  - ]:        787 :     m_outFile << std::setw(m_width) << out.str();
                 [ +  - ]
      77 [ +  - ][ +  - ]:        787 :     out.str("");
      78                 :            :   }
      79                 :            : 
      80                 :            :   // Output name of extra data
      81         [ +  + ]:        107 :   for (const auto& c : nameExt) {
      82 [ +  - ][ +  - ]:         10 :     out << column++ << ":<" << c << ">";
         [ +  - ][ +  - ]
      83 [ +  - ][ +  - ]:         10 :     m_outFile << std::setw(m_width) << out.str();
                 [ +  - ]
      84 [ +  - ][ +  - ]:         10 :     out.str("");
      85                 :            :   }
      86                 :            : 
      87         [ +  - ]:         97 :   m_outFile << std::endl;
      88                 :         97 : }
      89                 :            : 
      90                 :            : std::size_t
      91                 :     398535 : TxtStatWriter::stat( uint64_t it,
      92                 :            :                      tk::real t,
      93                 :            :                      const std::vector< tk::real >& ordinary,
      94                 :            :                      const std::vector< tk::real >& central,
      95                 :            :                      const std::vector< tk::real >& extra )
      96                 :            : // *****************************************************************************
      97                 :            : //  Write out statistics
      98                 :            : //! \param[in] it Iteration counter
      99                 :            : //! \param[in] t Time
     100                 :            : //! \param[in] ordinary Vector with the ordinary moment statistics
     101                 :            : //! \param[in] central Vector with the central moment statistics
     102                 :            : //! \param[in] extra Vector with extra data to be also written (besides stats)
     103                 :            : //! \return The total number of statistics written to the output file
     104                 :            : // *****************************************************************************
     105                 :            : {
     106                 :     398535 :   m_outFile << std::setw(10) << it;
     107                 :     398535 :   m_outFile << std::setw(m_width) << t;
     108                 :            : 
     109                 :            :   // Output ordinary moments
     110 [ +  + ][ +  - ]:    2636106 :   for (const auto& o : ordinary) m_outFile << std::setw(m_width) << o;
                 [ +  - ]
     111                 :            : 
     112                 :            :   // Output central moments
     113 [ +  + ][ +  - ]:    4875541 :   for (const auto& c : central) m_outFile << std::setw(m_width) << c;
                 [ +  - ]
     114                 :            : 
     115                 :            :   // Output extra data
     116 [ +  + ][ +  - ]:     398635 :   for (const auto& c : extra) m_outFile << std::setw(m_width) << c;
                 [ +  - ]
     117                 :            : 
     118                 :     398535 :   m_outFile << std::endl;
     119                 :            : 
     120                 :     398535 :   return ordinary.size() + central.size() + extra.size();
     121                 :            : }

Generated by: LCOV version 1.14