Quinoa all test code coverage report
Current view: top level - IO - DiagWriter.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 25 27 92.6 %
Date: 2024-04-29 14:42:33 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 34 41.2 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/IO/DiagWriter.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 diagnostics writer declaration
       9                 :            :   \details   This file declares the ASCII diagnostics writer class that
      10                 :            :      facilitates outputing diagnostics to text files.
      11                 :            : */
      12                 :            : // *****************************************************************************
      13                 :            : 
      14                 :            : #include <iostream>
      15                 :            : #include <iomanip>
      16                 :            : 
      17                 :            : #include "DiagWriter.hpp"
      18                 :            : 
      19                 :            : using tk::DiagWriter;
      20                 :            : 
      21                 :       3656 : DiagWriter::DiagWriter( const std::string& filename,
      22                 :            :                               ctr::TxtFloatFormatType format,
      23                 :            :                               std::streamsize precision,
      24                 :       3656 :                               std::ios_base::openmode mode ) :
      25                 :            :   Writer( filename, mode ),
      26                 :            :   m_precision( static_cast<int>(precision) ),
      27         [ -  + ]:       3656 :   m_width( std::max( 16, m_precision+8 ) )
      28                 :            : // *****************************************************************************
      29                 :            : //  Constructor
      30                 :            : //! \param[in] filename Output filename to which output the diagnostics
      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         [ +  + ]:       3656 :   if (format == ctr::TxtFloatFormatType::DEFAULT)
      38                 :            :     {} //m_outFile << std::defaultfloat;   GCC does not yet support this
      39         [ -  + ]:       2767 :   else if (format == ctr::TxtFloatFormatType::FIXED)
      40                 :          0 :     m_outFile << std::fixed;
      41         [ +  - ]:       2767 :   else if (format == ctr::TxtFloatFormatType::SCIENTIFIC)
      42                 :       2767 :     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         [ +  - ]:       3656 :   if (precision > 0 && precision < std::numeric_limits< tk::real >::digits10+2)
      47                 :       3656 :     m_outFile << std::setprecision( static_cast<int>(precision) );
      48                 :       3656 : }
      49                 :            : 
      50                 :            : void
      51                 :        205 : DiagWriter::header( const std::vector< std::string >& name ) const
      52                 :            : // *****************************************************************************
      53                 :            : //  Write out diagnostics file header
      54                 :            : //! \param[in] name Vector of strings with the names of diagnostics
      55                 :            : // *****************************************************************************
      56                 :            : {
      57                 :            :   m_outFile << "#" << std::setw(9) << "1:it"
      58                 :        205 :             << std::setw(m_width) << "2:t"
      59                 :        410 :             << std::setw(m_width) << "3:dt";
      60                 :        410 :   std::stringstream out;
      61                 :            : 
      62                 :            :   // Output names of diagnostics
      63                 :            :   std::size_t column = 4;
      64         [ +  + ]:       2522 :   for (const auto& n : name) {
      65 [ +  - ][ +  - ]:       4634 :     out << column++ << ':' << n;
      66         [ +  - ]:       2317 :     m_outFile << std::setw(m_width) << out.str();
      67         [ +  - ]:       4634 :     out.str("");
      68                 :            :   }
      69                 :            : 
      70                 :            :   m_outFile << std::endl;
      71                 :        205 : }
      72                 :            : 
      73                 :            : std::size_t
      74                 :       3451 : DiagWriter::diag( uint64_t it,
      75                 :            :                   tk::real t,
      76                 :            :                   tk::real dt,
      77                 :            :                   const std::vector< tk::real >& diagnostics )
      78                 :            : // *****************************************************************************
      79                 :            : //  Write out diagnostics
      80                 :            : //! \param[in] it Iteration counter
      81                 :            : //! \param[in] t Time
      82                 :            : //! \param[in] dt Time step size
      83                 :            : //! \param[in] diagnostics Vector with the diagnostics
      84                 :            : //! \return The total number of diagnostics written to the output file
      85                 :            : // *****************************************************************************
      86                 :            : {
      87                 :       3451 :   m_outFile << std::setw(10) << it
      88                 :       3451 :             << std::setw(m_width) << t
      89                 :       3451 :             << std::setw(m_width) << dt;
      90                 :            : 
      91                 :            :   // Output diagnostics
      92         [ +  + ]:      42877 :   for (const auto& d : diagnostics) m_outFile << std::setw(m_width) << d;
      93                 :            : 
      94                 :            :   m_outFile << std::endl;
      95                 :            : 
      96                 :       3451 :   return diagnostics.size();
      97                 :            : }

Generated by: LCOV version 1.14