Quinoa all test code coverage report
Current view: top level - IO - TxtStatWriter.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 0 36 0.0 %
Date: 2024-04-29 14:42:33 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 58 0.0 %

           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                 :          0 : TxtStatWriter::TxtStatWriter( const std::string& filename,
      22                 :            :                               ctr::TxtFloatFormatType format,
      23                 :            :                               std::streamsize precision,
      24                 :          0 :                               std::ios_base::openmode mode ) :
      25                 :            :   Writer( filename, mode ),
      26                 :            :   m_precision( static_cast<int>(precision) ),
      27         [ -  - ]:          0 :   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         [ -  - ]:          0 :   if (format == ctr::TxtFloatFormatType::DEFAULT)
      38                 :            :     {} //m_outFile << std::defaultfloat;   GCC does not yet support this
      39         [ -  - ]:          0 :   else if (format == ctr::TxtFloatFormatType::FIXED)
      40                 :          0 :     m_outFile << std::fixed;
      41         [ -  - ]:          0 :   else if (format == ctr::TxtFloatFormatType::SCIENTIFIC)
      42                 :          0 :     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         [ -  - ]:          0 :   if (precision > 0 && precision < std::numeric_limits< tk::real >::digits10+2)
      47                 :          0 :     m_outFile << std::setprecision( static_cast<int>(precision) );
      48                 :          0 : }
      49                 :            : 
      50                 :            : void
      51                 :          0 : 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                 :          0 :   m_outFile << "#" << std::setw(9) << "1:it";
      62                 :          0 :   m_outFile << std::setw(m_width) << "2:t";
      63                 :          0 :   std::stringstream out;
      64                 :            : 
      65                 :            :   // Output names of ordinary moments
      66                 :            :   std::size_t column = 3;
      67         [ -  - ]:          0 :   for (const auto& n : nameOrd) {
      68 [ -  - ][ -  - ]:          0 :     out << column++ << ":<" << n << ">";
      69         [ -  - ]:          0 :     m_outFile << std::setw(m_width) << out.str();
      70         [ -  - ]:          0 :     out.str("");
      71                 :            :   }
      72                 :            : 
      73                 :            :   // Output name of central moments
      74         [ -  - ]:          0 :   for (const auto& c : nameCen) {
      75 [ -  - ][ -  - ]:          0 :     out << column++ << ":<" << c << ">";
      76         [ -  - ]:          0 :     m_outFile << std::setw(m_width) << out.str();
      77         [ -  - ]:          0 :     out.str("");
      78                 :            :   }
      79                 :            : 
      80                 :            :   // Output name of extra data
      81         [ -  - ]:          0 :   for (const auto& c : nameExt) {
      82 [ -  - ][ -  - ]:          0 :     out << column++ << ":<" << c << ">";
      83         [ -  - ]:          0 :     m_outFile << std::setw(m_width) << out.str();
      84         [ -  - ]:          0 :     out.str("");
      85                 :            :   }
      86                 :            : 
      87                 :            :   m_outFile << std::endl;
      88                 :          0 : }
      89                 :            : 
      90                 :            : std::size_t
      91                 :          0 : 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                 :          0 :   m_outFile << std::setw(10) << it;
     107                 :          0 :   m_outFile << std::setw(m_width) << t;
     108                 :            : 
     109                 :            :   // Output ordinary moments
     110         [ -  - ]:          0 :   for (const auto& o : ordinary) m_outFile << std::setw(m_width) << o;
     111                 :            : 
     112                 :            :   // Output central moments
     113         [ -  - ]:          0 :   for (const auto& c : central) m_outFile << std::setw(m_width) << c;
     114                 :            : 
     115                 :            :   // Output extra data
     116         [ -  - ]:          0 :   for (const auto& c : extra) m_outFile << std::setw(m_width) << c;
     117                 :            : 
     118                 :            :   m_outFile << std::endl;
     119                 :            : 
     120                 :          0 :   return ordinary.size() + central.size() + extra.size();
     121                 :            : }

Generated by: LCOV version 1.14