14 #include "libmesh/exodusII_io.h" 50 dataStore(std::ostream & stream, std::shared_ptr<TableValueBase> & value_base,
void * context)
52 value_base->store(stream, context);
57 dataLoad(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())
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),
154 : _column_names(o._column_names),
155 _output_file_name(
""),
156 _output_row_index(o._output_row_index),
157 _headers_output(o._headers_output),
159 _output_time(o._output_time),
160 _csv_delimiter(o._csv_delimiter),
161 _csv_precision(o._csv_precision),
162 _column_names_unsorted(o._column_names_unsorted)
165 mooseError(
"Copying a FormattedTable with an open stream is not supported");
167 for (
const auto & it : o.
_data)
168 _data.emplace_back(it.first, it.second);
176 return _data.empty();
182 _append = append_existing_file;
188 _data.emplace_back(time, std::map<std::string, std::shared_ptr<TableValueBase>>());
194 mooseAssert(!
empty(),
"No Data stored in the FormattedTable");
195 return _data.rbegin()->first;
200 std::map<std::string, unsigned short> & col_widths,
201 std::vector<std::string>::iterator & col_begin,
202 std::vector<std::string>::iterator & col_end)
const 209 std::map<std::string, unsigned short> & col_widths,
210 std::vector<std::string>::iterator & col_begin,
211 std::vector<std::string>::iterator & col_end)
const 220 std::map<std::string, unsigned short> & col_widths,
221 std::vector<std::string>::iterator & col_begin,
222 std::vector<std::string>::iterator & col_end)
const 225 out << std::right << intersect_char;
228 for (
auto header_it = col_begin; header_it != col_end; ++header_it)
229 out << std::setw(col_widths[*header_it] + 2) << intersect_char;
251 unsigned int last_n_entries,
254 unsigned short term_width;
256 if (suggested_term_width ==
"ENVIRONMENT")
258 else if (suggested_term_width ==
"AUTO")
266 std::vector<std::string>::iterator col_it =
_column_names.begin();
267 std::vector<std::string>::iterator col_end =
_column_names.end();
269 std::vector<std::string>::iterator curr_begin = col_it;
270 std::vector<std::string>::iterator curr_end;
271 while (col_it != col_end)
273 std::map<std::string, unsigned short> col_widths;
275 unsigned int cols_in_group = 0;
276 while (curr_width < term_width && col_it != col_end)
281 curr_width += col_widths[*col_it] + 3;
285 if (col_it != col_end && cols_in_group >= 2)
288 col_widths.erase(*curr_end);
295 curr_begin = curr_end;
301 unsigned int last_n_entries,
302 std::map<std::string, unsigned short> & col_widths,
303 std::vector<std::string>::iterator & col_begin,
304 std::vector<std::string>::iterator & col_end)
314 for (
auto header_it = col_begin; header_it != col_end; ++header_it)
315 out <<
" " << std::setw(col_widths[*header_it]) << *header_it <<
"|";
319 auto data_it =
_data.begin();
322 if (
_data.size() > last_n_entries)
328 data_it +=
_data.size() - last_n_entries;
332 for (; data_it !=
_data.end(); ++data_it)
336 out << std::right << std::setw(
_column_width) << std::scientific << data_it->first <<
" |";
337 for (
auto header_it = col_begin; header_it != col_end; ++header_it)
339 auto & tmp = data_it->second;
340 out << std::setw(col_widths[*header_it]) << *tmp[*header_it] <<
" |";
372 for (
const auto & it :
_data)
376 std::ostringstream oss;
378 unsigned int w = oss.str().size();
383 for (
const auto & jt : it.second)
385 std::ostringstream oss;
387 unsigned int w = oss.str().size();
431 std::pair<Real, std::map<std::string, std::shared_ptr<TableValueBase>>> & row_data,
bool align)
447 std::map<std::string, std::shared_ptr<TableValueBase>> & tmp = row_data.second;
469 "'\nset title 'All Postprocessors'\nset xlabel 'time'\nset ylabel 'values'\nplot";
482 std::string extension, terminal;
489 else if (format ==
"ps")
492 terminal =
"postscript";
495 else if (format ==
"gif")
502 mooseError(
"gnuplot format \"" + format +
"\" is not supported.");
505 std::string dat_name = base_file +
".dat";
506 std::ofstream datfile;
507 datfile.open(dat_name.c_str(), std::ios::trunc | std::ios::out);
513 datfile <<
'\t' << col_name;
516 for (
auto & data_it :
_data)
518 datfile << data_it.first;
521 auto & tmp = data_it.second;
522 datfile <<
'\t' << *tmp[col_name];
530 std::string gp_name = base_file +
".gp";
531 std::ofstream gpfile;
532 gpfile.open(gp_name.c_str(), std::ios::trunc | std::ios::out);
543 gpfile <<
" '" << dat_name <<
"' using 1:" << column <<
" title '" << col_name
544 <<
"' with linespoints";
555 gpfile <<
"set output '" << col_name << extension <<
"'\n";
556 gpfile <<
"set ylabel '" << col_name <<
"'\n";
557 gpfile <<
"plot '" << dat_name <<
"' using 1:" << column <<
" title '" << col_name
558 <<
"' with linespoints\n\n";
577 auto begin =
_data.begin();
578 auto end =
_data.end();
579 if (last_n_entries && (last_n_entries <
_data.size()))
580 begin = end - last_n_entries;
582 for (
auto it = begin; it != end; ++it)
584 auto & datamap = it->second;
588 if (!datamap[col_name])
594 for (
auto & [key, val] : datamap)
604 return MooseEnum(
"ENVIRONMENT=-1 AUTO=0 80=80 120=120 160=160",
"ENVIRONMENT",
true);
std::string name(const ElemQuality q)
int stringToInteger(const std::string &input, bool throw_on_failure=false)
Robust string to integer conversion that fails for cases such at "1foo".
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
std::basic_ostream< charT, traits > * os
static void load(std::istream &stream, std::shared_ptr< TableValueBase > &value_base, void *context)
auto max(const L &left, const R &right)
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
std::string demangle(const char *name)
const std::string after_ext
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const std::string before_ext
const std::string before_terminal
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
unsigned short getTermWidth(bool use_environment)
Returns the width of the terminal using sys/ioctl.