diff --git a/ProcessLib/Output.cpp b/ProcessLib/Output.cpp index 62c3bcfed13af015b4b0b1346588ef284ffe46bb..b3b8153a92665c2f5b68c5b80e08eaa46611ddf1 100644 --- a/ProcessLib/Output.cpp +++ b/ProcessLib/Output.cpp @@ -168,39 +168,33 @@ void Output::doOutputAlways(Process const& process, BaseLib::RunTime time_output; time_output.start(); - SingleProcessData* spd_ptr = findSingleProcessData(process, process_id); - - std::string const output_file_name = - _output_file_prefix + "_pcs_" + std::to_string(process_id) - + "_ts_" + std::to_string(timestep) - + "_t_" + std::to_string(t) - + ".vtu"; - std::string const output_file_path = BaseLib::joinPaths(_output_directory, output_file_name); - + // Need to add variables of process to vtu even no output takes place. + processOutputData(t, x, process.getMesh(), process.getDOFTable(), + process.getProcessVariables(), + process.getSecondaryVariables(), process_output); // For the staggered scheme for the coupling, only the last process, which // gives the latest solution within a coupling loop, is allowed to make // output. - const bool make_output = - process_id == static_cast<int>(_single_process_data.size()) - 1 || - process.isMonolithicSchemeUsed(); - if (make_output) - { - DBUG("output to %s", output_file_path.c_str()); - } + if (!(process_id == static_cast<int>(_single_process_data.size()) - 1 || + process.isMonolithicSchemeUsed())) + return; - // Need to add variables of process to vtu even no output takes place. - doProcessOutput(output_file_path, make_output, _output_file_compression, - _output_file_data_mode, t, x, process.getMesh(), - process.getDOFTable(), process.getProcessVariables(), - process.getSecondaryVariables(), process_output); + std::string const output_file_name = + _output_file_prefix + "_pcs_" + std::to_string(process_id) + "_ts_" + + std::to_string(timestep) + "_t_" + std::to_string(t) + ".vtu"; + std::string const output_file_path = + BaseLib::joinPaths(_output_directory, output_file_name); - if (make_output) - { - spd_ptr->pvd_file.addVTUFile(output_file_name, t); - INFO("[time] Output of timestep %d took %g s.", timestep, - time_output.elapsed()); - } + DBUG("output to %s", output_file_path.c_str()); + + SingleProcessData* spd_ptr = findSingleProcessData(process, process_id); + spd_ptr->pvd_file.addVTUFile(output_file_name, t); + INFO("[time] Output of timestep %d took %g s.", timestep, + time_output.elapsed()); + + makeOutput(output_file_path, process.getMesh(), _output_file_compression, + _output_file_data_mode); } void Output::doOutput(Process const& process, @@ -252,37 +246,32 @@ void Output::doOutputNonlinearIteration(Process const& process, BaseLib::RunTime time_output; time_output.start(); + processOutputData(t, x, process.getMesh(), + process.getDOFTable(), process.getProcessVariables(), + process.getSecondaryVariables(), process_output); + + // For the staggered scheme for the coupling, only the last process, which + // gives the latest solution within a coupling loop, is allowed to make + // output. + if (!(process_id == static_cast<int>(_single_process_data.size()) - 1 || + process.isMonolithicSchemeUsed())) + return; + // Only check whether a process data is available for output. findSingleProcessData(process, process_id); std::string const output_file_name = - _output_file_prefix + "_pcs_" + std::to_string(process_id) - + "_ts_" + std::to_string(timestep) - + "_t_" + std::to_string(t) - + "_nliter_" + std::to_string(iteration) - + ".vtu"; - std::string const output_file_path = BaseLib::joinPaths(_output_directory, output_file_name); + _output_file_prefix + "_pcs_" + std::to_string(process_id) + "_ts_" + + std::to_string(timestep) + "_t_" + std::to_string(t) + "_nliter_" + + std::to_string(iteration) + ".vtu"; + std::string const output_file_path = + BaseLib::joinPaths(_output_directory, output_file_name); - // For the staggered scheme for the coupling, only the last process, which - // gives the latest solution within a coupling loop, is allowed to make - // output. - const bool make_output = - process_id == static_cast<int>(_single_process_data.size()) - 1 || - process.isMonolithicSchemeUsed(); - if (make_output) - { - DBUG("output iteration results to %s", output_file_path.c_str()); - } + DBUG("output iteration results to %s", output_file_path.c_str()); - doProcessOutput(output_file_path, make_output, _output_file_compression, - _output_file_data_mode, t, x, process.getMesh(), - process.getDOFTable(), process.getProcessVariables(), - process.getSecondaryVariables(), process_output); + INFO("[time] Output took %g s.", time_output.elapsed()); - if (make_output) - { - INFO("[time] Output took %g s.", time_output.elapsed()); - } + makeOutput(output_file_path, process.getMesh(), _output_file_compression, + _output_file_data_mode); } - } // namespace ProcessLib diff --git a/ProcessLib/ProcessOutput.cpp b/ProcessLib/ProcessOutput.cpp index e00be2d809a93887705d3994d916896187c19fb8..91b97812e3a96758195f4ba0db38b90342439e6c 100644 --- a/ProcessLib/ProcessOutput.cpp +++ b/ProcessLib/ProcessOutput.cpp @@ -40,20 +40,17 @@ ProcessOutput::ProcessOutput(BaseLib::ConfigTree const& output_config) } } -void doProcessOutput(std::string const& file_name, - bool const make_output, - bool const compress_output, - int const data_mode, - const double t, - GlobalVector const& x, - MeshLib::Mesh& mesh, - NumLib::LocalToGlobalIndexMap const& dof_table, - std::vector<std::reference_wrapper<ProcessVariable>> const& - process_variables, - SecondaryVariableCollection secondary_variables, - ProcessOutput const& process_output) +void processOutputData( + const double t, + GlobalVector const& x, + MeshLib::Mesh& mesh, + NumLib::LocalToGlobalIndexMap const& dof_table, + std::vector<std::reference_wrapper<ProcessVariable>> const& + process_variables, + SecondaryVariableCollection secondary_variables, + ProcessOutput const& process_output) { - DBUG("Process output."); + DBUG("Process output data."); // Copy result #ifdef USE_PETSC @@ -226,11 +223,11 @@ void doProcessOutput(std::string const& file_name, (void)t; #endif // USE_PETSC - if (!make_output) - { - return; - } +} +void makeOutput(std::string const& file_name, MeshLib::Mesh& mesh, + bool const compress_output, int const data_mode) +{ // Write output file DBUG("Writing output to \'%s\'.", file_name.c_str()); MeshLib::IO::VtuInterface vtu_interface(&mesh, data_mode, compress_output); diff --git a/ProcessLib/ProcessOutput.h b/ProcessLib/ProcessOutput.h index e55172a364f0fa9cba35e04e36dc4dd71a16d5b2..a443d5831a4bf76f32c655bc09f38310cdd519c2 100644 --- a/ProcessLib/ProcessOutput.h +++ b/ProcessLib/ProcessOutput.h @@ -14,7 +14,6 @@ namespace ProcessLib { - //! Holds information about which variables to write to output files. struct ProcessOutput final { @@ -28,21 +27,23 @@ struct ProcessOutput final bool output_residuals = false; }; +/// +/// Prepare the output data, i.e. add the solution to vtu data structure. +void processOutputData( + const double t, + GlobalVector const& x, + MeshLib::Mesh& mesh, + NumLib::LocalToGlobalIndexMap const& dof_table, + std::vector<std::reference_wrapper<ProcessVariable>> const& + process_variables, + SecondaryVariableCollection secondary_variables, + ProcessOutput const& process_output); + //! Writes output to the given \c file_name using the VTU file format. /// /// See Output::_output_file_data_mode documentation for the data_mode /// parameter. -void doProcessOutput(std::string const& file_name, - bool const make_output, - bool const compress_output, - int const data_mode, - const double t, - GlobalVector const& x, - MeshLib::Mesh& mesh, - NumLib::LocalToGlobalIndexMap const& dof_table, - std::vector<std::reference_wrapper<ProcessVariable>> const& - process_variables, - SecondaryVariableCollection secondary_variables, - ProcessOutput const& process_output); - -} // ProcessLib +void makeOutput(std::string const& file_name, MeshLib::Mesh& mesh, + bool const compress_output, int const data_mode); + +} // ProcessLib