Skip to content

Commit

Permalink
Address reviewer commands and maintain screen output order
Browse files Browse the repository at this point in the history
  • Loading branch information
aeslaughter committed Apr 20, 2017
1 parent 4011e41 commit 4f68362
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 8 deletions.
3 changes: 3 additions & 0 deletions framework/include/outputs/CSV.h
Expand Up @@ -91,6 +91,9 @@ class CSV : public TableOutput

/// Flag for writting vector postprocessor data
bool _write_vector_table;

/// Flag for sorting column names
const bool _sort_columns;
};

#endif /* CSV_H */
5 changes: 5 additions & 0 deletions framework/include/utils/FormattedTable.h
Expand Up @@ -111,6 +111,11 @@ class FormattedTable
*/
void setPrecision(unsigned int precision) { _csv_precision = precision; }

/**
* Sorts columns alphabetically.
*/
void sortColumns() { std::sort(_column_names.begin(), _column_names.end()); }

protected:
void printTablePiece(std::ostream & out,
unsigned int last_n_entries,
Expand Down
Expand Up @@ -98,10 +98,6 @@ class VectorPostprocessorData : public Restartable

std::set<std::string> _requested_items;
std::set<std::string> _supplied_items;

/// Lambda for looking at names in the std::pair of _values
// std::function< auto _compare_lambda = [&name](const std::pair<std::string,
// VectorPostprocessorState> & pair){ return pair.first == name; };
};

#endif // VECTORPOSTPROCESSORDATA_H
11 changes: 10 additions & 1 deletion framework/src/outputs/CSV.C
Expand Up @@ -24,6 +24,8 @@ validParams<CSV>()
// Get the parameters from the parent object
InputParameters params = validParams<TableOutput>();

params.addParam<bool>("sort_columns", false, "Toggle the sorting of columns alphabetically.");

// Options for aligning csv output with whitespace padding
params.addParam<bool>(
"align",
Expand All @@ -48,7 +50,8 @@ CSV::CSV(const InputParameters & parameters)
_set_delimiter(isParamValid("delimiter")),
_delimiter(_set_delimiter ? getParam<std::string>("delimiter") : ""),
_write_all_table(false),
_write_vector_table(false)
_write_vector_table(false),
_sort_columns(getParam<bool>("sort_columns"))
{
}

Expand Down Expand Up @@ -104,7 +107,11 @@ CSV::output(const ExecFlagType & type)

// Print the table containing all the data to a file
if (_write_all_table && !_all_data_table.empty() && processor_id() == 0)
{
if (_sort_columns)
_all_data_table.sortColumns();
_all_data_table.printCSV(filename(), 1, _align);
}

// Output each VectorPostprocessor's data to a file
if (_write_vector_table && processor_id() == 0)
Expand All @@ -119,6 +126,8 @@ CSV::output(const ExecFlagType & type)
if (_set_delimiter)
it.second.setDelimiter(_delimiter);
it.second.setPrecision(_precision);
if (_sort_columns)
it.second.sortColumns();
it.second.printCSV(output.str(), 1, _align);

if (_time_data)
Expand Down
4 changes: 4 additions & 0 deletions framework/src/outputs/Console.C
Expand Up @@ -590,6 +590,7 @@ Console::outputPostprocessors()
{
std::stringstream oss;
oss << "\nPostprocessor Values:\n";
_postprocessor_table.sortColumns();
_postprocessor_table.printTable(oss, _max_rows, _fit_mode);
_console << oss.str() << '\n';
}
Expand All @@ -605,7 +606,10 @@ Console::outputScalarVariables()
std::stringstream oss;
oss << "\nScalar Variable Values:\n";
if (processor_id() == 0)
{
_scalar_table.sortColumns();
_scalar_table.printTable(oss, _max_rows, _fit_mode);
}
_console << oss.str() << '\n';
}
}
Expand Down
1 change: 1 addition & 0 deletions framework/src/outputs/TableOutput.C
Expand Up @@ -73,6 +73,7 @@ TableOutput::TableOutput(const InputParameters & parameters)
: declareRecoverableData<FormattedTable>("all_data_table")),
_time_data(getParam<bool>("time_data")),
_time_column(getParam<bool>("time_column"))

{
}

Expand Down
1 change: 1 addition & 0 deletions framework/src/utils/FormattedTable.C
Expand Up @@ -294,6 +294,7 @@ FormattedTable::printCSV(const std::string & file_name, int interval, bool align
{
// Set the initial width to the names of the columns
width["time"] = 4;

for (const auto & col_name : _column_names)
width[col_name] = col_name.size();

Expand Down
6 changes: 3 additions & 3 deletions framework/src/vectorpostprocessors/VectorPostprocessorData.C
Expand Up @@ -67,12 +67,12 @@ VectorPostprocessorData::getVectorPostprocessorHelper(const VectorPostprocessorN
};

// Search for the vector, if it is not located create the entry in the storage
auto iter = std::find_if(vec_storage.begin(), vec_storage.end(), comp);
if (iter == vec_storage.end())
auto iter = std::find_if(vec_storage.rbegin(), vec_storage.rend(), comp);
if (iter == vec_storage.rend())
{
vec_storage.emplace_back(
std::pair<std::string, VectorPostprocessorState>(vector_name, VectorPostprocessorState()));
iter = vec_storage.end() - 1; // can't use rbegin() because we need a forward iterator
iter = vec_storage.rbegin();
}

auto & vec_struct = iter->second;
Expand Down
100 changes: 100 additions & 0 deletions test/tests/outputs/csv/csv_sort.i
@@ -0,0 +1,100 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 10
[]

[Variables]
[./u]
[../]
[./v]
[../]
[]

[AuxVariables]
[./aux0]
order = SECOND
family = SCALAR
[../]
[./aux1]
family = SCALAR
initial_condition = 5
[../]
[./aux2]
family = SCALAR
initial_condition = 10
[../]
[]

[Kernels]
[./diff_u]
type = Diffusion
variable = u
[../]
[./diff_v]
type = CoefDiffusion
variable = v
coef = 2
[../]
[]

[BCs]
[./right_u]
type = DirichletBC
variable = u
boundary = right
value = 1
[../]
[./left_u]
type = DirichletBC
variable = u
boundary = left
value = 0
[../]
[./right_v]
type = DirichletBC
variable = v
boundary = right
value = 3
[../]
[./left_v]
type = DirichletBC
variable = v
boundary = left
value = 2
[../]
[]

[Postprocessors]
[./num_vars]
type = NumVars
[../]
[./num_aux]
type = NumVars
system = auxiliary
[../]
[]

[Executioner]
type = Steady
solve_type = PJFNK
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
execute_on = 'timestep_end'
[./out]
type = CSV
sort_columns = true
[../]
[]

[ICs]
[./aux0_IC]
variable = aux0
values = '12 13'
type = ScalarComponentIC
[../]
[]
7 changes: 7 additions & 0 deletions test/tests/outputs/csv/tests
Expand Up @@ -52,4 +52,11 @@
input = csv_align.i
csvdiff = 'csv_align_out.csv'
[../]
[./sort]
# Tests that csv output can be sorted
type = CheckFiles
input = 'csv_sort.i'
check_files = csv_sort_out.csv
file_expect_out = "time,aux0_0,aux0_1,aux1,aux2,num_aux,num_vars"
[../]
[]

0 comments on commit 4f68362

Please sign in to comment.