Quinoa regression test code coverage report
Current view: top level - IO - TxtStatWriter.cpp (source / functions) Hit Total Coverage
Commit: Quinoa_v0.3-957-gb4f0efae0 Lines: 37 39 94.9 %
Date: 2021-11-11 13:17:06 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                 :     325906 : TxtStatWriter::TxtStatWriter( const std::string& filename,
      22                 :            :                               ctr::TxtFloatFormatType format,
      23                 :            :                               kw::precision::info::expect::type precision,
      24                 :     325906 :                               std::ios_base::openmode mode ) :
      25                 :            :   Writer( filename, mode ),
      26                 :            :   m_precision( static_cast<int>(precision) ),
      27                 :     325906 :   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         [ +  + ]:     325906 :   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 [ +  - ][ +  - ]:     325906 :   if (precision > 0 && precision < std::numeric_limits< tk::real >::digits10+2)
      47         [ +  - ]:     325906 :     m_outFile << std::setprecision( static_cast<int>(precision) );
      48                 :     325906 : }
      49                 :            : 
      50                 :            : void
      51                 :         78 : 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 [ +  - ][ +  - ]:         78 :   m_outFile << "#" << std::setw(9) << "1:it";
                 [ +  - ]
      62 [ +  - ][ +  - ]:         78 :   m_outFile << std::setw(m_width) << "2:t";
      63         [ +  - ]:        156 :   std::stringstream out;
      64                 :            : 
      65                 :            :   // Output names of ordinary moments
      66                 :         78 :   std::size_t column = 3;
      67         [ +  + ]:        651 :   for (const auto& n : nameOrd) {
      68 [ +  - ][ +  - ]:        573 :     out << column++ << ":<" << n << ">";
         [ +  - ][ +  - ]
      69 [ +  - ][ +  - ]:        573 :     m_outFile << std::setw(m_width) << out.str();
                 [ +  - ]
      70 [ +  - ][ +  - ]:        573 :     out.str("");
      71                 :            :   }
      72                 :            : 
      73                 :            :   // Output name of central moments
      74         [ +  + ]:        809 :   for (const auto& c : nameCen) {
      75 [ +  - ][ +  - ]:        731 :     out << column++ << ":<" << c << ">";
         [ +  - ][ +  - ]
      76 [ +  - ][ +  - ]:        731 :     m_outFile << std::setw(m_width) << out.str();
                 [ +  - ]
      77 [ +  - ][ +  - ]:        731 :     out.str("");
      78                 :            :   }
      79                 :            : 
      80                 :            :   // Output name of extra data
      81         [ +  + ]:         88 :   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         [ +  - ]:         78 :   m_outFile << std::endl;
      88                 :         78 : }
      89                 :            : 
      90                 :            : std::size_t
      91                 :     325828 : 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                 :     325828 :   m_outFile << std::setw(10) << it;
     107                 :     325828 :   m_outFile << std::setw(m_width) << t;
     108                 :            : 
     109                 :            :   // Output ordinary moments
     110 [ +  + ][ +  - ]:    2436486 :   for (const auto& o : ordinary) m_outFile << std::setw(m_width) << o;
                 [ +  - ]
     111                 :            : 
     112                 :            :   // Output central moments
     113 [ +  + ][ +  - ]:    4663222 :   for (const auto& c : central) m_outFile << std::setw(m_width) << c;
                 [ +  - ]
     114                 :            : 
     115                 :            :   // Output extra data
     116 [ +  + ][ +  - ]:     325928 :   for (const auto& c : extra) m_outFile << std::setw(m_width) << c;
                 [ +  - ]
     117                 :            : 
     118                 :     325828 :   m_outFile << std::endl;
     119                 :            : 
     120                 :     325828 :   return ordinary.size() + central.size() + extra.size();
     121                 :            : }

Generated by: LCOV version 1.14