www.mooseframework.org
FormattedTable.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef FORMATTEDTABLE_H
16 #define FORMATTEDTABLE_H
17 
18 // MOOSE includes
19 #include "Moose.h"
20 #include "MooseEnum.h"
21 #include "DataIO.h"
22 
23 // C++ includes
24 #include <fstream>
25 
26 // Forward declarations
27 class FormattedTable;
28 namespace libMesh
29 {
30 class ExodusII_IO;
31 }
32 
33 template <>
34 void dataStore(std::ostream & stream, FormattedTable & table, void * context);
35 template <>
36 void dataLoad(std::istream & stream, FormattedTable & v, void * context);
37 
42 {
43 public:
51 
56  FormattedTable(const FormattedTable & o);
57 
61  ~FormattedTable();
62 
66  bool empty() const;
67 
72  void append(bool append_existing_file);
73 
77  void addData(const std::string & name, Real value, Real time);
78 
83  void addData(const std::string & name, const std::vector<Real> & vector);
84 
88  Real & getLastData(const std::string & name);
89 
90  void clear();
91 
95  void outputTimeColumn(bool output_time) { _output_time = output_time; }
96 
97  // const std::map<Real, std::map<std::string, Real>> & getData() const { return _data; }
98 
107  void printTable(std::ostream & out, unsigned int last_n_entries = 0);
108  void printTable(std::ostream & out,
109  unsigned int last_n_entries,
110  const MooseEnum & suggested_term_width);
111  void printTable(const std::string & file_name);
112 
118  void printCSV(const std::string & file_name, int interval = 1, bool align = false);
119 
120  void printEnsight(const std::string & file_name);
121  void writeExodus(ExodusII_IO * ex_out, Real time);
122  void makeGnuplot(const std::string & base_file, const std::string & format);
123 
124  static MooseEnum getWidthModes();
125 
129  void setDelimiter(std::string delimiter) { _csv_delimiter = delimiter; }
130 
134  void setPrecision(unsigned int precision) { _csv_precision = precision; }
135 
139  void sortColumns();
140 
141 protected:
142  void printTablePiece(std::ostream & out,
143  unsigned int last_n_entries,
144  std::map<std::string, unsigned short> & col_widths,
145  std::vector<std::string>::iterator & col_begin,
146  std::vector<std::string>::iterator & col_end);
147 
148  void printOmittedRow(std::ostream & out,
149  std::map<std::string, unsigned short> & col_widths,
150  std::vector<std::string>::iterator & col_begin,
151  std::vector<std::string>::iterator & col_end) const;
152  void printRowDivider(std::ostream & out,
153  std::map<std::string, unsigned short> & col_widths,
154  std::vector<std::string>::iterator & col_begin,
155  std::vector<std::string>::iterator & col_end) const;
156 
157  void printNoDataRow(char intersect_char,
158  char fill_char,
159  std::ostream & out,
160  std::map<std::string, unsigned short> & col_widths,
161  std::vector<std::string>::iterator & col_begin,
162  std::vector<std::string>::iterator & col_end) const;
163 
167  unsigned short getTermWidth(bool use_environment) const;
168 
175  std::vector<std::pair<Real, std::map<std::string, Real>>> _data;
176 
178  std::map<std::string, unsigned int> _align_widths;
179 
181  std::vector<std::string> _column_names;
182 
184  static const unsigned short _column_width;
185 
187  static const unsigned short _min_pps_width;
188 
189 private:
191  void close();
192 
194  void open(const std::string & file_name);
195 
196  void printRow(std::pair<Real, std::map<std::string, Real>> & row_data, bool align);
197 
199  std::string _output_file_name;
200 
202  std::ofstream _output_file;
203 
208  std::size_t _output_row_index;
209 
212 
214  bool _append;
215 
218 
220  std::string _csv_delimiter;
221 
223  unsigned int _csv_precision;
224 
226  bool _column_names_unsorted = true;
227 
228  friend void
229  dataStore<FormattedTable>(std::ostream & stream, FormattedTable & table, void * context);
230  friend void dataLoad<FormattedTable>(std::istream & stream, FormattedTable & v, void * context);
231 };
232 
233 template <>
234 void dataStore(std::ostream & stream, FormattedTable & table, void * context);
235 template <>
236 void dataLoad(std::istream & stream, FormattedTable & v, void * context);
237 
238 #endif // FORMATTEDTABLE_H
void dataLoad(std::istream &stream, FormattedTable &v, void *context)
std::vector< std::pair< Real, std::map< std::string, Real > > > _data
Data structure for the console table: The first part of the pair tracks the independent variable (nor...
bool _stream_open
Keeps track of whether the current stream is open or not.
std::string _output_file_name
The optional output file stream.
std::size_t _output_row_index
Keeps track of the index indicating which vector elements have been output.
bool _output_time
Whether or not to output the Time column.
void setPrecision(unsigned int precision)
By default printCSV prints output to a precision of 14, this allows this to be changed.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
std::string _csv_delimiter
*.csv file delimiter, defaults to ","
static const unsigned short _min_pps_width
The absolute minimum PPS table width.
void outputTimeColumn(bool output_time)
Set whether or not to output time column.
std::ofstream _output_file
The stream handle (corresponds to _output_file_name)
void dataStore(std::ostream &stream, FormattedTable &table, void *context)
std::map< std::string, unsigned int > _align_widths
Alignment widths (only used if asked to print aligned to CSV output)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
the_pc close()
This class is used for building, formatting, and outputting tables of numbers.
unsigned int _csv_precision
*.csv file precision, defaults to 14
static const unsigned short _column_width
The single cell width used for all columns in the table.
std::vector< std::string > _column_names
The set of column names updated when data is inserted through the setter methods. ...
bool _append
Keeps track of whether we want to open an existing file for appending or overwriting.
void setDelimiter(std::string delimiter)
By default printCSV places "," between each entry, this allows this to be changed.