14#include "libmesh/exodusII_io.h"
50dataStore(std::ostream & stream, std::shared_ptr<TableValueBase> & value_base,
void * context)
52 value_base->store(stream, context);
57dataLoad(std::istream & stream, std::shared_ptr<TableValueBase> & value_base,
void * context)
61 if (type ==
typeid(
bool).name())
64 else if (type ==
typeid(
unsigned short int).name())
67 else if (type ==
typeid(
unsigned int).name())
70 else if (type ==
typeid(
unsigned long int).name())
73 else if (type ==
typeid(
unsigned long long int).name())
76 else if (type ==
typeid(
short int).name())
79 else if (type ==
typeid(
int).name())
82 else if (type ==
typeid(
long int).name())
85 else if (type ==
typeid(
long long int).name())
88 else if (type ==
typeid(
float).name())
91 else if (type ==
typeid(
double).name())
94 else if (type ==
typeid(
long double).name())
97 else if (type ==
typeid(
char).name())
100 else if (type ==
typeid(
char *).name())
103 else if (type ==
typeid(std::string).name())
107 mooseError(
"Unsupported table value type ", demangle(type.c_str()));
128 std::ios_base::openmode open_flags = std::ios::out;
130 open_flags |= std::ios::app;
133 open_flags |= std::ios::trunc;
140 mooseError(
"Unable to open file ", file_name);
144 : _output_row_index(0),
145 _headers_output(false),
150 _csv_use_scientific_notation(false)
155 : _column_names(o._column_names),
156 _output_file_name(
""),
157 _output_row_index(o._output_row_index),
158 _headers_output(o._headers_output),
160 _output_time(o._output_time),
161 _csv_delimiter(o._csv_delimiter),
162 _csv_precision(o._csv_precision),
163 _csv_use_scientific_notation(o._csv_use_scientific_notation),
164 _column_names_unsorted(o._column_names_unsorted)
167 mooseError(
"Copying a FormattedTable with an open stream is not supported");
169 for (
const auto & it : o.
_data)
170 _data.emplace_back(it.first, it.second);
178 return _data.empty();
184 _append = append_existing_file;
190 _data.emplace_back(time, std::map<std::string, std::shared_ptr<TableValueBase>>());
196 mooseAssert(!
empty(),
"No Data stored in the FormattedTable");
197 return _data.rbegin()->first;
202 std::map<std::string, unsigned short> & col_widths,
203 std::vector<std::string>::iterator & col_begin,
204 std::vector<std::string>::iterator & col_end)
const
211 std::map<std::string, unsigned short> & col_widths,
212 std::vector<std::string>::iterator & col_begin,
213 std::vector<std::string>::iterator & col_end)
const
222 std::map<std::string, unsigned short> & col_widths,
223 std::vector<std::string>::iterator & col_begin,
224 std::vector<std::string>::iterator & col_end)
const
227 out << std::right << intersect_char;
230 for (
auto header_it = col_begin; header_it != col_end; ++header_it)
231 out << std::setw(col_widths[*header_it] + 2) << intersect_char;
253 unsigned int last_n_entries,
256 unsigned short term_width;
258 if (suggested_term_width ==
"ENVIRONMENT")
260 else if (suggested_term_width ==
"AUTO")
268 std::vector<std::string>::iterator col_it =
_column_names.begin();
269 std::vector<std::string>::iterator col_end =
_column_names.end();
271 std::vector<std::string>::iterator curr_begin = col_it;
272 std::vector<std::string>::iterator curr_end;
273 while (col_it != col_end)
275 std::map<std::string, unsigned short> col_widths;
277 unsigned int cols_in_group = 0;
278 while (curr_width < term_width && col_it != col_end)
283 curr_width += col_widths[*col_it] + 3;
287 if (col_it != col_end && cols_in_group >= 2)
290 col_widths.erase(*curr_end);
296 printTablePiece(out, last_n_entries, col_widths, curr_begin, curr_end);
297 curr_begin = curr_end;
303 unsigned int last_n_entries,
304 std::map<std::string, unsigned short> & col_widths,
305 std::vector<std::string>::iterator & col_begin,
306 std::vector<std::string>::iterator & col_end)
315 out << std::setw(
_column_width) << std::left <<
" time" <<
" |";
316 for (
auto header_it = col_begin; header_it != col_end; ++header_it)
317 out <<
" " << std::setw(col_widths[*header_it]) << *header_it <<
"|";
321 auto data_it =
_data.begin();
324 if (
_data.size() > last_n_entries)
330 data_it +=
_data.size() - last_n_entries;
334 for (; data_it !=
_data.end(); ++data_it)
338 out << std::right << std::setw(
_column_width) << std::scientific << data_it->first <<
" |";
339 for (
auto header_it = col_begin; header_it != col_end; ++header_it)
341 auto & tmp = data_it->second;
342 out << std::setw(col_widths[*header_it]) << *tmp[*header_it] <<
" |";
374 for (
const auto & it :
_data)
378 std::ostringstream oss;
380 oss << std::scientific;
382 unsigned int w = oss.str().size();
387 for (
const auto & jt : it.second)
389 std::ostringstream oss;
391 oss << std::scientific;
393 unsigned int w = oss.str().size();
437 std::pair<Real, std::map<std::string, std::shared_ptr<TableValueBase>>> & row_data,
bool align)
458 std::map<std::string, std::shared_ptr<TableValueBase>> & tmp = row_data.second;
480 "'\nset title 'All Postprocessors'\nset xlabel 'time'\nset ylabel 'values'\nplot";
493 std::string extension, terminal;
500 else if (format ==
"ps")
503 terminal =
"postscript";
506 else if (format ==
"gif")
513 mooseError(
"gnuplot format \"" + format +
"\" is not supported.");
516 std::string dat_name = base_file +
".dat";
517 std::ofstream datfile;
518 datfile.open(dat_name.c_str(), std::ios::trunc | std::ios::out);
524 datfile <<
'\t' << col_name;
527 for (
auto & data_it :
_data)
529 datfile << data_it.first;
532 auto & tmp = data_it.second;
533 datfile <<
'\t' << *tmp[col_name];
541 std::string gp_name = base_file +
".gp";
542 std::ofstream gpfile;
543 gpfile.open(gp_name.c_str(), std::ios::trunc | std::ios::out);
554 gpfile <<
" '" << dat_name <<
"' using 1:" << column <<
" title '" << col_name
555 <<
"' with linespoints";
566 gpfile <<
"set output '" << col_name << extension <<
"'\n";
567 gpfile <<
"set ylabel '" << col_name <<
"'\n";
568 gpfile <<
"plot '" << dat_name <<
"' using 1:" << column <<
" title '" << col_name
569 <<
"' with linespoints\n\n";
588 auto begin =
_data.begin();
589 auto end =
_data.end();
590 if (last_n_entries && (last_n_entries <
_data.size()))
591 begin = end - last_n_entries;
593 for (
auto it = begin; it != end; ++it)
595 auto & datamap = it->second;
599 if (!datamap[col_name])
601 std::dynamic_pointer_cast<TableValueBase>(std::make_shared<
TableValue<char>>(
'0'));
605 for (
auto & [key, val] : datamap)
607 val = std::dynamic_pointer_cast<TableValueBase>(std::make_shared<
TableValue<char>>(
'0'));
615 return MooseEnum(
"ENVIRONMENT=-1 AUTO=0 80=80 120=120 160=160",
"ENVIRONMENT",
true);
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
static void load(std::istream &stream, std::shared_ptr< TableValueBase > &value_base, void *context)
int stringToInteger(const std::string &input, bool throw_on_failure)
unsigned short getTermWidth(bool use_environment)
const std::string before_ext
const std::string before_terminal
const std::string after_ext