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 << std::setw(
_column_width + 2) << intersect_char;
226 for (
auto header_it = col_begin; header_it != col_end; ++header_it)
227 out << std::setw(col_widths[*header_it] + 2) << intersect_char;
249 unsigned int last_n_entries,
252 unsigned short term_width;
254 if (suggested_term_width ==
"ENVIRONMENT")
256 else if (suggested_term_width ==
"AUTO")
264 std::vector<std::string>::iterator col_it =
_column_names.begin();
265 std::vector<std::string>::iterator col_end =
_column_names.end();
267 std::vector<std::string>::iterator curr_begin = col_it;
268 std::vector<std::string>::iterator curr_end;
269 while (col_it != col_end)
271 std::map<std::string, unsigned short> col_widths;
273 unsigned int cols_in_group = 0;
274 while (curr_width < term_width && col_it != col_end)
279 curr_width += col_widths[*col_it] + 3;
283 if (col_it != col_end && cols_in_group >= 2)
286 col_widths.erase(*curr_end);
293 curr_begin = curr_end;
299 unsigned int last_n_entries,
300 std::map<std::string, unsigned short> & col_widths,
301 std::vector<std::string>::iterator & col_begin,
302 std::vector<std::string>::iterator & col_end)
311 for (
auto header_it = col_begin; header_it != col_end; ++header_it)
312 out <<
" " << std::setw(col_widths[*header_it]) << *header_it <<
"|";
316 auto data_it =
_data.begin();
319 if (
_data.size() > last_n_entries)
325 data_it +=
_data.size() - last_n_entries;
329 for (; data_it !=
_data.end(); ++data_it)
331 out <<
"|" << std::right << std::setw(
_column_width) << std::scientific << data_it->first
333 for (
auto header_it = col_begin; header_it != col_end; ++header_it)
335 auto & tmp = data_it->second;
336 out << std::setw(col_widths[*header_it]) << *tmp[*header_it] <<
" |";
368 for (
const auto & it :
_data)
372 std::ostringstream oss;
374 unsigned int w = oss.str().size();
379 for (
const auto & jt : it.second)
381 std::ostringstream oss;
383 unsigned int w = oss.str().size();
427 std::pair<Real, std::map<std::string, std::shared_ptr<TableValueBase>>> & row_data,
bool align)
443 std::map<std::string, std::shared_ptr<TableValueBase>> & tmp = row_data.second;
465 "'\nset title 'All Postprocessors'\nset xlabel 'time'\nset ylabel 'values'\nplot";
478 std::string extension, terminal;
485 else if (format ==
"ps")
488 terminal =
"postscript";
491 else if (format ==
"gif")
498 mooseError(
"gnuplot format \"" + format +
"\" is not supported.");
501 std::string dat_name = base_file +
".dat";
502 std::ofstream datfile;
503 datfile.open(dat_name.c_str(), std::ios::trunc | std::ios::out);
509 datfile <<
'\t' << col_name;
512 for (
auto & data_it :
_data)
514 datfile << data_it.first;
517 auto & tmp = data_it.second;
518 datfile <<
'\t' << *tmp[col_name];
526 std::string gp_name = base_file +
".gp";
527 std::ofstream gpfile;
528 gpfile.open(gp_name.c_str(), std::ios::trunc | std::ios::out);
539 gpfile <<
" '" << dat_name <<
"' using 1:" << column <<
" title '" << col_name
540 <<
"' with linespoints";
551 gpfile <<
"set output '" << col_name << extension <<
"'\n";
552 gpfile <<
"set ylabel '" << col_name <<
"'\n";
553 gpfile <<
"plot '" << dat_name <<
"' using 1:" << column <<
" title '" << col_name
554 <<
"' with linespoints\n\n";
573 for (
auto & it :
_data)
575 if (!it.second[col_name])
576 it.second[col_name] =
583 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.