From 40e3a80df75464f56ccbfa93517f539a6686cef2 Mon Sep 17 00:00:00 2001 From: Cody Permann Date: Wed, 17 Oct 2018 11:31:20 -0600 Subject: [PATCH] Refactor method to obtain file name closes #12234 --- framework/include/outputs/CSV.h | 6 ++++++ framework/src/outputs/CSV.C | 37 ++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/framework/include/outputs/CSV.h b/framework/include/outputs/CSV.h index 8668b85a6180..cb055f2153c9 100644 --- a/framework/include/outputs/CSV.h +++ b/framework/include/outputs/CSV.h @@ -70,6 +70,12 @@ class CSV : public TableOutput */ virtual void outputVectorPostprocessors() override; + /** + * Generates a filename pattern for Vectorpostprocessors + * filebase + VPP name + time step + ".csv" + */ + std::string getVectorPostprocessorFileName(const std::string & vpp_name, bool include_time_step); + private: /// Flag for aligning data in .csv file bool _align; diff --git a/framework/src/outputs/CSV.C b/framework/src/outputs/CSV.C index e06f00ce33fe..7e6740dd70c2 100644 --- a/framework/src/outputs/CSV.C +++ b/framework/src/outputs/CSV.C @@ -93,6 +93,24 @@ CSV::outputVectorPostprocessors() _write_vector_table = true; } +std::string +CSV::getVectorPostprocessorFileName(const std::string & vpp_name, bool include_time_step) +{ + std::ostringstream file_name; + file_name << _file_base; + + auto short_name = MooseUtils::shortName(vpp_name); + if (short_name.size()) + file_name << '_' << short_name; + + if (include_time_step) + file_name << '_' << std::setw(_padding) << std::setprecision(0) << std::setfill('0') + << std::right << timeStep(); + file_name << ".csv"; + + return file_name.str(); +} + void CSV::output(const ExecFlagType & type) { @@ -114,25 +132,20 @@ CSV::output(const ExecFlagType & type) { for (auto & it : _vector_postprocessor_tables) { - std::ostringstream output; - output << _file_base << "_" << MooseUtils::shortName(it.first); - - if (!vpp_data.containsCompleteHistory(it.first)) - output << "_" << std::setw(_padding) << std::setprecision(0) << std::setfill('0') - << std::right << timeStep(); - output << ".csv"; - + auto vpp_name = it.first; it.second.setDelimiter(_delimiter); it.second.setPrecision(_precision); if (_sort_columns) it.second.sortColumns(); - it.second.printCSV(output.str(), 1, _align); + + auto include_time_suffix = !vpp_data.containsCompleteHistory(vpp_name); + + it.second.printCSV(getVectorPostprocessorFileName(vpp_name, include_time_suffix), 1, _align); if (_time_data) { - std::ostringstream filename; - filename << _file_base << "_" << MooseUtils::shortName(it.first) << "_time.csv"; - _vector_postprocessor_time_tables[it.first].printCSV(filename.str()); + std::string file_name = _file_base + '_' + MooseUtils::shortName(vpp_name) + "_time.csv"; + _vector_postprocessor_time_tables[vpp_name].printCSV(file_name); } } }