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-11-08 10:37:44 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                 :       3463 : DiagWriter::DiagWriter( const std::string& filename,
      22                 :            :                               ctr::TxtFloatFormatType format,
      23                 :            :                               std::streamsize precision,
      24                 :       3463 :                               std::ios_base::openmode mode ) :
      25                 :            :   Writer( filename, mode ),
      26                 :            :   m_precision( static_cast<int>(precision) ),
      27         [ -  + ]:       3463 :   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         [ +  + ]:       3463 :   if (format == ctr::TxtFloatFormatType::DEFAULT)
      38                 :            :     {} //m_outFile << std::defaultfloat;   GCC does not yet support this
      39         [ -  + ]:       2574 :   else if (format == ctr::TxtFloatFormatType::FIXED)
      40                 :          0 :     m_outFile << std::fixed;
      41         [ +  - ]:       2574 :   else if (format == ctr::TxtFloatFormatType::SCIENTIFIC)
      42                 :       2574 :     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         [ +  - ]:       3463 :   if (precision > 0 && precision < std::numeric_limits< tk::real >::digits10+2)
      47                 :       3463 :     m_outFile << std::setprecision( static_cast<int>(precision) );
      48                 :       3463 : }
      49                 :            : 
      50                 :            : void
      51                 :        199 : 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                 :        199 :             << std::setw(m_width) << "2:t"
      59                 :        398 :             << std::setw(m_width) << "3:dt";
      60                 :        398 :   std::stringstream out;
      61                 :            : 
      62                 :            :   // Output names of diagnostics
      63                 :            :   std::size_t column = 4;
      64         [ +  + ]:       2467 :   for (const auto& n : name) {
      65 [ +  - ][ +  - ]:       4536 :     out << column++ << ':' << n;
      66         [ +  - ]:       2268 :     m_outFile << std::setw(m_width) << out.str();
      67         [ +  - ]:       4536 :     out.str("");
      68                 :            :   }
      69                 :            : 
      70                 :            :   m_outFile << std::endl;
      71                 :        199 : }
      72                 :            : 
      73                 :            : std::size_t
      74                 :       3264 : 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                 :       3264 :   m_outFile << std::setw(10) << it
      88                 :       3264 :             << std::setw(m_width) << t
      89                 :       3264 :             << std::setw(m_width) << dt;
      90                 :            : 
      91                 :            :   // Output diagnostics
      92         [ +  + ]:      41140 :   for (const auto& d : diagnostics) m_outFile << std::setw(m_width) << d;
      93                 :            : 
      94                 :            :   m_outFile << std::endl;
      95                 :            : 
      96                 :       3264 :   return diagnostics.size();
      97                 :            : }

Generated by: LCOV version 1.14