Quinoa regression test code coverage report
Current view: top level - IO - DiagWriter.cpp (source / functions) Hit Total Coverage
Commit: Quinoa_v0.3-957-gb4f0efae0 Lines: 25 27 92.6 %
Date: 2021-11-09 13:40:20 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                 :       5728 : DiagWriter::DiagWriter( const std::string& filename,
      22                 :            :                               ctr::TxtFloatFormatType format,
      23                 :            :                               kw::precision::info::expect::type precision,
      24                 :       5728 :                               std::ios_base::openmode mode ) :
      25                 :            :   Writer( filename, mode ),
      26                 :            :   m_precision( static_cast<int>(precision) ),
      27         [ -  + ]:       5728 :   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         [ +  + ]:       5728 :   if (format == ctr::TxtFloatFormatType::DEFAULT)
      38                 :            :     {} //m_outFile << std::defaultfloat;   GCC does not yet support this
      39         [ -  + ]:       4257 :   else if (format == ctr::TxtFloatFormatType::FIXED)
      40                 :          0 :     m_outFile << std::fixed;
      41         [ +  - ]:       4257 :   else if (format == ctr::TxtFloatFormatType::SCIENTIFIC)
      42                 :       4257 :     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         [ +  - ]:       5728 :   if (precision > 0 && precision < std::numeric_limits< tk::real >::digits10+2)
      47                 :       5728 :     m_outFile << std::setprecision( static_cast<int>(precision) );
      48                 :       5728 : }
      49                 :            : 
      50                 :            : void
      51                 :        247 : 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                 :        247 :             << std::setw(m_width) << "2:t"
      59                 :        494 :             << std::setw(m_width) << "3:dt";
      60                 :        494 :   std::stringstream out;
      61                 :            : 
      62                 :            :   // Output names of diagnostics
      63                 :            :   std::size_t column = 4;
      64         [ +  + ]:       2186 :   for (const auto& n : name) {
      65 [ +  - ][ +  - ]:       3878 :     out << column++ << ':' << n;
      66         [ +  - ]:       1939 :     m_outFile << std::setw(m_width) << out.str();
      67         [ +  - ]:       3878 :     out.str("");
      68                 :            :   }
      69                 :            : 
      70                 :            :   m_outFile << std::endl;
      71                 :        247 : }
      72                 :            : 
      73                 :            : std::size_t
      74                 :       5481 : 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                 :       5481 :   m_outFile << std::setw(10) << it
      88                 :       5481 :             << std::setw(m_width) << t
      89                 :       5481 :             << std::setw(m_width) << dt;
      90                 :            : 
      91                 :            :   // Output diagnostics
      92         [ +  + ]:      68376 :   for (const auto& d : diagnostics) m_outFile << std::setw(m_width) << d;
      93                 :            : 
      94                 :            :   m_outFile << std::endl;
      95                 :            : 
      96                 :       5481 :   return diagnostics.size();
      97                 :            : }

Generated by: LCOV version 1.14