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 : 33 : /** 34 : * Class constructor. 35 : */ 36 : TableOutput(const InputParameters & parameters); 37 : 38 : void clear(); 39 : 40 : protected: 41 : /** 42 : * Populates the tables with scalar aux variables 43 : * 44 : * If an aux variable contains multiple components the output name for the 45 : * variable is appended with the component number (e.g., aux_0, aux_1, ...) 46 : */ 47 : virtual void outputScalarVariables() override; 48 : 49 : /** 50 : * Populates the tables with postprocessor values 51 : */ 52 : virtual void outputPostprocessors() override; 53 : 54 : /** 55 : * Populates the tables with Reporter values 56 : */ 57 : virtual void outputReporters() override; 58 : template <typename T> 59 : void outputReporter(const ReporterName & name); 60 : 61 : /** 62 : * Populates the tables with VectorPostprocessor values 63 : */ 64 : virtual void outputVectorPostprocessors() override; 65 : 66 : /// Flag for allowing all table data to become restartable 67 : bool _tables_restartable; 68 : 69 : /// Table containing postprocessor data 70 : FormattedTable & _postprocessor_table; 71 : 72 : /// Formatted tables for outputting vector postprocessor data. One per VectorPostprocessor 73 : std::map<std::string, FormattedTable> _vector_postprocessor_tables; 74 : 75 : /// Table for vector postprocessor time data 76 : std::map<std::string, FormattedTable> & _vector_postprocessor_time_tables; 77 : 78 : /// Table containing scalar aux variables 79 : FormattedTable & _scalar_table; 80 : 81 : /// Table containing Real Reporter values 82 : FormattedTable & _reporter_table; 83 : 84 : /// Table containing postprocessor values, scalar aux variables, and Real Reporters 85 : FormattedTable & _all_data_table; 86 : 87 : /// Tolerance used when deciding whether or not to add a new row to the table 88 : const Real _new_row_tol; 89 : 90 : /// Enable/disable VecptorPostprocessor time data file. 91 : const bool _time_data; 92 : 93 : /// Enable/disable output of time column for Postprocessors 94 : const bool _time_column; 95 : }; 96 : 97 : template <typename T> 98 : void 99 289406 : TableOutput::outputReporter(const ReporterName & name) 100 : { 101 : static_assert(TableValueBase::isSupportedType<T>(), "Unsupported table value type."); 102 : 103 289406 : if (_reporter_data.hasReporterValue<T>(name)) 104 : { 105 22697 : if (_reporter_table.empty() || !MooseUtils::absoluteFuzzyEqual(_reporter_table.getLastTime(), 106 22697 : getOutputTime(), 107 10838 : _new_row_tol)) 108 3016 : _reporter_table.addRow(getOutputTime()); 109 : 110 23160 : if (_all_data_table.empty() || !MooseUtils::absoluteFuzzyEqual(_all_data_table.getLastTime(), 111 23160 : getOutputTime(), 112 11301 : _new_row_tol)) 113 1911 : _all_data_table.addRow(getOutputTime()); 114 : 115 11859 : const T & value = _reporter_data.getReporterValue<T>(name); 116 11859 : _reporter_table.addData<T>(name.getCombinedName(), value); 117 11859 : _all_data_table.addData<T>(name.getCombinedName(), value); 118 : } 119 277547 : else if (_reporter_data.hasReporterValue<std::vector<T>>(name)) 120 : { 121 4500 : const std::string & obj_name = name.getObjectName(); 122 4500 : const std::string & val_name = name.getValueName(); 123 4500 : auto insert_pair = moose_try_emplace(_vector_postprocessor_tables, obj_name, FormattedTable()); 124 : 125 4500 : FormattedTable & table = insert_pair.first->second; 126 4500 : table.outputTimeColumn(false); 127 : 128 4500 : const std::vector<T> & vector = _reporter_data.getReporterValue<std::vector<T>>(name); 129 4500 : table.addData<T>(val_name, vector); 130 : 131 4500 : if (_time_data) 132 : { 133 0 : FormattedTable & t_table = _vector_postprocessor_time_tables[obj_name]; 134 0 : t_table.addData("timestep", _t_step, _time); 135 : } 136 : } 137 289406 : }