LCOV - code coverage report
Current view: top level - include/outputs - TableOutput.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 23 25 92.0 %
Date: 2025-08-08 20:01:16 Functions: 14 14 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : // MOOSE includes
      13             : #include "AdvancedOutput.h"
      14             : #include "FileOutput.h"
      15             : #include "FormattedTable.h"
      16             : 
      17             : /**
      18             :  * Base class for scalar variables and postprocessors output objects
      19             :  *
      20             :  * This class populates three FormattedTable objects that may then be used
      21             :  * by child classes for creating custom output objects:
      22             :  * _all_data_table - includes the data from both postprocessors and scalar aux variables
      23             :  * _postprocessor_table - includes the data from only the postprocessors
      24             :  * _scalar_table - includes the data from only the scalar aux variables
      25             :  *
      26             :  * @see CSV Console
      27             :  */
      28             : class TableOutput : public AdvancedOutput
      29             : {
      30             : public:
      31             :   static InputParameters validParams();
      32             :   /// Adds the exec flag MULTIAPP_FIXED_POINT_ITERATION_END to a parameter
      33             :   static void addMultiAppFixedPointIterationEndExecFlag(InputParameters & params,
      34             :                                                         const std::string & param);
      35             : 
      36             :   /**
      37             :    * Class constructor.
      38             :    */
      39             :   TableOutput(const InputParameters & parameters);
      40             : 
      41             :   void clear();
      42             : 
      43             : protected:
      44             :   /**
      45             :    * Populates the tables with scalar aux variables
      46             :    *
      47             :    * If an aux variable contains multiple components the output name for the
      48             :    * variable is appended with the component number (e.g., aux_0, aux_1, ...)
      49             :    */
      50             :   virtual void outputScalarVariables() override;
      51             : 
      52             :   /**
      53             :    * Populates the tables with postprocessor values
      54             :    */
      55             :   virtual void outputPostprocessors() override;
      56             : 
      57             :   /**
      58             :    * Checks to see if a new postprocessor row should be added
      59             :    *
      60             :    * @param[in] table  Table to add row to
      61             :    */
      62             :   bool shouldOutputPostprocessorsRow(const FormattedTable & table);
      63             : 
      64             :   /**
      65             :    * Outputs a new postprocessor row.
      66             :    *
      67             :    * This should be called only if shouldOutputPostprocessorRow() returns true.
      68             :    *
      69             :    * @param[out] table  Table to add row to
      70             :    */
      71             :   void outputPostprocessorsRow(FormattedTable & table);
      72             : 
      73             :   /**
      74             :    * Populates the tables with Reporter values
      75             :    */
      76             :   virtual void outputReporters() override;
      77             :   template <typename T>
      78             :   void outputReporter(const ReporterName & name);
      79             : 
      80             :   /**
      81             :    * Populates the tables with VectorPostprocessor values
      82             :    */
      83             :   virtual void outputVectorPostprocessors() override;
      84             : 
      85             :   /// Flag for allowing all table data to become restartable
      86             :   bool _tables_restartable;
      87             : 
      88             :   /// Table containing postprocessor data
      89             :   FormattedTable & _postprocessor_table;
      90             : 
      91             :   /// Formatted tables for outputting vector postprocessor data.  One per VectorPostprocessor
      92             :   std::map<std::string, FormattedTable> _vector_postprocessor_tables;
      93             : 
      94             :   /// Table for vector postprocessor time data
      95             :   std::map<std::string, FormattedTable> & _vector_postprocessor_time_tables;
      96             : 
      97             :   /// Table containing scalar aux variables
      98             :   FormattedTable & _scalar_table;
      99             : 
     100             :   /// Table containing Real Reporter values
     101             :   FormattedTable & _reporter_table;
     102             : 
     103             :   /// Table containing postprocessor values, scalar aux variables, and Real Reporters
     104             :   FormattedTable & _all_data_table;
     105             : 
     106             :   /// If true, new postprocessor rows can be added if any column has a new value
     107             :   const bool _check_all_columns_for_new_row;
     108             : 
     109             :   /// Tolerance used when deciding whether or not to add a new row to the table
     110             :   const Real _new_row_tol;
     111             : 
     112             :   /// Enable/disable VecptorPostprocessor time data file.
     113             :   const bool _time_data;
     114             : 
     115             :   /// Enable/disable output of time column for Postprocessors
     116             :   const bool _time_column;
     117             : };
     118             : 
     119             : template <typename T>
     120             : void
     121      314364 : TableOutput::outputReporter(const ReporterName & name)
     122             : {
     123             :   static_assert(TableValueBase::isSupportedType<T>(), "Unsupported table value type.");
     124             : 
     125      314364 :   if (_reporter_data.hasReporterValue<T>(name))
     126             :   {
     127       24525 :     if (_reporter_table.empty() || !MooseUtils::absoluteFuzzyEqual(_reporter_table.getLastTime(),
     128       24525 :                                                                    getOutputTime(),
     129       11703 :                                                                    _new_row_tol))
     130        3262 :       _reporter_table.addRow(getOutputTime());
     131             : 
     132       25039 :     if (_all_data_table.empty() || !MooseUtils::absoluteFuzzyEqual(_all_data_table.getLastTime(),
     133       25039 :                                                                    getOutputTime(),
     134       12217 :                                                                    _new_row_tol))
     135        2034 :       _all_data_table.addRow(getOutputTime());
     136             : 
     137       12822 :     const T & value = _reporter_data.getReporterValue<T>(name);
     138       12822 :     _reporter_table.addData<T>(name.getCombinedName(), value);
     139       12822 :     _all_data_table.addData<T>(name.getCombinedName(), value);
     140             :   }
     141      301542 :   else if (_reporter_data.hasReporterValue<std::vector<T>>(name))
     142             :   {
     143        4908 :     const std::string & obj_name = name.getObjectName();
     144        4908 :     const std::string & val_name = name.getValueName();
     145        4908 :     auto insert_pair = moose_try_emplace(_vector_postprocessor_tables, obj_name, FormattedTable());
     146             : 
     147        4908 :     FormattedTable & table = insert_pair.first->second;
     148        4908 :     table.outputTimeColumn(false);
     149             : 
     150        4908 :     const std::vector<T> & vector = _reporter_data.getReporterValue<std::vector<T>>(name);
     151        4908 :     table.addData<T>(val_name, vector);
     152             : 
     153        4908 :     if (_time_data)
     154             :     {
     155           0 :       FormattedTable & t_table = _vector_postprocessor_time_tables[obj_name];
     156           0 :       t_table.addData("timestep", _t_step, _time);
     157             :     }
     158             :   }
     159      314364 : }

Generated by: LCOV version 1.14